Search in sources :

Example 1 with LateStageAddMetadataRequest

use of org.broadleafcommerce.openadmin.server.dao.provider.metadata.request.LateStageAddMetadataRequest 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)

Aggregations

ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 AdminPresentationClass (org.broadleafcommerce.common.presentation.AdminPresentationClass)1 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)1 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)1 FieldMetadataProvider (org.broadleafcommerce.openadmin.server.dao.provider.metadata.FieldMetadataProvider)1 LateStageAddMetadataRequest (org.broadleafcommerce.openadmin.server.dao.provider.metadata.request.LateStageAddMetadataRequest)1 MetadataProviderResponse (org.broadleafcommerce.openadmin.server.service.type.MetadataProviderResponse)1 PersistentClass (org.hibernate.mapping.PersistentClass)1