Search in sources :

Example 1 with AdminPresentationMapFields

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

the class MapFieldsFieldMetadataProvider method addMetadata.

@Override
public MetadataProviderResponse addMetadata(AddFieldMetadataRequest addMetadataRequest, Map<String, FieldMetadata> metadata) {
    if (!canHandleFieldForConfiguredMetadata(addMetadataRequest, metadata)) {
        return MetadataProviderResponse.NOT_HANDLED;
    }
    AdminPresentationMapFields annot = addMetadataRequest.getRequestedField().getAnnotation(AdminPresentationMapFields.class);
    for (AdminPresentationMapField mapField : annot.mapDisplayFields()) {
        if (mapField.fieldPresentation().fieldType() == SupportedFieldType.UNKNOWN) {
            throw new IllegalArgumentException("fieldType property on AdminPresentation must be set for AdminPresentationMapField");
        }
        FieldMetadataOverride override = constructBasicMetadataOverride(mapField.fieldPresentation(), null, null);
        override.setFriendlyName(mapField.fieldPresentation().friendlyName());
        FieldInfo myInfo = new FieldInfo();
        myInfo.setName(addMetadataRequest.getRequestedField().getName() + FieldManager.MAPFIELDSEPARATOR + mapField.fieldName());
        buildBasicMetadata(addMetadataRequest.getParentClass(), addMetadataRequest.getTargetClass(), metadata, myInfo, override, addMetadataRequest.getDynamicEntityDao());
        setClassOwnership(addMetadataRequest.getParentClass(), addMetadataRequest.getTargetClass(), metadata, myInfo);
        BasicFieldMetadata basicFieldMetadata = (BasicFieldMetadata) metadata.get(myInfo.getName());
        if (!mapField.targetClass().equals(Void.class)) {
            if (mapField.targetClass().isInterface()) {
                throw new IllegalArgumentException("targetClass on @AdminPresentationMapField must be a concrete class");
            }
            basicFieldMetadata.setMapFieldValueClass(mapField.targetClass().getName());
        }
        if (!StringUtils.isEmpty(mapField.manyToField())) {
            basicFieldMetadata.setManyToField(mapField.manyToField());
        }
        AdminPresentationMap annotMap = addMetadataRequest.getRequestedField().getAnnotation(AdminPresentationMap.class);
        if (annotMap != null && !StringUtils.isEmpty(annotMap.toOneTargetProperty())) {
            basicFieldMetadata.setToOneTargetProperty(annotMap.toOneTargetProperty());
        } else if (!StringUtils.isEmpty(annot.toOneTargetProperty())) {
            basicFieldMetadata.setToOneTargetProperty(annot.toOneTargetProperty());
        }
        if (annotMap != null && !StringUtils.isEmpty(annotMap.toOneParentProperty())) {
            basicFieldMetadata.setToOneParentProperty(annotMap.toOneParentProperty());
        } else if (!StringUtils.isEmpty(annot.toOneParentProperty())) {
            basicFieldMetadata.setToOneParentProperty(annot.toOneParentProperty());
        }
        String mapKeyValueProperty = "key";
        if (StringUtils.isNotBlank(myInfo.getMapKey())) {
            mapKeyValueProperty = myInfo.getMapKey();
        }
        if (annotMap != null) {
            if (StringUtils.isNotBlank(annotMap.mapKeyValueProperty())) {
                mapKeyValueProperty = annotMap.mapKeyValueProperty();
            }
        }
        basicFieldMetadata.setMapKeyValueProperty(mapKeyValueProperty);
    }
    return MetadataProviderResponse.HANDLED;
}
Also used : AdminPresentationMapField(org.broadleafcommerce.common.presentation.AdminPresentationMapField) AdminPresentationMapFields(org.broadleafcommerce.common.presentation.AdminPresentationMapFields) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) FieldMetadataOverride(org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride) FieldInfo(org.broadleafcommerce.openadmin.server.dao.FieldInfo) AdminPresentationMap(org.broadleafcommerce.common.presentation.AdminPresentationMap) FieldMetadataOverride(org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride)

Aggregations

AdminPresentationMap (org.broadleafcommerce.common.presentation.AdminPresentationMap)1 AdminPresentationMapField (org.broadleafcommerce.common.presentation.AdminPresentationMapField)1 AdminPresentationMapFields (org.broadleafcommerce.common.presentation.AdminPresentationMapFields)1 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)1 FieldMetadataOverride (org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride)1 FieldInfo (org.broadleafcommerce.openadmin.server.dao.FieldInfo)1