Class SkuCustomPersistenceHandler
- All Implemented Interfaces:
org.broadleafcommerce.openadmin.server.service.handler.CustomPersistenceHandler,org.springframework.core.Ordered
- Author:
- Phillip Verheyden
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.broadleafcommerce.openadmin.server.service.persistence.module.PersistenceModuleprotected org.broadleafcommerce.core.catalog.service.CatalogServicestatic Stringstatic StringThis represents the field that all of the product option values will be stored in.protected org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.CriteriaTranslatorprotected jakarta.persistence.EntityManagerstatic Stringstatic Stringprotected org.broadleafcommerce.common.sandbox.SandBoxHelperprotected SkuMetadataCacheServiceprotected booleanFields inherited from interface org.broadleafcommerce.openadmin.server.service.handler.CustomPersistenceHandler
DEFAULT_ORDERFields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.broadleafcommerce.openadmin.dto.Entityadd(org.broadleafcommerce.openadmin.dto.PersistencePackage persistencePackage, org.broadleafcommerce.openadmin.server.dao.DynamicEntityDao dynamicEntityDao, org.broadleafcommerce.openadmin.server.service.persistence.module.RecordHelper helper) voidapplyAdditionalFetchCriteria(List<org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FilterMapping> filterMappings, org.broadleafcommerce.openadmin.dto.CriteriaTransferObject cto, org.broadleafcommerce.openadmin.dto.PersistencePackage persistencePackage) Available override point for subclasses if they would like to add additional criteria via the queryCritiera.protected voidapplyInventoryRestrictions(List<org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FilterMapping> filterMappings, org.broadleafcommerce.openadmin.dto.CriteriaTransferObject cto, org.broadleafcommerce.openadmin.dto.PersistencePackage persistencePackage) voidapplyProductOptionValueCriteria(List<org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FilterMapping> filterMappings, org.broadleafcommerce.openadmin.dto.CriteriaTransferObject cto, org.broadleafcommerce.openadmin.dto.PersistencePackage persistencePackage, String skuPropertyPrefix) protected voidapplySkuBundleItemValueCriteria(List<org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FilterMapping> filterMappings, org.broadleafcommerce.openadmin.dto.CriteriaTransferObject cto, org.broadleafcommerce.openadmin.dto.PersistencePackage persistencePackage) Add filter restriction such that a ProductBundle cannot add its own default sku as a Sku Bundle Itemprotected voidassociateProductOptionValuesToSku(org.broadleafcommerce.openadmin.dto.Entity entity, org.broadleafcommerce.core.catalog.domain.Sku adminInstance, org.broadleafcommerce.openadmin.server.dao.DynamicEntityDao dynamicEntityDao) This initially removes all of the product option values that are currently related to the Sku and then re-associates theProductOptionValuesprotected BooleancanHandle(org.broadleafcommerce.openadmin.dto.PersistencePackage persistencePackage, org.broadleafcommerce.common.presentation.client.OperationType operationType) Since this is the default for all Skus, it's possible that we are providing custom criteria for this Sku lookup.canHandleAdd(org.broadleafcommerce.openadmin.dto.PersistencePackage persistencePackage) canHandleFetch(org.broadleafcommerce.openadmin.dto.PersistencePackage persistencePackage) canHandleInspect(org.broadleafcommerce.openadmin.dto.PersistencePackage persistencePackage) canHandleUpdate(org.broadleafcommerce.openadmin.dto.PersistencePackage persistencePackage) org.broadleafcommerce.openadmin.dto.FieldMetadatacreateConsolidatedOptionField(Class<?> inheritedFromType) Creates the metadata necessary for displaying all of the product option values in a single field.protected org.broadleafcommerce.openadmin.dto.FieldMetadatacreateExplicitEnumerationIndividualOptionField(org.broadleafcommerce.core.catalog.domain.ProductOption option, int order) org.broadleafcommerce.openadmin.dto.FieldMetadatacreateIndividualOptionField(org.broadleafcommerce.core.catalog.domain.ProductOption option, int order) Creates an individual property for the specified product option.protected org.broadleafcommerce.openadmin.dto.FieldMetadatacreateToOneIndividualOptionField(org.broadleafcommerce.core.catalog.domain.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.org.broadleafcommerce.openadmin.dto.DynamicResultSetfetch(org.broadleafcommerce.openadmin.dto.PersistencePackage persistencePackage, org.broadleafcommerce.openadmin.dto.CriteriaTransferObject cto, org.broadleafcommerce.openadmin.server.dao.DynamicEntityDao dynamicEntityDao, org.broadleafcommerce.openadmin.server.service.persistence.module.RecordHelper helper) protected voidfilterOutProductMetadata(Map<String, org.broadleafcommerce.openadmin.dto.FieldMetadata> map) org.broadleafcommerce.openadmin.dto.Propertyorg.broadleafcommerce.openadmin.dto.PropertygetConsolidatedOptionProperty(Collection<org.broadleafcommerce.core.catalog.domain.ProductOptionValue> values) Returns aPropertyfilled out with a delimited list of the values that are passed in.protected LonggetOwningProductBundlesDefaultSkuId(org.broadleafcommerce.openadmin.dto.SectionCrumb sectionCrumb) protected StringgetOwningProductId(org.broadleafcommerce.openadmin.dto.SectionCrumb[] sectionCrumbs) protected String[]getPolymorphicClasses(Class<?> clazz, jakarta.persistence.EntityManager em, boolean useCache) protected List<org.broadleafcommerce.openadmin.dto.Property>getProductOptionProperties(org.broadleafcommerce.openadmin.dto.Entity entity) org.broadleafcommerce.openadmin.dto.DynamicResultSetinspect(org.broadleafcommerce.openadmin.dto.PersistencePackage persistencePackage, org.broadleafcommerce.openadmin.server.dao.DynamicEntityDao dynamicEntityDao, org.broadleafcommerce.openadmin.server.service.persistence.module.InspectHelper helper) Build out the extra fields for the product optionsprotected booleanisSkuBundleItemLookup(org.broadleafcommerce.openadmin.dto.PersistencePackage pkg, org.broadleafcommerce.openadmin.dto.SectionCrumb[] sectionCrumbs) org.broadleafcommerce.openadmin.dto.Entityupdate(org.broadleafcommerce.openadmin.dto.PersistencePackage persistencePackage, org.broadleafcommerce.openadmin.server.dao.DynamicEntityDao dynamicEntityDao, org.broadleafcommerce.openadmin.server.service.persistence.module.RecordHelper helper) voidupdateProductOptionFieldsForFetch(List<Serializable> records, org.broadleafcommerce.openadmin.dto.Entity[] payload) Sets theProductOptionValues of the givenSkus in a list format for display in a ListGrid context.protected org.broadleafcommerce.openadmin.dto.EntityvalidateAvailableProductOption(org.broadleafcommerce.core.catalog.domain.Product product, List<org.broadleafcommerce.openadmin.dto.Property> productOptionProperties) Verify that all selected options are among the available product options.protected org.broadleafcommerce.openadmin.dto.EntityvalidateNotEmptyProductOptions(List<org.broadleafcommerce.openadmin.dto.Property> productOptionProperties) Verify that product options are not empty.protected org.broadleafcommerce.openadmin.dto.EntityvalidateNotNullProductOptions(List<org.broadleafcommerce.openadmin.dto.Property> productOptionProperties) Verify that none of the selected options is null.protected org.broadleafcommerce.openadmin.dto.EntityvalidateUniqueProductOptionValueCombination(org.broadleafcommerce.core.catalog.domain.Product product, List<org.broadleafcommerce.openadmin.dto.Property> productOptionProperties, org.broadleafcommerce.core.catalog.domain.Sku currentSku) Ensures that the given list ofProductOptionValueIDs 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
protected org.broadleafcommerce.openadmin.server.service.persistence.module.PersistenceModule adornedPersistenceModule -
extensionManager
-
catalogService
protected org.broadleafcommerce.core.catalog.service.CatalogService catalogService -
em
protected jakarta.persistence.EntityManager em -
criteriaTranslator
protected org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.CriteriaTranslator criteriaTranslator -
sandBoxHelper
protected org.broadleafcommerce.common.sandbox.SandBoxHelper sandBoxHelper
-
-
Constructor Details
-
SkuCustomPersistenceHandler
public SkuCustomPersistenceHandler()
-
-
Method Details
-
canHandleInspect
public Boolean canHandleInspect(org.broadleafcommerce.openadmin.dto.PersistencePackage persistencePackage) - Specified by:
canHandleInspectin interfaceorg.broadleafcommerce.openadmin.server.service.handler.CustomPersistenceHandler- Overrides:
canHandleInspectin classorg.broadleafcommerce.openadmin.server.service.handler.CustomPersistenceHandlerAdapter
-
canHandleFetch
public Boolean canHandleFetch(org.broadleafcommerce.openadmin.dto.PersistencePackage persistencePackage) - Specified by:
canHandleFetchin interfaceorg.broadleafcommerce.openadmin.server.service.handler.CustomPersistenceHandler- Overrides:
canHandleFetchin classorg.broadleafcommerce.openadmin.server.service.handler.CustomPersistenceHandlerAdapter
-
canHandleAdd
public Boolean canHandleAdd(org.broadleafcommerce.openadmin.dto.PersistencePackage persistencePackage) - Specified by:
canHandleAddin interfaceorg.broadleafcommerce.openadmin.server.service.handler.CustomPersistenceHandler- Overrides:
canHandleAddin classorg.broadleafcommerce.openadmin.server.service.handler.CustomPersistenceHandlerAdapter
-
canHandleUpdate
public Boolean canHandleUpdate(org.broadleafcommerce.openadmin.dto.PersistencePackage persistencePackage) - Specified by:
canHandleUpdatein interfaceorg.broadleafcommerce.openadmin.server.service.handler.CustomPersistenceHandler- Overrides:
canHandleUpdatein classorg.broadleafcommerce.openadmin.server.service.handler.CustomPersistenceHandlerAdapter
-
canHandle
protected Boolean canHandle(org.broadleafcommerce.openadmin.dto.PersistencePackage persistencePackage, org.broadleafcommerce.common.presentation.client.OperationType operationType) 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 org.broadleafcommerce.openadmin.dto.DynamicResultSet inspect(org.broadleafcommerce.openadmin.dto.PersistencePackage persistencePackage, org.broadleafcommerce.openadmin.server.dao.DynamicEntityDao dynamicEntityDao, org.broadleafcommerce.openadmin.server.service.persistence.module.InspectHelper helper) throws org.broadleafcommerce.common.exception.ServiceException Build out the extra fields for the product options- Specified by:
inspectin interfaceorg.broadleafcommerce.openadmin.server.service.handler.CustomPersistenceHandler- Overrides:
inspectin classorg.broadleafcommerce.openadmin.server.service.handler.CustomPersistenceHandlerAdapter- Throws:
org.broadleafcommerce.common.exception.ServiceException
-
getOwningProductId
protected String getOwningProductId(org.broadleafcommerce.openadmin.dto.SectionCrumb[] sectionCrumbs) -
filterOutProductMetadata
-
createConsolidatedOptionField
public org.broadleafcommerce.openadmin.dto.FieldMetadata createConsolidatedOptionField(Class<?> inheritedFromType) 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
public org.broadleafcommerce.openadmin.dto.Property getConsolidatedOptionProperty(Collection<org.broadleafcommerce.core.catalog.domain.ProductOptionValue> values) Returns aPropertyfilled 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 fetchedEntitydto.- Parameters:
values-- Returns:
-
getBlankConsolidatedOptionProperty
public org.broadleafcommerce.openadmin.dto.Property getBlankConsolidatedOptionProperty()- Returns:
- a blank
Propertycorresponding to the CONSOLIDATED_PRODUCT_OPTIONS_FIELD_NAME
-
createIndividualOptionField
public org.broadleafcommerce.openadmin.dto.FieldMetadata createIndividualOptionField(org.broadleafcommerce.core.catalog.domain.ProductOption option, int order) 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 org.broadleafcommerce.openadmin.dto.FieldMetadata createExplicitEnumerationIndividualOptionField(org.broadleafcommerce.core.catalog.domain.ProductOption option, int order) -
createToOneIndividualOptionField
protected org.broadleafcommerce.openadmin.dto.FieldMetadata createToOneIndividualOptionField(org.broadleafcommerce.core.catalog.domain.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.- Parameters:
option-order-- Returns:
-
fetch
public org.broadleafcommerce.openadmin.dto.DynamicResultSet fetch(org.broadleafcommerce.openadmin.dto.PersistencePackage persistencePackage, org.broadleafcommerce.openadmin.dto.CriteriaTransferObject cto, org.broadleafcommerce.openadmin.server.dao.DynamicEntityDao dynamicEntityDao, org.broadleafcommerce.openadmin.server.service.persistence.module.RecordHelper helper) throws org.broadleafcommerce.common.exception.ServiceException - Specified by:
fetchin interfaceorg.broadleafcommerce.openadmin.server.service.handler.CustomPersistenceHandler- Overrides:
fetchin classorg.broadleafcommerce.openadmin.server.service.handler.CustomPersistenceHandlerAdapter- Throws:
org.broadleafcommerce.common.exception.ServiceException
-
applyInventoryRestrictions
protected void applyInventoryRestrictions(List<org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FilterMapping> filterMappings, org.broadleafcommerce.openadmin.dto.CriteriaTransferObject cto, org.broadleafcommerce.openadmin.dto.PersistencePackage persistencePackage) -
updateProductOptionFieldsForFetch
public void updateProductOptionFieldsForFetch(List<Serializable> records, org.broadleafcommerce.openadmin.dto.Entity[] payload) Sets theProductOptionValues of the givenSkus in a list format for display in a ListGrid context.- Parameters:
records-payload-
-
applySkuBundleItemValueCriteria
protected void applySkuBundleItemValueCriteria(List<org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FilterMapping> filterMappings, org.broadleafcommerce.openadmin.dto.CriteriaTransferObject cto, org.broadleafcommerce.openadmin.dto.PersistencePackage persistencePackage) Add filter restriction such that a ProductBundle cannot add its own default sku as a Sku Bundle Item -
isSkuBundleItemLookup
protected boolean isSkuBundleItemLookup(org.broadleafcommerce.openadmin.dto.PersistencePackage pkg, org.broadleafcommerce.openadmin.dto.SectionCrumb[] sectionCrumbs) -
getOwningProductBundlesDefaultSkuId
protected Long getOwningProductBundlesDefaultSkuId(org.broadleafcommerce.openadmin.dto.SectionCrumb sectionCrumb) -
applyProductOptionValueCriteria
public void applyProductOptionValueCriteria(List<org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FilterMapping> filterMappings, org.broadleafcommerce.openadmin.dto.CriteriaTransferObject cto, org.broadleafcommerce.openadmin.dto.PersistencePackage persistencePackage, String skuPropertyPrefix) -
applyAdditionalFetchCriteria
public void applyAdditionalFetchCriteria(List<org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FilterMapping> filterMappings, org.broadleafcommerce.openadmin.dto.CriteriaTransferObject cto, org.broadleafcommerce.openadmin.dto.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 org.broadleafcommerce.openadmin.dto.Entity add(org.broadleafcommerce.openadmin.dto.PersistencePackage persistencePackage, org.broadleafcommerce.openadmin.server.dao.DynamicEntityDao dynamicEntityDao, org.broadleafcommerce.openadmin.server.service.persistence.module.RecordHelper helper) throws org.broadleafcommerce.common.exception.ServiceException - Specified by:
addin interfaceorg.broadleafcommerce.openadmin.server.service.handler.CustomPersistenceHandler- Overrides:
addin classorg.broadleafcommerce.openadmin.server.service.handler.CustomPersistenceHandlerAdapter- Throws:
org.broadleafcommerce.common.exception.ServiceException
-
update
public org.broadleafcommerce.openadmin.dto.Entity update(org.broadleafcommerce.openadmin.dto.PersistencePackage persistencePackage, org.broadleafcommerce.openadmin.server.dao.DynamicEntityDao dynamicEntityDao, org.broadleafcommerce.openadmin.server.service.persistence.module.RecordHelper helper) throws org.broadleafcommerce.common.exception.ServiceException - Specified by:
updatein interfaceorg.broadleafcommerce.openadmin.server.service.handler.CustomPersistenceHandler- Overrides:
updatein classorg.broadleafcommerce.openadmin.server.service.handler.CustomPersistenceHandlerAdapter- Throws:
org.broadleafcommerce.common.exception.ServiceException
-
getPolymorphicClasses
protected String[] getPolymorphicClasses(Class<?> clazz, jakarta.persistence.EntityManager em, boolean useCache) - Overrides:
getPolymorphicClassesin classorg.broadleafcommerce.openadmin.server.service.handler.CustomPersistenceHandlerAdapter
-
associateProductOptionValuesToSku
protected void associateProductOptionValuesToSku(org.broadleafcommerce.openadmin.dto.Entity entity, org.broadleafcommerce.core.catalog.domain.Sku adminInstance, org.broadleafcommerce.openadmin.server.dao.DynamicEntityDao dynamicEntityDao) This initially removes all of the product option values that are currently related to the Sku and then re-associates theProductOptionValues- Parameters:
entity-adminInstance-
-
validateAvailableProductOption
protected org.broadleafcommerce.openadmin.dto.Entity validateAvailableProductOption(org.broadleafcommerce.core.catalog.domain.Product product, List<org.broadleafcommerce.openadmin.dto.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
protected List<org.broadleafcommerce.openadmin.dto.Property> getProductOptionProperties(org.broadleafcommerce.openadmin.dto.Entity entity) -
validateUniqueProductOptionValueCombination
protected org.broadleafcommerce.openadmin.dto.Entity validateUniqueProductOptionValueCombination(org.broadleafcommerce.core.catalog.domain.Product product, List<org.broadleafcommerce.openadmin.dto.Property> productOptionProperties, org.broadleafcommerce.core.catalog.domain.Sku currentSku) Ensures that the given list ofProductOptionValueIDs is unique for the givenProduct.If sku browsing is enabled, then it is assumed that a single combination of
ProductOptionValueIDs is not unique and more than oneSkucould have the exact same combination ofProductOptionValueIDs. 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
protected org.broadleafcommerce.openadmin.dto.Entity validateNotNullProductOptions(List<org.broadleafcommerce.openadmin.dto.Property> productOptionProperties) 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
protected org.broadleafcommerce.openadmin.dto.Entity validateNotEmptyProductOptions(List<org.broadleafcommerce.openadmin.dto.Property> productOptionProperties) Verify that product options are not empty.- Parameters:
productOptionProperties- product Option properties- Returns:
- null if successfully validation, the error entity otherwise
-