use of org.broadleafcommerce.openadmin.dto.BasicFieldMetadata in project BroadleafCommerce by BroadleafCommerce.
the class BasicFieldMetadataProvider method buildAdminPresentationToOneLookupOverride.
protected void buildAdminPresentationToOneLookupOverride(Map<String, FieldMetadata> mergedProperties, Map<String, AdminPresentationToOneLookupOverride> presentationOverrides, String propertyName, String key) {
AdminPresentationToOneLookupOverride override = presentationOverrides.get(propertyName);
if (override != null) {
AdminPresentationToOneLookup annot = override.value();
if (annot != null) {
if (!(mergedProperties.get(key) instanceof BasicFieldMetadata)) {
return;
}
BasicFieldMetadata metadata = (BasicFieldMetadata) mergedProperties.get(key);
metadata.setFieldType(SupportedFieldType.ADDITIONAL_FOREIGN_KEY);
metadata.setExplicitFieldType(SupportedFieldType.ADDITIONAL_FOREIGN_KEY);
metadata.setLookupDisplayProperty(annot.lookupDisplayProperty());
metadata.setForcePopulateChildProperties(annot.forcePopulateChildProperties());
metadata.setEnableTypeaheadLookup(annot.enableTypeaheadLookup());
if (!StringUtils.isEmpty(annot.lookupDisplayProperty())) {
metadata.setForeignKeyDisplayValueProperty(annot.lookupDisplayProperty());
}
metadata.setCustomCriteria(annot.customCriteria());
metadata.setUseServerSideInspectionCache(annot.useServerSideInspectionCache());
}
}
}
use of org.broadleafcommerce.openadmin.dto.BasicFieldMetadata 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.BasicFieldMetadata in project BroadleafCommerce by BroadleafCommerce.
the class BasicFieldMetadataProvider method buildAdminPresentationDataDrivenEnumerationOverride.
protected void buildAdminPresentationDataDrivenEnumerationOverride(Map<String, FieldMetadata> mergedProperties, Map<String, AdminPresentationDataDrivenEnumerationOverride> presentationOverrides, String propertyName, String key) {
AdminPresentationDataDrivenEnumerationOverride override = presentationOverrides.get(propertyName);
if (override != null) {
AdminPresentationDataDrivenEnumeration annot = override.value();
if (annot != null) {
if (!(mergedProperties.get(key) instanceof BasicFieldMetadata)) {
return;
}
BasicFieldMetadata metadata = (BasicFieldMetadata) mergedProperties.get(key);
metadata.setFieldType(SupportedFieldType.DATA_DRIVEN_ENUMERATION);
metadata.setExplicitFieldType(SupportedFieldType.DATA_DRIVEN_ENUMERATION);
metadata.setOptionListEntity(annot.optionListEntity().getName());
metadata.setHideEnumerationIfEmpty(annot.optionHideIfEmpty());
if (metadata.getOptionListEntity().equals(DataDrivenEnumerationValueImpl.class.getName())) {
metadata.setOptionValueFieldName("key");
metadata.setOptionDisplayFieldName("display");
} else if (metadata.getOptionListEntity() == null && (StringUtils.isEmpty(metadata.getOptionValueFieldName()) || StringUtils.isEmpty(metadata.getOptionDisplayFieldName()))) {
throw new IllegalArgumentException("Problem setting up data driven enumeration for (" + propertyName + "). The optionListEntity, optionValueFieldName and optionDisplayFieldName properties must all be included if not using DataDrivenEnumerationValueImpl as the optionListEntity.");
} else {
metadata.setOptionValueFieldName(annot.optionValueFieldName());
metadata.setOptionDisplayFieldName(annot.optionDisplayFieldName());
}
if (!ArrayUtils.isEmpty(annot.optionFilterParams())) {
String[][] params = new String[annot.optionFilterParams().length][3];
for (int j = 0; j < params.length; j++) {
params[j][0] = annot.optionFilterParams()[j].param();
params[j][1] = annot.optionFilterParams()[j].value();
params[j][2] = String.valueOf(annot.optionFilterParams()[j].paramType());
}
metadata.setOptionFilterParams(params);
} else {
metadata.setOptionFilterParams(new String[][] {});
}
if (!StringUtils.isEmpty(metadata.getOptionListEntity())) {
buildDataDrivenEnumList(metadata);
}
}
}
}
use of org.broadleafcommerce.openadmin.dto.BasicFieldMetadata in project BroadleafCommerce by BroadleafCommerce.
the class DefaultFieldMetadataProvider method addMetadata.
@Override
public MetadataProviderResponse addMetadata(AddFieldMetadataRequest addMetadataRequest, Map<String, FieldMetadata> metadata) {
Map<String, Object> idMetadata = addMetadataRequest.getDynamicEntityDao().getIdMetadata(addMetadataRequest.getTargetClass());
if (idMetadata != null) {
String idField = (String) idMetadata.get("name");
boolean processField;
// allow id fields without AdminPresentation annotation to pass through
processField = idField.equals(addMetadataRequest.getRequestedField().getName());
if (!processField) {
List<String> propertyNames = addMetadataRequest.getDynamicEntityDao().getPropertyNames(addMetadataRequest.getTargetClass());
if (!CollectionUtils.isEmpty(propertyNames)) {
List<org.hibernate.type.Type> propertyTypes = addMetadataRequest.getDynamicEntityDao().getPropertyTypes(addMetadataRequest.getTargetClass());
int index = propertyNames.indexOf(addMetadataRequest.getRequestedField().getName());
if (index >= 0) {
Type myType = propertyTypes.get(index);
// allow OneToOne, ManyToOne and Embeddable fields to pass through
processField = myType.isCollectionType() || myType.isAssociationType() || myType.isComponentType() || myType.isEntityType();
}
}
}
if (processField) {
FieldInfo info = buildFieldInfo(addMetadataRequest.getRequestedField());
BasicFieldMetadata basicMetadata = new BasicFieldMetadata();
basicMetadata.setName(addMetadataRequest.getRequestedField().getName());
basicMetadata.setExcluded(false);
metadata.put(addMetadataRequest.getRequestedField().getName(), basicMetadata);
setClassOwnership(addMetadataRequest.getParentClass(), addMetadataRequest.getTargetClass(), metadata, info);
return MetadataProviderResponse.HANDLED;
}
}
return MetadataProviderResponse.NOT_HANDLED;
}
use of org.broadleafcommerce.openadmin.dto.BasicFieldMetadata in project BroadleafCommerce by BroadleafCommerce.
the class DynamicEntityDaoImpl method getPropertiesForPrimitiveClass.
@Override
public Map<String, FieldMetadata> getPropertiesForPrimitiveClass(String propertyName, String friendlyPropertyName, Class<?> targetClass, Class<?> parentClass, MergedPropertyType mergedPropertyType) {
Map<String, FieldMetadata> fields = new HashMap<>();
BasicFieldMetadata presentationAttribute = new BasicFieldMetadata();
presentationAttribute.setFriendlyName(friendlyPropertyName);
if (String.class.isAssignableFrom(targetClass)) {
presentationAttribute.setExplicitFieldType(SupportedFieldType.STRING);
presentationAttribute.setVisibility(VisibilityEnum.VISIBLE_ALL);
fields.put(propertyName, metadata.getFieldMetadata("", propertyName, null, SupportedFieldType.STRING, null, parentClass, presentationAttribute, mergedPropertyType, this));
} else if (Boolean.class.isAssignableFrom(targetClass)) {
presentationAttribute.setExplicitFieldType(SupportedFieldType.BOOLEAN);
presentationAttribute.setVisibility(VisibilityEnum.VISIBLE_ALL);
fields.put(propertyName, metadata.getFieldMetadata("", propertyName, null, SupportedFieldType.BOOLEAN, null, parentClass, presentationAttribute, mergedPropertyType, this));
} else if (Date.class.isAssignableFrom(targetClass)) {
presentationAttribute.setExplicitFieldType(SupportedFieldType.DATE);
presentationAttribute.setVisibility(VisibilityEnum.VISIBLE_ALL);
fields.put(propertyName, metadata.getFieldMetadata("", propertyName, null, SupportedFieldType.DATE, null, parentClass, presentationAttribute, mergedPropertyType, this));
} else if (Money.class.isAssignableFrom(targetClass)) {
presentationAttribute.setExplicitFieldType(SupportedFieldType.MONEY);
presentationAttribute.setVisibility(VisibilityEnum.VISIBLE_ALL);
fields.put(propertyName, metadata.getFieldMetadata("", propertyName, null, SupportedFieldType.MONEY, null, parentClass, presentationAttribute, mergedPropertyType, this));
} else if (Byte.class.isAssignableFrom(targetClass) || Integer.class.isAssignableFrom(targetClass) || Long.class.isAssignableFrom(targetClass) || Short.class.isAssignableFrom(targetClass)) {
presentationAttribute.setExplicitFieldType(SupportedFieldType.INTEGER);
presentationAttribute.setVisibility(VisibilityEnum.VISIBLE_ALL);
fields.put(propertyName, metadata.getFieldMetadata("", propertyName, null, SupportedFieldType.INTEGER, null, parentClass, presentationAttribute, mergedPropertyType, this));
} else if (Double.class.isAssignableFrom(targetClass) || BigDecimal.class.isAssignableFrom(targetClass)) {
presentationAttribute.setExplicitFieldType(SupportedFieldType.DECIMAL);
presentationAttribute.setVisibility(VisibilityEnum.VISIBLE_ALL);
fields.put(propertyName, metadata.getFieldMetadata("", propertyName, null, SupportedFieldType.DECIMAL, null, parentClass, presentationAttribute, mergedPropertyType, this));
}
((BasicFieldMetadata) fields.get(propertyName)).setLength(255);
((BasicFieldMetadata) fields.get(propertyName)).setForeignKeyCollection(false);
((BasicFieldMetadata) fields.get(propertyName)).setRequired(true);
((BasicFieldMetadata) fields.get(propertyName)).setUnique(true);
((BasicFieldMetadata) fields.get(propertyName)).setScale(100);
((BasicFieldMetadata) fields.get(propertyName)).setPrecision(100);
return fields;
}
Aggregations