Search in sources :

Example 91 with Property

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

the class AdminEntityServiceImpl method getRequestForEntityForm.

public PersistencePackageRequest getRequestForEntityForm(EntityForm entityForm, String[] customCriteria, List<SectionCrumb> sectionCrumbs) {
    // Ensure the ID property is on the form
    Field idField = entityForm.findField(entityForm.getIdProperty());
    if (idField == null) {
        idField = new Field();
        idField.setName(entityForm.getIdProperty());
        idField.setValue(entityForm.getId());
        entityForm.getFields().put(entityForm.getIdProperty(), idField);
    } else {
        idField.setValue(entityForm.getId());
    }
    List<Property> propList = getPropertiesFromEntityForm(entityForm);
    Property[] properties = new Property[propList.size()];
    properties = propList.toArray(properties);
    Entity entity = new Entity();
    entity.setProperties(properties);
    String entityType = entityForm.getEntityType();
    if (StringUtils.isEmpty(entityType)) {
        entityType = entityForm.getCeilingEntityClassname();
    }
    entity.setType(new String[] { entityType });
    PersistencePackageRequest ppr = PersistencePackageRequest.standard().withEntity(entity).withCustomCriteria(customCriteria).withCeilingEntityClassname(entityForm.getCeilingEntityClassname()).withSectionCrumbs(sectionCrumbs).withRequestingEntityName(entityForm.getMainEntityName());
    return ppr;
}
Also used : Field(org.broadleafcommerce.openadmin.web.form.entity.Field) AdminMainEntity(org.broadleafcommerce.common.admin.domain.AdminMainEntity) Entity(org.broadleafcommerce.openadmin.dto.Entity) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) BLCSystemProperty(org.broadleafcommerce.common.util.BLCSystemProperty) Property(org.broadleafcommerce.openadmin.dto.Property)

Example 92 with Property

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

the class DynamicEntityRemoteService method cleanEntity.

protected void cleanEntity(Entity entity) throws ServiceException {
    Property currentProperty = null;
    try {
        for (Property property : entity.getProperties()) {
            currentProperty = property;
            property.setRawValue(property.getValue());
            property.setValue(exploitProtectionService.cleanStringWithResults(property.getValue()));
            property.setUnHtmlEncodedValue(StringEscapeUtils.unescapeHtml(property.getValue()));
        }
    } catch (CleanStringException e) {
        StringBuilder sb = new StringBuilder();
        for (int j = 0; j < e.getCleanResults().getNumberOfErrors(); j++) {
            sb.append("\n");
            sb.append(j + 1);
            sb.append(") ");
            sb.append((String) e.getCleanResults().getErrorMessages().get(j));
            sb.append("\n");
        }
        sb.append("\nNote - Antisamy policy in effect. Set a new policy file to modify validation behavior/strictness.");
        entity.addValidationError(currentProperty.getName(), sb.toString());
    }
}
Also used : CleanStringException(org.broadleafcommerce.common.security.service.CleanStringException) Property(org.broadleafcommerce.openadmin.dto.Property)

Example 93 with Property

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

the class PageTemplateCustomPersistenceHandler method processIncludeId.

protected void processIncludeId(boolean includeId, Page page, List<Property> propertiesList) {
    if (includeId) {
        Property property = new Property();
        propertiesList.add(property);
        property.setName("id");
        property.setValue(String.valueOf(page.getId()));
    }
}
Also used : Property(org.broadleafcommerce.openadmin.dto.Property)

Example 94 with Property

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

the class PageTemplateCustomPersistenceHandler method addOrUpdate.

protected Entity addOrUpdate(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
    try {
        String pageId = persistencePackage.getCustomCriteria()[1];
        if (StringUtils.isBlank(pageId)) {
            return persistencePackage.getEntity();
        }
        Page page = pageService.findPageById(Long.valueOf(pageId));
        Property[] properties = dynamicFieldUtil.buildDynamicPropertyList(getFieldGroups(page, null), PageTemplate.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(), "Page dynamic fields failed validation");
        }
        List<String> templateFieldNames = new ArrayList<String>(20);
        for (FieldGroup group : getFieldGroups(page, null)) {
            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, PageField> pageFieldMap = page.getPageFields();
        for (Property property : persistencePackage.getEntity().getProperties()) {
            if (property.getEnabled() && templateFieldNames.contains(property.getName())) {
                PageField pageField = pageFieldMap.get(property.getName());
                if (pageField != null) {
                    boolean isDirty = (pageField.getValue() == null && property.getValue() != null) || (pageField.getValue() != null && property.getValue() == null);
                    if (isDirty || (pageField.getValue() != null && property.getValue() != null && !pageField.getValue().trim().equals(property.getValue().trim()))) {
                        dirtyFields.add(property.getName());
                        dirtyFieldsOrigVals.put(property.getName(), pageField.getValue());
                        pageField.setValue(property.getValue());
                        pageField = dynamicEntityDao.merge(pageField);
                    }
                } else {
                    pageField = new PageFieldImpl();
                    pageField.setFieldKey(property.getName());
                    pageField.setValue(property.getValue());
                    pageField.setPage(page);
                    dynamicEntityDao.persist(pageField);
                    dirtyFields.add(property.getName());
                }
            }
        }
        List<String> removeItems = new ArrayList<String>();
        for (String key : pageFieldMap.keySet()) {
            if (persistencePackage.getEntity().findProperty(key) == null) {
                removeItems.add(key);
            }
        }
        if (removeItems.size() > 0) {
            for (String removeKey : removeItems) {
                pageFieldMap.remove(removeKey);
            }
        }
        Collections.sort(dirtyFields);
        Entity entity = fetchEntityBasedOnId(pageId, dirtyFields);
        for (Map.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 update for entity: " + ceilingEntityFullyQualifiedClassname, e);
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) AdminMainEntity(org.broadleafcommerce.common.admin.domain.AdminMainEntity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) ValidationException(org.broadleafcommerce.openadmin.server.service.ValidationException) HashMap(java.util.HashMap) FieldGroup(org.broadleafcommerce.cms.field.domain.FieldGroup) FieldDefinition(org.broadleafcommerce.cms.field.domain.FieldDefinition) ArrayList(java.util.ArrayList) Page(org.broadleafcommerce.cms.page.domain.Page) ServiceException(org.broadleafcommerce.common.exception.ServiceException) ValidationException(org.broadleafcommerce.openadmin.server.service.ValidationException) PageField(org.broadleafcommerce.cms.page.domain.PageField) ServiceException(org.broadleafcommerce.common.exception.ServiceException) Property(org.broadleafcommerce.openadmin.dto.Property) HashMap(java.util.HashMap) Map(java.util.Map) PageFieldImpl(org.broadleafcommerce.cms.page.domain.PageFieldImpl)

Example 95 with Property

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

the class PageTemplateCustomPersistenceHandler method processFieldGroups.

protected void processFieldGroups(List<String> dirtyFields, Map<String, PageField> pageFieldMap, List<Property> propertiesList, List<FieldGroup> fieldGroups) {
    for (FieldGroup fieldGroup : fieldGroups) {
        for (FieldDefinition def : fieldGroup.getFieldDefinitions()) {
            Property property = new Property();
            propertiesList.add(property);
            property.setName(def.getName());
            String value = null;
            if (!MapUtils.isEmpty(pageFieldMap)) {
                PageField pageField = pageFieldMap.get(def.getName());
                if (pageField == null) {
                    value = "";
                } else {
                    value = pageField.getValue();
                }
            }
            property.setValue(value);
            if (!CollectionUtils.isEmpty(dirtyFields) && dirtyFields.contains(property.getName())) {
                property.setIsDirty(true);
            }
            if (StringUtils.isNotBlank(def.getAdditionalForeignKeyClass())) {
                property.getMetadata().setOwningClass(def.getAdditionalForeignKeyClass());
            }
        }
    }
}
Also used : PageField(org.broadleafcommerce.cms.page.domain.PageField) FieldGroup(org.broadleafcommerce.cms.field.domain.FieldGroup) FieldDefinition(org.broadleafcommerce.cms.field.domain.FieldDefinition) Property(org.broadleafcommerce.openadmin.dto.Property)

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