Search in sources :

Example 6 with FieldMetadataProvider

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

the class DynamicEntityDaoImpl method getSimpleMergedProperties.

@Override
public Map<String, FieldMetadata> getSimpleMergedProperties(String entityName, PersistencePerspective persistencePerspective) {
    Class<?>[] entityClasses;
    try {
        entityClasses = getAllPolymorphicEntitiesFromCeiling(Class.forName(entityName));
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
    if (!ArrayUtils.isEmpty(entityClasses)) {
        return getMergedProperties(entityName, entityClasses, (ForeignKey) persistencePerspective.getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.FOREIGNKEY), persistencePerspective.getAdditionalNonPersistentProperties(), persistencePerspective.getAdditionalForeignKeys(), MergedPropertyType.PRIMARY, persistencePerspective.getPopulateToOneFields(), persistencePerspective.getIncludeFields(), persistencePerspective.getExcludeFields(), persistencePerspective.getConfigurationKey(), "");
    } else {
        Map<String, FieldMetadata> mergedProperties = new HashMap<>();
        Class<?> targetClass;
        try {
            targetClass = Class.forName(entityName);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        Map<String, FieldMetadata> attributesMap = metadata.getFieldMetadataForTargetClass(null, targetClass, this, "");
        for (String property : attributesMap.keySet()) {
            FieldMetadata presentationAttribute = attributesMap.get(property);
            if (!presentationAttribute.getExcluded()) {
                Field field = FieldManager.getSingleField(targetClass, property);
                if (!Modifier.isStatic(field.getModifiers())) {
                    boolean handled = false;
                    for (FieldMetadataProvider provider : fieldMetadataProviders) {
                        MetadataProviderResponse response = provider.addMetadataFromFieldType(new AddMetadataFromFieldTypeRequest(field, targetClass, null, new ForeignKey[] {}, MergedPropertyType.PRIMARY, null, null, "", property, null, false, 0, attributesMap, presentationAttribute, ((BasicFieldMetadata) presentationAttribute).getExplicitFieldType(), field.getType(), this), mergedProperties);
                        if (MetadataProviderResponse.NOT_HANDLED != response) {
                            handled = true;
                        }
                        if (MetadataProviderResponse.HANDLED_BREAK == response) {
                            break;
                        }
                    }
                    if (!handled) {
                        // this provider is not included in the provider list on purpose - it is designed to handle basic
                        // AdminPresentation fields, and those fields not admin presentation annotated at all
                        defaultFieldMetadataProvider.addMetadataFromFieldType(new AddMetadataFromFieldTypeRequest(field, targetClass, null, new ForeignKey[] {}, MergedPropertyType.PRIMARY, null, null, "", property, null, false, 0, attributesMap, presentationAttribute, ((BasicFieldMetadata) presentationAttribute).getExplicitFieldType(), field.getType(), this), mergedProperties);
                    }
                }
            }
        }
        return mergedProperties;
    }
}
Also used : FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) HashMap(java.util.HashMap) MetadataProviderResponse(org.broadleafcommerce.openadmin.server.service.type.MetadataProviderResponse) ForeignKey(org.broadleafcommerce.openadmin.dto.ForeignKey) Field(java.lang.reflect.Field) FieldMetadataProvider(org.broadleafcommerce.openadmin.server.dao.provider.metadata.FieldMetadataProvider) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) PersistentClass(org.hibernate.mapping.PersistentClass) AdminPresentationClass(org.broadleafcommerce.common.presentation.AdminPresentationClass) 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