Extending the Page API

You can extend the Page API to add support for page types that SAP SmartEdit does not support by default. For example, if you want to create a page that is customized for your solution but that is not provided by default by the SAP Commerce Cloud, you can extend the Page API to support your customized solution.

The Page API exposes pages. You can extend the default solution to expose customized pages. You can extend the default solution as follows:

  • Create a PageData DTO
  • Set up data subclass mapping
  • Create populators
  • Add populators to converters

To provide cloning support to your custom page, you can extend the default solution as follows:

  • Create a PageData WsDTO
  • Set up WsDTO subclass mapping.

Create a PageData DTO

You extend the PageData DTO using the extends attribute and by adding the properties required to support your implementation to your beans.xml file, as shown in the following code example:

<bean class="com.mycompany.extendedapi.data.CustomPageData" extends="de.hybris.platform.cmswebservices.data.AbstractPageData">
  <property name="label" type="String" />
</bean>

Set Up Data Subclass Mapping

To expose your customized page in your API, you must explicitly configure the subclass type mapping in your spring.xml file, as shown in the following code example:

<bean parent="subclassMapping">
  <property name="parentClass"
        value="de.hybris.platform.cmswebservices.data.AbstractPageData" />
  <property name="subclassesSet">
    <set>
      <value>com.mycompany.extendedapi.data.CustomPageData</value>
    </set>
  </property>
</bean>

Create the Populator

To create the populator:

  1. Create the populators on both directions, from Model to Data and from Data to Model, by implementing the Populator interface as shown in the following example:

    public class CustomPageModelToDataPopulator implements Populator<CustomPageModel, CustomPageData>
    {
        @Override
        public void populate(final CustomPageModel source, final CustomPageData target) throws ConversionException
        {
            target.setLabel(source.getLabel());
        }
    }
     
    public class CustomPageDataToModelPopulator implements Populator<CustomPageData, CustomPageModel>
    {
        @Override
        public void populate(final CustomPageData source, final CustomPageModel target) throws ConversionException
        {
            target.setLabel(source.getLabel());
        }
    }
    
  2. Register your populator as a Spring bean in the spring.xml file as shown in the following example:

    <bean id="customPageModelToDataPopulator" class="com.mycompany.extendedapi.facade.populator.CustomPageModelToDataPopulator" />
    <bean id="customPageDataToModelPopulator" class="com.mycompany.extendedapi.facade.populator.CustomPageDataToModelPopulator" />

Add Populators to Converters

Once you have written the populators, you must register them to the corresponding converter.

Spring Beans for the Model-to-Data Populator

You must create a converter as a Spring bean and register the newly created Model-to-Data populator in it.

<bean class="de.hybris.platform.cmsfacades.restrictions.service.impl.DefaultRestrictionModelToDataConverter"
    p:typecode="CMSCustomRestriction" p:converter-ref="customRestrictionModelConverter" />	
 
<alias name="defaultCustomPageModelToDataConverter" alias="customPageModelToDataConverter" />
<bean id="defaultCustomPageModelToDataConverter" parent="abstractPopulatingConverter">
	<property name="targetClass" value="com.mycompany.extendedapi.data.CustomPageData" />
	<property name="populators">
		<list merge="true">
			<ref bean="basicPageModelPopulator" />
			<ref bean="customPageModelToDataPopulator" />
		</list>
	</property>
</bean>
 
<bean depends-on="pageModelConverterFactory" parent="mapMergeDirective">
	<property name="key">
    	<value type="java.lang.Class">com.mycompany.extendedapi.model.CustomPageModel</value>
	</property>
	<property name="value" ref="customPageModelToDataPopulator"/>
</bean>

Spring Beans for the Data-to-Model Populator

You must create a converter as a Spring bean and register the newly created Model to Data populator in it as shown in the following code excerpt:

<alias name="defaultCustomPageDataToModelConverter" alias="customPageDataToModelConverter" />
<bean id="defaultCustomPageDataToModelConverter" parent="abstractPopulatingConverter">
	<property name="targetClass" value="com.mycompany.extendedapi.model.CustomPageModel" />
	<property name="populators">
		<list merge="true">
			<ref bean="basicPageDataPopulator" />
			<ref bean="customPageDataToModelPopulator" />
		</list>
	</property>
</bean>
 
<bean depends-on="pageDataPopulatorFactory" parent="mapMergeDirective">
	<property name="key">
    	<value type="java.lang.Class">com.mycompany.extendedapi.data.CustomPageData</value>
	</property>
	<property name="value" ref="customPageDataToModelPopulator"/>
</bean>

Adding Support to Clone Pages

If you want to clone your custom pages, you must do the following:

  1. Create a PageData WsDTO
  2. Set up data subclass mapping

Create the PageData WsDTO to Support Page Cloning

To enable cloning for your custom page type, you extend the PageData WsDTO using the extends attribute and by adding the properties required to support your implementation to your beans.xml file, as shown in the following code example:

<bean class="com.mycompany.extendedapi.dto.CustomPageWsDTO" extends="de.hybris.platform.cmssmarteditwebservices.dto.AbstractPageWsDTO">
  <property name="label" type="String" />
</bean>

Set Up the Data Subclass Mapping to Support Page Cloning

To enable cloning for your customized page in your API, you must explicitly configure the subclass type mapping in your spring.xml file, as shown in the following code example:

<bean parent="subclassMapping">
  <property name="parentClass"
        value="de.hybris.platform.cmssmarteditwebservices.dto.AbstractPageWsDTO" />
  <property name="subclassesSet">
    <set>
      <value>com.mycompany.extendedapi.dto.CustomPageWsDTO</value>
    </set>
  </property>
</bean>
<bean parent="fieldMapper">
	<property name="sourceClass" value="com.mycompany.extendedapi.dto.CustomPageWsDTO" />
	<property name="destClass" value="com.mycompany.extendedapi.data.CustomPageData" />
</bean>