use of org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride in project BroadleafCommerce by BroadleafCommerce.
the class BasicEntityMetadataProvider method overrideMetadataViaXml.
@Override
public MetadataProviderResponse overrideMetadataViaXml(OverrideViaXmlRequest overrideViaXmlRequest, Map<String, TabMetadata> metadata) {
Map<String, MetadataOverride> overrides = getTargetedOverride(overrideViaXmlRequest.getDynamicEntityDao(), overrideViaXmlRequest.getRequestedConfigKey(), overrideViaXmlRequest.getRequestedCeilingEntity());
if (overrides != null) {
for (String overrideKey : overrides.keySet()) {
MetadataOverride overrideMetadata = overrides.get(overrideKey);
if (overrideMetadata instanceof GroupMetadataOverride) {
GroupMetadataOverride groupOverrideMetadata = (GroupMetadataOverride) overrideMetadata;
applyGroupMetadataOverrideViaXml(overrideKey, groupOverrideMetadata, metadata);
} else if (!(overrideMetadata instanceof FieldMetadataOverride)) {
// Strictly applies to a Tab
applyTabMetadataOverrideViaXml(overrideKey, overrideMetadata, metadata);
}
}
}
return MetadataProviderResponse.HANDLED;
}
use of org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride in project BroadleafCommerce by BroadleafCommerce.
the class BasicFieldMetadataProvider method overrideMergeMetadata.
protected FieldMetadataOverride overrideMergeMetadata(AdminPresentationMergeOverride merge) {
FieldMetadataOverride fieldMetadataOverride = new FieldMetadataOverride();
Map<String, AdminPresentationMergeEntry> overrideValues = getAdminPresentationEntries(merge.mergeEntries());
for (Map.Entry<String, AdminPresentationMergeEntry> entry : overrideValues.entrySet()) {
String stringValue = entry.getValue().overrideValue();
if (entry.getKey().equals(PropertyType.AdminPresentation.FRIENDLYNAME)) {
fieldMetadataOverride.setFriendlyName(stringValue);
} else if (entry.getKey().equals(PropertyType.AdminPresentation.ADDFRIENDLYNAME)) {
fieldMetadataOverride.setAddFriendlyName(stringValue);
} else if (entry.getKey().equals(PropertyType.AdminPresentation.SECURITYLEVEL)) {
fieldMetadataOverride.setSecurityLevel(stringValue);
} else if (entry.getKey().equals(PropertyType.AdminPresentation.GROUP)) {
fieldMetadataOverride.setGroup(stringValue);
} else if (entry.getKey().equals(PropertyType.AdminPresentation.TAB)) {
fieldMetadataOverride.setTab(stringValue);
} else if (entry.getKey().equals(PropertyType.AdminPresentation.COLUMNWIDTH)) {
fieldMetadataOverride.setColumnWidth(stringValue);
} else if (entry.getKey().equals(PropertyType.AdminPresentation.BROADLEAFENUMERATION)) {
fieldMetadataOverride.setBroadleafEnumeration(stringValue);
} else if (entry.getKey().equals(PropertyType.AdminPresentation.HIDEENUMERATIONIFEMPTY)) {
fieldMetadataOverride.setHideEnumerationIfEmpty(StringUtils.isEmpty(stringValue) ? entry.getValue().booleanOverrideValue() : Boolean.parseBoolean(stringValue));
} else if (entry.getKey().equals(PropertyType.AdminPresentation.FIELDCOMPONENTRENDERER)) {
fieldMetadataOverride.setFieldComponentRenderer(SupportedFieldType.valueOf(stringValue));
} else if (entry.getKey().equals(PropertyType.AdminPresentation.FIELDCOMPONENTRENDERERTEMPLATE)) {
fieldMetadataOverride.setFieldComponentRendererTemplate(stringValue);
} else if (entry.getKey().equals(PropertyType.AdminPresentation.GRIDFIELDCOMPONENTRENDERER)) {
fieldMetadataOverride.setGridFieldComponentRenderer(SupportedFieldType.valueOf(stringValue));
} else if (entry.getKey().equals(PropertyType.AdminPresentation.GRIDFIELDCOMPONENTRENDERERTEMPLATE)) {
fieldMetadataOverride.setGridFieldComponentRendererTemplate(stringValue);
} else if (entry.getKey().equals(PropertyType.AdminPresentation.TOOLTIP)) {
fieldMetadataOverride.setTooltip(stringValue);
} else if (entry.getKey().equals(PropertyType.AdminPresentation.HELPTEXT)) {
fieldMetadataOverride.setHelpText(stringValue);
} else if (entry.getKey().equals(PropertyType.AdminPresentation.HINT)) {
fieldMetadataOverride.setHint(stringValue);
} else if (entry.getKey().equals(PropertyType.AdminPresentation.SHOWIFPROPERTY)) {
fieldMetadataOverride.setShowIfProperty(stringValue);
} else if (entry.getKey().equals(PropertyType.AdminPresentation.SHOWIFFIELDEQUALS)) {
processShowIfFieldEqualsAnnotations(entry.getValue().showIfFieldEquals(), fieldMetadataOverride);
} else if (entry.getKey().equals(PropertyType.AdminPresentation.CURRENCYCODEFIELD)) {
fieldMetadataOverride.setCurrencyCodeField(stringValue);
} else if (entry.getKey().equals(PropertyType.AdminPresentation.RULEIDENTIFIER)) {
fieldMetadataOverride.setRuleIdentifier(stringValue);
} else if (entry.getKey().equals(PropertyType.AdminPresentation.ORDER)) {
fieldMetadataOverride.setOrder(StringUtils.isEmpty(stringValue) ? entry.getValue().intOverrideValue() : Integer.parseInt(stringValue));
} else if (entry.getKey().equals(PropertyType.AdminPresentation.GRIDORDER)) {
fieldMetadataOverride.setGridOrder(StringUtils.isEmpty(stringValue) ? entry.getValue().intOverrideValue() : Integer.parseInt(stringValue));
} else if (entry.getKey().equals(PropertyType.AdminPresentation.VISIBILITY)) {
fieldMetadataOverride.setVisibility(VisibilityEnum.valueOf(stringValue));
} else if (entry.getKey().equals(PropertyType.AdminPresentation.FIELDTYPE)) {
fieldMetadataOverride.setFieldType(SupportedFieldType.valueOf(stringValue));
} else if (entry.getKey().equals(PropertyType.AdminPresentation.GROUPORDER)) {
fieldMetadataOverride.setGroupOrder(StringUtils.isEmpty(stringValue) ? entry.getValue().intOverrideValue() : Integer.parseInt(stringValue));
} else if (entry.getKey().equals(PropertyType.AdminPresentation.GROUPCOLLAPSED)) {
fieldMetadataOverride.setGroupCollapsed(StringUtils.isEmpty(stringValue) ? entry.getValue().booleanOverrideValue() : Boolean.parseBoolean(stringValue));
} else if (entry.getKey().equals(PropertyType.AdminPresentation.TABORDER)) {
fieldMetadataOverride.setTabOrder(StringUtils.isEmpty(stringValue) ? entry.getValue().intOverrideValue() : Integer.parseInt(stringValue));
} else if (entry.getKey().equals(PropertyType.AdminPresentation.LARGEENTRY)) {
fieldMetadataOverride.setLargeEntry(StringUtils.isEmpty(stringValue) ? entry.getValue().booleanOverrideValue() : Boolean.parseBoolean(stringValue));
} else if (entry.getKey().equals(PropertyType.AdminPresentation.PROMINENT)) {
fieldMetadataOverride.setProminent(StringUtils.isEmpty(stringValue) ? entry.getValue().booleanOverrideValue() : Boolean.parseBoolean(stringValue));
} else if (entry.getKey().equals(PropertyType.AdminPresentation.READONLY)) {
fieldMetadataOverride.setReadOnly(StringUtils.isEmpty(stringValue) ? entry.getValue().booleanOverrideValue() : Boolean.parseBoolean(stringValue));
} else if (entry.getKey().equals(PropertyType.AdminPresentation.REQUIREDOVERRIDE)) {
if (RequiredOverride.IGNORED != RequiredOverride.valueOf(stringValue)) {
fieldMetadataOverride.setRequiredOverride(RequiredOverride.REQUIRED == RequiredOverride.valueOf(stringValue));
}
} else if (entry.getKey().equals(PropertyType.AdminPresentation.EXCLUDED)) {
fieldMetadataOverride.setExcluded(StringUtils.isEmpty(stringValue) ? entry.getValue().booleanOverrideValue() : Boolean.parseBoolean(stringValue));
} else if (entry.getKey().equals(PropertyType.AdminPresentation.DEFAULTVALUE)) {
fieldMetadataOverride.setDefaultValue(stringValue);
} else if (entry.getKey().equals(PropertyType.AdminPresentation.VALIDATIONCONFIGURATIONS)) {
processValidationAnnotations(entry.getValue().validationConfigurations(), fieldMetadataOverride);
} else if (entry.getKey().equals(PropertyType.AdminPresentation.ASSOCIATEDFIELDNAME)) {
fieldMetadataOverride.setAssociatedFieldName(stringValue);
} else if (entry.getKey().equals(PropertyType.AdminPresentationToOneLookup.LOOKUPDISPLAYPROPERTY)) {
fieldMetadataOverride.setLookupDisplayProperty(stringValue);
fieldMetadataOverride.setForeignKeyDisplayValueProperty(stringValue);
} else if (entry.getKey().equals(PropertyType.AdminPresentationToOneLookup.FORCEPOPULATECHILDPROPERTIES)) {
fieldMetadataOverride.setForcePopulateChildProperties(StringUtils.isEmpty(stringValue) ? entry.getValue().booleanOverrideValue() : Boolean.parseBoolean(stringValue));
} else if (entry.getKey().equals(PropertyType.AdminPresentationToOneLookup.ENABLETYPEAHEADLOOKUP)) {
fieldMetadataOverride.setEnableTypeaheadLookup(StringUtils.isEmpty(stringValue) ? entry.getValue().booleanOverrideValue() : Boolean.parseBoolean(stringValue));
} else if (entry.getKey().equals(PropertyType.AdminPresentationToOneLookup.USESERVERSIDEINSPECTIONCACHE)) {
fieldMetadataOverride.setUseServerSideInspectionCache(StringUtils.isEmpty(stringValue) ? entry.getValue().booleanOverrideValue() : Boolean.parseBoolean(stringValue));
} else if (entry.getKey().equals(PropertyType.AdminPresentationToOneLookup.LOOKUPTYPE)) {
fieldMetadataOverride.setLookupType(LookupType.valueOf(stringValue));
} else if (entry.getKey().equals(PropertyType.AdminPresentationToOneLookup.CUSTOMCRITERIA)) {
fieldMetadataOverride.setCustomCriteria(entry.getValue().stringArrayOverrideValue());
} else if (entry.getKey().equals(PropertyType.AdminPresentationDataDrivenEnumeration.OPTIONLISTENTITY)) {
fieldMetadataOverride.setOptionListEntity(stringValue);
} else if (entry.getKey().equals(PropertyType.AdminPresentationDataDrivenEnumeration.OPTIONVALUEFIELDNAME)) {
fieldMetadataOverride.setOptionValueFieldName(stringValue);
} else if (entry.getKey().equals(PropertyType.AdminPresentationDataDrivenEnumeration.OPTIONDISPLAYFIELDNAME)) {
fieldMetadataOverride.setOptionDisplayFieldName(stringValue);
} else if (entry.getKey().equals(PropertyType.AdminPresentationDataDrivenEnumeration.OPTIONHIDEIFEMPTY)) {
fieldMetadataOverride.setHideEnumerationIfEmpty(StringUtils.isEmpty(stringValue) ? entry.getValue().booleanOverrideValue() : Boolean.parseBoolean(stringValue));
} else if (entry.getKey().equals(PropertyType.AdminPresentationDataDrivenEnumeration.OPTIONCANEDITVALUES)) {
fieldMetadataOverride.setOptionCanEditValues(StringUtils.isEmpty(stringValue) ? entry.getValue().booleanOverrideValue() : Boolean.parseBoolean(stringValue));
} else if (entry.getKey().equals(PropertyType.AdminPresentationDataDrivenEnumeration.OPTIONFILTERPARAMS)) {
OptionFilterParam[] optionFilterParams = entry.getValue().optionFilterParams();
String[][] params = new String[optionFilterParams.length][3];
for (int j = 0; j < params.length; j++) {
params[j][0] = optionFilterParams[j].param();
params[j][1] = optionFilterParams[j].value();
params[j][2] = String.valueOf(optionFilterParams[j].paramType());
}
fieldMetadataOverride.setOptionFilterValues(params);
} else if (entry.getKey().equals(PropertyType.AdminPresentation.CANLINKTOEXTERNALENTITY)) {
fieldMetadataOverride.setCanLinkToExternalEntity(StringUtils.isEmpty(stringValue) ? entry.getValue().booleanOverrideValue() : Boolean.parseBoolean(stringValue));
} else if (entry.getKey().equals(PropertyType.AdminPresentation.TRANSLATABLE)) {
fieldMetadataOverride.setTranslatable(StringUtils.isEmpty(stringValue) ? entry.getValue().booleanOverrideValue() : Boolean.parseBoolean(stringValue));
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Unrecognized type: " + entry.getKey() + ". Not setting on basic field.");
}
}
}
return fieldMetadataOverride;
}
use of org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride 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;
}
use of org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride 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;
}
use of org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride in project BroadleafCommerce by BroadleafCommerce.
the class BasicFieldMetadataProvider method constructBasicMetadataOverride.
protected FieldMetadataOverride constructBasicMetadataOverride(AdminPresentation annot, AdminPresentationToOneLookup toOneLookup, AdminPresentationDataDrivenEnumeration dataDrivenEnumeration) {
if (annot != null) {
FieldMetadataOverride override = new FieldMetadataOverride();
override.setBroadleafEnumeration(annot.broadleafEnumeration());
override.setHideEnumerationIfEmpty(annot.hideEnumerationIfEmpty());
override.setFieldComponentRenderer(annot.fieldComponentRenderer());
override.setFieldComponentRendererTemplate(annot.fieldComponentRendererTemplate());
override.setGridFieldComponentRenderer(annot.gridFieldComponentRenderer());
override.setGridFieldComponentRendererTemplate(annot.gridFieldComponentRendererTemplate());
override.setColumnWidth(annot.columnWidth());
override.setExplicitFieldType(annot.fieldType());
override.setDisplayType(annot.displayType());
override.setFieldType(annot.fieldType());
override.setGroup(annot.group());
override.setGroupCollapsed(annot.groupCollapsed());
override.setGroupOrder(annot.groupOrder());
override.setTab(annot.tab());
override.setRuleIdentifier(annot.ruleIdentifier());
override.setTabOrder(annot.tabOrder());
override.setHelpText(annot.helpText());
override.setHint(annot.hint());
override.setLargeEntry(annot.largeEntry());
override.setFriendlyName(annot.friendlyName());
override.setAddFriendlyName(annot.addFriendlyName());
override.setSecurityLevel(annot.securityLevel());
override.setOrder(annot.order());
override.setGridOrder(annot.gridOrder());
override.setVisibility(annot.visibility());
override.setProminent(annot.prominent());
override.setReadOnly(annot.readOnly());
override.setShowIfProperty(annot.showIfProperty());
override.setCurrencyCodeField(annot.currencyCodeField());
override.setRuleIdentifier(annot.ruleIdentifier());
override.setTranslatable(annot.translatable());
override.setDefaultValue(annot.defaultValue());
override.setAssociatedFieldName(annot.associatedFieldName());
override.setAllowNoValueEnumOption(annot.allowNoValueEnumOption());
override.setCanLinkToExternalEntity(annot.canLinkToExternalEntity());
if (annot.showIfFieldEquals().length != 0) {
processShowIfFieldEqualsAnnotations(annot.showIfFieldEquals(), override);
}
if (annot.validationConfigurations().length != 0) {
processValidationAnnotations(annot.validationConfigurations(), override);
}
if (annot.requiredOverride() != RequiredOverride.IGNORED) {
override.setRequiredOverride(annot.requiredOverride() == RequiredOverride.REQUIRED);
}
override.setExcluded(annot.excluded());
override.setTooltip(annot.tooltip());
// the following annotations are complimentary to AdminPresentation
if (toOneLookup != null) {
override.setExplicitFieldType(SupportedFieldType.ADDITIONAL_FOREIGN_KEY);
override.setFieldType(SupportedFieldType.ADDITIONAL_FOREIGN_KEY);
override.setLookupDisplayProperty(toOneLookup.lookupDisplayProperty());
override.setForcePopulateChildProperties(toOneLookup.forcePopulateChildProperties());
override.setEnableTypeaheadLookup(toOneLookup.enableTypeaheadLookup());
override.setCustomCriteria(toOneLookup.customCriteria());
override.setUseServerSideInspectionCache(toOneLookup.useServerSideInspectionCache());
override.setToOneLookupCreatedViaAnnotation(true);
override.setLookupType(toOneLookup.lookupType());
}
if (dataDrivenEnumeration != null) {
override.setExplicitFieldType(SupportedFieldType.DATA_DRIVEN_ENUMERATION);
override.setFieldType(SupportedFieldType.DATA_DRIVEN_ENUMERATION);
override.setOptionCanEditValues(dataDrivenEnumeration.optionCanEditValues());
override.setHideEnumerationIfEmpty(dataDrivenEnumeration.optionHideIfEmpty());
override.setOptionDisplayFieldName(dataDrivenEnumeration.optionDisplayFieldName());
if (!ArrayUtils.isEmpty(dataDrivenEnumeration.optionFilterParams())) {
Serializable[][] params = new Serializable[dataDrivenEnumeration.optionFilterParams().length][3];
for (int j = 0; j < params.length; j++) {
params[j][0] = dataDrivenEnumeration.optionFilterParams()[j].param();
params[j][1] = dataDrivenEnumeration.optionFilterParams()[j].value();
params[j][2] = dataDrivenEnumeration.optionFilterParams()[j].paramType();
}
override.setOptionFilterValues(params);
}
override.setOptionListEntity(dataDrivenEnumeration.optionListEntity().getName());
override.setOptionValueFieldName(dataDrivenEnumeration.optionValueFieldName());
}
return override;
}
throw new IllegalArgumentException("AdminPresentation annotation not found on field");
}
Aggregations