Search in sources :

Example 1 with MergedPropertyType

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);
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) MergedPropertyType(org.broadleafcommerce.openadmin.dto.MergedPropertyType)

Example 2 with MergedPropertyType

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;
    }
}
Also used : ProductOption(org.broadleafcommerce.core.catalog.domain.ProductOption) ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) HashMap(java.util.HashMap) Product(org.broadleafcommerce.core.catalog.domain.Product) MergedPropertyType(org.broadleafcommerce.openadmin.dto.MergedPropertyType) ServiceException(org.broadleafcommerce.common.exception.ServiceException) SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) Map(java.util.Map) HashMap(java.util.HashMap) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet)

Example 3 with MergedPropertyType

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;
    }
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) ServiceException(org.broadleafcommerce.common.exception.ServiceException) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) MergedPropertyType(org.broadleafcommerce.openadmin.dto.MergedPropertyType) ServiceException(org.broadleafcommerce.common.exception.ServiceException)

Example 4 with MergedPropertyType

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));
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) HashMap(java.util.HashMap) CustomPersistenceHandler(org.broadleafcommerce.openadmin.server.service.handler.CustomPersistenceHandler) PersistenceModule(org.broadleafcommerce.openadmin.server.service.persistence.module.PersistenceModule) MergedPropertyType(org.broadleafcommerce.openadmin.dto.MergedPropertyType) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with MergedPropertyType

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();
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) PersistenceManager(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceManager) HashMap(java.util.HashMap) MergedPropertyType(org.broadleafcommerce.openadmin.dto.MergedPropertyType) ServiceException(org.broadleafcommerce.common.exception.ServiceException) HashMap(java.util.HashMap) Map(java.util.Map) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet)

Aggregations

MergedPropertyType (org.broadleafcommerce.openadmin.dto.MergedPropertyType)10 HashMap (java.util.HashMap)9 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)9 Map (java.util.Map)8 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)7 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)7 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)6 ServiceException (org.broadleafcommerce.common.exception.ServiceException)4 PersistencePerspective (org.broadleafcommerce.openadmin.dto.PersistencePerspective)4 ArrayList (java.util.ArrayList)3 PersistencePerspectiveItemType (org.broadleafcommerce.common.presentation.client.PersistencePerspectiveItemType)3 SupportedFieldType (org.broadleafcommerce.common.presentation.client.SupportedFieldType)3 ComponentType (org.hibernate.type.ComponentType)3 Type (org.hibernate.type.Type)3 Field (java.lang.reflect.Field)2 Iterator (java.util.Iterator)2 PersistentClass (org.hibernate.mapping.PersistentClass)2 Property (org.hibernate.mapping.Property)2 Method (java.lang.reflect.Method)1 Comparator (java.util.Comparator)1