Tuesday 24 May 2016

overview on Converters and Populators...!!!


Converters and Populators:
Converter:
If I want to convert my Model to DTO directly in facade layer then I can use converter. A converter is the one that constructs data objects from Models or service layers. It converters data from source to target using Populators. We can say converter contains one or more Populators. Converters create an object of DTO.

It converts data object to Model using populator and Model to data object using Reverse populator. The Data object is always created from a spring bean that is defined in the beans.xml file for the extension.All the converters are an instance of AbstractConverter or AbstractPopulatingConverter

Ex: Product Converter, Cart Converter, Customer Review Converter etc.

Note: No concrete Converters should be written, all converters should be spring configured only and should use the AbstractConverter base class.
Populators:
Populators break the code for filling up data in DTO. This is required because, not each DTO needs all attributes of a model. Each Populator carries out one or more related updates to the Data Object. Each population step can invoke services or copy data from the source business object to Facade Data object. Facades always use a Converter to create a new instance of a Data Object and then invoke Populators or other Converters to fulfill the task of building up the Data Object.
  1. It contains conversion logic
  2. We cannot use this directly in code, before that Converters should be spring injected and used.
  3. Populators are used in facade layer only.
  4. Reverse Populators are used in Service layer.
Ex: Product data populator, cart populator, gender data populator etc.

We have two types of Populators:
  1. Configurable Populators
  2. Modifiable Configurable Populators
ConfigurablePopulators may implement different conversion rules based on a set of enums.

1. First the converter creates a data object using all the Populators which fill the mandatory fields.
2. Then a configurable populator fills the fields which are only required by some components/pages of the front-end. It has a Map<enums option, populator>.
Modifiable Configurable Populators enables you to modify ConfigurablePopulators that implement the ModifiableConfigurablePopulator interface, which includes adding Populators to, and removing Populators from already configured ConfigurablePopulator beans.
Modifications are configured as spring beans that extend the abstract parent configurablePopulatorModification bean. They register themselves with the target populator during context initialization.
The commercefacades-spring.xml file contains the definition of the abstract configurablePopulatorModification parent bean, which defines the init method that executes the registration with the target populator.

7 comments:

  1. Superb Explanation, Keep Going..:)

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  2. Great Explanation!

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. I am beginner in hybirs and your explanation on the concepts are quite good... "It converts data object to Model using populator and Model to data object using Reverse populator" is this statement is correct ? As per your explanation converts convert the modal object to data object, in the converter internally calls multiple populators but your statement is differ. May be i am wrong, please excuse.

    ReplyDelete
  5. There is a populator 'defaultProductConfiguredPopulator'(with alias 'productConfiguredPopulator') defined in commercefacades-spring.xml and it has a map of product options to populateors. Three more populators(productConfiguredPopulator, productBundlePopulator & productBundleDisablePopulator) have been added to this map in configurablebundlefacades-spring.xml.

    However the issue i am facing is that the three populators are not added to the map properly even though the extension 'configurablebundlefacades' has been added to localextensions.xml.

    When i open the PDP of any product, i get this in tomcat logs:
    WARN [hybrisHTTP12] [DefaultModifableConfigurablePopulator] No populator configured for option [STARTING_BUNDLES].

    Any idea whats going wrong?

    ReplyDelete