Class SkuCustomPersistenceHandler
- All Implemented Interfaces:
CustomPersistenceHandler
,org.springframework.core.Ordered
- Author:
- Phillip Verheyden
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected PersistenceModule
protected CatalogService
static String
static String
This represents the field that all of the product option values will be stored in.protected CriteriaTranslator
protected jakarta.persistence.EntityManager
static String
static String
protected SandBoxHelper
protected SkuMetadataCacheService
protected boolean
Fields inherited from interface org.broadleafcommerce.openadmin.server.service.handler.CustomPersistenceHandler
DEFAULT_ORDER
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd
(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) void
applyAdditionalFetchCriteria
(List<FilterMapping> filterMappings, CriteriaTransferObject cto, PersistencePackage persistencePackage) Available override point for subclasses if they would like to add additional criteria via the queryCritiera.protected void
applyInventoryRestrictions
(List<FilterMapping> filterMappings, CriteriaTransferObject cto, PersistencePackage persistencePackage) void
applyProductOptionValueCriteria
(List<FilterMapping> filterMappings, CriteriaTransferObject cto, PersistencePackage persistencePackage, String skuPropertyPrefix) protected void
applySkuBundleItemValueCriteria
(List<FilterMapping> filterMappings, CriteriaTransferObject cto, PersistencePackage persistencePackage) Add filter restriction such that a ProductBundle cannot add its own default sku as a Sku Bundle Itemprotected void
associateProductOptionValuesToSku
(Entity entity, Sku adminInstance, DynamicEntityDao dynamicEntityDao) This initially removes all of the product option values that are currently related to the Sku and then re-associates theProductOptionValue
sprotected Boolean
canHandle
(PersistencePackage persistencePackage, OperationType operationType) Since this is the default for all Skus, it's possible that we are providing custom criteria for this Sku lookup.canHandleAdd
(PersistencePackage persistencePackage) Is this persistence handler capable of dealing with an add request from the admincanHandleFetch
(PersistencePackage persistencePackage) Is this persistence handler capable of dealing with an fetch request from the admincanHandleInspect
(PersistencePackage persistencePackage) Is this persistence handler capable of dealing with an inspect request from the admincanHandleUpdate
(PersistencePackage persistencePackage) Is this persistence handler capable of dealing with an update request from the admincreateConsolidatedOptionField
(Class<?> inheritedFromType) Creates the metadata necessary for displaying all of the product option values in a single field.protected FieldMetadata
createExplicitEnumerationIndividualOptionField
(ProductOption option, int order) createIndividualOptionField
(ProductOption option, int order) Creates an individual property for the specified product option.protected FieldMetadata
createToOneIndividualOptionField
(ProductOption option, int order) Using a ToOne lookup performs much better for large product option value lists, speeds up initial page load, and is generally more accurate in relation to option value updates and how they impact available selections and cache.fetch
(PersistencePackage persistencePackage, CriteriaTransferObject cto, DynamicEntityDao dynamicEntityDao, RecordHelper helper) protected void
Returns aProperty
filled out with a delimited list of the values that are passed in.protected Long
getOwningProductBundlesDefaultSkuId
(SectionCrumb sectionCrumb) protected String
getOwningProductId
(SectionCrumb[] sectionCrumbs) protected String[]
getPolymorphicClasses
(Class<?> clazz, jakarta.persistence.EntityManager em, boolean useCache) getProductOptionProperties
(Entity entity) inspect
(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, InspectHelper helper) Build out the extra fields for the product optionsprotected boolean
isSkuBundleItemLookup
(PersistencePackage pkg, SectionCrumb[] sectionCrumbs) update
(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) void
updateProductOptionFieldsForFetch
(List<Serializable> records, Entity[] payload) Sets theProductOptionValue
s of the givenSku
s in a list format for display in a ListGrid context.protected Entity
validateAvailableProductOption
(Product product, List<Property> productOptionProperties) Verify that all selected options are among the available product options.protected Entity
validateNotEmptyProductOptions
(List<Property> productOptionProperties) Verify that product options are not empty.protected Entity
validateNotNullProductOptions
(List<Property> productOptionProperties) Verify that none of the selected options is null.protected Entity
validateUniqueProductOptionValueCombination
(Product product, List<Property> productOptionProperties, Sku currentSku) Ensures that the given list ofProductOptionValue
IDs is unique for the givenProduct
.Methods inherited from class org.broadleafcommerce.openadmin.server.service.handler.CustomPersistenceHandlerAdapter
canHandleRemove, getClassForName, getMetadata, getOrder, getResultSet, isAdornedListOperation, isAssignableFrom, isBasicOperation, isMapOperation, meetsCustomCriteria, remove, willHandleSecurity
-
Field Details
-
PRODUCT_OPTION_FIELD_PREFIX
-
INVENTORY_ONLY_CRITERIA
-
CONSOLIDATED_PRODUCT_OPTIONS_FIELD_NAME
This represents the field that all of the product option values will be stored in. This would be used in the case where there are a bunch of product options and displaying each option as a grid header would have everything squashed together. Filtering on this field is currently unsupported. -
CONSOLIDATED_PRODUCT_OPTIONS_DELIMETER
-
useToOneLookupSkuProductOptionValue
@Value("${use.to.one.lookup.sku.product.option.value:false}") protected boolean useToOneLookupSkuProductOptionValue -
skuMetadataCacheService
-
adornedPersistenceModule
-
extensionManager
-
catalogService
-
em
protected jakarta.persistence.EntityManager em -
criteriaTranslator
-
sandBoxHelper
-
-
Constructor Details
-
SkuCustomPersistenceHandler
public SkuCustomPersistenceHandler()
-
-
Method Details
-
canHandleInspect
Description copied from interface:CustomPersistenceHandler
Is this persistence handler capable of dealing with an inspect request from the admin- Specified by:
canHandleInspect
in interfaceCustomPersistenceHandler
- Overrides:
canHandleInspect
in classCustomPersistenceHandlerAdapter
- Parameters:
persistencePackage
- details about the inspect operation- Returns:
- whether or not this handler supports inspects
-
canHandleFetch
Description copied from interface:CustomPersistenceHandler
Is this persistence handler capable of dealing with an fetch request from the admin- Specified by:
canHandleFetch
in interfaceCustomPersistenceHandler
- Overrides:
canHandleFetch
in classCustomPersistenceHandlerAdapter
- Parameters:
persistencePackage
- details about the fetch operation- Returns:
- whether or not this handler supports fetches
-
canHandleAdd
Description copied from interface:CustomPersistenceHandler
Is this persistence handler capable of dealing with an add request from the admin- Specified by:
canHandleAdd
in interfaceCustomPersistenceHandler
- Overrides:
canHandleAdd
in classCustomPersistenceHandlerAdapter
- Parameters:
persistencePackage
- details about the add operation- Returns:
- whether or not this handler supports adds
-
canHandleUpdate
Description copied from interface:CustomPersistenceHandler
Is this persistence handler capable of dealing with an update request from the admin- Specified by:
canHandleUpdate
in interfaceCustomPersistenceHandler
- Overrides:
canHandleUpdate
in classCustomPersistenceHandlerAdapter
- Parameters:
persistencePackage
- details about the update operation- Returns:
- whether or not this handler supports updatess
-
canHandle
Since this is the default for all Skus, it's possible that we are providing custom criteria for this Sku lookup. In that case, we probably want to delegate to a child class, so only use this particular persistence handler if there is no custom criteria being used and the ceiling entity is an instance of Sku. The exception to this rule is when we are pulling back Media, since the admin actually uses Sku for the ceiling entity class name. That should be handled by the map structure module though, so only handle things in the Sku custom persistence handler for OperationType.BASIC -
inspect
public DynamicResultSet inspect(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, InspectHelper helper) throws ServiceException Build out the extra fields for the product options- Specified by:
inspect
in interfaceCustomPersistenceHandler
- Overrides:
inspect
in classCustomPersistenceHandlerAdapter
- Throws:
ServiceException
-
getOwningProductId
-
filterOutProductMetadata
-
createConsolidatedOptionField
Creates the metadata necessary for displaying all of the product option values in a single field. The display of this field is a single string with every product option value appended to it separated by a semicolon. This method should be invoked on an inspect for whatever is utilizing this so that the property will be ready to be populated on fetch.The metadata that is returned will also be set to prominent by default so that it will be ready to display on whatever grid is being inspected. If you do not want this behavior you will need to override this functionality in the metadata that is returned.
- Parameters:
inheritedFromType
- which type this should appear on. This would normally be SkuImpl.class, but if you want to display this field with a different entity then this should be that entity- Returns:
-
getConsolidatedOptionProperty
Returns aProperty
filled out with a delimited list of the values that are passed in. This should be invoked on a fetch and the returned property should be added to the fetchedEntity
dto.- Parameters:
values
-- Returns:
-
getBlankConsolidatedOptionProperty
- Returns:
- a blank
Property
corresponding to the CONSOLIDATED_PRODUCT_OPTIONS_FIELD_NAME
-
createIndividualOptionField
Creates an individual property for the specified product option. This should set up an enum field whose values will be the option values for this option. This is useful when you would like to display each product option in as its own field in a grid so that you can further filter by product option values.
In order for these fields to be utilized property on the fetch, in the GWT frontend you must use the for your datasource.
- Parameters:
option
-order
-- Returns:
-
createExplicitEnumerationIndividualOptionField
protected FieldMetadata createExplicitEnumerationIndividualOptionField(ProductOption option, int order) -
createToOneIndividualOptionField
Using a ToOne lookup performs much better for large product option value lists, speeds up initial page load, and is generally more accurate in relation to option value updates and how they impact available selections and cache.- Parameters:
option
-order
-- Returns:
-
fetch
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException - Specified by:
fetch
in interfaceCustomPersistenceHandler
- Overrides:
fetch
in classCustomPersistenceHandlerAdapter
- Throws:
ServiceException
-
applyInventoryRestrictions
protected void applyInventoryRestrictions(List<FilterMapping> filterMappings, CriteriaTransferObject cto, PersistencePackage persistencePackage) -
updateProductOptionFieldsForFetch
Sets theProductOptionValue
s of the givenSku
s in a list format for display in a ListGrid context.- Parameters:
records
-payload
-
-
applySkuBundleItemValueCriteria
protected void applySkuBundleItemValueCriteria(List<FilterMapping> filterMappings, CriteriaTransferObject cto, PersistencePackage persistencePackage) Add filter restriction such that a ProductBundle cannot add its own default sku as a Sku Bundle Item -
isSkuBundleItemLookup
-
getOwningProductBundlesDefaultSkuId
-
applyProductOptionValueCriteria
public void applyProductOptionValueCriteria(List<FilterMapping> filterMappings, CriteriaTransferObject cto, PersistencePackage persistencePackage, String skuPropertyPrefix) -
applyAdditionalFetchCriteria
public void applyAdditionalFetchCriteria(List<FilterMapping> filterMappings, CriteriaTransferObject cto, PersistencePackage persistencePackage) Available override point for subclasses if they would like to add additional criteria via the queryCritiera. At the point that this method has been called, criteria from the frontend has already been applied, thus allowing you to override from there as well.
Subclasses that choose to override this should also call this super method so that correct filter criteria can be applied for product option values
-
add
public Entity add(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException - Specified by:
add
in interfaceCustomPersistenceHandler
- Overrides:
add
in classCustomPersistenceHandlerAdapter
- Throws:
ServiceException
-
update
public Entity update(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException - Specified by:
update
in interfaceCustomPersistenceHandler
- Overrides:
update
in classCustomPersistenceHandlerAdapter
- Throws:
ServiceException
-
getPolymorphicClasses
protected String[] getPolymorphicClasses(Class<?> clazz, jakarta.persistence.EntityManager em, boolean useCache) - Overrides:
getPolymorphicClasses
in classCustomPersistenceHandlerAdapter
-
associateProductOptionValuesToSku
protected void associateProductOptionValuesToSku(Entity entity, Sku adminInstance, DynamicEntityDao dynamicEntityDao) This initially removes all of the product option values that are currently related to the Sku and then re-associates theProductOptionValue
s- Parameters:
entity
-adminInstance
-
-
validateAvailableProductOption
protected Entity validateAvailableProductOption(Product product, List<Property> productOptionProperties) Verify that all selected options are among the available product options.- Parameters:
product
- productproductOptionProperties
- product Option properties- Returns:
- null if successfully validation, the error entity otherwise
-
getProductOptionProperties
-
validateUniqueProductOptionValueCombination
protected Entity validateUniqueProductOptionValueCombination(Product product, List<Property> productOptionProperties, Sku currentSku) Ensures that the given list ofProductOptionValue
IDs is unique for the givenProduct
.If sku browsing is enabled, then it is assumed that a single combination of
ProductOptionValue
IDs is not unique and more than oneSku
could have the exact same combination ofProductOptionValue
IDs. In this case, the following validation is skipped.- Parameters:
product
-productOptionProperties
-currentSku
- - for update operations, this is the current Sku that is being updated; should be excluded from attempting validation- Returns:
- null if successfully validation, the error entity otherwise
-
validateNotNullProductOptions
Verify that none of the selected options is null. If one of the option's value is null, means that the option in the combo box wasn't correctly selected.- Parameters:
productOptionProperties
- product Option properties- Returns:
- null if successfully validation, the error entity otherwise
-
validateNotEmptyProductOptions
Verify that product options are not empty.- Parameters:
productOptionProperties
- product Option properties- Returns:
- null if successfully validation, the error entity otherwise
-