Search in sources :

Example 1 with FieldMetadataProvider

use of org.broadleafcommerce.openadmin.server.dao.provider.metadata.FieldMetadataProvider 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 2 with FieldMetadataProvider

use of org.broadleafcommerce.openadmin.server.dao.provider.metadata.FieldMetadataProvider in project BroadleafCommerce by BroadleafCommerce.

the class DynamicEntityDaoImpl method getMergedProperties.

@Override
public Map<String, FieldMetadata> getMergedProperties(String ceilingEntityFullyQualifiedClassname, Class<?>[] entities, ForeignKey foreignField, String[] additionalNonPersistentProperties, ForeignKey[] additionalForeignFields, MergedPropertyType mergedPropertyType, Boolean populateManyToOneFields, String[] includeFields, String[] excludeFields, String configurationKey, String prefix) {
    Map<String, FieldMetadata> mergedProperties = getMergedPropertiesRecursively(ceilingEntityFullyQualifiedClassname, entities, foreignField, additionalNonPersistentProperties, additionalForeignFields, mergedPropertyType, populateManyToOneFields, includeFields, excludeFields, configurationKey, new ArrayList<Class<?>>(), prefix, false, "");
    final List<String> removeKeys = new ArrayList<>();
    for (final String key : mergedProperties.keySet()) {
        if (mergedProperties.get(key).getExcluded() != null && mergedProperties.get(key).getExcluded()) {
            removeKeys.add(key);
        }
    }
    for (String removeKey : removeKeys) {
        mergedProperties.remove(removeKey);
    }
    // Allow field metadata providers to contribute additional fields here. These latestage handlers take place
    // after any cached lookups occur, and are ideal for adding in dynamic properties that are not globally cacheable
    // like properties gleaned from reflection typically are.
    Set<String> keys = new HashSet<>(mergedProperties.keySet());
    for (Class<?> targetClass : entities) {
        for (String key : keys) {
            LateStageAddMetadataRequest amr = new LateStageAddMetadataRequest(key, null, targetClass, this, "");
            boolean foundOneOrMoreHandlers = false;
            for (FieldMetadataProvider fieldMetadataProvider : fieldMetadataProviders) {
                MetadataProviderResponse response = fieldMetadataProvider.lateStageAddMetadata(amr, mergedProperties);
                if (MetadataProviderResponse.NOT_HANDLED != response) {
                    foundOneOrMoreHandlers = true;
                }
                if (MetadataProviderResponse.HANDLED_BREAK == response) {
                    break;
                }
            }
            if (!foundOneOrMoreHandlers) {
                defaultFieldMetadataProvider.lateStageAddMetadata(amr, mergedProperties);
            }
        }
    }
    return mergedProperties;
}
Also used : LateStageAddMetadataRequest(org.broadleafcommerce.openadmin.server.dao.provider.metadata.request.LateStageAddMetadataRequest) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) MetadataProviderResponse(org.broadleafcommerce.openadmin.server.service.type.MetadataProviderResponse) ArrayList(java.util.ArrayList) FieldMetadataProvider(org.broadleafcommerce.openadmin.server.dao.provider.metadata.FieldMetadataProvider) PersistentClass(org.hibernate.mapping.PersistentClass) AdminPresentationClass(org.broadleafcommerce.common.presentation.AdminPresentationClass) HashSet(java.util.HashSet)

Example 3 with FieldMetadataProvider

use of org.broadleafcommerce.openadmin.server.dao.provider.metadata.FieldMetadataProvider in project BroadleafCommerce by BroadleafCommerce.

the class Metadata method getFieldMetadataForTargetClass.

public Map<String, FieldMetadata> getFieldMetadataForTargetClass(Class<?> parentClass, Class<?> targetClass, DynamicEntityDao dynamicEntityDao, String prefix) {
    Map<String, FieldMetadata> metadata = new HashMap<>();
    Field[] fields = dynamicEntityDao.getAllFields(targetClass);
    for (Field field : fields) {
        boolean foundOneOrMoreHandlers = false;
        for (FieldMetadataProvider fieldMetadataProvider : fieldMetadataProviders) {
            MetadataProviderResponse response = fieldMetadataProvider.addMetadata(new AddFieldMetadataRequest(field, parentClass, targetClass, dynamicEntityDao, prefix), metadata);
            if (MetadataProviderResponse.NOT_HANDLED != response) {
                foundOneOrMoreHandlers = true;
            }
            if (MetadataProviderResponse.HANDLED_BREAK == response) {
                break;
            }
        }
        if (!foundOneOrMoreHandlers) {
            defaultFieldMetadataProvider.addMetadata(new AddFieldMetadataRequest(field, parentClass, targetClass, dynamicEntityDao, prefix), metadata);
        }
    }
    return metadata;
}
Also used : Field(java.lang.reflect.Field) DefaultFieldMetadataProvider(org.broadleafcommerce.openadmin.server.dao.provider.metadata.DefaultFieldMetadataProvider) FieldMetadataProvider(org.broadleafcommerce.openadmin.server.dao.provider.metadata.FieldMetadataProvider) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) HashMap(java.util.HashMap) MetadataProviderResponse(org.broadleafcommerce.openadmin.server.service.type.MetadataProviderResponse) AddFieldMetadataRequest(org.broadleafcommerce.openadmin.server.dao.provider.metadata.request.AddFieldMetadataRequest)

Example 4 with FieldMetadataProvider

use of org.broadleafcommerce.openadmin.server.dao.provider.metadata.FieldMetadataProvider in project BroadleafCommerce by BroadleafCommerce.

the class Metadata method getFieldMetadata.

public FieldMetadata getFieldMetadata(String prefix, final String propertyName, final List<Property> componentProperties, final SupportedFieldType type, final SupportedFieldType secondaryType, final Type entityType, Class<?> targetClass, final FieldMetadata presentationAttribute, final MergedPropertyType mergedPropertyType, final DynamicEntityDao dynamicEntityDao) {
    if (presentationAttribute.getTargetClass() == null) {
        presentationAttribute.setTargetClass(targetClass.getName());
        presentationAttribute.setFieldName(propertyName);
    }
    presentationAttribute.setInheritedFromType(targetClass.getName());
    presentationAttribute.setAvailableToTypes(new String[] { targetClass.getName() });
    boolean handled = false;
    for (FieldMetadataProvider fieldMetadataProvider : fieldMetadataProviders) {
        MetadataProviderResponse response = fieldMetadataProvider.addMetadataFromMappingData(new AddMetadataFromMappingDataRequest(componentProperties, type, secondaryType, entityType, propertyName, mergedPropertyType, dynamicEntityDao), presentationAttribute);
        if (MetadataProviderResponse.NOT_HANDLED != response) {
            handled = true;
        }
        if (MetadataProviderResponse.HANDLED_BREAK == response) {
            break;
        }
    }
    if (!handled) {
        defaultFieldMetadataProvider.addMetadataFromMappingData(new AddMetadataFromMappingDataRequest(componentProperties, type, secondaryType, entityType, propertyName, mergedPropertyType, dynamicEntityDao), presentationAttribute);
    }
    return presentationAttribute;
}
Also used : DefaultFieldMetadataProvider(org.broadleafcommerce.openadmin.server.dao.provider.metadata.DefaultFieldMetadataProvider) FieldMetadataProvider(org.broadleafcommerce.openadmin.server.dao.provider.metadata.FieldMetadataProvider) AddMetadataFromMappingDataRequest(org.broadleafcommerce.openadmin.server.dao.provider.metadata.request.AddMetadataFromMappingDataRequest) MetadataProviderResponse(org.broadleafcommerce.openadmin.server.service.type.MetadataProviderResponse)

Example 5 with FieldMetadataProvider

use of org.broadleafcommerce.openadmin.server.dao.provider.metadata.FieldMetadataProvider in project BroadleafCommerce by BroadleafCommerce.

the class DynamicEntityDaoImpl method buildProperties.

protected void buildProperties(Class<?> targetClass, ForeignKey foreignField, ForeignKey[] additionalForeignFields, String[] additionalNonPersistentProperties, MergedPropertyType mergedPropertyType, Map<String, FieldMetadata> presentationAttributes, List<Property> componentProperties, Map<String, FieldMetadata> fields, List<String> propertyNames, List<Type> propertyTypes, String idProperty, Boolean populateManyToOneFields, String[] includeFields, String[] excludeFields, String configurationKey, String ceilingEntityFullyQualifiedClassname, List<Class<?>> parentClasses, String prefix, Boolean isParentExcluded, Boolean isComponentPrefix, String parentPrefix) {
    int j = 0;
    Comparator<String> propertyComparator = new Comparator<String>() {

        @Override
        public int compare(String o1, String o2) {
            // check for property name equality and for map field properties
            if (o1.equals(o2) || o1.startsWith(o2 + FieldManager.MAPFIELDSEPARATOR) || o2.startsWith(o1 + FieldManager.MAPFIELDSEPARATOR)) {
                return 0;
            }
            return o1.compareTo(o2);
        }
    };
    List<String> presentationKeyList = new ArrayList<>(presentationAttributes.keySet());
    Collections.sort(presentationKeyList);
    for (String propertyName : propertyNames) {
        final Type type = propertyTypes.get(j);
        boolean isPropertyForeignKey = testForeignProperty(foreignField, prefix, propertyName);
        int additionalForeignKeyIndexPosition = findAdditionalForeignKeyIndex(additionalForeignFields, prefix, propertyName);
        j++;
        Field myField = getFieldManager().getField(targetClass, propertyName);
        if (myField == null) {
            // try to get the field with the prefix - needed for advanced collections that appear in @Embedded classes
            myField = getFieldManager().getField(targetClass, prefix + propertyName);
        }
        if (!type.isAnyType() && !type.isCollectionType() || isPropertyForeignKey || additionalForeignKeyIndexPosition >= 0 || Collections.binarySearch(presentationKeyList, propertyName, propertyComparator) >= 0) {
            if (myField != null) {
                boolean handled = false;
                for (FieldMetadataProvider provider : fieldMetadataProviders) {
                    FieldMetadata presentationAttribute = presentationAttributes.get(propertyName);
                    if (presentationAttribute != null) {
                        setExcludedBasedOnShowIfProperty(presentationAttribute);
                    }
                    MetadataProviderResponse response = provider.addMetadataFromFieldType(new AddMetadataFromFieldTypeRequest(myField, targetClass, foreignField, additionalForeignFields, mergedPropertyType, componentProperties, idProperty, prefix, propertyName, type, isPropertyForeignKey, additionalForeignKeyIndexPosition, presentationAttributes, presentationAttribute, null, type.getReturnedClass(), this), fields);
                    if (MetadataProviderResponse.NOT_HANDLED != response) {
                        handled = true;
                    }
                    if (MetadataProviderResponse.HANDLED_BREAK == response) {
                        break;
                    }
                }
                if (!handled) {
                    buildBasicProperty(myField, targetClass, foreignField, additionalForeignFields, additionalNonPersistentProperties, mergedPropertyType, presentationAttributes, componentProperties, fields, idProperty, populateManyToOneFields, includeFields, excludeFields, configurationKey, ceilingEntityFullyQualifiedClassname, parentClasses, prefix, isParentExcluded, propertyName, type, isPropertyForeignKey, additionalForeignKeyIndexPosition, isComponentPrefix, parentPrefix);
                }
            }
        }
    }
}
Also used : FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) MetadataProviderResponse(org.broadleafcommerce.openadmin.server.service.type.MetadataProviderResponse) ArrayList(java.util.ArrayList) Comparator(java.util.Comparator) Field(java.lang.reflect.Field) MergedPropertyType(org.broadleafcommerce.openadmin.dto.MergedPropertyType) PersistencePerspectiveItemType(org.broadleafcommerce.common.presentation.client.PersistencePerspectiveItemType) SupportedFieldType(org.broadleafcommerce.common.presentation.client.SupportedFieldType) ComponentType(org.hibernate.type.ComponentType) Type(org.hibernate.type.Type) FieldMetadataProvider(org.broadleafcommerce.openadmin.server.dao.provider.metadata.FieldMetadataProvider) AddMetadataFromFieldTypeRequest(org.broadleafcommerce.openadmin.server.dao.provider.metadata.request.AddMetadataFromFieldTypeRequest)

Aggregations

FieldMetadataProvider (org.broadleafcommerce.openadmin.server.dao.provider.metadata.FieldMetadataProvider)6 MetadataProviderResponse (org.broadleafcommerce.openadmin.server.service.type.MetadataProviderResponse)6 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)5 Field (java.lang.reflect.Field)3 AdminPresentationClass (org.broadleafcommerce.common.presentation.AdminPresentationClass)3 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)3 DefaultFieldMetadataProvider (org.broadleafcommerce.openadmin.server.dao.provider.metadata.DefaultFieldMetadataProvider)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 AddMetadataFromFieldTypeRequest (org.broadleafcommerce.openadmin.server.dao.provider.metadata.request.AddMetadataFromFieldTypeRequest)2 PersistentClass (org.hibernate.mapping.PersistentClass)2 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 PersistencePerspectiveItemType (org.broadleafcommerce.common.presentation.client.PersistencePerspectiveItemType)1 SupportedFieldType (org.broadleafcommerce.common.presentation.client.SupportedFieldType)1 ForeignKey (org.broadleafcommerce.openadmin.dto.ForeignKey)1 MergedPropertyType (org.broadleafcommerce.openadmin.dto.MergedPropertyType)1 AddFieldMetadataRequest (org.broadleafcommerce.openadmin.server.dao.provider.metadata.request.AddFieldMetadataRequest)1 AddMetadataFromMappingDataRequest (org.broadleafcommerce.openadmin.server.dao.provider.metadata.request.AddMetadataFromMappingDataRequest)1 LateStageAddMetadataRequest (org.broadleafcommerce.openadmin.server.dao.provider.metadata.request.LateStageAddMetadataRequest)1