use of org.broadleafcommerce.common.presentation.AdminPresentationMapField 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;
}
Aggregations