use of org.broadleafcommerce.openadmin.dto.BasicFieldMetadata in project BroadleafCommerce by BroadleafCommerce.
the class FormBuilderServiceImpl method constructSelectizeOptionMap.
@Override
public Map<String, Object> constructSelectizeOptionMap(DynamicResultSet drs, ClassMetadata cmd) {
Map<String, Object> result = new HashMap<>();
List<Map<String, String>> options = new ArrayList<>();
List<Field> headerFields = new ArrayList<>();
for (Property p : cmd.getProperties()) {
if (p.getMetadata() instanceof BasicFieldMetadata) {
BasicFieldMetadata md = (BasicFieldMetadata) p.getMetadata();
if (md.isProminent() != null && md.isProminent() && !ArrayUtils.contains(getGridHiddenVisibilities(), md.getVisibility())) {
Field hf = createHeaderField(p, md);
headerFields.add(hf);
}
}
}
for (Entity e : drs.getRecords()) {
Map<String, String> selectizeOption = new HashMap<>();
for (Field headerField : headerFields) {
Property p = e.findProperty(headerField.getName());
if (p != null) {
selectizeOption.put("name", p.getValue());
break;
}
}
if (e.findProperty("id") != null) {
selectizeOption.put("id", e.findProperty("id").getValue());
}
if (e.findProperty(ALTERNATE_ID_PROPERTY) != null) {
selectizeOption.put("alternateId", e.findProperty(ALTERNATE_ID_PROPERTY).getValue());
}
options.add(selectizeOption);
}
result.put("options", options);
return result;
}
use of org.broadleafcommerce.openadmin.dto.BasicFieldMetadata in project BroadleafCommerce by BroadleafCommerce.
the class FormBuilderServiceImpl method setEntityFormFields.
protected void setEntityFormFields(ClassMetadata cmd, EntityForm ef, List<Property> properties) {
List<Field> homelessFields = new ArrayList<>();
List<Field> fieldsWithAssociations = new ArrayList<>();
for (Property property : properties) {
if (property.getMetadata() instanceof BasicFieldMetadata) {
BasicFieldMetadata fmd = (BasicFieldMetadata) property.getMetadata();
if (!ArrayUtils.contains(getFormHiddenVisibilities(), fmd.getVisibility())) {
// Depending on visibility, field for the particular property is not created on the form
String fieldType = fmd.getFieldType() == null ? null : fmd.getFieldType().toString();
// Create the field and set some basic attributes
Field f;
if (fieldType.equals(SupportedFieldType.BROADLEAF_ENUMERATION.toString()) || fieldType.equals(SupportedFieldType.EXPLICIT_ENUMERATION.toString()) || fieldType.equals(SupportedFieldType.DATA_DRIVEN_ENUMERATION.toString()) || fieldType.equals(SupportedFieldType.EMPTY_ENUMERATION.toString())) {
// We're dealing with fields that should render as drop-downs, so set their possible values
f = new ComboField();
((ComboField) f).setOptions(fmd.getEnumerationValues());
if (fmd.getHideEnumerationIfEmpty() != null && fmd.getHideEnumerationIfEmpty().booleanValue() && ((ComboField) f).getOptions().size() == 0) {
f.setIsVisible(false);
}
} else if (fieldType.equals(SupportedFieldType.CODE.toString())) {
f = new CodeField();
} else if (fieldType.equals(SupportedFieldType.RULE_SIMPLE.toString()) || fieldType.equals(SupportedFieldType.RULE_SIMPLE_TIME.toString()) || fieldType.equals(SupportedFieldType.RULE_WITH_QUANTITY.toString())) {
// We're dealing with rule builders, so we'll create those specialized fields
f = new RuleBuilderField();
((RuleBuilderField) f).setJsonFieldName(property.getName() + "Json");
((RuleBuilderField) f).setDataWrapper(new DataWrapper());
((RuleBuilderField) f).setFieldBuilder(fmd.getRuleIdentifier());
((RuleBuilderField) f).setDisplayType(fmd.getDisplayType().toString());
String blankJsonString = "{\"data\":[]}";
((RuleBuilderField) f).setJson(blankJsonString);
DataWrapper dw = convertJsonToDataWrapper(blankJsonString);
if (dw != null) {
((RuleBuilderField) f).setDataWrapper(dw);
}
if (fieldType.equals(SupportedFieldType.RULE_SIMPLE.toString())) {
((RuleBuilderField) f).setRuleType("rule-builder-simple");
} else if (fieldType.equals(SupportedFieldType.RULE_WITH_QUANTITY.toString())) {
((RuleBuilderField) f).setRuleType("rule-builder-with-quantity");
} else if (fieldType.equals(SupportedFieldType.RULE_SIMPLE_TIME.toString())) {
((RuleBuilderField) f).setRuleType("rule-builder-simple-time");
}
} else if (LookupType.DROPDOWN.equals(fmd.getLookupType())) {
// We're dealing with a to-one field that wants to be rendered as a dropdown instead of in a
// modal, so we'll provision the combo field here. Available options will be set as part of a
// subsequent operation
f = new ComboField();
} else if (fieldType.equals(SupportedFieldType.MEDIA.toString())) {
f = new MediaField();
} else {
// Create a default field since there was no specialized handler
f = new Field();
}
Boolean required = fmd.getRequiredOverride();
if (required == null) {
required = fmd.getRequired();
}
Boolean allowNoValueEnum = fmd.getAllowNoValueEnumOption();
if (allowNoValueEnum != null) {
f.setAllowNoValueEnumOption(allowNoValueEnum);
}
f.withName(property.getName()).withFieldType(fieldType).withFieldComponentRenderer(getFieldComponentRenderer(fmd)).withGridFieldComponentRenderer(getGridFieldComponentRenderer(fmd)).withOrder(fmd.getOrder()).withFriendlyName(fmd.getFriendlyName()).withForeignKeyDisplayValueProperty(fmd.getForeignKeyDisplayValueProperty()).withForeignKeyClass(fmd.getForeignKeyClass()).withForeignKeySectionPath(getAdminSectionPath(fmd.getForeignKeyClass())).withOwningEntityClass(fmd.getOwningClass() != null ? fmd.getOwningClass() : fmd.getInheritedFromType()).withRequired(required).withReadOnly(fmd.getReadOnly()).withTranslatable(fmd.getTranslatable()).withAlternateOrdering((Boolean) fmd.getAdditionalMetadata().get(Field.ALTERNATE_ORDERING)).withLargeEntry(fmd.isLargeEntry()).withHint(fmd.getHint()).withTooltip(fmd.getTooltip()).withHelp(fmd.getHelpText()).withTypeaheadEnabled(fmd.getEnableTypeaheadLookup()).withCanLinkToExternalEntity(fmd.getCanLinkToExternalEntity()).withAssociatedFieldName(fmd.getAssociatedFieldName());
String defaultValue = fmd.getDefaultValue();
if (defaultValue != null) {
defaultValue = extractDefaultValueFromFieldData(fieldType, fmd);
f.withValue(defaultValue);
}
if (StringUtils.isBlank(f.getFriendlyName())) {
f.setFriendlyName(f.getName());
}
// If is form hidden, set visible to false
if (VisibilityEnum.FORM_EXPLICITLY_HIDDEN.equals(fmd.getVisibility())) {
f.setIsVisible(false);
}
if (VisibilityEnum.VISIBLE_ALL.equals(fmd.getVisibility())) {
f.setIsVisible(true);
}
// Add the field to the appropriate FieldGroup
if (fmd.getGroup() == null) {
homelessFields.add(f);
} else {
ef.addField(cmd, f, fmd.getGroup(), fmd.getGroupOrder(), fmd.getTab(), fmd.getTabOrder());
}
if (StringUtils.isNotEmpty(fmd.getAssociatedFieldName())) {
fieldsWithAssociations.add(f);
}
}
}
}
for (Field f : homelessFields) {
ef.addField(cmd, f, null, null, null, null);
}
for (Field f : fieldsWithAssociations) {
Field associatedField = findAssociatedField(ef, f);
if (associatedField != null) {
associatedField.setShouldRender(false);
f.setAssociatedFieldName(associatedField.getName());
} else {
f.setAssociatedFieldName(null);
}
}
}
use of org.broadleafcommerce.openadmin.dto.BasicFieldMetadata in project BroadleafCommerce by BroadleafCommerce.
the class FormBuilderServiceImpl method populateEntityFormFieldValues.
@Override
public void populateEntityFormFieldValues(ClassMetadata cmd, Entity entity, EntityForm ef) {
// Set the appropriate property values
for (Property p : cmd.getProperties()) {
if (p.getMetadata() instanceof BasicFieldMetadata) {
BasicFieldMetadata basicFM = (BasicFieldMetadata) p.getMetadata();
Property entityProp = entity.findProperty(p.getName());
boolean explicitlyShown = VisibilityEnum.FORM_EXPLICITLY_SHOWN.equals(basicFM.getVisibility());
// always show special map fields
if (p.getName().equals("key") || p.getName().equals("priorKey")) {
explicitlyShown = true;
}
if (entityProp == null && explicitlyShown) {
Field field = ef.findField(p.getName());
if (field != null) {
field.setValue(null);
}
} else if (entityProp == null && !SupportedFieldType.PASSWORD_CONFIRM.equals(basicFM.getExplicitFieldType())) {
ef.removeField(p.getName());
} else {
Field field = ef.findField(p.getName());
if (field != null) {
if (entityProp != null) {
// protect against null - can happen with password confirmation fields (i.e. admin user)
field.setDirty(entityProp.getIsDirty());
}
if (basicFM.getFieldType() == SupportedFieldType.RULE_SIMPLE || basicFM.getFieldType() == SupportedFieldType.RULE_SIMPLE_TIME || basicFM.getFieldType() == SupportedFieldType.RULE_WITH_QUANTITY) {
RuleBuilderField rbf = (RuleBuilderField) field;
if (entity.getPMap().containsKey(rbf.getJsonFieldName())) {
String json = entity.getPMap().get(rbf.getJsonFieldName()).getValue();
rbf.setJson(json);
DataWrapper dw = convertJsonToDataWrapper(json);
if (dw != null) {
rbf.setDataWrapper(dw);
}
}
}
if (basicFM.getFieldType() == SupportedFieldType.MEDIA) {
field.setValue(entityProp.getValue());
field.setDisplayValue(entityProp.getDisplayValue());
MediaField mf = (MediaField) field;
Class<MediaDto> type = entityConfiguration.lookupEntityClass(MediaDto.class.getName(), MediaDto.class);
mf.setMedia(mediaBuilderService.convertJsonToMedia(entityProp.getUnHtmlEncodedValue(), type));
} else if (!SupportedFieldType.PASSWORD_CONFIRM.equals(basicFM.getExplicitFieldType())) {
field.setValue(entityProp.getValue());
field.setDisplayValue(entityProp.getDisplayValue());
}
}
}
}
}
}
use of org.broadleafcommerce.openadmin.dto.BasicFieldMetadata in project BroadleafCommerce by BroadleafCommerce.
the class BasicEntityMetadataProvider method addTabAndGroupMetadataFromCmdProperties.
@Override
public MetadataProviderResponse addTabAndGroupMetadataFromCmdProperties(ClassMetadata cmd, Map<String, TabMetadata> metadata) {
for (Property p : cmd.getProperties()) {
FieldMetadata fmd = p.getMetadata();
boolean isExcluded = fmd.getExcluded() != null && fmd.getExcluded() == true;
boolean isHidden = fmd instanceof BasicFieldMetadata && ((BasicFieldMetadata) fmd).getVisibility() != null && (((BasicFieldMetadata) fmd).getVisibility().equals(VisibilityEnum.HIDDEN_ALL) || ((BasicFieldMetadata) fmd).getVisibility().equals(VisibilityEnum.FORM_HIDDEN));
if (!(isExcluded || isHidden)) {
GroupMetadata groupMetadata = getGroupFromMetadata(fmd.getGroup(), metadata);
if (groupMetadata == null) {
TabMetadata tabMetadata = getTabFromMetadata(fmd.getTab(), metadata);
Map<String, GroupMetadata> groupMetadataMap = tabMetadata == null || tabMetadata.getGroupMetadata() == null ? new HashMap<String, GroupMetadata>() : tabMetadata.getGroupMetadata();
if (tabMetadata == null && !(fmd.getTab() == null || fmd.getTab().isEmpty())) {
tabMetadata = new TabMetadata();
tabMetadata.setTabName(fmd.getTab());
tabMetadata.setTabOrder(fmd.getTabOrder());
tabMetadata.setOwningClass(cmd.getPolymorphicEntities().getFullyQualifiedClassname());
tabMetadata.setGroupMetadata(groupMetadataMap);
metadata.put(fmd.getTab(), tabMetadata);
}
// is a collection being added to only the specified tab, not a group as well.
if (!(fmd.getGroup() == null || fmd.getGroup().isEmpty())) {
groupMetadata = new GroupMetadata();
groupMetadata.setOwningClass(cmd.getPolymorphicEntities().getFullyQualifiedClassname());
groupMetadata.setGroupName(fmd.getGroup());
groupMetadata.setGroupOrder(fmd.getGroupOrder());
groupMetadata.setColumn(0);
groupMetadata.setUntitled(false);
groupMetadata.setCollapsed(false);
groupMetadataMap.put(fmd.getGroup(), groupMetadata);
}
}
}
}
return MetadataProviderResponse.HANDLED;
}
use of org.broadleafcommerce.openadmin.dto.BasicFieldMetadata in project BroadleafCommerce by BroadleafCommerce.
the class BasicFieldMetadataProvider method buildBasicMetadata.
protected void buildBasicMetadata(Class<?> parentClass, Class<?> targetClass, Map<String, FieldMetadata> attributes, FieldInfo field, FieldMetadataOverride basicFieldMetadata, DynamicEntityDao dynamicEntityDao) {
BasicFieldMetadata serverMetadata = (BasicFieldMetadata) attributes.get(field.getName());
BasicFieldMetadata metadata;
if (serverMetadata != null) {
metadata = serverMetadata;
} else {
metadata = new BasicFieldMetadata();
}
metadata.setName(field.getName());
metadata.setTargetClass(targetClass.getName());
metadata.setFieldName(field.getName());
if (basicFieldMetadata.getFieldType() != null) {
metadata.setFieldType(basicFieldMetadata.getFieldType());
}
if (basicFieldMetadata.getDisplayType() != null) {
metadata.setDisplayType(basicFieldMetadata.getDisplayType());
}
if (basicFieldMetadata.getFieldComponentRenderer() != null) {
metadata.setFieldComponentRenderer(basicFieldMetadata.getFieldComponentRenderer());
}
if (basicFieldMetadata.getFieldComponentRendererTemplate() != null) {
metadata.setFieldComponentRendererTemplate(basicFieldMetadata.getFieldComponentRendererTemplate());
}
if (basicFieldMetadata.getGridFieldComponentRenderer() != null) {
metadata.setGridFieldComponentRenderer(basicFieldMetadata.getGridFieldComponentRenderer());
}
if (basicFieldMetadata.getGridFieldComponentRendererTemplate() != null) {
metadata.setGridFieldComponentRendererTemplate(basicFieldMetadata.getGridFieldComponentRendererTemplate());
}
if (basicFieldMetadata.getFriendlyName() != null) {
metadata.setFriendlyName(basicFieldMetadata.getFriendlyName());
}
if (basicFieldMetadata.getAddFriendlyName() != null) {
metadata.setAddFriendlyName(basicFieldMetadata.getAddFriendlyName());
}
if (basicFieldMetadata.getSecurityLevel() != null) {
metadata.setSecurityLevel(basicFieldMetadata.getSecurityLevel());
}
if (basicFieldMetadata.getVisibility() != null) {
metadata.setVisibility(basicFieldMetadata.getVisibility());
}
if (basicFieldMetadata.getOrder() != null) {
metadata.setOrder(basicFieldMetadata.getOrder());
}
if (basicFieldMetadata.getGridOrder() != null) {
metadata.setGridOrder(basicFieldMetadata.getGridOrder());
}
if (basicFieldMetadata.getExplicitFieldType() != null) {
metadata.setExplicitFieldType(basicFieldMetadata.getExplicitFieldType());
}
if (metadata.getExplicitFieldType() == SupportedFieldType.ADDITIONAL_FOREIGN_KEY) {
// this is a lookup - exclude the fields on this OneToOne or ManyToOne field
if (basicFieldMetadata.getForcePopulateChildProperties() == null || !basicFieldMetadata.getForcePopulateChildProperties()) {
metadata.setChildrenExcluded(true);
}
}
if (basicFieldMetadata.getExcluded() != null) {
if (LOG.isDebugEnabled()) {
if (basicFieldMetadata.getExcluded()) {
LOG.debug("buildBasicMetadata:Excluding " + field.getName() + " because it was explicitly declared in config");
} else {
LOG.debug("buildBasicMetadata:Showing " + field.getName() + " because it was explicitly declared in config");
}
}
metadata.setExcluded(basicFieldMetadata.getExcluded());
}
if (basicFieldMetadata.getGroup() != null) {
metadata.setGroup(basicFieldMetadata.getGroup());
}
if (basicFieldMetadata.getGroupOrder() != null) {
metadata.setGroupOrder(basicFieldMetadata.getGroupOrder());
}
if (basicFieldMetadata.getGroupCollapsed() != null) {
metadata.setGroupCollapsed(basicFieldMetadata.getGroupCollapsed());
}
if (basicFieldMetadata.getTab() != null) {
metadata.setTab(basicFieldMetadata.getTab());
}
if (basicFieldMetadata.getTabOrder() != null) {
metadata.setTabOrder(basicFieldMetadata.getTabOrder());
}
if (basicFieldMetadata.isLargeEntry() != null) {
metadata.setLargeEntry(basicFieldMetadata.isLargeEntry());
}
if (basicFieldMetadata.isProminent() != null) {
metadata.setProminent(basicFieldMetadata.isProminent());
}
if (basicFieldMetadata.getColumnWidth() != null) {
metadata.setColumnWidth(basicFieldMetadata.getColumnWidth());
}
if (basicFieldMetadata.getBroadleafEnumeration() != null) {
metadata.setBroadleafEnumeration(basicFieldMetadata.getBroadleafEnumeration());
}
if (!StringUtils.isEmpty(metadata.getBroadleafEnumeration()) && metadata.getFieldType() == SupportedFieldType.BROADLEAF_ENUMERATION) {
try {
setupBroadleafEnumeration(metadata.getBroadleafEnumeration(), metadata, dynamicEntityDao);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
if (basicFieldMetadata.getHideEnumerationIfEmpty() != null) {
metadata.setHideEnumerationIfEmpty(basicFieldMetadata.getHideEnumerationIfEmpty());
}
if (basicFieldMetadata.getReadOnly() != null) {
metadata.setReadOnly(basicFieldMetadata.getReadOnly());
}
if (basicFieldMetadata.getTooltip() != null) {
metadata.setTooltip(basicFieldMetadata.getTooltip());
}
if (basicFieldMetadata.getHelpText() != null) {
metadata.setHelpText(basicFieldMetadata.getHelpText());
}
if (basicFieldMetadata.getHint() != null) {
metadata.setHint(basicFieldMetadata.getHint());
}
if (basicFieldMetadata.getShowIfProperty() != null) {
metadata.setShowIfProperty(basicFieldMetadata.getShowIfProperty());
}
if (basicFieldMetadata.getShowIfFieldEquals() != null) {
metadata.setShowIfFieldEquals(basicFieldMetadata.getShowIfFieldEquals());
}
if (basicFieldMetadata.getCurrencyCodeField() != null) {
metadata.setCurrencyCodeField(basicFieldMetadata.getCurrencyCodeField());
}
if (basicFieldMetadata.getLookupDisplayProperty() != null) {
metadata.setLookupDisplayProperty(basicFieldMetadata.getLookupDisplayProperty());
metadata.setForeignKeyDisplayValueProperty(basicFieldMetadata.getLookupDisplayProperty());
}
if (basicFieldMetadata.getForcePopulateChildProperties() != null) {
metadata.setForcePopulateChildProperties(basicFieldMetadata.getForcePopulateChildProperties());
}
if (basicFieldMetadata.getEnableTypeaheadLookup() != null) {
metadata.setEnableTypeaheadLookup(basicFieldMetadata.getEnableTypeaheadLookup());
}
if (basicFieldMetadata.getCustomCriteria() != null) {
metadata.setCustomCriteria(basicFieldMetadata.getCustomCriteria());
}
if (basicFieldMetadata.getUseServerSideInspectionCache() != null) {
metadata.setUseServerSideInspectionCache(basicFieldMetadata.getUseServerSideInspectionCache());
}
if (basicFieldMetadata.getToOneLookupCreatedViaAnnotation() != null) {
metadata.setToOneLookupCreatedViaAnnotation(basicFieldMetadata.getToOneLookupCreatedViaAnnotation());
}
if (basicFieldMetadata.getOptionListEntity() != null) {
metadata.setOptionListEntity(basicFieldMetadata.getOptionListEntity());
}
if (metadata.getOptionListEntity() != null && metadata.getOptionListEntity().equals(DataDrivenEnumerationValueImpl.class.getName())) {
metadata.setOptionValueFieldName("key");
metadata.setOptionDisplayFieldName("display");
} else {
if (basicFieldMetadata.getOptionValueFieldName() != null) {
metadata.setOptionValueFieldName(basicFieldMetadata.getOptionValueFieldName());
}
if (basicFieldMetadata.getOptionDisplayFieldName() != null) {
metadata.setOptionDisplayFieldName(basicFieldMetadata.getOptionDisplayFieldName());
}
}
if (!StringUtils.isEmpty(metadata.getOptionListEntity()) && (StringUtils.isEmpty(metadata.getOptionValueFieldName()) || StringUtils.isEmpty(metadata.getOptionDisplayFieldName()))) {
throw new IllegalArgumentException("Problem setting up data driven enumeration for (" + field.getName() + "). The optionListEntity, optionValueFieldName and optionDisplayFieldName properties must all be included if not using DataDrivenEnumerationValueImpl as the optionListEntity.");
}
if (basicFieldMetadata.getOptionFilterValues() != null) {
String[][] options = new String[basicFieldMetadata.getOptionFilterValues().length][3];
int j = 0;
for (Serializable[] option : basicFieldMetadata.getOptionFilterValues()) {
options[j][0] = String.valueOf(option[0]);
options[j][1] = String.valueOf(option[1]);
options[j][2] = String.valueOf(option[2]);
}
metadata.setOptionFilterParams(options);
}
if (!StringUtils.isEmpty(metadata.getOptionListEntity())) {
buildDataDrivenEnumList(metadata);
}
if (basicFieldMetadata.getRequiredOverride() != null) {
metadata.setRequiredOverride(basicFieldMetadata.getRequiredOverride());
}
if (basicFieldMetadata.getValidationConfigurations() != null) {
metadata.setValidationConfigurations(basicFieldMetadata.getValidationConfigurations());
}
if ((basicFieldMetadata.getFieldType() == SupportedFieldType.RULE_SIMPLE || basicFieldMetadata.getFieldType() == SupportedFieldType.RULE_WITH_QUANTITY || basicFieldMetadata.getFieldType() == SupportedFieldType.RULE_SIMPLE_TIME) && basicFieldMetadata.getRuleIdentifier() == null) {
throw new IllegalArgumentException("ruleIdentifier property must be set on AdminPresentation when the fieldType is RULE_SIMPLE, RULE_WITH_QUANTITY");
}
if (basicFieldMetadata.getRuleIdentifier() != null) {
metadata.setRuleIdentifier(basicFieldMetadata.getRuleIdentifier());
}
if (basicFieldMetadata.getLookupType() != null) {
metadata.setLookupType(basicFieldMetadata.getLookupType());
}
if (basicFieldMetadata.getTranslatable() != null) {
metadata.setTranslatable(basicFieldMetadata.getTranslatable());
}
if (basicFieldMetadata.getIsDerived() != null) {
metadata.setDerived(basicFieldMetadata.getIsDerived());
}
if (basicFieldMetadata.getDefaultValue() != null) {
metadata.setDefaultValue(basicFieldMetadata.getDefaultValue());
}
if (basicFieldMetadata.getAssociatedFieldName() != null) {
metadata.setAssociatedFieldName(basicFieldMetadata.getAssociatedFieldName());
}
if (basicFieldMetadata.getCanLinkToExternalEntity() != null) {
metadata.setCanLinkToExternalEntity(basicFieldMetadata.getCanLinkToExternalEntity());
}
attributes.put(field.getName(), metadata);
}
Aggregations