Search in sources :

Example 1 with BasicFieldMetadata

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

the class BasicFieldMetadataProvider method buildAdminPresentationToOneLookupOverride.

protected void buildAdminPresentationToOneLookupOverride(Map<String, FieldMetadata> mergedProperties, Map<String, AdminPresentationToOneLookupOverride> presentationOverrides, String propertyName, String key) {
    AdminPresentationToOneLookupOverride override = presentationOverrides.get(propertyName);
    if (override != null) {
        AdminPresentationToOneLookup annot = override.value();
        if (annot != null) {
            if (!(mergedProperties.get(key) instanceof BasicFieldMetadata)) {
                return;
            }
            BasicFieldMetadata metadata = (BasicFieldMetadata) mergedProperties.get(key);
            metadata.setFieldType(SupportedFieldType.ADDITIONAL_FOREIGN_KEY);
            metadata.setExplicitFieldType(SupportedFieldType.ADDITIONAL_FOREIGN_KEY);
            metadata.setLookupDisplayProperty(annot.lookupDisplayProperty());
            metadata.setForcePopulateChildProperties(annot.forcePopulateChildProperties());
            metadata.setEnableTypeaheadLookup(annot.enableTypeaheadLookup());
            if (!StringUtils.isEmpty(annot.lookupDisplayProperty())) {
                metadata.setForeignKeyDisplayValueProperty(annot.lookupDisplayProperty());
            }
            metadata.setCustomCriteria(annot.customCriteria());
            metadata.setUseServerSideInspectionCache(annot.useServerSideInspectionCache());
        }
    }
}
Also used : BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) AdminPresentationToOneLookup(org.broadleafcommerce.common.presentation.AdminPresentationToOneLookup) AdminPresentationToOneLookupOverride(org.broadleafcommerce.common.presentation.override.AdminPresentationToOneLookupOverride)

Example 2 with BasicFieldMetadata

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

the class BasicFieldMetadataProvider method overrideViaXml.

@Override
public MetadataProviderResponse overrideViaXml(OverrideViaXmlRequest overrideViaXmlRequest, Map<String, FieldMetadata> metadata) {
    Map<String, MetadataOverride> overrides = getTargetedOverride(overrideViaXmlRequest.getDynamicEntityDao(), overrideViaXmlRequest.getRequestedConfigKey(), overrideViaXmlRequest.getRequestedCeilingEntity());
    if (overrides != null) {
        for (String propertyName : overrides.keySet()) {
            MetadataOverride localMetadata = overrides.get(propertyName);
            if (localMetadata instanceof FieldMetadataOverride) {
                FieldMetadataOverride localFieldMetadata = (FieldMetadataOverride) localMetadata;
                for (String key : metadata.keySet()) {
                    if (key.equals(propertyName)) {
                        try {
                            if (metadata.get(key) instanceof BasicFieldMetadata) {
                                BasicFieldMetadata serverMetadata = (BasicFieldMetadata) metadata.get(key);
                                if (serverMetadata.getTargetClass() != null) {
                                    Class<?> targetClass = Class.forName(serverMetadata.getTargetClass());
                                    Class<?> parentClass = null;
                                    if (serverMetadata.getOwningClass() != null) {
                                        parentClass = Class.forName(serverMetadata.getOwningClass());
                                    }
                                    String fieldName = serverMetadata.getFieldName();
                                    Field field = overrideViaXmlRequest.getDynamicEntityDao().getFieldManager().getField(targetClass, fieldName);
                                    Map<String, FieldMetadata> temp = new HashMap<>(1);
                                    temp.put(field.getName(), serverMetadata);
                                    FieldInfo info = buildFieldInfo(field);
                                    buildBasicMetadata(parentClass, targetClass, temp, info, localFieldMetadata, overrideViaXmlRequest.getDynamicEntityDao());
                                    serverMetadata = (BasicFieldMetadata) temp.get(field.getName());
                                    metadata.put(key, serverMetadata);
                                    if (overrideViaXmlRequest.getParentExcluded()) {
                                        if (LOG.isDebugEnabled()) {
                                            LOG.debug("applyMetadataOverrides:Excluding " + key + "because the parent was excluded");
                                        }
                                        serverMetadata.setExcluded(true);
                                    }
                                }
                            }
                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
        }
    }
    return MetadataProviderResponse.HANDLED;
}
Also used : FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FieldMetadataOverride(org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride) Field(java.lang.reflect.Field) FieldMetadataOverride(org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride) MetadataOverride(org.broadleafcommerce.openadmin.dto.override.MetadataOverride) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) FieldInfo(org.broadleafcommerce.openadmin.server.dao.FieldInfo) AdminPresentationMergeOverride(org.broadleafcommerce.common.presentation.override.AdminPresentationMergeOverride) RequiredOverride(org.broadleafcommerce.common.presentation.RequiredOverride) AdminPresentationToOneLookupOverride(org.broadleafcommerce.common.presentation.override.AdminPresentationToOneLookupOverride) AdminPresentationOverride(org.broadleafcommerce.common.presentation.override.AdminPresentationOverride) AdminPresentationDataDrivenEnumerationOverride(org.broadleafcommerce.common.presentation.override.AdminPresentationDataDrivenEnumerationOverride) FieldMetadataOverride(org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride) MetadataOverride(org.broadleafcommerce.openadmin.dto.override.MetadataOverride)

Example 3 with BasicFieldMetadata

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

the class BasicFieldMetadataProvider method buildAdminPresentationDataDrivenEnumerationOverride.

protected void buildAdminPresentationDataDrivenEnumerationOverride(Map<String, FieldMetadata> mergedProperties, Map<String, AdminPresentationDataDrivenEnumerationOverride> presentationOverrides, String propertyName, String key) {
    AdminPresentationDataDrivenEnumerationOverride override = presentationOverrides.get(propertyName);
    if (override != null) {
        AdminPresentationDataDrivenEnumeration annot = override.value();
        if (annot != null) {
            if (!(mergedProperties.get(key) instanceof BasicFieldMetadata)) {
                return;
            }
            BasicFieldMetadata metadata = (BasicFieldMetadata) mergedProperties.get(key);
            metadata.setFieldType(SupportedFieldType.DATA_DRIVEN_ENUMERATION);
            metadata.setExplicitFieldType(SupportedFieldType.DATA_DRIVEN_ENUMERATION);
            metadata.setOptionListEntity(annot.optionListEntity().getName());
            metadata.setHideEnumerationIfEmpty(annot.optionHideIfEmpty());
            if (metadata.getOptionListEntity().equals(DataDrivenEnumerationValueImpl.class.getName())) {
                metadata.setOptionValueFieldName("key");
                metadata.setOptionDisplayFieldName("display");
            } else if (metadata.getOptionListEntity() == null && (StringUtils.isEmpty(metadata.getOptionValueFieldName()) || StringUtils.isEmpty(metadata.getOptionDisplayFieldName()))) {
                throw new IllegalArgumentException("Problem setting up data driven enumeration for (" + propertyName + "). The optionListEntity, optionValueFieldName and optionDisplayFieldName properties must all be included if not using DataDrivenEnumerationValueImpl as the optionListEntity.");
            } else {
                metadata.setOptionValueFieldName(annot.optionValueFieldName());
                metadata.setOptionDisplayFieldName(annot.optionDisplayFieldName());
            }
            if (!ArrayUtils.isEmpty(annot.optionFilterParams())) {
                String[][] params = new String[annot.optionFilterParams().length][3];
                for (int j = 0; j < params.length; j++) {
                    params[j][0] = annot.optionFilterParams()[j].param();
                    params[j][1] = annot.optionFilterParams()[j].value();
                    params[j][2] = String.valueOf(annot.optionFilterParams()[j].paramType());
                }
                metadata.setOptionFilterParams(params);
            } else {
                metadata.setOptionFilterParams(new String[][] {});
            }
            if (!StringUtils.isEmpty(metadata.getOptionListEntity())) {
                buildDataDrivenEnumList(metadata);
            }
        }
    }
}
Also used : BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) AdminPresentationDataDrivenEnumerationOverride(org.broadleafcommerce.common.presentation.override.AdminPresentationDataDrivenEnumerationOverride) AdminPresentationDataDrivenEnumeration(org.broadleafcommerce.common.presentation.AdminPresentationDataDrivenEnumeration) DataDrivenEnumerationValueImpl(org.broadleafcommerce.common.enumeration.domain.DataDrivenEnumerationValueImpl)

Example 4 with BasicFieldMetadata

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

the class DefaultFieldMetadataProvider method addMetadata.

@Override
public MetadataProviderResponse addMetadata(AddFieldMetadataRequest addMetadataRequest, Map<String, FieldMetadata> metadata) {
    Map<String, Object> idMetadata = addMetadataRequest.getDynamicEntityDao().getIdMetadata(addMetadataRequest.getTargetClass());
    if (idMetadata != null) {
        String idField = (String) idMetadata.get("name");
        boolean processField;
        // allow id fields without AdminPresentation annotation to pass through
        processField = idField.equals(addMetadataRequest.getRequestedField().getName());
        if (!processField) {
            List<String> propertyNames = addMetadataRequest.getDynamicEntityDao().getPropertyNames(addMetadataRequest.getTargetClass());
            if (!CollectionUtils.isEmpty(propertyNames)) {
                List<org.hibernate.type.Type> propertyTypes = addMetadataRequest.getDynamicEntityDao().getPropertyTypes(addMetadataRequest.getTargetClass());
                int index = propertyNames.indexOf(addMetadataRequest.getRequestedField().getName());
                if (index >= 0) {
                    Type myType = propertyTypes.get(index);
                    // allow OneToOne, ManyToOne and Embeddable fields to pass through
                    processField = myType.isCollectionType() || myType.isAssociationType() || myType.isComponentType() || myType.isEntityType();
                }
            }
        }
        if (processField) {
            FieldInfo info = buildFieldInfo(addMetadataRequest.getRequestedField());
            BasicFieldMetadata basicMetadata = new BasicFieldMetadata();
            basicMetadata.setName(addMetadataRequest.getRequestedField().getName());
            basicMetadata.setExcluded(false);
            metadata.put(addMetadataRequest.getRequestedField().getName(), basicMetadata);
            setClassOwnership(addMetadataRequest.getParentClass(), addMetadataRequest.getTargetClass(), metadata, info);
            return MetadataProviderResponse.HANDLED;
        }
    }
    return MetadataProviderResponse.NOT_HANDLED;
}
Also used : SupportedFieldType(org.broadleafcommerce.common.presentation.client.SupportedFieldType) Type(org.hibernate.type.Type) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) FieldInfo(org.broadleafcommerce.openadmin.server.dao.FieldInfo) FieldMetadataOverride(org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride) MetadataOverride(org.broadleafcommerce.openadmin.dto.override.MetadataOverride)

Example 5 with BasicFieldMetadata

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

the class DynamicEntityDaoImpl method getPropertiesForPrimitiveClass.

@Override
public Map<String, FieldMetadata> getPropertiesForPrimitiveClass(String propertyName, String friendlyPropertyName, Class<?> targetClass, Class<?> parentClass, MergedPropertyType mergedPropertyType) {
    Map<String, FieldMetadata> fields = new HashMap<>();
    BasicFieldMetadata presentationAttribute = new BasicFieldMetadata();
    presentationAttribute.setFriendlyName(friendlyPropertyName);
    if (String.class.isAssignableFrom(targetClass)) {
        presentationAttribute.setExplicitFieldType(SupportedFieldType.STRING);
        presentationAttribute.setVisibility(VisibilityEnum.VISIBLE_ALL);
        fields.put(propertyName, metadata.getFieldMetadata("", propertyName, null, SupportedFieldType.STRING, null, parentClass, presentationAttribute, mergedPropertyType, this));
    } else if (Boolean.class.isAssignableFrom(targetClass)) {
        presentationAttribute.setExplicitFieldType(SupportedFieldType.BOOLEAN);
        presentationAttribute.setVisibility(VisibilityEnum.VISIBLE_ALL);
        fields.put(propertyName, metadata.getFieldMetadata("", propertyName, null, SupportedFieldType.BOOLEAN, null, parentClass, presentationAttribute, mergedPropertyType, this));
    } else if (Date.class.isAssignableFrom(targetClass)) {
        presentationAttribute.setExplicitFieldType(SupportedFieldType.DATE);
        presentationAttribute.setVisibility(VisibilityEnum.VISIBLE_ALL);
        fields.put(propertyName, metadata.getFieldMetadata("", propertyName, null, SupportedFieldType.DATE, null, parentClass, presentationAttribute, mergedPropertyType, this));
    } else if (Money.class.isAssignableFrom(targetClass)) {
        presentationAttribute.setExplicitFieldType(SupportedFieldType.MONEY);
        presentationAttribute.setVisibility(VisibilityEnum.VISIBLE_ALL);
        fields.put(propertyName, metadata.getFieldMetadata("", propertyName, null, SupportedFieldType.MONEY, null, parentClass, presentationAttribute, mergedPropertyType, this));
    } else if (Byte.class.isAssignableFrom(targetClass) || Integer.class.isAssignableFrom(targetClass) || Long.class.isAssignableFrom(targetClass) || Short.class.isAssignableFrom(targetClass)) {
        presentationAttribute.setExplicitFieldType(SupportedFieldType.INTEGER);
        presentationAttribute.setVisibility(VisibilityEnum.VISIBLE_ALL);
        fields.put(propertyName, metadata.getFieldMetadata("", propertyName, null, SupportedFieldType.INTEGER, null, parentClass, presentationAttribute, mergedPropertyType, this));
    } else if (Double.class.isAssignableFrom(targetClass) || BigDecimal.class.isAssignableFrom(targetClass)) {
        presentationAttribute.setExplicitFieldType(SupportedFieldType.DECIMAL);
        presentationAttribute.setVisibility(VisibilityEnum.VISIBLE_ALL);
        fields.put(propertyName, metadata.getFieldMetadata("", propertyName, null, SupportedFieldType.DECIMAL, null, parentClass, presentationAttribute, mergedPropertyType, this));
    }
    ((BasicFieldMetadata) fields.get(propertyName)).setLength(255);
    ((BasicFieldMetadata) fields.get(propertyName)).setForeignKeyCollection(false);
    ((BasicFieldMetadata) fields.get(propertyName)).setRequired(true);
    ((BasicFieldMetadata) fields.get(propertyName)).setUnique(true);
    ((BasicFieldMetadata) fields.get(propertyName)).setScale(100);
    ((BasicFieldMetadata) fields.get(propertyName)).setPrecision(100);
    return fields;
}
Also used : BigInteger(java.math.BigInteger) Money(org.broadleafcommerce.common.money.Money) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) HashMap(java.util.HashMap) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)

Aggregations

BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)66 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)33 Property (org.broadleafcommerce.openadmin.dto.Property)28 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)19 Map (java.util.Map)14 Entity (org.broadleafcommerce.openadmin.dto.Entity)11 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)10 AdminMainEntity (org.broadleafcommerce.common.admin.domain.AdminMainEntity)9 FieldMetadataOverride (org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride)9 Field (java.lang.reflect.Field)8 PersistenceException (org.broadleafcommerce.openadmin.server.service.persistence.PersistenceException)8 ServiceException (org.broadleafcommerce.common.exception.ServiceException)7 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)7 ComboField (org.broadleafcommerce.openadmin.web.form.entity.ComboField)7 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)7 Serializable (java.io.Serializable)6 SecurityServiceException (org.broadleafcommerce.common.exception.SecurityServiceException)6 MetadataOverride (org.broadleafcommerce.openadmin.dto.override.MetadataOverride)6 FieldInfo (org.broadleafcommerce.openadmin.server.dao.FieldInfo)6