use of org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride in project BroadleafCommerce by BroadleafCommerce.
the class AdornedTargetCollectionFieldMetadataProvider method overrideViaAnnotation.
@Override
public MetadataProviderResponse overrideViaAnnotation(OverrideViaAnnotationRequest overrideViaAnnotationRequest, Map<String, FieldMetadata> metadata) {
if (!canHandleAnnotationOverride(overrideViaAnnotationRequest, metadata)) {
return MetadataProviderResponse.NOT_HANDLED;
}
Map<String, AdminPresentationAdornedTargetCollectionOverride> presentationAdornedTargetCollectionOverrides = new HashMap<String, AdminPresentationAdornedTargetCollectionOverride>();
AdminPresentationOverrides myOverrides = overrideViaAnnotationRequest.getRequestedEntity().getAnnotation(AdminPresentationOverrides.class);
if (myOverrides != null) {
for (AdminPresentationAdornedTargetCollectionOverride myOverride : myOverrides.adornedTargetCollections()) {
presentationAdornedTargetCollectionOverrides.put(myOverride.name(), myOverride);
}
}
for (String propertyName : presentationAdornedTargetCollectionOverrides.keySet()) {
for (String key : metadata.keySet()) {
if (key.startsWith(propertyName)) {
buildAdminPresentationAdornedTargetCollectionOverride(overrideViaAnnotationRequest.getPrefix(), overrideViaAnnotationRequest.getParentExcluded(), metadata, presentationAdornedTargetCollectionOverrides, propertyName, key, overrideViaAnnotationRequest.getDynamicEntityDao());
}
}
}
AdminPresentationMergeOverrides myMergeOverrides = overrideViaAnnotationRequest.getRequestedEntity().getAnnotation(AdminPresentationMergeOverrides.class);
if (myMergeOverrides != null) {
for (AdminPresentationMergeOverride override : myMergeOverrides.value()) {
String propertyName = override.name();
Map<String, FieldMetadata> loopMap = new HashMap<String, FieldMetadata>();
loopMap.putAll(metadata);
for (Map.Entry<String, FieldMetadata> entry : loopMap.entrySet()) {
if (entry.getKey().startsWith(propertyName) || StringUtils.isEmpty(propertyName)) {
FieldMetadata targetMetadata = entry.getValue();
if (targetMetadata instanceof AdornedTargetCollectionMetadata) {
AdornedTargetCollectionMetadata serverMetadata = (AdornedTargetCollectionMetadata) targetMetadata;
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 = overrideViaAnnotationRequest.getDynamicEntityDao().getFieldManager().getField(targetClass, fieldName);
Map<String, FieldMetadata> temp = new HashMap<String, FieldMetadata>(1);
temp.put(field.getName(), serverMetadata);
FieldInfo info = buildFieldInfo(field);
FieldMetadataOverride fieldMetadataOverride = overrideAdornedTargetMergeMetadata(override);
if (serverMetadata.getExcluded() != null && serverMetadata.getExcluded() && (fieldMetadataOverride.getExcluded() == null || fieldMetadataOverride.getExcluded())) {
continue;
}
buildAdornedTargetCollectionMetadata(parentClass, targetClass, temp, info, fieldMetadataOverride, overrideViaAnnotationRequest.getDynamicEntityDao());
serverMetadata = (AdornedTargetCollectionMetadata) temp.get(field.getName());
metadata.put(entry.getKey(), serverMetadata);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}
}
}
}
return MetadataProviderResponse.HANDLED;
}
use of org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride in project BroadleafCommerce by BroadleafCommerce.
the class AdornedTargetCollectionFieldMetadataProvider method constructAdornedTargetCollectionMetadataOverride.
protected FieldMetadataOverride constructAdornedTargetCollectionMetadataOverride(AdminPresentationAdornedTargetCollection adornedTargetCollection) {
if (adornedTargetCollection != null) {
FieldMetadataOverride override = new FieldMetadataOverride();
override.setGridVisibleFields(adornedTargetCollection.gridVisibleFields());
override.setSelectizeVisibleField(adornedTargetCollection.selectizeVisibleField());
override.setIgnoreAdornedProperties(adornedTargetCollection.ignoreAdornedProperties());
override.setMaintainedAdornedTargetFields(adornedTargetCollection.maintainedAdornedTargetFields());
override.setParentObjectIdProperty(adornedTargetCollection.parentObjectIdProperty());
override.setParentObjectProperty(adornedTargetCollection.parentObjectProperty());
override.setSortAscending(adornedTargetCollection.sortAscending());
override.setSortProperty(adornedTargetCollection.sortProperty());
override.setTargetObjectIdProperty(adornedTargetCollection.targetObjectIdProperty());
override.setTargetObjectProperty(adornedTargetCollection.targetObjectProperty());
override.setJoinEntityClass(adornedTargetCollection.joinEntityClass());
override.setCustomCriteria(adornedTargetCollection.customCriteria());
override.setUseServerSideInspectionCache(adornedTargetCollection.useServerSideInspectionCache());
override.setExcluded(adornedTargetCollection.excluded());
override.setFriendlyName(adornedTargetCollection.friendlyName());
override.setReadOnly(adornedTargetCollection.readOnly());
override.setOrder(adornedTargetCollection.order());
override.setTab(adornedTargetCollection.tab());
override.setTabOrder(adornedTargetCollection.tabOrder());
override.setGroup(adornedTargetCollection.group());
override.setSecurityLevel(adornedTargetCollection.securityLevel());
override.setAddType(adornedTargetCollection.operationTypes().addType());
override.setFetchType(adornedTargetCollection.operationTypes().fetchType());
override.setRemoveType(adornedTargetCollection.operationTypes().removeType());
override.setUpdateType(adornedTargetCollection.operationTypes().updateType());
override.setInspectType(adornedTargetCollection.operationTypes().inspectType());
override.setShowIfProperty(adornedTargetCollection.showIfProperty());
override.setCurrencyCodeField(adornedTargetCollection.currencyCodeField());
override.setAdornedTargetAddMethodType(adornedTargetCollection.addType());
override.setLazyFetch(adornedTargetCollection.lazyFetch());
override.setManualFetch(adornedTargetCollection.manualFetch());
if (adornedTargetCollection.showIfFieldEquals().length != 0) {
processShowIfFieldEqualsAnnotations(adornedTargetCollection.showIfFieldEquals(), override);
}
return override;
}
throw new IllegalArgumentException("AdminPresentationAdornedTargetCollection annotation not found on field.");
}
Aggregations