Search in sources :

Example 6 with FieldDefinition

use of org.broadleafcommerce.cms.field.domain.FieldDefinition 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)

Example 7 with FieldDefinition

use of org.broadleafcommerce.cms.field.domain.FieldDefinition in project BroadleafCommerce by BroadleafCommerce.

the class DynamicFieldPersistenceHandlerHelper method buildDynamicPropertyList.

/**
 * Builds all of the metadata for all of the dynamic properties within a {@link StructuredContentType}, gleaned from
 * the {@link FieldGroup}s and {@link FieldDefinition}s.
 *
 * @param fieldGroups groups that the {@link Property}s are built from
 * @param inheritedType the value that each built {@link FieldMetadata} for each property will use to notate where the
 * dynamic field actually came from (meaning {@link FieldMetadata#setAvailableToTypes(String[])} and {@link FieldMetadata#setInheritedFromType(String)}
 * @return
 */
public Property[] buildDynamicPropertyList(List<FieldGroup> fieldGroups, Class<?> inheritedType) {
    List<Property> propertiesList = new ArrayList<Property>();
    int groupCount = 1;
    int fieldCount = 0;
    for (FieldGroup group : fieldGroups) {
        List<FieldDefinition> definitions = group.getFieldDefinitions();
        for (FieldDefinition def : definitions) {
            Property property = buildDynamicProperty(def, inheritedType);
            BasicFieldMetadata fieldMetadata = (BasicFieldMetadata) property.getMetadata();
            fieldMetadata.setOrder(fieldCount++);
            fieldMetadata.setGroup(group.getName());
            fieldMetadata.setGroupOrder(groupCount);
            fieldMetadata.setGroupCollapsed(group.getInitCollapsedFlag());
            propertiesList.add(property);
        }
        groupCount++;
        fieldCount = 0;
    }
    Property property = new Property();
    property.setName("id");
    BasicFieldMetadata fieldMetadata = new BasicFieldMetadata();
    property.setMetadata(fieldMetadata);
    fieldMetadata.setFieldType(SupportedFieldType.ID);
    fieldMetadata.setSecondaryType(SupportedFieldType.INTEGER);
    fieldMetadata.setMutable(true);
    fieldMetadata.setInheritedFromType(inheritedType.getName());
    fieldMetadata.setAvailableToTypes(new String[] { inheritedType.getName() });
    fieldMetadata.setForeignKeyCollection(false);
    fieldMetadata.setMergedPropertyType(MergedPropertyType.PRIMARY);
    fieldMetadata.setName("id");
    fieldMetadata.setFriendlyName("ID");
    fieldMetadata.setSecurityLevel("");
    fieldMetadata.setVisibility(VisibilityEnum.HIDDEN_ALL);
    fieldMetadata.setExplicitFieldType(SupportedFieldType.UNKNOWN);
    fieldMetadata.setLargeEntry(false);
    fieldMetadata.setProminent(false);
    fieldMetadata.setColumnWidth("*");
    fieldMetadata.setBroadleafEnumeration("");
    fieldMetadata.setReadOnly(true);
    propertiesList.add(property);
    Property[] properties = new Property[propertiesList.size()];
    properties = propertiesList.toArray(properties);
    Arrays.sort(properties, new Comparator<Property>() {

        @Override
        public int compare(Property o1, Property o2) {
            /*
                     * First, compare properties based on order fields
                     */
            if (o1.getMetadata().getOrder() != null && o2.getMetadata().getOrder() != null) {
                return o1.getMetadata().getOrder().compareTo(o2.getMetadata().getOrder());
            } else if (o1.getMetadata().getOrder() != null && o2.getMetadata().getOrder() == null) {
                /*
                          * Always favor fields that have an order identified
                          */
                return -1;
            } else if (o1.getMetadata().getOrder() == null && o2.getMetadata().getOrder() != null) {
                /*
                          * Always favor fields that have an order identified
                          */
                return 1;
            } else if (o1.getMetadata().getFriendlyName() != null && o2.getMetadata().getFriendlyName() != null) {
                return o1.getMetadata().getFriendlyName().compareTo(o2.getMetadata().getFriendlyName());
            } else {
                return o1.getName().compareTo(o2.getName());
            }
        }
    });
    return properties;
}
Also used : FieldGroup(org.broadleafcommerce.cms.field.domain.FieldGroup) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) FieldDefinition(org.broadleafcommerce.cms.field.domain.FieldDefinition) ArrayList(java.util.ArrayList) Property(org.broadleafcommerce.openadmin.dto.Property)

Example 8 with FieldDefinition

use of org.broadleafcommerce.cms.field.domain.FieldDefinition in project BroadleafCommerce by BroadleafCommerce.

the class PageServiceUtility method getFieldDefinition.

protected FieldDefinition getFieldDefinition(Page page, String fieldKey) {
    ExtensionResultHolder<FieldDefinition> erh = new ExtensionResultHolder<FieldDefinition>();
    ExtensionResultStatusType result = extensionManager.getProxy().getFieldDefinition(erh, page, fieldKey);
    if (result == ExtensionResultStatusType.HANDLED) {
        return erh.getResult();
    }
    if (page.getPageTemplate() != null) {
        for (PageTemplateFieldGroupXref fgXrefs : page.getPageTemplate().getFieldGroupXrefs()) {
            for (FieldDefinition fd : fgXrefs.getFieldGroup().getFieldDefinitions()) {
                if (fd.getName().equals(fieldKey)) {
                    return fd;
                }
            }
        }
    }
    return null;
}
Also used : PageTemplateFieldGroupXref(org.broadleafcommerce.cms.page.domain.PageTemplateFieldGroupXref) FieldDefinition(org.broadleafcommerce.cms.field.domain.FieldDefinition) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Aggregations

FieldDefinition (org.broadleafcommerce.cms.field.domain.FieldDefinition)8 FieldGroup (org.broadleafcommerce.cms.field.domain.FieldGroup)6 Property (org.broadleafcommerce.openadmin.dto.Property)5 ArrayList (java.util.ArrayList)4 PageField (org.broadleafcommerce.cms.page.domain.PageField)3 StructuredContentField (org.broadleafcommerce.cms.structure.domain.StructuredContentField)3 StructuredContentFieldXref (org.broadleafcommerce.cms.structure.domain.StructuredContentFieldXref)3 Entity (org.broadleafcommerce.openadmin.dto.Entity)3 HashMap (java.util.HashMap)2 StructuredContent (org.broadleafcommerce.cms.structure.domain.StructuredContent)2 StructuredContentType (org.broadleafcommerce.cms.structure.domain.StructuredContentType)2 ServiceException (org.broadleafcommerce.common.exception.ServiceException)2 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)2 ValidationException (org.broadleafcommerce.openadmin.server.service.ValidationException)2 BigDecimal (java.math.BigDecimal)1 Map (java.util.Map)1 Page (org.broadleafcommerce.cms.page.domain.Page)1 PageFieldImpl (org.broadleafcommerce.cms.page.domain.PageFieldImpl)1 PageTemplateFieldGroupXref (org.broadleafcommerce.cms.page.domain.PageTemplateFieldGroupXref)1 StructuredContentFieldImpl (org.broadleafcommerce.cms.structure.domain.StructuredContentFieldImpl)1