Search in sources :

Example 1 with MediaDto

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());
                    }
                }
            }
        }
    }
}
Also used : DataWrapper(org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper) CodeField(org.broadleafcommerce.openadmin.web.form.entity.CodeField) RuleBuilderField(org.broadleafcommerce.openadmin.web.form.component.RuleBuilderField) Field(org.broadleafcommerce.openadmin.web.form.entity.Field) ComboField(org.broadleafcommerce.openadmin.web.form.entity.ComboField) MediaField(org.broadleafcommerce.openadmin.web.form.component.MediaField) MediaDto(org.broadleafcommerce.common.media.domain.MediaDto) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) RuleBuilderField(org.broadleafcommerce.openadmin.web.form.component.RuleBuilderField) MediaField(org.broadleafcommerce.openadmin.web.form.component.MediaField) Property(org.broadleafcommerce.openadmin.dto.Property)

Aggregations

MediaDto (org.broadleafcommerce.common.media.domain.MediaDto)1 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)1 Property (org.broadleafcommerce.openadmin.dto.Property)1 MediaField (org.broadleafcommerce.openadmin.web.form.component.MediaField)1 RuleBuilderField (org.broadleafcommerce.openadmin.web.form.component.RuleBuilderField)1 CodeField (org.broadleafcommerce.openadmin.web.form.entity.CodeField)1 ComboField (org.broadleafcommerce.openadmin.web.form.entity.ComboField)1 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)1 DataWrapper (org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper)1