Search in sources :

Example 21 with Property

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

the class SkuCustomPersistenceHandler method associateProductOptionValuesToSku.

/**
 * This initially removes all of the product option values that are currently related to the Sku and then re-associates
 * the {@link ProductOptionValue}s
 * @param entity
 * @param adminInstance
 */
protected void associateProductOptionValuesToSku(Entity entity, Sku adminInstance, DynamicEntityDao dynamicEntityDao) {
    // Get the list of product option value ids that were selected from the form
    List<Long> productOptionValueIds = new ArrayList<>();
    for (Property property : getProductOptionProperties(entity)) {
        Long propId = Long.parseLong(property.getValue());
        productOptionValueIds.add(propId);
        property.setIsDirty(true);
    }
    // Only process associations if product option value changes came in via the form
    if (CollectionUtils.isNotEmpty(productOptionValueIds)) {
        // remove the current list of product option values from the Sku
        if (adminInstance.getProductOptionValueXrefs().size() > 0) {
            Iterator<SkuProductOptionValueXref> iterator = adminInstance.getProductOptionValueXrefs().iterator();
            while (iterator.hasNext()) {
                dynamicEntityDao.remove(iterator.next());
            }
            dynamicEntityDao.merge(adminInstance);
        }
        // Associate the product option values from the form with the Sku
        for (Long id : productOptionValueIds) {
            // Simply find the changed ProductOptionValues directly - seems to work better with sandboxing code
            ProductOptionValue pov = (ProductOptionValue) dynamicEntityDao.find(ProductOptionValueImpl.class, id);
            SkuProductOptionValueXref xref = new SkuProductOptionValueXrefImpl(adminInstance, pov);
            xref = dynamicEntityDao.merge(xref);
            adminInstance.getProductOptionValueXrefs().add(xref);
        }
    }
}
Also used : SkuProductOptionValueXref(org.broadleafcommerce.core.catalog.domain.SkuProductOptionValueXref) ProductOptionValue(org.broadleafcommerce.core.catalog.domain.ProductOptionValue) ArrayList(java.util.ArrayList) SkuProductOptionValueXrefImpl(org.broadleafcommerce.core.catalog.domain.SkuProductOptionValueXrefImpl) Property(org.broadleafcommerce.openadmin.dto.Property) ProductOptionValueImpl(org.broadleafcommerce.core.catalog.domain.ProductOptionValueImpl)

Example 22 with Property

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

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

the class PageTemplateCustomPersistenceHandler method fetchDynamicEntity.

@Override
public Entity fetchDynamicEntity(Serializable root, List<String> dirtyFields, boolean includeId) throws Exception {
    Page page = (Page) root;
    Map<String, PageField> pageFieldMap = page.getPageFields();
    Entity entity = new Entity();
    entity.setType(new String[] { PageTemplateImpl.class.getName() });
    List<Property> propertiesList = new ArrayList<Property>();
    List<FieldGroup> fieldGroups = getFieldGroups(page, null);
    processFieldGroups(dirtyFields, pageFieldMap, propertiesList, fieldGroups);
    processIncludeId(includeId, page, propertiesList);
    entity.setProperties(propertiesList.toArray(new Property[] {}));
    return entity;
}
Also used : PageField(org.broadleafcommerce.cms.page.domain.PageField) Entity(org.broadleafcommerce.openadmin.dto.Entity) AdminMainEntity(org.broadleafcommerce.common.admin.domain.AdminMainEntity) FieldGroup(org.broadleafcommerce.cms.field.domain.FieldGroup) ArrayList(java.util.ArrayList) PageTemplateImpl(org.broadleafcommerce.cms.page.domain.PageTemplateImpl) Page(org.broadleafcommerce.cms.page.domain.Page) Property(org.broadleafcommerce.openadmin.dto.Property)

Example 24 with Property

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

the class StructuredContentTypeCustomPersistenceHandler method fetchDynamicEntity.

@Override
public Entity fetchDynamicEntity(Serializable root, List<String> dirtyFields, boolean includeId) throws Exception {
    StructuredContent structuredContent = (StructuredContent) root;
    Map<String, StructuredContentFieldXref> structuredContentFieldMap = structuredContent.getStructuredContentFieldXrefs();
    Entity entity = new Entity();
    entity.setType(new String[] { StructuredContentType.class.getName() });
    List<Property> propertiesList = new ArrayList<Property>();
    for (FieldGroup fieldGroup : structuredContent.getStructuredContentType().getStructuredContentFieldTemplate().getFieldGroups()) {
        for (FieldDefinition def : fieldGroup.getFieldDefinitions()) {
            Property property = new Property();
            property.setName(def.getName());
            String value = null;
            if (!MapUtils.isEmpty(structuredContentFieldMap)) {
                StructuredContentFieldXref structuredContentFieldXref = structuredContentFieldMap.get(def.getName());
                if (structuredContentFieldXref != null) {
                    StructuredContentField structuredContentField = structuredContentFieldXref.getStructuredContentField();
                    if (structuredContentField != null) {
                        value = structuredContentField.getValue();
                    }
                }
            }
            property.setValue(value);
            if (!CollectionUtils.isEmpty(dirtyFields) && dirtyFields.contains(property.getName())) {
                property.setIsDirty(true);
            }
            propertiesList.add(property);
        }
    }
    if (includeId) {
        Property property = new Property();
        propertiesList.add(property);
        property.setName("id");
        property.setValue(String.valueOf(structuredContent.getId()));
    }
    entity.setProperties(propertiesList.toArray(new Property[] {}));
    return entity;
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldGroup(org.broadleafcommerce.cms.field.domain.FieldGroup) StructuredContentField(org.broadleafcommerce.cms.structure.domain.StructuredContentField) FieldDefinition(org.broadleafcommerce.cms.field.domain.FieldDefinition) ArrayList(java.util.ArrayList) StructuredContentType(org.broadleafcommerce.cms.structure.domain.StructuredContentType) StructuredContentFieldXref(org.broadleafcommerce.cms.structure.domain.StructuredContentFieldXref) Property(org.broadleafcommerce.openadmin.dto.Property) StructuredContent(org.broadleafcommerce.cms.structure.domain.StructuredContent)

Example 25 with Property

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

the class StructuredContentTypeCustomPersistenceHandler method addOrUpdate.

protected Entity addOrUpdate(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
    try {
        String structuredContentId = persistencePackage.getCustomCriteria()[1];
        StructuredContent structuredContent = structuredContentService.findStructuredContentById(Long.valueOf(structuredContentId));
        Property[] properties = dynamicFieldUtil.buildDynamicPropertyList(structuredContent.getStructuredContentType().getStructuredContentFieldTemplate().getFieldGroups(), StructuredContentType.class);
        Map<String, FieldMetadata> md = new HashMap<String, FieldMetadata>();
        for (Property property : properties) {
            md.put(property.getName(), property.getMetadata());
        }
        boolean validated = helper.validate(persistencePackage.getEntity(), null, md);
        if (!validated) {
            throw new ValidationException(persistencePackage.getEntity(), "Structured Content dynamic fields failed validation");
        }
        List<String> templateFieldNames = new ArrayList<String>(20);
        for (FieldGroup group : structuredContent.getStructuredContentType().getStructuredContentFieldTemplate().getFieldGroups()) {
            for (FieldDefinition def : group.getFieldDefinitions()) {
                templateFieldNames.add(def.getName());
            }
        }
        Map<String, String> dirtyFieldsOrigVals = new HashMap<String, String>();
        List<String> dirtyFields = new ArrayList<String>();
        Map<String, StructuredContentFieldXref> structuredContentFieldMap = structuredContent.getStructuredContentFieldXrefs();
        for (Property property : persistencePackage.getEntity().getProperties()) {
            if (property.getEnabled() && templateFieldNames.contains(property.getName())) {
                StructuredContentFieldXref scXref = structuredContentFieldMap.get(property.getName());
                if (scXref != null && scXref.getStructuredContentField() != null) {
                    StructuredContentField structuredContentField = scXref.getStructuredContentField();
                    boolean isDirty = (structuredContentField.getValue() == null && property.getValue() != null) || (structuredContentField.getValue() != null && property.getValue() == null);
                    if (isDirty || (structuredContentField.getValue() != null && property.getValue() != null && !structuredContentField.getValue().trim().equals(property.getValue().trim()))) {
                        dirtyFields.add(property.getName());
                        dirtyFieldsOrigVals.put(property.getName(), structuredContentField.getValue());
                        structuredContentField.setValue(property.getValue());
                        scXref = dynamicEntityDao.merge(scXref);
                    }
                } else {
                    StructuredContentField structuredContentField = new StructuredContentFieldImpl();
                    structuredContentField.setFieldKey(property.getName());
                    structuredContentField.setValue(property.getValue());
                    StructuredContentFieldXref scfx = new StructuredContentFieldXrefImpl();
                    scfx.setStructuredContent(structuredContent);
                    scfx.setKey(property.getName());
                    scfx.setStrucuturedContentField(structuredContentField);
                    scfx = dynamicEntityDao.persist(scfx);
                    dirtyFields.add(property.getName());
                }
            }
        }
        List<String> removeItems = new ArrayList<String>();
        for (String key : structuredContentFieldMap.keySet()) {
            if (persistencePackage.getEntity().findProperty(key) == null) {
                removeItems.add(key);
            }
        }
        if (removeItems.size() > 0) {
            for (String removeKey : removeItems) {
                structuredContentFieldMap.remove(removeKey);
            }
        }
        Collections.sort(dirtyFields);
        Entity entity = fetchEntityBasedOnId(structuredContentId, dirtyFields);
        for (Entry<String, String> entry : dirtyFieldsOrigVals.entrySet()) {
            entity.getPMap().get(entry.getKey()).setOriginalValue(entry.getValue());
            entity.getPMap().get(entry.getKey()).setOriginalDisplayValue(entry.getValue());
        }
        return entity;
    } catch (ValidationException e) {
        throw e;
    } catch (Exception e) {
        throw new ServiceException("Unable to perform fetch for entity: " + ceilingEntityFullyQualifiedClassname, e);
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) ValidationException(org.broadleafcommerce.openadmin.server.service.ValidationException) StructuredContentFieldXrefImpl(org.broadleafcommerce.cms.structure.domain.StructuredContentFieldXrefImpl) HashMap(java.util.HashMap) FieldGroup(org.broadleafcommerce.cms.field.domain.FieldGroup) FieldDefinition(org.broadleafcommerce.cms.field.domain.FieldDefinition) ArrayList(java.util.ArrayList) ServiceException(org.broadleafcommerce.common.exception.ServiceException) ValidationException(org.broadleafcommerce.openadmin.server.service.ValidationException) StructuredContent(org.broadleafcommerce.cms.structure.domain.StructuredContent) ServiceException(org.broadleafcommerce.common.exception.ServiceException) StructuredContentField(org.broadleafcommerce.cms.structure.domain.StructuredContentField) StructuredContentFieldXref(org.broadleafcommerce.cms.structure.domain.StructuredContentFieldXref) Property(org.broadleafcommerce.openadmin.dto.Property) StructuredContentFieldImpl(org.broadleafcommerce.cms.structure.domain.StructuredContentFieldImpl)

Aggregations

Property (org.broadleafcommerce.openadmin.dto.Property)120 Entity (org.broadleafcommerce.openadmin.dto.Entity)62 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)45 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)38 ArrayList (java.util.ArrayList)28 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)26 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)25 DataWrapper (org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper)21 SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)19 HashMap (java.util.HashMap)18 AdminMainEntity (org.broadleafcommerce.common.admin.domain.AdminMainEntity)18 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)16 Map (java.util.Map)15 ServiceException (org.broadleafcommerce.common.exception.ServiceException)15 BasicCollectionMetadata (org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata)15 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)15 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14 AdornedTargetCollectionMetadata (org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)13 RuleBuilderField (org.broadleafcommerce.openadmin.web.form.component.RuleBuilderField)12 ComboField (org.broadleafcommerce.openadmin.web.form.entity.ComboField)12