Extending the Site API

The Site API exposes site information. You can extend the default solution to support the customized ordering of results by exposing additional site information in the SiteData DTO.

The SiteData DTO is a direct mapping of the information available in the CMSSiteModel. To expose additon site information, you must do the following:

  1. Extend the SiteData DTO.
  2. Extend the populator.
  3. Customize the order of the site results

Extending the SiteData DTO

You extend the SiteData DTO by using the extends attribute and by adding the properties required to support your implementation to your beans.xml file.

<bean class="myextenion.dto.MyCustomSiteData" extends="de.hybris.platform.cmswebservices.dto.SiteData">
   <property name="customAttribute" type="String" />
</bean>

Extending the Populator

To expose your customized attribute over the Site API, you must populate your custom DTO. You do this by changing the populator that is used in your spring.xml file, as shown in the following example:

<alias name="myCustomCmsSiteModelConverter" alias="cmsSiteModelConverter" />
<bean id="myCustomCmsSiteModelConverter" parent="abstractPopulatingConverter">
   <property name="targetClass" value="myextenion.dto.MyCustomSiteData"/>
   <property name="populators">
      <list merge="true">
         <ref bean="myCustomCmsSiteModelPopulator" />
      </list>
   </property>
</bean>
 
<bean id="myCustomCmsSiteModelPopulator" class="myextenion.sites.facade.populator.model.MyCustomCmsSiteModelPopulator">
   <property name="localizationService" ref="cmsLocalizationService"/>
</bean>

The following code excerpt shows an example of a potential candidate implementation of MyCustomCmsSiteModelPopulator:

public class MyCustomCmsSiteModelPopulator extends CmsSiteModelPopulator {

    @Override
    public void populate(final CMSSiteModel source, final SiteData target) throws ConversionException {
		super.populate(source, target); // LINE 4
		MyCustomSiteData localTarget = (MyCustomSiteData) target;
        localTarget.setCustomAttribute(source.getMyAttributeToMap());
    }
}

As shown in the example, we have extended the implementation of the default CmsSiteModelPopulator and delegated to the default implementation by calling super.populate. This will populate the standard attributes of the original DTO. The code in the new populator will then create a custom attribute mapping.

Customizing the Order of the Sites

The Site API ensures that items in the JSON arrays are sorted consistently. You use the siteDataComparator attribute of the DefaultCmsSiteFacade to customize how sites are sorted. The following excerpt from the cmsfacades-spring.xml file shows how this is done:

<alias name="defaultCmsSiteFacade" alias="cmsSiteFacade" />
<bean id="defaultCmsSiteFacade" class="de.hybris.platform.cmswebservices.sites.facade.impl.DefaultCmsSiteFacade">
   <property name="cmsAdminSiteService" ref="cmsAdminSiteService"/>
   <property name="cmsSiteModelConverter" ref="cmsSiteModelConverter"/>
   <property name="siteDataComparator" ref="siteDataComparator"/>
</bean>

<alias name="defaultSiteDataComparator" alias="siteDataComparator" />
<bean id="defaultSiteDataComparator" class="de.hybris.platform.cmswebservices.sites.facade.SiteDataUidComparator"/>

To customize the order in which sites are sorted, you must implement your own CustomSiteDataCustomAttributeComparator. You must then wire it into your spring.xml file instead of the default comparator. The following code example shows how this is done:

<alias name="customSiteDataComparator" alias="siteDataComparator" />
<bean id="customSiteDataComparator" class="myextenion.sites.facade.CustomSiteDataCustomAttributeComparator"/>