Search in sources :

Example 1 with FieldMetadata

use of org.broadleafcommerce.openadmin.dto.FieldMetadata 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 2 with FieldMetadata

use of org.broadleafcommerce.openadmin.dto.FieldMetadata in project BroadleafCommerce by BroadleafCommerce.

the class CollectionFieldMetadataProvider method buildAdminPresentationCollectionOverride.

protected void buildAdminPresentationCollectionOverride(String prefix, Boolean isParentExcluded, Map<String, FieldMetadata> mergedProperties, Map<String, AdminPresentationCollectionOverride> presentationCollectionOverrides, String propertyName, String key, DynamicEntityDao dynamicEntityDao) {
    AdminPresentationCollectionOverride override = presentationCollectionOverrides.get(propertyName);
    if (override != null) {
        AdminPresentationCollection annot = override.value();
        if (annot != null) {
            String testKey = prefix + key;
            if ((testKey.startsWith(propertyName + ".") || testKey.equals(propertyName)) && annot.excluded()) {
                FieldMetadata metadata = mergedProperties.get(key);
                if (LOG.isDebugEnabled()) {
                    LOG.debug("buildAdminPresentationCollectionOverride:Excluding " + key + "because an override annotation declared " + testKey + "to be excluded");
                }
                metadata.setExcluded(true);
                return;
            }
            if ((testKey.startsWith(propertyName + ".") || testKey.equals(propertyName)) && !annot.excluded()) {
                FieldMetadata metadata = mergedProperties.get(key);
                if (!isParentExcluded) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("buildAdminPresentationCollectionOverride:Showing " + key + "because an override annotation declared " + testKey + " to not be excluded");
                    }
                    metadata.setExcluded(false);
                }
            }
            if (!(mergedProperties.get(key) instanceof BasicCollectionMetadata)) {
                return;
            }
            BasicCollectionMetadata serverMetadata = (BasicCollectionMetadata) mergedProperties.get(key);
            if (serverMetadata.getTargetClass() != null) {
                try {
                    Class<?> targetClass = Class.forName(serverMetadata.getTargetClass());
                    Class<?> parentClass = null;
                    if (serverMetadata.getOwningClass() != null) {
                        parentClass = Class.forName(serverMetadata.getOwningClass());
                    }
                    String fieldName = serverMetadata.getFieldName();
                    Field field = dynamicEntityDao.getFieldManager().getField(targetClass, fieldName);
                    FieldMetadataOverride localMetadata = constructBasicCollectionMetadataOverride(annot);
                    // do not include the previous metadata - we want to construct a fresh metadata from the override annotation
                    Map<String, FieldMetadata> temp = new HashMap<String, FieldMetadata>(1);
                    FieldInfo info = buildFieldInfo(field);
                    buildCollectionMetadata(parentClass, targetClass, temp, info, localMetadata, prefix);
                    BasicCollectionMetadata result = (BasicCollectionMetadata) temp.get(field.getName());
                    result.setInheritedFromType(serverMetadata.getInheritedFromType());
                    result.setAvailableToTypes(serverMetadata.getAvailableToTypes());
                    mergedProperties.put(key, result);
                    if (isParentExcluded) {
                        if (LOG.isDebugEnabled()) {
                            LOG.debug("buildAdminPresentationCollectionOverride:Excluding " + key + "because the parent was excluded");
                        }
                        serverMetadata.setExcluded(true);
                    }
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
Also used : FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) AdminPresentationCollectionOverride(org.broadleafcommerce.common.presentation.override.AdminPresentationCollectionOverride) HashMap(java.util.HashMap) AdminPresentationCollection(org.broadleafcommerce.common.presentation.AdminPresentationCollection) FieldMetadataOverride(org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) Field(java.lang.reflect.Field) BasicCollectionMetadata(org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata) FieldInfo(org.broadleafcommerce.openadmin.server.dao.FieldInfo)

Example 3 with FieldMetadata

use of org.broadleafcommerce.openadmin.dto.FieldMetadata 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 FieldMetadata

use of org.broadleafcommerce.openadmin.dto.FieldMetadata 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 FieldMetadata

use of org.broadleafcommerce.openadmin.dto.FieldMetadata in project BroadleafCommerce by BroadleafCommerce.

the class MapFieldMetadataProvider method buildAdminPresentationMapOverride.

protected void buildAdminPresentationMapOverride(String prefix, Boolean isParentExcluded, Map<String, FieldMetadata> mergedProperties, Map<String, AdminPresentationMapOverride> presentationMapOverrides, String propertyName, String key, DynamicEntityDao dynamicEntityDao) {
    AdminPresentationMapOverride override = presentationMapOverrides.get(propertyName);
    if (override != null) {
        AdminPresentationMap annot = override.value();
        if (annot != null) {
            String testKey = prefix + key;
            if ((testKey.startsWith(propertyName + ".") || testKey.equals(propertyName)) && annot.excluded()) {
                FieldMetadata metadata = mergedProperties.get(key);
                if (LOG.isDebugEnabled()) {
                    LOG.debug("buildAdminPresentationMapOverride:Excluding " + key + "because an override annotation declared " + testKey + "to be excluded");
                }
                metadata.setExcluded(true);
                return;
            }
            if ((testKey.startsWith(propertyName + ".") || testKey.equals(propertyName)) && !annot.excluded()) {
                FieldMetadata metadata = mergedProperties.get(key);
                if (!isParentExcluded) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("buildAdminPresentationMapOverride:Showing " + key + "because an override annotation declared " + testKey + " to not be excluded");
                    }
                    metadata.setExcluded(false);
                }
            }
            if (!(mergedProperties.get(key) instanceof MapMetadata)) {
                return;
            }
            MapMetadata serverMetadata = (MapMetadata) mergedProperties.get(key);
            if (serverMetadata.getTargetClass() != null) {
                try {
                    Class<?> targetClass = Class.forName(serverMetadata.getTargetClass());
                    Class<?> parentClass = null;
                    if (serverMetadata.getOwningClass() != null) {
                        parentClass = Class.forName(serverMetadata.getOwningClass());
                    }
                    String fieldName = serverMetadata.getFieldName();
                    Field field = dynamicEntityDao.getFieldManager().getField(targetClass, fieldName);
                    FieldMetadataOverride localMetadata = constructMapMetadataOverride(annot);
                    // do not include the previous metadata - we want to construct a fresh metadata from the override annotation
                    Map<String, FieldMetadata> temp = new HashMap<String, FieldMetadata>(1);
                    FieldInfo info = buildFieldInfo(field);
                    buildMapMetadata(parentClass, targetClass, temp, info, localMetadata, dynamicEntityDao, serverMetadata.getPrefix());
                    MapMetadata result = (MapMetadata) temp.get(field.getName());
                    result.setInheritedFromType(serverMetadata.getInheritedFromType());
                    result.setAvailableToTypes(serverMetadata.getAvailableToTypes());
                    mergedProperties.put(key, result);
                    if (isParentExcluded) {
                        if (LOG.isDebugEnabled()) {
                            LOG.debug("buildAdminPresentationMapOverride:Excluding " + key + "because the parent was excluded");
                        }
                        serverMetadata.setExcluded(true);
                    }
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
Also used : FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) HashMap(java.util.HashMap) FieldMetadataOverride(org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride) AdminPresentationMap(org.broadleafcommerce.common.presentation.AdminPresentationMap) Field(java.lang.reflect.Field) AdminPresentationMapOverride(org.broadleafcommerce.common.presentation.override.AdminPresentationMapOverride) MapMetadata(org.broadleafcommerce.openadmin.dto.MapMetadata) FieldInfo(org.broadleafcommerce.openadmin.server.dao.FieldInfo)

Aggregations

FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)114 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)80 Entity (org.broadleafcommerce.openadmin.dto.Entity)51 ServiceException (org.broadleafcommerce.common.exception.ServiceException)46 PersistencePerspective (org.broadleafcommerce.openadmin.dto.PersistencePerspective)44 HashMap (java.util.HashMap)39 Property (org.broadleafcommerce.openadmin.dto.Property)38 Map (java.util.Map)28 ArrayList (java.util.ArrayList)23 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)22 Field (java.lang.reflect.Field)19 SecurityServiceException (org.broadleafcommerce.common.exception.SecurityServiceException)19 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)19 Serializable (java.io.Serializable)18 InvocationTargetException (java.lang.reflect.InvocationTargetException)18 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)18 CriteriaTransferObject (org.broadleafcommerce.openadmin.dto.CriteriaTransferObject)17 BasicCollectionMetadata (org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata)15 FieldMetadataOverride (org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride)15 AdornedTargetCollectionMetadata (org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)13