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"/commerce-legacy/> <bean id="abstractChangeSetPolicy" abstract="true" class="com.elasticpath.service.changeset.impl.ChangeSetPolicyImpl"> <property name="changeSetDao" ref="changeSetDao"/commerce-legacy/> <property name="businessObjectResolver" ref="businessObjectResolver"/commerce-legacy/> <property name="businessObjectGroupDao" ref="businessObjectGroupDao"/commerce-legacy/> <property name="metadataResolvers"> <list> <ref bean="promotionMetadataResolver"/commerce-legacy/> <ref bean="productMetadataResolver"/commerce-legacy/> <ref bean="productSkuMetadataResolver"/commerce-legacy/> <ref bean="categoryMetadataResolver"/commerce-legacy/> <ref bean="dynamicContentMetadataResolver"/commerce-legacy/> <ref bean="dynamicContentDeliveryMetadataResolver"/commerce-legacy/> <ref bean="priceListDescriptorMetadataResolver"/commerce-legacy/> <ref bean="priceListAssignmentMetadataResolver"/commerce-legacy/> <ref bean="categoryTypeMetadataResolver"/commerce-legacy/> <ref bean="savedConditionMetadataResolver"/commerce-legacy/> <ref bean="baseAmountMetadataResolver"/commerce-legacy/> <ref bean="catalogMetadataResolver"/commerce-legacy/> <ref bean="attributeMetadataResolver"/commerce-legacy/> <ref bean="skuOptionMetadataResolver"/commerce-legacy/> <ref bean="skuOptionValueMetadataResolver"/commerce-legacy/> <ref bean="productTypeMetadataResolver"/commerce-legacy/> <ref bean="brandMetadataResolver"/commerce-legacy/> </list> </property> <property name="changeSetDependentResolvers"> <list> <ref bean="baseAmountChangeSetDependencyResolver"/commerce-legacy/> <ref bean="productChangeSetDependencyResolver"/commerce-legacy/> <ref bean="productBundleChangeSetDependencyResolver"/commerce-legacy/> <ref bean="categoryChangeSetDependencyResolver"/commerce-legacy/> <ref bean="skuChangeSetDependencyResolver"/commerce-legacy/> <ref bean="promotionChangeSetDependencyResolver"/commerce-legacy/> <ref bean="catalogCategoryTypeChangeSetResolver"/commerce-legacy/> <ref bean="productTypeChangeSetDependencyResolver"/commerce-legacy/> </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.
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"/commerce-legacy/> </entry> <entry key="com.elasticpath.common.dto.pricing.BaseAmountDTO"> <bean class="com.elasticpath.service.changeset.impl.BaseAmountDtoGuidResolver"/commerce-legacy/> </entry> </map> </property> <property name="defaultObjectGuidResolver" ref="defaultObjectGuidResolver"/commerce-legacy/>
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); }