org.broadleafcommerce.admin.server.service.handler
Class SkuCustomPersistenceHandler

java.lang.Object
  extended by org.broadleafcommerce.openadmin.server.service.handler.CustomPersistenceHandlerAdapter
      extended by org.broadleafcommerce.admin.server.service.handler.SkuCustomPersistenceHandler
All Implemented Interfaces:
CustomPersistenceHandler

public class SkuCustomPersistenceHandler
extends CustomPersistenceHandlerAdapter

Author:
Phillip Verheyden

Field Summary
protected  CatalogService catalogService
           
static String CONSOLIDATED_PRODUCT_OPTIONS_DELIMETER
           
static String CONSOLIDATED_PRODUCT_OPTIONS_FIELD_NAME
          This represents the field that all of the product option values will be stored in.
static String PRODUCT_OPTION_FIELD_PREFIX
           
 
Constructor Summary
SkuCustomPersistenceHandler()
           
 
Method Summary
 Entity add(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper)
           
 void applyAdditionalFetchCriteria(com.anasoft.os.daofusion.criteria.PersistentEntityCriteria queryCriteria, com.anasoft.os.daofusion.cto.client.CriteriaTransferObject cto, PersistencePackage persistencePackage)
          Available override point for subclasses if they would like to add additional criteria via the queryCritiera.
static void applyProductOptionValueCriteria(com.anasoft.os.daofusion.criteria.PersistentEntityCriteria queryCriteria, com.anasoft.os.daofusion.cto.client.CriteriaTransferObject cto, PersistencePackage persistencePackage, String skuPropertyPrefix)
           
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 the PrdouctOptionValues
protected  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.
 Boolean canHandleAdd(PersistencePackage persistencePackage)
           
 Boolean canHandleFetch(PersistencePackage persistencePackage)
           
 Boolean canHandleInspect(PersistencePackage persistencePackage)
           
 Boolean canHandleUpdate(PersistencePackage persistencePackage)
           
static FieldMetadata createConsolidatedOptionField(Class<?> inheritedFromType)
          Creates the metadata necessary for displaying all of the product option values in a single field.
static FieldMetadata createIndividualOptionField(ProductOption option, int order)
          Creates an individual property for the specified product option.
 DynamicResultSet fetch(PersistencePackage persistencePackage, com.anasoft.os.daofusion.cto.client.CriteriaTransferObject cto, DynamicEntityDao dynamicEntityDao, RecordHelper helper)
           
static Property getConsolidatedOptionProperty(List<ProductOptionValue> values)
          Returns a Property filled out with a delimited list of the values that are passed in.
protected  List<Property> getProductOptionProperties(Entity entity)
           
static org.hibernate.Criteria getSkuCriteria(com.anasoft.os.daofusion.criteria.PersistentEntityCriteria criteria, Class entityClass, DynamicEntityDao deDao, String skuPropertyPrefix)
          Returns the Hibernate criteria with the proper table aliases based on the PersistentEntityCriteria representation.
static String getStringValueFromGetter(String propertyName, Sku sku, RecordHelper helper)
          Under the covers this uses PropertyUtils to call the getter of the property name for the given Sku, then undergoes conversion according to the formatters from helper.
 DynamicResultSet inspect(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, InspectHelper helper)
          Build out the extra fields for the product options
 Entity update(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper)
           
protected  Entity validateUniqueProductOptionValueCombination(Product product, List<Property> productOptionProperties, Sku currentSku)
          Ensures that the given list of ProductOptionValue IDs is unique for the given Product
 
Methods inherited from class org.broadleafcommerce.openadmin.server.service.handler.CustomPersistenceHandlerAdapter
canHandleRemove, remove, willHandleSecurity
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PRODUCT_OPTION_FIELD_PREFIX

public static String PRODUCT_OPTION_FIELD_PREFIX

CONSOLIDATED_PRODUCT_OPTIONS_FIELD_NAME

public static String 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

public static String CONSOLIDATED_PRODUCT_OPTIONS_DELIMETER

catalogService

protected CatalogService catalogService
Constructor Detail

SkuCustomPersistenceHandler

public SkuCustomPersistenceHandler()
Method Detail

canHandleInspect

public Boolean canHandleInspect(PersistencePackage persistencePackage)
Specified by:
canHandleInspect in interface CustomPersistenceHandler
Overrides:
canHandleInspect in class CustomPersistenceHandlerAdapter

canHandleFetch

public Boolean canHandleFetch(PersistencePackage persistencePackage)
Specified by:
canHandleFetch in interface CustomPersistenceHandler
Overrides:
canHandleFetch in class CustomPersistenceHandlerAdapter

canHandleAdd

public Boolean canHandleAdd(PersistencePackage persistencePackage)
Specified by:
canHandleAdd in interface CustomPersistenceHandler
Overrides:
canHandleAdd in class CustomPersistenceHandlerAdapter

canHandleUpdate

public Boolean canHandleUpdate(PersistencePackage persistencePackage)
Specified by:
canHandleUpdate in interface CustomPersistenceHandler
Overrides:
canHandleUpdate in class CustomPersistenceHandlerAdapter

canHandle

protected 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. 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 interface CustomPersistenceHandler
Overrides:
inspect in class CustomPersistenceHandlerAdapter
Throws:
ServiceException

createConsolidatedOptionField

public static 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 static Property getConsolidatedOptionProperty(List<ProductOptionValue> values)
Returns a Property 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 fetched Entity dto.

Parameters:
values -
Returns:
See Also:
#createConsolidatedOptionField(Class)};

createIndividualOptionField

public static FieldMetadata createIndividualOptionField(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 SkuBasicClientEntityModule for your datasource.

Parameters:
option -
order -
Returns:

fetch

public DynamicResultSet fetch(PersistencePackage persistencePackage,
                              com.anasoft.os.daofusion.cto.client.CriteriaTransferObject cto,
                              DynamicEntityDao dynamicEntityDao,
                              RecordHelper helper)
                       throws ServiceException
Specified by:
fetch in interface CustomPersistenceHandler
Overrides:
fetch in class CustomPersistenceHandlerAdapter
Throws:
ServiceException

getSkuCriteria

public static org.hibernate.Criteria getSkuCriteria(com.anasoft.os.daofusion.criteria.PersistentEntityCriteria criteria,
                                                    Class entityClass,
                                                    DynamicEntityDao deDao,
                                                    String skuPropertyPrefix)
Returns the Hibernate criteria with the proper table aliases based on the PersistentEntityCriteria representation. Should be used in a fetch for both the row count criteria and actual fetch criteria. This will also apply the given CTO onto returned Hibernate criteria This can also be used if you are attempting to filter on an object that could contain a Sku 'ToOne' relationship that might need to be filtered on. For instance, InventoryImpl has a 'Sku' property called 'sku'. In this scenario, the skuPropertyPrefix would be 'sku'.

Returns:

getStringValueFromGetter

public static String getStringValueFromGetter(String propertyName,
                                              Sku sku,
                                              RecordHelper helper)
                                       throws IllegalAccessException,
                                              InvocationTargetException,
                                              NoSuchMethodException
Under the covers this uses PropertyUtils to call the getter of the property name for the given Sku, then undergoes conversion according to the formatters from helper. This also attempts to only get the first-level properties so it does not try to get values for things like 'sku.weight.weight', but only 'sku.weight'.

Parameters:
propertyName - - name of the property in relation to sku. Thus, if you are attempting to bring back the sku name, the propertyName should just be 'name' rather than 'sku.name'.
sku - the Sku instance to get the value from
helper - a RecordHelper to help convert decimals and dates to their string equivalents
Returns:
the String value from sku for propertyName
Throws:
NoSuchMethodException
InvocationTargetException
IllegalAccessException

applyProductOptionValueCriteria

public static void applyProductOptionValueCriteria(com.anasoft.os.daofusion.criteria.PersistentEntityCriteria queryCriteria,
                                                   com.anasoft.os.daofusion.cto.client.CriteriaTransferObject cto,
                                                   PersistencePackage persistencePackage,
                                                   String skuPropertyPrefix)

applyAdditionalFetchCriteria

public void applyAdditionalFetchCriteria(com.anasoft.os.daofusion.criteria.PersistentEntityCriteria queryCriteria,
                                         com.anasoft.os.daofusion.cto.client.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 interface CustomPersistenceHandler
Overrides:
add in class CustomPersistenceHandlerAdapter
Throws:
ServiceException

update

public Entity update(PersistencePackage persistencePackage,
                     DynamicEntityDao dynamicEntityDao,
                     RecordHelper helper)
              throws ServiceException
Specified by:
update in interface CustomPersistenceHandler
Overrides:
update in class CustomPersistenceHandlerAdapter
Throws:
ServiceException

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 the PrdouctOptionValues

Parameters:
entity -
adminInstance -

getProductOptionProperties

protected List<Property> getProductOptionProperties(Entity entity)

validateUniqueProductOptionValueCombination

protected Entity validateUniqueProductOptionValueCombination(Product product,
                                                             List<Property> productOptionProperties,
                                                             Sku currentSku)
Ensures that the given list of ProductOptionValue IDs is unique for the given Product

Parameters:
product -
productOptionValueIds -
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


Copyright © 2013. All Rights Reserved.