Announcement Announcement Module
Collapse
No announcement yet.
Controller not updated with Converters Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Controller not updated with Converters

    Hi,

    I've encountered a bit complex issue and hope someone could help on the way solving this...

    - I have four entities: Customer, Product, Summary, Offer;
    - My relationships:
    Customer 1 - N Offer
    Offer 1 - N Product
    Offer 1 - N Summary

    Now, after adding the Offer 1 - N Summary relationship the OfferController_Roo_Controller wasn't updated with the
    getSummaryConverter and the relevant conversionService.addConverter(getSummaryConverter ());
    part in registerConverters(). Since quiting and restartingthe Roo shel didn't help I've added to following lines manually to the aspect(bad practice, I know) to see whether it works or not:

    Code:
    	Converter<Summary, String> getSummaryConverter() {
    		return new Converter<Summary, String>() {
    			public String convert(Summary product) {
    				return new StringBuilder().append("").toString();
    			}
    		};
    	}
    
    	@PostConstruct
    	void registerConverters() {
    		conversionService.addConverter(getCustomerConverter());
    		conversionService.addConverter(getSummaryConverter());
    		conversionService.addConverter(getOfferConverter());
    		conversionService.addConverter(getProductConverter());
    	}
    Well, the modifications worked, so I've pushed them into Offer(see classes below) with the conversionService field (had to, since I nedded it to override the @PostConstruct annotated registerConverters() method).

    Reason for pushing functionality in the Controller class was that, Roo kept erasing (updateing) my aspect and haven't generated the SummaryConverter itself (should be in this case?)

    And here is the actual problem, Roo stoped updateing the OfferController_Roo_Controller aspect, stating:

    HTML Code:
    Field 'conversionService' already defined in target type 'com.telco.web.OfferController' (ITD target 'com.telco.web.OfferController_Roo_Controller').
    - Is this the intended behaviour after the changes I've described?
    - Marking conversionService transient or adding an accessor method to it would be a great help(workaruond)
    - As regarding the original issue, has somebody experienced similar behaviour (Converter is not added to Controller aspect) after adding a second 1...N relation ship?
    - Are the relationships well defined(correct syntex, not semantics)

    Thanks in advance.
    Daniel
    ps.: Using STS bundle 2.5.0 with the associated Maven etc distributions installed on Windows Seven.
    Last edited by DanielA; Dec 7th, 2010, 06:10 AM.

  • #2
    The classes

    I have the following entity classes:
    Code:
    @RooJavaBean
    @RooToString
    @RooEntity(finders = {"findOffersByCustomer",  "findOffersByTextOrStartDateOrEndDateOrType"})
    public class Offer {
    
        @OneToMany(cascade = CascadeType.ALL, mappedBy = "offer")
        private Set<Product> products = new HashSet<Product>();
        
        @OneToMany(cascade = CascadeType.ALL, mappedBy = "offer")
        private Set<Summary> summarys = new HashSet<Summary>();
    
        @ManyToOne
        private Customer customer;
    
    //several String & Double fields
       }

    Code:
    @RooJavaBean
    @RooToString
    @RooEntity(finders = { "findProductsByOffer" })
    public class Product {
    
        @ManyToOne
        private Offer offer;
    
        @NotNull
        @Enumerated
        private ProductType type = ProductType.CustomerNetwork;
    
        private Integer quantity = 0;
    
        private Double cost = 0.0;
    
        private Double sellPrise = 0.0;
    
        public Double getSumMargin(){
        	return getQuantity()*(getSellPrise()-getCost());    	
        }
    }
    
    public class Summary {
    
        @ManyToOne
        private Offer offer;
    
        public Summary() {
        }
    
    //several String & Double fields
    }
    
    
    @RooJavaBean
    @RooToString
    @RooEntity
    public class Customer {
    
    	 @OneToMany(cascade = CascadeType.ALL, mappedBy = "customer")
    	 private Set<Offer> offers = new HashSet<Offer>();
    
    	
        @Size(min = 3, max = 30)
        private String customerName;
    
        private String ugyfelmenedzser = "Minta Janos";
    
    }
    Code:
    @RooWebScaffold(path = "offers", formBackingObject = Offer.class)
    @RequestMapping("/offers")
    @Controller
    public class OfferController {
    
    	@Autowired
    	private GenericConversionService conversionService;
    
    	Converter<Customer, String> getCustomerConverter() {
    		return new Converter<Customer, String>() {
    			public String convert(Customer customer) {
    				return new StringBuilder().append(customer.getCustomerName())
    						.toString();
    			}
    		};
    	}
    
    	Converter<Offer, String> getOfferConverter() {
    		return new Converter<Offer, String>() {
    			public String convert(Offer offer) {
    				return new StringBuilder().append(offer.getStartDate());
    			}
    		};
    	}
    
    	Converter<Product, String> getProductConverter() {
    		return new Converter<Product, String>() {
    			public String convert(Product product) {
    				return new StringBuilder().append(product.getQuantity());
    			}
    		};
    	}
    
    	Converter<Summary, String> getSummaryConverter() {
    		return new Converter<Summary, String>() {
    			public String convert(Summary product) {
    				return new StringBuilder().append("NOt implemented yet").toString();
    			}
    		};
    	}
    
    	@PostConstruct
    	void registerConverters() {
    		conversionService.addConverter(getCustomerConverter());
    		conversionService.addConverter(getSummaryConverter());
    		conversionService.addConverter(getOfferConverter());
    		conversionService.addConverter(getProductConverter());
    	}
    
    }

    Comment


    • #3
      Just a quick question. Did you forget to include the annotations on the Summary class when you copied your code to this post, or are they actually not their in your code? If your Summary source file indeed doesn't have the @RooEntity and @RooJavaBean annotations, then that very well might be your problem.

      Comment


      • #4
        Unfortunately (or fortunately?) the annotations are there as follows:

        @RooJavaBean
        @RooToString
        @RooEntity(finders = {"findSummarysByOffer"})
        public class Summary {
        ...}

        Comment


        • #5
          Finally figured out:
          I hadn't declared any Fields in Summary, only had some calculator methods (for financial calculations based on an Offfer) and displayed them in user-managed jspx tags. Simple wanted to create a diffferent(derived) view of the data.

          It worked, but had the described effect: Roo hadn't generate a Converter for the class in entities that referenced it, since there wasn't any Field to display from Roo's point of view.

          I still have to customize Converter behaviour and thus facing the problem with the conversionCervice field:

          Roo hangs when trying to manage the Roo_Controller file after push-in refactoring of the Converter factory methods and required registerConverters() method and the conversionCervice field.

          I would realy like to hear an oppinion from the Roo team wether this is intended or should a Jira ticket be opened for it?

          Thanks in advance, D

          Comment

          Working...
          X