Class RuleFieldPersistenceProvider
java.lang.Object
org.broadleafcommerce.openadmin.server.service.persistence.module.provider.AbstractFieldPersistenceProvider
org.broadleafcommerce.openadmin.server.service.persistence.module.provider.FieldPersistenceProviderAdapter
org.broadleafcommerce.openadmin.server.service.persistence.module.provider.RuleFieldPersistenceProvider
- All Implemented Interfaces:
FieldPersistenceProvider,org.springframework.core.Ordered
@Component("blRuleFieldPersistenceProvider")
@Scope("prototype")
public class RuleFieldPersistenceProvider
extends FieldPersistenceProviderAdapter
Provides persistence (read/write) behavior for rule builder fields. This includes two types: Rule with quantity, and
simple rule. OfferImpl#targetItemCriteria and OfferImpl#offerMatchRules are examples of each, respectively. This class
is only compatible with quantity-based rules modeled using a Set and @OneToMany, and with simple rules modeled using
a Map and @OneToMany.
- Author:
- Jeff Fischer
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected RuleBuilderFieldServiceFactoryprotected RuleFieldExtractionUtilityprotected org.broadleafcommerce.common.sandbox.SandBoxHelperFields inherited from interface org.broadleafcommerce.openadmin.server.service.persistence.module.provider.FieldPersistenceProvider
BASIC, HTML, MAP_FIELD, MEDIA, MONEY, RULEFields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleancanHandleExtraction(ExtractValueRequest extractValueRequest, Property property) protected booleancanHandlePersistence(PopulateValueRequest populateValueRequest, Serializable instance) protected StringclearMvelString(DataDTOToMVELTranslator translator, String entityKey, String fieldService, DataDTO dto) protected PropertyconvertQuantityBasedRuleToJson(MVELToDataWrapperTranslator translator, com.fasterxml.jackson.databind.ObjectMapper mapper, Collection<org.broadleafcommerce.common.rule.QuantityBasedRule> quantityBasedRules, String jsonProp, String fieldService) protected PropertyconvertSimpleRuleToJson(MVELToDataWrapperTranslator translator, com.fasterxml.jackson.databind.ObjectMapper mapper, org.broadleafcommerce.common.rule.SimpleRule simpleRule, String jsonProp, String fieldService) protected ObjectextractParent(PopulateValueRequest populateValueRequest, Serializable instance) This method is intended to find the object that the field is supposed to be populated on.protected voidextractQuantityRule(ExtractValueRequest extractValueRequest, com.fasterxml.jackson.databind.ObjectMapper mapper, MVELToDataWrapperTranslator translator) protected voidextractSimpleRule(ExtractValueRequest extractValueRequest, Property property, com.fasterxml.jackson.databind.ObjectMapper mapper, MVELToDataWrapperTranslator translator) extractValue(ExtractValueRequest extractValueRequest, Property property) Retrieve the property value from the requestedValue field from the request.filterProperties(AddFilterPropertiesRequest addFilterPropertiesRequest, Map<String, FieldMetadata> properties) Filter the list of properties posted by the admin during and add or update.static Objectprotected static Field[]getAllFields(Class<?> targetClass) protected LonggetContainedRuleId(org.broadleafcommerce.common.rule.SimpleRule simpleRule, jakarta.persistence.EntityManager em) intgetOrder()protected LonggetRuleId(org.broadleafcommerce.common.rule.SimpleRule rule, jakarta.persistence.EntityManager em) protected Class<?>getStartingValueType(PopulateValueRequest populateValueRequest) protected booleanisEmbeddable(Class<?> clazz) This method is responsible for determining whether the class is embeddable.protected StringparseParentProperty(String propertyName) protected booleanpopulateQuantityRule(PopulateValueRequest populateValueRequest, Serializable instance) protected booleanpopulateSimpleRule(PopulateValueRequest populateValueRequest, Serializable instance) populateValue(PopulateValueRequest populateValueRequest, Serializable instance) Set the property value on the target object.protected ObjectrecursivelyExtractParent(PopulateValueRequest populateValueRequest, Serializable instance) This method is responsible for recursively tracing the properties parents to find the correct parent to apply the field update to.protected LongtransformId(Long id, Object rule) protected booleanupdateQuantityRule(jakarta.persistence.EntityManager em, DataDTOToMVELTranslator translator, String entityKey, String fieldService, String jsonPropertyValue, Collection<org.broadleafcommerce.common.rule.QuantityBasedRule> criteriaList, Class<?> memberType, Object parent, String mappedBy, Property property) protected voidupdateSimpleRule(PopulateValueRequest populateValueRequest, String mvel, boolean persist, org.broadleafcommerce.common.rule.SimpleRule rule) Methods inherited from class org.broadleafcommerce.openadmin.server.service.persistence.module.provider.FieldPersistenceProviderAdapter
addSearchMapping, checkDirtyState, isFieldDirty, setNonDisplayableValuesMethods inherited from class org.broadleafcommerce.openadmin.server.service.persistence.module.provider.AbstractFieldPersistenceProvider
alwaysRun, buildFieldInfo, canHandlePopulateNull, getListFieldType, getMapFieldType
-
Field Details
-
ruleBuilderFieldServiceFactory
-
sandBoxHelper
protected org.broadleafcommerce.common.sandbox.SandBoxHelper sandBoxHelper -
ruleFieldExtractionUtility
-
extensionManager
-
cascadeExtensionManager
-
-
Constructor Details
-
RuleFieldPersistenceProvider
public RuleFieldPersistenceProvider()
-
-
Method Details
-
findContainedRuleIfApplicable
-
getAllFields
-
canHandlePersistence
protected boolean canHandlePersistence(PopulateValueRequest populateValueRequest, Serializable instance) -
canHandleExtraction
-
populateValue
public MetadataProviderResponse populateValue(PopulateValueRequest populateValueRequest, Serializable instance) throws PersistenceException Description copied from interface:FieldPersistenceProviderSet the property value on the target object. Implementations should translate the requestedValue field from the request and set on the instance parameter. You are basically taking the string value submitted by the admin application and converting it into the format required to set on the target field of instance (which should be a JPA managed entity). Used during admin create and update events.- Specified by:
populateValuein interfaceFieldPersistenceProvider- Overrides:
populateValuein classFieldPersistenceProviderAdapter- Parameters:
populateValueRequest- contains the requested value and support classes.instance- the persistence entity instance on which to set the value harvested from the request- Returns:
- whether or not the implementation handled the persistence request
- Throws:
PersistenceException
-
extractValue
public MetadataProviderResponse extractValue(ExtractValueRequest extractValueRequest, Property property) throws PersistenceException Description copied from interface:FieldPersistenceProviderRetrieve the property value from the requestedValue field from the request. Implementations should translate the requestedValue and set on the property parameter. The requestedValue is the field value taken from the JPA managed entity instance. You are taking this field value and converting it into a string representation appropriate for the property instance parameter. Used during admin fetch events.- Specified by:
extractValuein interfaceFieldPersistenceProvider- Overrides:
extractValuein classFieldPersistenceProviderAdapter- Parameters:
extractValueRequest- contains the requested value and support classes.property- the property for the admin that will contain the information harvested from the persistence value- Returns:
- whether or not the implementation handled the persistence request
- Throws:
PersistenceException
-
filterProperties
public MetadataProviderResponse filterProperties(AddFilterPropertiesRequest addFilterPropertiesRequest, Map<String, FieldMetadata> properties) Description copied from interface:FieldPersistenceProviderFilter the list of properties posted by the admin during and add or update. This is the property list immediately before persistence is attempted. Properties may be altered, removed or added.- Specified by:
filterPropertiesin interfaceFieldPersistenceProvider- Overrides:
filterPropertiesin classFieldPersistenceProviderAdapter- Parameters:
addFilterPropertiesRequest- contains the Entity instance.properties- the collection of properties to filter- Returns:
- whether or not the implementation handled the persistence request
-
extractSimpleRule
protected void extractSimpleRule(ExtractValueRequest extractValueRequest, Property property, com.fasterxml.jackson.databind.ObjectMapper mapper, MVELToDataWrapperTranslator translator) -
extractQuantityRule
protected void extractQuantityRule(ExtractValueRequest extractValueRequest, com.fasterxml.jackson.databind.ObjectMapper mapper, MVELToDataWrapperTranslator translator) -
populateSimpleRule
protected boolean populateSimpleRule(PopulateValueRequest populateValueRequest, Serializable instance) throws Exception - Throws:
Exception
-
getRuleId
protected Long getRuleId(org.broadleafcommerce.common.rule.SimpleRule rule, jakarta.persistence.EntityManager em) -
getContainedRuleId
protected Long getContainedRuleId(org.broadleafcommerce.common.rule.SimpleRule simpleRule, jakarta.persistence.EntityManager em) -
transformId
-
extractParent
protected Object extractParent(PopulateValueRequest populateValueRequest, Serializable instance) throws IllegalAccessException, FieldNotAvailableException This method is intended to find the object that the field is supposed to be populated on. Typically, this is the instance itself, but sometimes it may be a property of an object this instance relates to.This method ignores parent candidates that implement
Embeddableas the proper parent for these fields is the object itself and not the embedded object.- Parameters:
populateValueRequest- thePopulateValueRequestinstance- the Object we are populating field values on- Returns:
- the proper parent for the
PopulateValueRequest - Throws:
IllegalAccessExceptionFieldNotAvailableException
-
recursivelyExtractParent
protected Object recursivelyExtractParent(PopulateValueRequest populateValueRequest, Serializable instance) throws FieldNotAvailableException, IllegalAccessException This method is responsible for recursively tracing the properties parents to find the correct parent to apply the field update to.- Parameters:
populateValueRequest- the populate value requestinstance- the entity that to populate a field value on- Returns:
- the proper parent or original instance if no closer parent is found
- Throws:
FieldNotAvailableExceptionIllegalAccessException
-
parseParentProperty
-
isEmbeddable
This method is responsible for determining whether the class is embeddable. If it is we don't want to check if the entity manager contains the instance since embeddables are not entities.- Parameters:
clazz- the parent class of the populate value request- Returns:
- whether the class is embeddable
-
populateQuantityRule
protected boolean populateQuantityRule(PopulateValueRequest populateValueRequest, Serializable instance) throws FieldNotAvailableException, IllegalAccessException -
convertSimpleRuleToJson
protected Property convertSimpleRuleToJson(MVELToDataWrapperTranslator translator, com.fasterxml.jackson.databind.ObjectMapper mapper, org.broadleafcommerce.common.rule.SimpleRule simpleRule, String jsonProp, String fieldService) -
convertQuantityBasedRuleToJson
protected Property convertQuantityBasedRuleToJson(MVELToDataWrapperTranslator translator, com.fasterxml.jackson.databind.ObjectMapper mapper, Collection<org.broadleafcommerce.common.rule.QuantityBasedRule> quantityBasedRules, String jsonProp, String fieldService) -
updateQuantityRule
protected boolean updateQuantityRule(jakarta.persistence.EntityManager em, DataDTOToMVELTranslator translator, String entityKey, String fieldService, String jsonPropertyValue, Collection<org.broadleafcommerce.common.rule.QuantityBasedRule> criteriaList, Class<?> memberType, Object parent, String mappedBy, Property property) -
clearMvelString
protected String clearMvelString(DataDTOToMVELTranslator translator, String entityKey, String fieldService, DataDTO dto) throws MVELTranslationException - Throws:
MVELTranslationException
-
updateSimpleRule
protected void updateSimpleRule(PopulateValueRequest populateValueRequest, String mvel, boolean persist, org.broadleafcommerce.common.rule.SimpleRule rule) throws IllegalAccessException, FieldNotAvailableException -
getStartingValueType
protected Class<?> getStartingValueType(PopulateValueRequest populateValueRequest) throws ClassNotFoundException, IllegalAccessException -
getOrder
public int getOrder()- Specified by:
getOrderin interfaceorg.springframework.core.Ordered- Overrides:
getOrderin classFieldPersistenceProviderAdapter
-