Search in sources :

Example 1 with AdminPresentation

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

the class BasicFieldMetadataProvider method addMetadata.

@Override
public MetadataProviderResponse addMetadata(AddFieldMetadataRequest addMetadataRequest, Map<String, FieldMetadata> metadata) {
    if (!canHandleFieldForConfiguredMetadata(addMetadataRequest, metadata)) {
        return MetadataProviderResponse.NOT_HANDLED;
    }
    AdminPresentation annot = addMetadataRequest.getRequestedField().getAnnotation(AdminPresentation.class);
    FieldInfo info = buildFieldInfo(addMetadataRequest.getRequestedField());
    FieldMetadataOverride override = constructBasicMetadataOverride(annot, addMetadataRequest.getRequestedField().getAnnotation(AdminPresentationToOneLookup.class), addMetadataRequest.getRequestedField().getAnnotation(AdminPresentationDataDrivenEnumeration.class));
    buildBasicMetadata(addMetadataRequest.getParentClass(), addMetadataRequest.getTargetClass(), metadata, info, override, addMetadataRequest.getDynamicEntityDao());
    setClassOwnership(addMetadataRequest.getParentClass(), addMetadataRequest.getTargetClass(), metadata, info);
    return MetadataProviderResponse.HANDLED;
}
Also used : AdminPresentation(org.broadleafcommerce.common.presentation.AdminPresentation) AdminPresentationToOneLookup(org.broadleafcommerce.common.presentation.AdminPresentationToOneLookup) FieldInfo(org.broadleafcommerce.openadmin.server.dao.FieldInfo) FieldMetadataOverride(org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride) AdminPresentationDataDrivenEnumeration(org.broadleafcommerce.common.presentation.AdminPresentationDataDrivenEnumeration) 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 AdminPresentation

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

the class OracleRequiredFieldManagerModifier method canHandle.

@Override
public boolean canHandle(Field field, Object value, EntityManager em) {
    if (!dialectHelper.isOracle(em)) {
        return false;
    }
    Column column = field.getAnnotation(Column.class);
    AdminPresentation adminPresentation = field.getAnnotation(AdminPresentation.class);
    return adminPresentation != null && isRequiredField(adminPresentation, column) && isStringFieldType(field, adminPresentation);
}
Also used : Column(javax.persistence.Column) AdminPresentation(org.broadleafcommerce.common.presentation.AdminPresentation) RequiredOverride(org.broadleafcommerce.common.presentation.RequiredOverride)

Example 3 with AdminPresentation

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

the class BasicFieldMetadataProvider method buildAdminPresentationOverride.

protected void buildAdminPresentationOverride(String prefix, Boolean isParentExcluded, Map<String, FieldMetadata> mergedProperties, Map<String, AdminPresentationOverride> presentationOverrides, String propertyName, String key, DynamicEntityDao dynamicEntityDao) {
    AdminPresentationOverride override = presentationOverrides.get(propertyName);
    if (override != null) {
        AdminPresentation 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("buildAdminPresentationOverride: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("buildAdminPresentationOverride:Showing " + key + "because an override annotation declared " + testKey + " to not be excluded");
                    }
                    metadata.setExcluded(false);
                }
            }
            if (!(mergedProperties.get(key) instanceof BasicFieldMetadata)) {
                return;
            }
            BasicFieldMetadata serverMetadata = (BasicFieldMetadata) 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 = constructBasicMetadataOverride(annot, null, null);
                    // do not include the previous metadata - we want to construct a fresh metadata from the override annotation
                    Map<String, FieldMetadata> temp = new HashMap<>(1);
                    FieldInfo info = buildFieldInfo(field);
                    buildBasicMetadata(parentClass, targetClass, temp, info, localMetadata, dynamicEntityDao);
                    BasicFieldMetadata result = (BasicFieldMetadata) temp.get(field.getName());
                    result.setInheritedFromType(serverMetadata.getInheritedFromType());
                    result.setAvailableToTypes(serverMetadata.getAvailableToTypes());
                    result.setFieldType(serverMetadata.getFieldType());
                    result.setSecondaryType(serverMetadata.getSecondaryType());
                    result.setLength(serverMetadata.getLength());
                    result.setScale(serverMetadata.getScale());
                    result.setPrecision(serverMetadata.getPrecision());
                    result.setRequired(serverMetadata.getRequired());
                    result.setUnique(serverMetadata.getUnique());
                    result.setForeignKeyCollection(serverMetadata.getForeignKeyCollection());
                    result.setMutable(serverMetadata.getMutable());
                    result.setMergedPropertyType(serverMetadata.getMergedPropertyType());
                    mergedProperties.put(key, result);
                    if (isParentExcluded) {
                        if (LOG.isDebugEnabled()) {
                            LOG.debug("buildAdminPresentationOverride:Excluding " + key + "because the parent was excluded");
                        }
                        serverMetadata.setExcluded(true);
                    }
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
Also used : AdminPresentationOverride(org.broadleafcommerce.common.presentation.override.AdminPresentationOverride) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AdminPresentation(org.broadleafcommerce.common.presentation.AdminPresentation) FieldMetadataOverride(org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride) Field(java.lang.reflect.Field) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) FieldInfo(org.broadleafcommerce.openadmin.server.dao.FieldInfo)

Aggregations

AdminPresentation (org.broadleafcommerce.common.presentation.AdminPresentation)3 RequiredOverride (org.broadleafcommerce.common.presentation.RequiredOverride)2 AdminPresentationOverride (org.broadleafcommerce.common.presentation.override.AdminPresentationOverride)2 FieldMetadataOverride (org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride)2 FieldInfo (org.broadleafcommerce.openadmin.server.dao.FieldInfo)2 Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Column (javax.persistence.Column)1 AdminPresentationDataDrivenEnumeration (org.broadleafcommerce.common.presentation.AdminPresentationDataDrivenEnumeration)1 AdminPresentationToOneLookup (org.broadleafcommerce.common.presentation.AdminPresentationToOneLookup)1 AdminPresentationDataDrivenEnumerationOverride (org.broadleafcommerce.common.presentation.override.AdminPresentationDataDrivenEnumerationOverride)1 AdminPresentationMergeOverride (org.broadleafcommerce.common.presentation.override.AdminPresentationMergeOverride)1 AdminPresentationToOneLookupOverride (org.broadleafcommerce.common.presentation.override.AdminPresentationToOneLookupOverride)1 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)1 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)1 MetadataOverride (org.broadleafcommerce.openadmin.dto.override.MetadataOverride)1