Search in sources :

Example 1 with ClassMetadata

use of org.broadleafcommerce.openadmin.dto.ClassMetadata 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 ClassMetadata

use of org.broadleafcommerce.openadmin.dto.ClassMetadata 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 ClassMetadata

use of org.broadleafcommerce.openadmin.dto.ClassMetadata in project BroadleafCommerce by BroadleafCommerce.

the class PageTemplateCustomPersistenceHandler method inspect.

@Override
public DynamicResultSet inspect(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, InspectHelper helper) throws ServiceException {
    String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
    try {
        List<FieldGroup> fieldGroups = getFieldGroups(persistencePackage, dynamicEntityDao);
        ClassMetadata metadata = new ClassMetadata();
        metadata.setCeilingType(PageTemplate.class.getName());
        ClassTree entities = new ClassTree(PageTemplateImpl.class.getName());
        metadata.setPolymorphicEntities(entities);
        Property[] properties = dynamicFieldUtil.buildDynamicPropertyList(fieldGroups, PageTemplate.class);
        metadata.setProperties(properties);
        DynamicResultSet results = new DynamicResultSet(metadata);
        return results;
    } catch (Exception e) {
        throw new ServiceException("Unable to perform inspect for entity: " + ceilingEntityFullyQualifiedClassname, e);
    }
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) ServiceException(org.broadleafcommerce.common.exception.ServiceException) FieldGroup(org.broadleafcommerce.cms.field.domain.FieldGroup) PageTemplate(org.broadleafcommerce.cms.page.domain.PageTemplate) ClassTree(org.broadleafcommerce.openadmin.dto.ClassTree) PageTemplateImpl(org.broadleafcommerce.cms.page.domain.PageTemplateImpl) Property(org.broadleafcommerce.openadmin.dto.Property) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) ServiceException(org.broadleafcommerce.common.exception.ServiceException) ValidationException(org.broadleafcommerce.openadmin.server.service.ValidationException)

Example 4 with ClassMetadata

use of org.broadleafcommerce.openadmin.dto.ClassMetadata 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 5 with ClassMetadata

use of org.broadleafcommerce.openadmin.dto.ClassMetadata in project BroadleafCommerce by BroadleafCommerce.

the class AdminProductController method showUpdateAdditionalSku.

protected String showUpdateAdditionalSku(HttpServletRequest request, Model model, String id, String collectionItemId, Map<String, String> pathVars, EntityForm entityForm) throws Exception {
    String collectionField = "additionalSkus";
    // Find out metadata for the additionalSkus property
    String mainClassName = getClassNameForSection(SECTION_KEY);
    List<SectionCrumb> sectionCrumbs = getSectionCrumbs(request, SECTION_KEY, id);
    ClassMetadata mainMetadata = service.getClassMetadata(getSectionPersistencePackageRequest(mainClassName, sectionCrumbs, pathVars)).getDynamicResultSet().getClassMetaData();
    Property collectionProperty = mainMetadata.getPMap().get(collectionField);
    FieldMetadata md = collectionProperty.getMetadata();
    // Find the metadata and the entity for the selected sku
    PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(md, sectionCrumbs).withCustomCriteria(new String[] { id });
    ClassMetadata collectionMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
    if (collectionMetadata.getCeilingType().equals(SkuImpl.class.getName())) {
        collectionMetadata.setCeilingType(Sku.class.getName());
    }
    Entity entity = service.getRecord(ppr, collectionItemId, collectionMetadata, true).getDynamicResultSet().getRecords()[0];
    String currentTabName = getCurrentTabName(pathVars, collectionMetadata);
    Map<String, DynamicResultSet> subRecordsMap = service.getRecordsForSelectedTab(collectionMetadata, entity, sectionCrumbs, currentTabName);
    if (entityForm == null) {
        entityForm = formService.createEntityForm(collectionMetadata, entity, subRecordsMap, sectionCrumbs);
    } else {
        entityForm.clearFieldsMap();
        formService.populateEntityForm(collectionMetadata, entity, subRecordsMap, entityForm, sectionCrumbs);
        // remove all the actions since we're not trying to redisplay them on the form
        entityForm.removeAllActions();
    }
    entityForm.removeAction(DefaultEntityFormActions.DELETE);
    // Ensure that operations on the Sku subcollections go to the proper URL
    for (ListGrid lg : entityForm.getAllListGrids()) {
        lg.setSectionKey("org.broadleafcommerce.core.catalog.domain.Sku");
        lg.setSectionCrumbs(sectionCrumbs);
    }
    model.addAttribute("entityForm", entityForm);
    model.addAttribute("viewType", "modal/simpleEditEntity");
    model.addAttribute("currentUrl", request.getRequestURL().toString());
    model.addAttribute("modalHeaderType", ModalHeaderType.UPDATE_COLLECTION_ITEM.getType());
    model.addAttribute("collectionProperty", collectionProperty);
    setModelAttributes(model, SECTION_KEY);
    return "modules/modalContainer";
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid) SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) Sku(org.broadleafcommerce.core.catalog.domain.Sku) Property(org.broadleafcommerce.openadmin.dto.Property) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet)

Aggregations

ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)52 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)36 SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)32 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)26 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)26 Property (org.broadleafcommerce.openadmin.dto.Property)25 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)22 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)21 Entity (org.broadleafcommerce.openadmin.dto.Entity)19 HashMap (java.util.HashMap)16 BasicCollectionMetadata (org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata)11 ListGrid (org.broadleafcommerce.openadmin.web.form.component.ListGrid)11 Map (java.util.Map)10 EntityForm (org.broadleafcommerce.openadmin.web.form.entity.EntityForm)10 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)9 ArrayList (java.util.ArrayList)8 AdornedTargetCollectionMetadata (org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)8 PersistenceResponse (org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse)8 MergedPropertyType (org.broadleafcommerce.openadmin.dto.MergedPropertyType)7 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)7