Saturday, 18 March 2017

Bean filtering

The Main Idea Behind this Bean Filtering is to Remove the Unwanted Attributes from the Response that was Returned. In ATG and Endeca when we take most of the Services are From OOTB one Which has its own Model Class and the Response are as it is Defined in those Classes .

This Bean Filter Services gives the Way by which we dont need to alter the Logic, instead We can Define the Attributes to be Returned or not .

The BeanFilterService filters the properties of a java bean or repository item and converts beans into a map of properties. The BeanFilterService reads XML definition files that define which properties of a Java class or repository item should be included in the filtered view of the object. The XML definitions include ways to remap property names and transform properties. 
By default, the BeanFilterService is applied to the ModelMap by the REST MVC framework before generating a JSON or XML response. However, you can filter objects at any time. 

There are two types of bean filters, 

1)repository items 

2)Java bean classes.

We are Going to See Detail about the Java Bean Classes 

How you can mention this bean filtering?  follow the following way 
 
<bean-filtering>
  <bean type="atg.userprofiling.Profile">
    <filter id="default">
      <property name="email" />
      <property name="lastName" />
      <property name="firstName" />
      <property name="dataSource" />
      <property name="homeAddress.postalCode" target="homeAddress.postalCode" />
      <property name="gender" />
      <property name="dateOfBirth" />
    </filter>
  </bean>
</bean-filtering>

From the above definition, we have defined bean Profile for which only the above properties will be  returned.  Other properties will be removed . 
 
Bean filters combine filter definitions from all classes or interfaces for an object using the filter-id property.

<bean type="atg.commerce.order.ElectronicShippingGroup>
    <filter id="summary">
      <property name="emailAddress"/>
      <property name="shippingAddress" hidden="true"/>
    </filter>
  <component>

When you define the hidden=true then that property will be removed . Once if you have defined in the above way it will be registered in the following component path 

/atg/dynamo/service/filter/bean/XmlFilterService 

This will be called on the final layer and return the properties defined .

Same like this Endeca has a contentItem bean filter which can be extended and used for filtering content item for endeca. You have to define each and every class like above to get removed .

1 comment:
Write comments