Search in sources :

Example 1 with MetadataOverride

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

the class BasicEntityMetadataProvider method overrideMetadataViaXml.

@Override
public MetadataProviderResponse overrideMetadataViaXml(OverrideViaXmlRequest overrideViaXmlRequest, Map<String, TabMetadata> metadata) {
    Map<String, MetadataOverride> overrides = getTargetedOverride(overrideViaXmlRequest.getDynamicEntityDao(), overrideViaXmlRequest.getRequestedConfigKey(), overrideViaXmlRequest.getRequestedCeilingEntity());
    if (overrides != null) {
        for (String overrideKey : overrides.keySet()) {
            MetadataOverride overrideMetadata = overrides.get(overrideKey);
            if (overrideMetadata instanceof GroupMetadataOverride) {
                GroupMetadataOverride groupOverrideMetadata = (GroupMetadataOverride) overrideMetadata;
                applyGroupMetadataOverrideViaXml(overrideKey, groupOverrideMetadata, metadata);
            } else if (!(overrideMetadata instanceof FieldMetadataOverride)) {
                // Strictly applies to a Tab
                applyTabMetadataOverrideViaXml(overrideKey, overrideMetadata, metadata);
            }
        }
    }
    return MetadataProviderResponse.HANDLED;
}
Also used : FieldMetadataOverride(org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride) GroupMetadataOverride(org.broadleafcommerce.openadmin.dto.override.GroupMetadataOverride) MetadataOverride(org.broadleafcommerce.openadmin.dto.override.MetadataOverride) GroupMetadataOverride(org.broadleafcommerce.openadmin.dto.override.GroupMetadataOverride) FieldMetadataOverride(org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride) FieldMetadataOverride(org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride) AdminTabPresentationOverride(org.broadleafcommerce.common.presentation.override.AdminTabPresentationOverride) AdminGroupPresentationOverride(org.broadleafcommerce.common.presentation.override.AdminGroupPresentationOverride) GroupMetadataOverride(org.broadleafcommerce.openadmin.dto.override.GroupMetadataOverride) MetadataOverride(org.broadleafcommerce.openadmin.dto.override.MetadataOverride)

Example 2 with MetadataOverride

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

the class BasicFieldMetadataProvider 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 BasicFieldMetadata) {
                                BasicFieldMetadata serverMetadata = (BasicFieldMetadata) 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<>(1);
                                    temp.put(field.getName(), serverMetadata);
                                    FieldInfo info = buildFieldInfo(field);
                                    buildBasicMetadata(parentClass, targetClass, temp, info, localFieldMetadata, overrideViaXmlRequest.getDynamicEntityDao());
                                    serverMetadata = (BasicFieldMetadata) temp.get(field.getName());
                                    metadata.put(key, serverMetadata);
                                    if (overrideViaXmlRequest.getParentExcluded()) {
                                        if (LOG.isDebugEnabled()) {
                                            LOG.debug("applyMetadataOverrides:Excluding " + key + "because the parent was excluded");
                                        }
                                        serverMetadata.setExcluded(true);
                                    }
                                }
                            }
                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
        }
    }
    return MetadataProviderResponse.HANDLED;
}
Also used : FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FieldMetadataOverride(org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride) Field(java.lang.reflect.Field) FieldMetadataOverride(org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride) MetadataOverride(org.broadleafcommerce.openadmin.dto.override.MetadataOverride) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) FieldInfo(org.broadleafcommerce.openadmin.server.dao.FieldInfo) AdminPresentationMergeOverride(org.broadleafcommerce.common.presentation.override.AdminPresentationMergeOverride) RequiredOverride(org.broadleafcommerce.common.presentation.RequiredOverride) AdminPresentationToOneLookupOverride(org.broadleafcommerce.common.presentation.override.AdminPresentationToOneLookupOverride) AdminPresentationOverride(org.broadleafcommerce.common.presentation.override.AdminPresentationOverride) AdminPresentationDataDrivenEnumerationOverride(org.broadleafcommerce.common.presentation.override.AdminPresentationDataDrivenEnumerationOverride) FieldMetadataOverride(org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride) MetadataOverride(org.broadleafcommerce.openadmin.dto.override.MetadataOverride)

Example 3 with MetadataOverride

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

the class CollectionFieldMetadataProvider 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 BasicCollectionMetadata) {
                                BasicCollectionMetadata serverMetadata = (BasicCollectionMetadata) 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);
                                    buildCollectionMetadata(parentClass, targetClass, temp, info, localFieldMetadata, overrideViaXmlRequest.getPrefix());
                                    serverMetadata = (BasicCollectionMetadata) temp.get(field.getName());
                                    metadata.put(key, serverMetadata);
                                    if (overrideViaXmlRequest.getParentExcluded()) {
                                        if (LOG.isDebugEnabled()) {
                                            LOG.debug("applyCollectionMetadataOverrides: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) BasicCollectionMetadata(org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata) FieldInfo(org.broadleafcommerce.openadmin.server.dao.FieldInfo) FieldMetadataOverride(org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride) AdminPresentationMergeOverride(org.broadleafcommerce.common.presentation.override.AdminPresentationMergeOverride) MetadataOverride(org.broadleafcommerce.openadmin.dto.override.MetadataOverride) AdminPresentationCollectionOverride(org.broadleafcommerce.common.presentation.override.AdminPresentationCollectionOverride)

Example 4 with MetadataOverride

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

the class MapFieldMetadataProvider 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 MapMetadata) {
                                MapMetadata serverMetadata = (MapMetadata) 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);
                                    buildMapMetadata(parentClass, targetClass, temp, info, localFieldMetadata, overrideViaXmlRequest.getDynamicEntityDao(), serverMetadata.getPrefix());
                                    serverMetadata = (MapMetadata) temp.get(field.getName());
                                    metadata.put(key, serverMetadata);
                                    if (overrideViaXmlRequest.getParentExcluded()) {
                                        if (LOG.isDebugEnabled()) {
                                            LOG.debug("applyMapMetadataOverrides: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) Field(java.lang.reflect.Field) FieldMetadataOverride(org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride) MetadataOverride(org.broadleafcommerce.openadmin.dto.override.MetadataOverride) MapMetadata(org.broadleafcommerce.openadmin.dto.MapMetadata) FieldInfo(org.broadleafcommerce.openadmin.server.dao.FieldInfo) FieldMetadataOverride(org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride) AdminPresentationMergeOverride(org.broadleafcommerce.common.presentation.override.AdminPresentationMergeOverride) AdminPresentationMapOverride(org.broadleafcommerce.common.presentation.override.AdminPresentationMapOverride) MetadataOverride(org.broadleafcommerce.openadmin.dto.override.MetadataOverride)

Example 5 with MetadataOverride

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

the class DefaultFieldMetadataProvider method overrideExclusionsFromXml.

public void overrideExclusionsFromXml(OverrideViaXmlRequest overrideViaXmlRequest, Map<String, FieldMetadata> metadata) {
    // override any and all exclusions derived from xml
    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;
                Boolean excluded = localFieldMetadata.getExcluded();
                for (String key : metadata.keySet()) {
                    String testKey = overrideViaXmlRequest.getPrefix() + key;
                    if ((testKey.startsWith(propertyName + ".") || testKey.equals(propertyName)) && excluded != null && excluded) {
                        FieldMetadata fieldMetadata = metadata.get(key);
                        if (LOG.isDebugEnabled()) {
                            LOG.debug("setExclusionsBasedOnParents:Excluding " + key + "because an override annotation declared " + testKey + " to be excluded");
                        }
                        fieldMetadata.setExcluded(true);
                        continue;
                    }
                    if ((testKey.startsWith(propertyName + ".") || testKey.equals(propertyName)) && excluded != null && !excluded) {
                        FieldMetadata fieldMetadata = metadata.get(key);
                        if (!overrideViaXmlRequest.getParentExcluded()) {
                            if (LOG.isDebugEnabled()) {
                                LOG.debug("setExclusionsBasedOnParents:Showing " + key + "because an override annotation declared " + testKey + " to not be excluded");
                            }
                            fieldMetadata.setExcluded(false);
                        }
                    }
                }
            }
        }
    }
}
Also used : FieldMetadataOverride(org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride) MetadataOverride(org.broadleafcommerce.openadmin.dto.override.MetadataOverride) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) FieldMetadataOverride(org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride)

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