use of org.broadleafcommerce.openadmin.dto.MergedPropertyType in project BroadleafCommerce by BroadleafCommerce.
the class OfferCustomPersistenceHandler method inspect.
@Override
public DynamicResultSet inspect(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, InspectHelper helper) throws ServiceException {
Class ceilingEntityClass = getClassForName(persistencePackage.getCeilingEntityFullyQualifiedClassname());
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
Map<MergedPropertyType, Map<String, FieldMetadata>> allMergedProperties = new HashMap<MergedPropertyType, Map<String, FieldMetadata>>();
// retrieve the default properties for WorkflowEvents
Map<String, FieldMetadata> properties = helper.getSimpleMergedProperties(ceilingEntityClass.getCanonicalName(), persistencePerspective);
properties.put(SHOW_ADVANCED_VISIBILITY_OPTIONS, buildAdvancedVisibilityOptionsFieldMetaData());
properties.put(QUALIFIERS_CAN_BE_QUALIFIERS, buildQualifiersCanBeQualifiersFieldMetaData());
properties.put(QUALIFIERS_CAN_BE_TARGETS, buildQualifiersCanBeTargetsFieldMetaData());
properties.put(STACKABLE, buildStackableFieldMetaData());
if (isActiveFilter) {
properties.put(IS_ACTIVE, buildIsActiveFieldMetaData());
}
allMergedProperties.put(MergedPropertyType.PRIMARY, properties);
Class<?>[] entityClasses = dynamicEntityDao.getAllPolymorphicEntitiesFromCeiling(ceilingEntityClass);
ClassMetadata mergedMetadata = helper.buildClassMetadata(entityClasses, persistencePackage, allMergedProperties);
return new DynamicResultSet(mergedMetadata, null, null);
}
use of org.broadleafcommerce.openadmin.dto.MergedPropertyType in project BroadleafCommerce by BroadleafCommerce.
the class SkuCustomPersistenceHandler method inspect.
/**
* Build out the extra fields for the product options
*/
@Override
public DynamicResultSet inspect(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, InspectHelper helper) throws ServiceException {
try {
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
Map<MergedPropertyType, Map<String, FieldMetadata>> allMergedProperties = new HashMap<>();
String productIdStr = null;
if (persistencePackage.getCustomCriteria() != null && persistencePackage.getCustomCriteria().length > 0) {
productIdStr = persistencePackage.getCustomCriteria()[0];
}
String cacheKey = skuMetadataCacheService.buildCacheKey(productIdStr);
Map<String, FieldMetadata> properties = null;
boolean useCache = skuMetadataCacheService.useCache();
if (useCache) {
properties = skuMetadataCacheService.getFromCache(cacheKey);
}
if (properties == null) {
// Grab the default properties for the Sku
properties = helper.getSimpleMergedProperties(SkuImpl.class.getName(), persistencePerspective);
boolean isFirstCriteriaNAN = persistencePackage.getCustomCriteria() == null || persistencePackage.getCustomCriteria().length == 0;
if (!isFirstCriteriaNAN && useToOneLookupSkuProductOptionValue) {
isFirstCriteriaNAN = !DIGIT.matchesAllOf(persistencePackage.getCustomCriteria()[0]);
}
if (isFirstCriteriaNAN) {
// look up all the ProductOptions and then create new fields for each of them
List<ProductOption> options = catalogService.readAllProductOptions();
int order = 0;
for (ProductOption option : options) {
// add this to the built Sku properties
FieldMetadata md = createIndividualOptionField(option, order);
if (md != null) {
properties.put("productOption" + option.getId(), md);
}
}
} else {
// If we have a product to filter the list of available product options, then use it
try {
Long productId = Long.parseLong(persistencePackage.getCustomCriteria()[0]);
Product product = catalogService.findProductById(productId);
for (ProductOption option : product.getProductOptions()) {
FieldMetadata md = createIndividualOptionField(option, 0);
if (md != null) {
properties.put("productOption" + option.getId(), md);
}
}
} catch (NumberFormatException e) {
// the criteria wasn't a product id, just don't do anything
}
}
// also build the consolidated field; if using the SkuBasicClientEntityModule then this field will be
// permanently hidden
properties.put(CONSOLIDATED_PRODUCT_OPTIONS_FIELD_NAME, createConsolidatedOptionField(SkuImpl.class));
if (useCache) {
skuMetadataCacheService.addToCache(cacheKey, properties);
}
}
allMergedProperties.put(MergedPropertyType.PRIMARY, properties);
// allow the adorned list to contribute properties as well in the case of Sku bundle items
adornedPersistenceModule.setPersistenceManager((PersistenceManager) helper);
adornedPersistenceModule.updateMergedProperties(persistencePackage, allMergedProperties);
Class<?>[] entityClasses = dynamicEntityDao.getAllPolymorphicEntitiesFromCeiling(SkuImpl.class);
for (Map.Entry<MergedPropertyType, Map<String, FieldMetadata>> entry : allMergedProperties.entrySet()) {
filterOutProductMetadata(entry.getValue());
}
ClassMetadata mergedMetadata = helper.buildClassMetadata(entityClasses, persistencePackage, allMergedProperties);
DynamicResultSet results = new DynamicResultSet(mergedMetadata, null, null);
return results;
} catch (Exception e) {
ServiceException ex = new ServiceException("Unable to retrieve inspection results for " + persistencePackage.getCeilingEntityFullyQualifiedClassname(), e);
throw ex;
}
}
use of org.broadleafcommerce.openadmin.dto.MergedPropertyType in project BroadleafCommerce by BroadleafCommerce.
the class TimeDTOCustomPersistenceHandler method inspect.
@Override
public DynamicResultSet inspect(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, InspectHelper helper) throws ServiceException {
String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
try {
Map<MergedPropertyType, Map<String, FieldMetadata>> allMergedProperties = new HashMap<MergedPropertyType, Map<String, FieldMetadata>>();
Map<String, FieldMetadata> mergedProperties = dynamicEntityDao.getSimpleMergedProperties(ceilingEntityFullyQualifiedClassname, persistencePackage.getPersistencePerspective());
allMergedProperties.put(MergedPropertyType.PRIMARY, mergedProperties);
ClassMetadata mergedMetadata = helper.buildClassMetadata(new Class<?>[] { Class.forName(ceilingEntityFullyQualifiedClassname) }, persistencePackage, allMergedProperties);
DynamicResultSet results = new DynamicResultSet(mergedMetadata);
return results;
} catch (Exception e) {
ServiceException ex = new ServiceException("Unable to retrieve inspection results for " + persistencePackage.getCeilingEntityFullyQualifiedClassname(), e);
throw ex;
}
}
use of org.broadleafcommerce.openadmin.dto.MergedPropertyType in project BroadleafCommerce by BroadleafCommerce.
the class PersistenceManagerImpl method inspect.
@Override
public PersistenceResponse inspect(PersistencePackage persistencePackage) throws ServiceException, ClassNotFoundException {
for (PersistenceManagerEventHandler handler : persistenceManagerEventHandlers) {
PersistenceManagerEventHandlerResponse response = handler.preInspect(this, persistencePackage);
if (PersistenceManagerEventHandlerResponse.PersistenceManagerEventHandlerResponseStatus.HANDLED_BREAK == response.getStatus()) {
break;
}
}
// check to see if there is a custom handler registered
for (CustomPersistenceHandler handler : getCustomPersistenceHandlers()) {
if (handler.canHandleInspect(persistencePackage)) {
if (!handler.willHandleSecurity(persistencePackage)) {
adminRemoteSecurityService.securityCheck(persistencePackage, EntityOperationType.INSPECT);
}
DynamicResultSet results = handler.inspect(persistencePackage, dynamicEntityDao, this);
return executePostInspectHandlers(persistencePackage, new PersistenceResponse().withDynamicResultSet(results));
}
}
adminRemoteSecurityService.securityCheck(persistencePackage, EntityOperationType.INSPECT);
Class<?>[] entities = getPolymorphicEntities(persistencePackage.getCeilingEntityFullyQualifiedClassname());
Map<MergedPropertyType, Map<String, FieldMetadata>> allMergedProperties = new HashMap<>();
for (PersistenceModule module : modules) {
module.updateMergedProperties(persistencePackage, allMergedProperties);
}
ClassMetadata classMetadata = buildClassMetadata(entities, persistencePackage, allMergedProperties);
DynamicResultSet results = new DynamicResultSet(classMetadata);
return executePostInspectHandlers(persistencePackage, new PersistenceResponse().withDynamicResultSet(results));
}
use of org.broadleafcommerce.openadmin.dto.MergedPropertyType in project BroadleafCommerce by BroadleafCommerce.
the class CustomPersistenceHandlerAdapter method getResultSet.
/**
* This is a helper method that can be invoked as the last step in a custom inspect phase. It will assemble the
* appropriate DynamicResultSet from the given parameters.
*/
protected DynamicResultSet getResultSet(PersistencePackage persistencePackage, InspectHelper helper, Map<String, FieldMetadata> metadata) throws ServiceException {
String entityName = persistencePackage.getCeilingEntityFullyQualifiedClassname();
try {
if (helper instanceof PersistenceManager) {
Class<?>[] entities = ((PersistenceManager) helper).getPolymorphicEntities(entityName);
Map<MergedPropertyType, Map<String, FieldMetadata>> allMergedProperties = new HashMap<MergedPropertyType, Map<String, FieldMetadata>>();
allMergedProperties.put(MergedPropertyType.PRIMARY, metadata);
ClassMetadata mergedMetadata = helper.buildClassMetadata(entities, persistencePackage, allMergedProperties);
DynamicResultSet results = new DynamicResultSet(mergedMetadata);
return results;
}
} catch (ClassNotFoundException e) {
throw new ServiceException(e);
}
return new DynamicResultSet();
}
Aggregations