Search in sources :

Example 1 with AdminPresentationClass

use of org.broadleafcommerce.common.presentation.AdminPresentationClass 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 AdminPresentationClass

use of org.broadleafcommerce.common.presentation.AdminPresentationClass 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 3 with AdminPresentationClass

use of org.broadleafcommerce.common.presentation.AdminPresentationClass in project BroadleafCommerce by BroadleafCommerce.

the class DynamicEntityDaoImpl method getClassTree.

@Override
public ClassTree getClassTree(Class<?>[] polymorphicClasses) {
    String ceilingClass = null;
    for (Class<?> clazz : polymorphicClasses) {
        AdminPresentationClass classPresentation = AnnotationUtils.findAnnotation(clazz, AdminPresentationClass.class);
        if (classPresentation != null) {
            String ceilingEntity = classPresentation.ceilingDisplayEntity();
            if (!StringUtils.isEmpty(ceilingEntity)) {
                ceilingClass = ceilingEntity;
                break;
            }
        }
    }
    if (ceilingClass != null) {
        int pos = -1;
        int j = 0;
        for (Class<?> clazz : polymorphicClasses) {
            if (clazz.getName().equals(ceilingClass)) {
                pos = j;
                break;
            }
            j++;
        }
        if (pos >= 0) {
            Class<?>[] temp = new Class<?>[pos + 1];
            System.arraycopy(polymorphicClasses, 0, temp, 0, j + 1);
            polymorphicClasses = temp;
        }
    }
    ClassTree classTree = null;
    if (!ArrayUtils.isEmpty(polymorphicClasses)) {
        Class<?> topClass = polymorphicClasses[polymorphicClasses.length - 1];
        classTree = new ClassTree(topClass.getName(), isExcludeClassFromPolymorphism(topClass));
        createClassTreeFromAnnotation(topClass, classTree);
        for (int j = polymorphicClasses.length - 1; j >= 0; j--) {
            addClassToTree(polymorphicClasses[j], classTree);
        }
        classTree.finalizeStructure(1);
    }
    return classTree;
}
Also used : AdminPresentationClass(org.broadleafcommerce.common.presentation.AdminPresentationClass) ClassTree(org.broadleafcommerce.openadmin.dto.ClassTree) PersistentClass(org.hibernate.mapping.PersistentClass) AdminPresentationClass(org.broadleafcommerce.common.presentation.AdminPresentationClass)

Aggregations

AdminPresentationClass (org.broadleafcommerce.common.presentation.AdminPresentationClass)3 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)2 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)1 ClassTree (org.broadleafcommerce.openadmin.dto.ClassTree)1 DefaultFieldMetadataProvider (org.broadleafcommerce.openadmin.server.dao.provider.metadata.DefaultFieldMetadataProvider)1 FieldMetadataProvider (org.broadleafcommerce.openadmin.server.dao.provider.metadata.FieldMetadataProvider)1 OverrideViaAnnotationRequest (org.broadleafcommerce.openadmin.server.dao.provider.metadata.request.OverrideViaAnnotationRequest)1 OverrideViaXmlRequest (org.broadleafcommerce.openadmin.server.dao.provider.metadata.request.OverrideViaXmlRequest)1 MetadataProviderResponse (org.broadleafcommerce.openadmin.server.service.type.MetadataProviderResponse)1 PersistentClass (org.hibernate.mapping.PersistentClass)1