Search in sources :

Example 6 with FieldMetadata

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

the class MapFieldMetadataProvider method overrideViaAnnotation.

@Override
public MetadataProviderResponse overrideViaAnnotation(OverrideViaAnnotationRequest overrideViaAnnotationRequest, Map<String, FieldMetadata> metadata) {
    if (!canHandleAnnotationOverride(overrideViaAnnotationRequest, metadata)) {
        return MetadataProviderResponse.NOT_HANDLED;
    }
    Map<String, AdminPresentationMapOverride> presentationMapOverrides = new HashMap<String, AdminPresentationMapOverride>();
    AdminPresentationOverrides myOverrides = overrideViaAnnotationRequest.getRequestedEntity().getAnnotation(AdminPresentationOverrides.class);
    if (myOverrides != null) {
        for (AdminPresentationMapOverride myOverride : myOverrides.maps()) {
            presentationMapOverrides.put(myOverride.name(), myOverride);
        }
    }
    for (String propertyName : presentationMapOverrides.keySet()) {
        for (String key : metadata.keySet()) {
            if (key.startsWith(propertyName)) {
                buildAdminPresentationMapOverride(overrideViaAnnotationRequest.getPrefix(), overrideViaAnnotationRequest.getParentExcluded(), metadata, presentationMapOverrides, propertyName, key, overrideViaAnnotationRequest.getDynamicEntityDao());
            }
        }
    }
    AdminPresentationMergeOverrides myMergeOverrides = overrideViaAnnotationRequest.getRequestedEntity().getAnnotation(AdminPresentationMergeOverrides.class);
    if (myMergeOverrides != null) {
        for (AdminPresentationMergeOverride override : myMergeOverrides.value()) {
            String propertyName = override.name();
            Map<String, FieldMetadata> loopMap = new HashMap<String, FieldMetadata>();
            loopMap.putAll(metadata);
            for (Map.Entry<String, FieldMetadata> entry : loopMap.entrySet()) {
                if (entry.getKey().startsWith(propertyName) || StringUtils.isEmpty(propertyName)) {
                    FieldMetadata targetMetadata = entry.getValue();
                    if (targetMetadata instanceof MapMetadata) {
                        MapMetadata serverMetadata = (MapMetadata) targetMetadata;
                        if (serverMetadata.getTargetClass() != null) {
                            try {
                                Class<?> targetClass = Class.forName(serverMetadata.getTargetClass());
                                Class<?> parentClass = null;
                                if (serverMetadata.getOwningClass() != null) {
                                    parentClass = Class.forName(serverMetadata.getOwningClass());
                                }
                                String fieldName = serverMetadata.getFieldName();
                                Field field = overrideViaAnnotationRequest.getDynamicEntityDao().getFieldManager().getField(targetClass, fieldName);
                                Map<String, FieldMetadata> temp = new HashMap<String, FieldMetadata>(1);
                                temp.put(field.getName(), serverMetadata);
                                FieldInfo info = buildFieldInfo(field);
                                FieldMetadataOverride fieldMetadataOverride = overrideMapMergeMetadata(override);
                                if (serverMetadata.getExcluded() != null && serverMetadata.getExcluded() && (fieldMetadataOverride.getExcluded() == null || fieldMetadataOverride.getExcluded())) {
                                    continue;
                                }
                                buildMapMetadata(parentClass, targetClass, temp, info, fieldMetadataOverride, overrideViaAnnotationRequest.getDynamicEntityDao(), serverMetadata.getPrefix());
                                serverMetadata = (MapMetadata) temp.get(field.getName());
                                metadata.put(entry.getKey(), serverMetadata);
                            } catch (Exception e) {
                                throw new RuntimeException(e);
                            }
                        }
                    }
                }
            }
        }
    }
    return MetadataProviderResponse.HANDLED;
}
Also used : AdminPresentationOverrides(org.broadleafcommerce.common.presentation.override.AdminPresentationOverrides) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) HashMap(java.util.HashMap) FieldMetadataOverride(org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride) AdminPresentationMergeOverride(org.broadleafcommerce.common.presentation.override.AdminPresentationMergeOverride) Field(java.lang.reflect.Field) AdminPresentationMapOverride(org.broadleafcommerce.common.presentation.override.AdminPresentationMapOverride) AdminPresentationMergeOverrides(org.broadleafcommerce.common.presentation.override.AdminPresentationMergeOverrides) HashMap(java.util.HashMap) Map(java.util.Map) AdminPresentationMap(org.broadleafcommerce.common.presentation.AdminPresentationMap) MapMetadata(org.broadleafcommerce.openadmin.dto.MapMetadata) FieldInfo(org.broadleafcommerce.openadmin.server.dao.FieldInfo) FieldMetadataOverride(org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride) AdminPresentationMergeOverride(org.broadleafcommerce.common.presentation.override.AdminPresentationMergeOverride) AdminPresentationMapOverride(org.broadleafcommerce.common.presentation.override.AdminPresentationMapOverride) MetadataOverride(org.broadleafcommerce.openadmin.dto.override.MetadataOverride)

Example 7 with FieldMetadata

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

the class Metadata method overrideMetadata.

public Map<String, FieldMetadata> overrideMetadata(Class<?>[] entities, PropertyBuilder propertyBuilder, String prefix, Boolean isParentExcluded, String ceilingEntityFullyQualifiedClassname, String configurationKey, DynamicEntityDao dynamicEntityDao) {
    Boolean classAnnotatedPopulateManyToOneFields = null;
    // go in reverse order since I want the lowest subclass override to come last to guarantee that it takes effect
    for (int i = entities.length - 1; i >= 0; i--) {
        AdminPresentationClass adminPresentationClass = AnnotationUtils.findAnnotation(entities[i], AdminPresentationClass.class);
        if (adminPresentationClass != null && adminPresentationClass.populateToOneFields() != PopulateToOneFieldsEnum.NOT_SPECIFIED) {
            classAnnotatedPopulateManyToOneFields = adminPresentationClass.populateToOneFields() == PopulateToOneFieldsEnum.TRUE;
            break;
        }
    }
    Map<String, FieldMetadata> mergedProperties = propertyBuilder.execute(classAnnotatedPopulateManyToOneFields);
    for (int i = entities.length - 1; i >= 0; i--) {
        boolean handled = false;
        for (FieldMetadataProvider fieldMetadataProvider : fieldMetadataProviders) {
            MetadataProviderResponse response = fieldMetadataProvider.overrideViaAnnotation(new OverrideViaAnnotationRequest(entities[i], isParentExcluded, dynamicEntityDao, prefix), mergedProperties);
            if (MetadataProviderResponse.NOT_HANDLED != response) {
                handled = true;
            }
            if (MetadataProviderResponse.HANDLED_BREAK == response) {
                break;
            }
        }
        if (!handled) {
            defaultFieldMetadataProvider.overrideViaAnnotation(new OverrideViaAnnotationRequest(entities[i], isParentExcluded, dynamicEntityDao, prefix), mergedProperties);
        }
    }
    ((DefaultFieldMetadataProvider) defaultFieldMetadataProvider).overrideExclusionsFromXml(new OverrideViaXmlRequest(configurationKey, ceilingEntityFullyQualifiedClassname, prefix, isParentExcluded, dynamicEntityDao), mergedProperties);
    boolean handled = false;
    for (FieldMetadataProvider fieldMetadataProvider : fieldMetadataProviders) {
        MetadataProviderResponse response = fieldMetadataProvider.overrideViaXml(new OverrideViaXmlRequest(configurationKey, ceilingEntityFullyQualifiedClassname, prefix, isParentExcluded, dynamicEntityDao), mergedProperties);
        if (MetadataProviderResponse.NOT_HANDLED != response) {
            handled = true;
        }
        if (MetadataProviderResponse.HANDLED_BREAK == response) {
            break;
        }
    }
    if (!handled) {
        defaultFieldMetadataProvider.overrideViaXml(new OverrideViaXmlRequest(configurationKey, ceilingEntityFullyQualifiedClassname, prefix, isParentExcluded, dynamicEntityDao), mergedProperties);
    }
    return mergedProperties;
}
Also used : AdminPresentationClass(org.broadleafcommerce.common.presentation.AdminPresentationClass) DefaultFieldMetadataProvider(org.broadleafcommerce.openadmin.server.dao.provider.metadata.DefaultFieldMetadataProvider) DefaultFieldMetadataProvider(org.broadleafcommerce.openadmin.server.dao.provider.metadata.DefaultFieldMetadataProvider) FieldMetadataProvider(org.broadleafcommerce.openadmin.server.dao.provider.metadata.FieldMetadataProvider) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) OverrideViaXmlRequest(org.broadleafcommerce.openadmin.server.dao.provider.metadata.request.OverrideViaXmlRequest) MetadataProviderResponse(org.broadleafcommerce.openadmin.server.service.type.MetadataProviderResponse) OverrideViaAnnotationRequest(org.broadleafcommerce.openadmin.server.dao.provider.metadata.request.OverrideViaAnnotationRequest)

Example 8 with FieldMetadata

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

the class AbstractFieldMetadataProvider method setClassOwnership.

protected void setClassOwnership(Class<?> parentClass, Class<?> targetClass, Map<String, FieldMetadata> attributes, FieldInfo field) {
    FieldMetadata metadata = attributes.get(field.getName());
    if (metadata != null) {
        AdminPresentationClass adminPresentationClass;
        if (parentClass != null) {
            metadata.setOwningClass(parentClass.getName());
            adminPresentationClass = AnnotationUtils.findAnnotation(parentClass, AdminPresentationClass.class);
        } else {
            adminPresentationClass = AnnotationUtils.findAnnotation(targetClass, AdminPresentationClass.class);
        }
        if (adminPresentationClass != null) {
            String friendlyName = adminPresentationClass.friendlyName();
            if (!StringUtils.isEmpty(friendlyName) && StringUtils.isEmpty(metadata.getOwningClassFriendlyName())) {
                metadata.setOwningClassFriendlyName(friendlyName);
            }
        }
    }
}
Also used : AdminPresentationClass(org.broadleafcommerce.common.presentation.AdminPresentationClass) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)

Example 9 with FieldMetadata

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

the class DynamicEntityDaoImpl method applyForeignKeyPrecedence.

protected void applyForeignKeyPrecedence(ForeignKey foreignField, ForeignKey[] additionalForeignFields, Map<String, FieldMetadata> mergedProperties) {
    for (String key : mergedProperties.keySet()) {
        boolean isForeign = false;
        if (foreignField != null) {
            isForeign = foreignField.getManyToField().equals(key);
        }
        if (!isForeign && !ArrayUtils.isEmpty(additionalForeignFields)) {
            for (ForeignKey foreignKey : additionalForeignFields) {
                isForeign = foreignKey.getManyToField().equals(key);
                if (isForeign) {
                    break;
                }
            }
        }
        if (isForeign) {
            FieldMetadata metadata = mergedProperties.get(key);
            metadata.setExcluded(false);
        }
    }
}
Also used : FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) ForeignKey(org.broadleafcommerce.openadmin.dto.ForeignKey)

Example 10 with FieldMetadata

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

FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)114 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)80 Entity (org.broadleafcommerce.openadmin.dto.Entity)51 ServiceException (org.broadleafcommerce.common.exception.ServiceException)46 PersistencePerspective (org.broadleafcommerce.openadmin.dto.PersistencePerspective)44 HashMap (java.util.HashMap)39 Property (org.broadleafcommerce.openadmin.dto.Property)38 Map (java.util.Map)28 ArrayList (java.util.ArrayList)23 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)22 Field (java.lang.reflect.Field)19 SecurityServiceException (org.broadleafcommerce.common.exception.SecurityServiceException)19 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)19 Serializable (java.io.Serializable)18 InvocationTargetException (java.lang.reflect.InvocationTargetException)18 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)18 CriteriaTransferObject (org.broadleafcommerce.openadmin.dto.CriteriaTransferObject)17 BasicCollectionMetadata (org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata)15 FieldMetadataOverride (org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride)15 AdornedTargetCollectionMetadata (org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)13