use of org.broadleafcommerce.common.media.domain.MediaDto 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());
}
}
}
}
}
}
Aggregations