Search in sources :

Example 6 with MetadataOverride

use of org.broadleafcommerce.openadmin.dto.override.MetadataOverride in project BroadleafCommerce by BroadleafCommerce.

the class AdornedTargetCollectionFieldMetadataProvider method overrideViaXml.

@Override
public MetadataProviderResponse overrideViaXml(OverrideViaXmlRequest overrideViaXmlRequest, Map<String, FieldMetadata> metadata) {
    Map<String, MetadataOverride> overrides = getTargetedOverride(overrideViaXmlRequest.getDynamicEntityDao(), overrideViaXmlRequest.getRequestedConfigKey(), overrideViaXmlRequest.getRequestedCeilingEntity());
    if (overrides != null) {
        for (String propertyName : overrides.keySet()) {
            MetadataOverride localMetadata = overrides.get(propertyName);
            if (localMetadata instanceof FieldMetadataOverride) {
                FieldMetadataOverride localFieldMetadata = (FieldMetadataOverride) localMetadata;
                for (String key : metadata.keySet()) {
                    if (key.equals(propertyName)) {
                        try {
                            if (metadata.get(key) instanceof AdornedTargetCollectionMetadata) {
                                AdornedTargetCollectionMetadata serverMetadata = (AdornedTargetCollectionMetadata) metadata.get(key);
                                if (serverMetadata.getTargetClass() != null) {
                                    Class<?> targetClass = Class.forName(serverMetadata.getTargetClass());
                                    Class<?> parentClass = null;
                                    if (serverMetadata.getOwningClass() != null) {
                                        parentClass = Class.forName(serverMetadata.getOwningClass());
                                    }
                                    String fieldName = serverMetadata.getFieldName();
                                    Field field = overrideViaXmlRequest.getDynamicEntityDao().getFieldManager().getField(targetClass, fieldName);
                                    Map<String, FieldMetadata> temp = new HashMap<String, FieldMetadata>(1);
                                    temp.put(field.getName(), serverMetadata);
                                    FieldInfo info = buildFieldInfo(field);
                                    buildAdornedTargetCollectionMetadata(parentClass, targetClass, temp, info, localFieldMetadata, overrideViaXmlRequest.getDynamicEntityDao());
                                    serverMetadata = (AdornedTargetCollectionMetadata) temp.get(field.getName());
                                    metadata.put(key, serverMetadata);
                                    if (overrideViaXmlRequest.getParentExcluded()) {
                                        if (LOG.isDebugEnabled()) {
                                            LOG.debug("applyAdornedTargetCollectionMetadataOverrides:Excluding " + key + "because parent is marked as excluded.");
                                        }
                                        serverMetadata.setExcluded(true);
                                    }
                                }
                            }
                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
        }
    }
    return MetadataProviderResponse.HANDLED;
}
Also used : FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) HashMap(java.util.HashMap) FieldMetadataOverride(org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) Field(java.lang.reflect.Field) FieldMetadataOverride(org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride) MetadataOverride(org.broadleafcommerce.openadmin.dto.override.MetadataOverride) AdornedTargetCollectionMetadata(org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata) FieldInfo(org.broadleafcommerce.openadmin.server.dao.FieldInfo) AdminPresentationAdornedTargetCollectionOverride(org.broadleafcommerce.common.presentation.override.AdminPresentationAdornedTargetCollectionOverride) FieldMetadataOverride(org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride) AdminPresentationMergeOverride(org.broadleafcommerce.common.presentation.override.AdminPresentationMergeOverride) MetadataOverride(org.broadleafcommerce.openadmin.dto.override.MetadataOverride)

Aggregations

FieldMetadataOverride (org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride)6 MetadataOverride (org.broadleafcommerce.openadmin.dto.override.MetadataOverride)6 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)5 Field (java.lang.reflect.Field)4 HashMap (java.util.HashMap)4 AdminPresentationMergeOverride (org.broadleafcommerce.common.presentation.override.AdminPresentationMergeOverride)4 FieldInfo (org.broadleafcommerce.openadmin.server.dao.FieldInfo)4 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)2 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)2 LinkedHashMap (java.util.LinkedHashMap)1 RequiredOverride (org.broadleafcommerce.common.presentation.RequiredOverride)1 AdminGroupPresentationOverride (org.broadleafcommerce.common.presentation.override.AdminGroupPresentationOverride)1 AdminPresentationAdornedTargetCollectionOverride (org.broadleafcommerce.common.presentation.override.AdminPresentationAdornedTargetCollectionOverride)1 AdminPresentationCollectionOverride (org.broadleafcommerce.common.presentation.override.AdminPresentationCollectionOverride)1 AdminPresentationDataDrivenEnumerationOverride (org.broadleafcommerce.common.presentation.override.AdminPresentationDataDrivenEnumerationOverride)1 AdminPresentationMapOverride (org.broadleafcommerce.common.presentation.override.AdminPresentationMapOverride)1 AdminPresentationOverride (org.broadleafcommerce.common.presentation.override.AdminPresentationOverride)1 AdminPresentationToOneLookupOverride (org.broadleafcommerce.common.presentation.override.AdminPresentationToOneLookupOverride)1 AdminTabPresentationOverride (org.broadleafcommerce.common.presentation.override.AdminTabPresentationOverride)1 AdornedTargetCollectionMetadata (org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)1