Elastic Path Commerce Development

ChangeSetPolicy

ChangeSetPolicy

ChangeSetPolicy controls various aspects of Change Set behavior, including:

Out of the box, Elastic Path includes a default Change Set Policy implementation, ChangeSetPolicyImpl, which is configured in:

            core/ep-core/src/main/resources/spring/service/service.xml
	<bean id="changeSetPolicy" parent="abstractChangeSetPolicy"/>

	<bean id="abstractChangeSetPolicy" abstract="true" class="com.elasticpath.service.changeset.impl.ChangeSetPolicyImpl">
		<property name="changeSetDao" ref="changeSetDao"/>
		<property name="businessObjectResolver" ref="businessObjectResolver"/>
		<property name="businessObjectGroupDao" ref="businessObjectGroupDao"/>
		<property name="metadataResolvers">
			<list>
				<ref bean="promotionMetadataResolver"/>
				<ref bean="productMetadataResolver"/>
				<ref bean="productSkuMetadataResolver"/>
				<ref bean="categoryMetadataResolver"/>
				<ref bean="dynamicContentMetadataResolver"/>
				<ref bean="dynamicContentDeliveryMetadataResolver"/>
				<ref bean="priceListDescriptorMetadataResolver"/>
				<ref bean="priceListAssignmentMetadataResolver"/>
				<ref bean="categoryTypeMetadataResolver"/>
				<ref bean="savedConditionMetadataResolver"/>
				<ref bean="baseAmountMetadataResolver"/>
				<ref bean="catalogMetadataResolver"/>
				<ref bean="attributeMetadataResolver"/>
				<ref bean="skuOptionMetadataResolver"/>
				<ref bean="skuOptionValueMetadataResolver"/>
				<ref bean="productTypeMetadataResolver"/>
				<ref bean="brandMetadataResolver"/>
			</list>
		</property>
		<property name="changeSetDependentResolvers">
			<list>
                <ref bean="baseAmountChangeSetDependencyResolver"/>
                <ref bean="productChangeSetDependencyResolver"/>
				<ref bean="productBundleChangeSetDependencyResolver"/>
				<ref bean="categoryChangeSetDependencyResolver"/>
				<ref bean="skuChangeSetDependencyResolver"/>
				<ref bean="promotionChangeSetDependencyResolver"/>
				<ref bean="catalogCategoryTypeChangeSetResolver"/>
				<ref bean="productTypeChangeSetDependencyResolver"/>
			</list>
		</property>
	</bean>

         

Supporting New Object Types in Change Sets

The objectTypes property in the changeSetPolicy bean definition is a map of object types keyed on the interface class name.

<property name="objectTypes">
    <map>
        <entry>
            <key><value>com.elasticpath.domain.catalog.ProductBundle</value></key>
            <value>Product Bundle</value>
        </entry>
        <entry>
            <key><value>com.elasticpath.domain.catalog.Product</value></key>
            <value>Product</value>
        </entry>
        <entry>
            <key><value>com.elasticpath.domain.catalog.ProductSku</value></key>
            <value>Product SKU</value>
        </entry>
...

To add support for a new business object, add a new key-value pair to the map.

Note:

New business object types may also require new Object GUID resolvers.

Configuring Object GUID Resolvers

All business objects that can be added to Change Sets are required to have a globally unique business identifier. Many Elastic Path domain objects have a built-in GUID property, but others do not.

Object GUID resolvers are used to locate the unique business identifier of a business object. The following resolvers are available out of the box:

  • DefaultObjectGuidResolver, used for most Elastic Path domain object types, this simply uses the domain object's GUID as the business object GUID.
  • CategoryGuidResolver, which constructs a GUID from the Category's non-unique GUID and the parent Catalog's GUID.
  • PriceListDescriptorGuidResolver, which uses the PriceListDescriptorDTO's GUID.
  • BaseAmountDtoGuidResolver, which uses the BaseAmountDTO's GUID.

The supported object GUID resolvers are defined in the objectGuidResolvers of the changeSetPolicy bean. The default GUID resolver is set in the defaultObjectGuidResolver property.

<property name="objectGuidResolvers">
    <map>
        <entry key="com.elasticpath.domain.catalog.Category">
            <bean class="com.elasticpath.service.changeset.impl.CategoryGuidResolver" />
        </entry>
        <entry key="com.elasticpath.common.dto.pricing.PriceListDescriptorDTO">
            <bean class="com.elasticpath.service.changeset.impl.PriceListDescriptorGuidResolver"/>
        </entry>
        <entry key="com.elasticpath.common.dto.pricing.BaseAmountDTO">
            <bean class="com.elasticpath.service.changeset.impl.BaseAmountDtoGuidResolver"/>
        </entry>
    </map>
</property>
<property name="defaultObjectGuidResolver" ref="defaultObjectGuidResolver"/>

If you need to support additional business object types that cannot use one of these resolvers, you can create a custom resolver by extending ObjectGuidResolver and adding a mapping to the objectGuidResolvers property of the changeSetPolicy bean definition.

Controlling Addition of Objects to Change Sets

The isChangeAllowed method of ChangeSetPolicy is implemented to determine whether objects can be added to the specified Change Set. The default implementation simply checks to see if the Change Set is in the OPEN state.

public boolean isChangeAllowed(final String changeSetGuid) {
    final ChangeSet changeSet = this.changeSetDao.findByGuid(changeSetGuid);
    if (changeSet == null) {
        LOG.info("Change set with GUID: " + changeSetGuid + " could not be found");
        return true;
    }
    final ChangeSetStateCode stateCode = changeSet.getStateCode();

    return ObjectUtils.equals(ChangeSetStateCode.OPEN, stateCode);
}