Search in sources :

Example 1 with FieldDTO

use of org.broadleafcommerce.openadmin.web.rulebuilder.dto.FieldDTO in project BroadleafCommerce by BroadleafCommerce.

the class MVELToDataWrapperTranslator method appendExpression.

public void appendExpression(String phrase, RuleBuilderFieldService fieldService, DataDTO parentDTO, List<ExpressionDTO> myCriteriaList) throws MVELTranslationException {
    Expression expression = phraseTranslator.createExpression(phrase);
    FieldDTO field = fieldService.getField(expression.getField());
    if (field == null) {
        throw new MVELTranslationException(MVELTranslationException.SPECIFIED_FIELD_NOT_FOUND, "MVEL phrase is not " + "compatible with the RuleBuilderFieldService associated with the current rules builder. " + "Unable to find the field specified: (" + expression.getField() + ")");
    }
    SupportedFieldType type = fieldService.getSupportedFieldType(expression.getField());
    ExpressionDTO expressionDTO = createExpressionDTO(expression);
    postProcessCriteria(parentDTO, myCriteriaList, expressionDTO, type);
}
Also used : SupportedFieldType(org.broadleafcommerce.common.presentation.client.SupportedFieldType) Expression(org.broadleafcommerce.openadmin.web.rulebuilder.statement.Expression) FieldDTO(org.broadleafcommerce.openadmin.web.rulebuilder.dto.FieldDTO) ExpressionDTO(org.broadleafcommerce.openadmin.web.rulebuilder.dto.ExpressionDTO)

Example 2 with FieldDTO

use of org.broadleafcommerce.openadmin.web.rulebuilder.dto.FieldDTO in project BroadleafCommerce by BroadleafCommerce.

the class AbstractRuleBuilderFieldService method constructFieldDTOFromFieldData.

protected FieldDTO constructFieldDTOFromFieldData(FieldData field) {
    FieldDTO fieldDTO = new FieldDTO();
    // translate the label to display
    String label = field.getFieldLabel();
    BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
    MessageSource messages = context.getMessageSource();
    if (messages != null) {
        label = messages.getMessage(label, null, label, context.getJavaLocale());
    }
    fieldDTO.setLabel(label);
    fieldDTO.setId(field.getFieldName());
    fieldDTO.setOperators(field.getOperators());
    fieldDTO.setSelectizeSectionKey(field.getSelectizeSectionKey());
    fieldDTO.setValues(field.getOptions());
    if (SupportedFieldType.BROADLEAF_ENUMERATION.equals(field.getFieldType())) {
        fieldDTO.setInput("select");
    } else {
        fieldDTO.setInput("text");
    }
    return fieldDTO;
}
Also used : BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) MessageSource(org.springframework.context.MessageSource) FieldDTO(org.broadleafcommerce.openadmin.web.rulebuilder.dto.FieldDTO)

Example 3 with FieldDTO

use of org.broadleafcommerce.openadmin.web.rulebuilder.dto.FieldDTO in project BroadleafCommerce by BroadleafCommerce.

the class FormBuilderServiceImpl method buildMainListGrid.

@Override
public ListGrid buildMainListGrid(DynamicResultSet drs, ClassMetadata cmd, String sectionKey, List<SectionCrumb> sectionCrumbs) throws ServiceException {
    List<Field> headerFields = new ArrayList<>();
    ListGrid.Type type = ListGrid.Type.MAIN;
    String idProperty = "id";
    FieldWrapper wrapper = new FieldWrapper();
    ArrayList<FieldDTO> defaultWrapperFields = new ArrayList<>();
    for (Property p : cmd.getProperties()) {
        if (p.getMetadata() instanceof BasicFieldMetadata) {
            BasicFieldMetadata fmd = (BasicFieldMetadata) p.getMetadata();
            if (SupportedFieldType.ID.equals(fmd.getFieldType())) {
                idProperty = fmd.getName();
            }
            if (fmd.isProminent() != null && fmd.isProminent() && !ArrayUtils.contains(getGridHiddenVisibilities(), fmd.getVisibility())) {
                Field hf = createHeaderField(p, fmd);
                headerFields.add(hf);
                defaultWrapperFields.add(constructFieldDTOFromFieldData(hf, fmd));
            }
            if (fmd.getIsFilter() != null && fmd.getIsFilter()) {
                wrapper.getFields().add(constructFieldDTOFromFieldData(createHeaderField(p, fmd), fmd));
            }
        }
    }
    ListGrid listGrid = createListGrid(cmd.getCeilingType(), headerFields, type, drs, sectionKey, 0, idProperty, sectionCrumbs);
    if (CollectionUtils.isNotEmpty(listGrid.getHeaderFields())) {
        // Set the first column to be able to link to the main entity
        listGrid.getHeaderFields().iterator().next().setMainEntityLink(true);
    } else {
        String message = "There are no listgrid header fields configured for the class " + cmd.getCeilingType();
        message += "Please mark some @AdminPresentation fields with 'prominent = true'";
        LOG.error(message);
    }
    Date c = new Date();
    String friendlyName = "listGrid" + c.getTime();
    // Set up the filter builder params
    listGrid.setJsonFieldName(friendlyName + "Json");
    listGrid.setFriendlyName(friendlyName);
    listGrid.setFieldBuilder("RULE_SIMPLE");
    if (CollectionUtils.isEmpty(wrapper.getFields())) {
        wrapper.setFields(defaultWrapperFields);
    }
    listGrid.setFieldWrapper(wrapper);
    listGrid.setHideFriendlyName(true);
    String blankJsonString = "{\"data\":[]}";
    listGrid.setJson(blankJsonString);
    DataWrapper dw = convertJsonToDataWrapper(blankJsonString);
    if (dw != null) {
        listGrid.setDataWrapper(dw);
    }
    listGrid.addModalRowAction(DefaultListGridActions.SINGLE_SELECT);
    listGrid.setSelectType(ListGrid.SelectType.SINGLE_SELECT);
    extensionManager.getProxy().modifyListGrid(listGrid.getClassName(), listGrid);
    return listGrid;
}
Also used : ArrayList(java.util.ArrayList) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid) Date(java.util.Date) 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) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) FieldWrapper(org.broadleafcommerce.openadmin.web.rulebuilder.dto.FieldWrapper) Property(org.broadleafcommerce.openadmin.dto.Property) FieldDTO(org.broadleafcommerce.openadmin.web.rulebuilder.dto.FieldDTO)

Example 4 with FieldDTO

use of org.broadleafcommerce.openadmin.web.rulebuilder.dto.FieldDTO in project BroadleafCommerce by BroadleafCommerce.

the class FormBuilderServiceImpl method buildCollectionListGrid.

@Override
public ListGrid buildCollectionListGrid(String containingEntityId, DynamicResultSet drs, Property field, String sectionKey, List<SectionCrumb> sectionCrumbs) throws ServiceException {
    FieldMetadata fmd = field.getMetadata();
    // Get the class metadata for this particular field
    PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(fmd, sectionCrumbs);
    if (field != null) {
        ppr.setSectionEntityField(field.getName());
    }
    ClassMetadata cmd = adminEntityService.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
    List<Field> headerFields = new ArrayList<>();
    ListGrid.Type type = null;
    boolean editable = false;
    boolean sortable = false;
    boolean readOnly = false;
    boolean hideIdColumn = false;
    boolean canFilterAndSort = true;
    boolean modalSingleSelectable = false;
    boolean modalMultiSelectable = false;
    boolean selectize = false;
    boolean isMedia = false;
    boolean isLookup = false;
    String sortProperty = null;
    FieldWrapper wrapper = new FieldWrapper();
    ArrayList<FieldDTO> defaultWrapperFields = new ArrayList<>();
    String idProperty = "id";
    for (Property property : cmd.getProperties()) {
        if (property.getMetadata() instanceof BasicFieldMetadata && SupportedFieldType.ID == ((BasicFieldMetadata) property.getMetadata()).getFieldType() && // make sure it's a property for this entity - not an association
        !property.getName().contains(".")) {
            idProperty = property.getName();
            break;
        }
    }
    // kind of field this is.
    if (fmd instanceof BasicFieldMetadata) {
        readOnly = ((BasicFieldMetadata) fmd).getReadOnly();
        modalSingleSelectable = true;
        for (Property p : cmd.getProperties()) {
            if (p.getMetadata() instanceof BasicFieldMetadata) {
                BasicFieldMetadata md = (BasicFieldMetadata) p.getMetadata();
                if (SupportedFieldType.ID.equals(md.getFieldType())) {
                    idProperty = md.getName();
                }
                if (md.isProminent() != null && md.isProminent() && !ArrayUtils.contains(getGridHiddenVisibilities(), md.getVisibility())) {
                    Field hf = createHeaderField(p, md);
                    headerFields.add(hf);
                    defaultWrapperFields.add(constructFieldDTOFromFieldData(hf, md));
                }
                if (md.getIsFilter() != null && md.getIsFilter()) {
                    Field f = createHeaderField(p, md);
                    wrapper.getFields().add(constructFieldDTOFromFieldData(f, md));
                }
            }
        }
        type = ListGrid.Type.TO_ONE;
    } else if (fmd instanceof BasicCollectionMetadata) {
        BasicCollectionMetadata bcm = (BasicCollectionMetadata) fmd;
        readOnly = !bcm.isMutable();
        if (AddMethodType.LOOKUP.equals(bcm.getAddMethodType())) {
            isLookup = true;
        }
        if (AddMethodType.SELECTIZE_LOOKUP.equals(bcm.getAddMethodType())) {
            Property p = cmd.getPMap().get(bcm.getSelectizeVisibleField());
            if (p != null) {
                BasicFieldMetadata md = (BasicFieldMetadata) p.getMetadata();
                Field hf = createHeaderField(p, md);
                headerFields.add(hf);
                wrapper.getFields().add(constructFieldDTOFromFieldData(hf, md));
            }
        } else {
            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);
                        defaultWrapperFields.add(constructFieldDTOFromFieldData(hf, md));
                    }
                    if (md.getIsFilter() != null && md.getIsFilter()) {
                        Field f = createHeaderField(p, md);
                        wrapper.getFields().add(constructFieldDTOFromFieldData(f, md));
                    }
                }
            }
        }
        type = ListGrid.Type.BASIC;
        if (AddMethodType.PERSIST.equals(bcm.getAddMethodType()) || AddMethodType.PERSIST_EMPTY.equals(bcm.getAddMethodType())) {
            editable = true;
        } else if (AddMethodType.SELECTIZE_LOOKUP.equals(bcm.getAddMethodType())) {
            selectize = true;
            modalSingleSelectable = true;
        } else {
            modalSingleSelectable = true;
        }
        sortable = StringUtils.isNotBlank(bcm.getSortProperty());
        if (sortable) {
            sortProperty = bcm.getSortProperty();
        }
    } else if (fmd instanceof AdornedTargetCollectionMetadata) {
        modalSingleSelectable = true;
        readOnly = !((AdornedTargetCollectionMetadata) fmd).isMutable();
        AdornedTargetCollectionMetadata atcmd = (AdornedTargetCollectionMetadata) fmd;
        if (AdornedTargetAddMethodType.LOOKUP.equals(atcmd.getAdornedTargetAddMethodType())) {
            isLookup = true;
        }
        if (AdornedTargetAddMethodType.SELECTIZE_LOOKUP.equals(atcmd.getAdornedTargetAddMethodType())) {
            selectize = true;
            Property p = cmd.getPMap().get(atcmd.getSelectizeVisibleField());
            if (p != null) {
                BasicFieldMetadata md = (BasicFieldMetadata) p.getMetadata();
                Field hf = createHeaderField(p, md);
                headerFields.add(hf);
                wrapper.getFields().add(constructFieldDTOFromFieldData(hf, md));
            }
        } else {
            for (String fieldName : atcmd.getGridVisibleFields()) {
                Property p = cmd.getPMap().get(fieldName);
                if (p != null) {
                    BasicFieldMetadata md = (BasicFieldMetadata) p.getMetadata();
                    Field hf = createHeaderField(p, md);
                    headerFields.add(hf);
                    wrapper.getFields().add(constructFieldDTOFromFieldData(hf, md));
                }
            }
        }
        type = ListGrid.Type.ADORNED;
        if (atcmd.getMaintainedAdornedTargetFields().length > 0) {
            editable = true;
        }
        AdornedTargetList adornedList = (AdornedTargetList) atcmd.getPersistencePerspective().getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.ADORNEDTARGETLIST);
        sortable = StringUtils.isNotBlank(adornedList.getSortField());
        if (sortable) {
            sortProperty = adornedList.getSortField();
        }
    } else if (fmd instanceof MapMetadata) {
        readOnly = !((MapMetadata) fmd).isMutable();
        MapMetadata mmd = (MapMetadata) fmd;
        Property p2 = cmd.getPMap().get("key");
        BasicFieldMetadata keyMd = (BasicFieldMetadata) p2.getMetadata();
        keyMd.setFriendlyName(getMapKeyFriendlyName(p2));
        Field hf = createHeaderField(p2, keyMd);
        headerFields.add(hf);
        wrapper.getFields().add(constructFieldDTOFromFieldData(hf, keyMd));
        if (mmd.isSimpleValue()) {
            Property valueProperty = cmd.getPMap().get("value");
            BasicFieldMetadata valueMd = (BasicFieldMetadata) valueProperty.getMetadata();
            valueMd.setFriendlyName("Value");
            hf = createHeaderField(valueProperty, valueMd);
            headerFields.add(hf);
            wrapper.getFields().add(constructFieldDTOFromFieldData(hf, valueMd));
            idProperty = "key";
            hideIdColumn = true;
        } else {
            for (Property p : cmd.getProperties()) {
                if (p.getMetadata() instanceof BasicFieldMetadata) {
                    BasicFieldMetadata md = (BasicFieldMetadata) p.getMetadata();
                    String valueClassName = mmd.getValueClassName();
                    if (!StringUtils.isEmpty(mmd.getToOneTargetProperty())) {
                        Class<?> clazz;
                        try {
                            clazz = Class.forName(mmd.getValueClassName());
                        } catch (ClassNotFoundException e) {
                            throw ExceptionHelper.refineException(e);
                        }
                        java.lang.reflect.Field nestedField = FieldManager.getSingleField(clazz, mmd.getToOneTargetProperty());
                        ManyToOne manyToOne = nestedField.getAnnotation(ManyToOne.class);
                        if (manyToOne != null && !manyToOne.targetEntity().getName().equals(void.class.getName())) {
                            valueClassName = manyToOne.targetEntity().getName();
                        } else {
                            OneToOne oneToOne = nestedField.getAnnotation(OneToOne.class);
                            if (oneToOne != null && !oneToOne.targetEntity().getName().equals(void.class.getName())) {
                                valueClassName = oneToOne.targetEntity().getName();
                            }
                        }
                    }
                    if (md.getTargetClass().equals(valueClassName)) {
                        if (md.isProminent() != null && md.isProminent() && !ArrayUtils.contains(getGridHiddenVisibilities(), md.getVisibility())) {
                            hf = createHeaderField(p, md);
                            headerFields.add(hf);
                            defaultWrapperFields.add(constructFieldDTOFromFieldData(hf, md));
                            // Is this a media listgrid
                            if (hf.getFieldType().equals("ASSET_LOOKUP")) {
                                isMedia = true;
                            }
                        }
                        if (md.getIsFilter() != null && md.getIsFilter()) {
                            wrapper.getFields().add(constructFieldDTOFromFieldData(hf, md));
                        }
                    }
                }
            }
        }
        type = ListGrid.Type.MAP;
        editable = true;
        canFilterAndSort = false;
    }
    String ceilingType = "";
    if (fmd instanceof BasicFieldMetadata) {
        ceilingType = cmd.getCeilingType();
    } else if (fmd instanceof CollectionMetadata) {
        ceilingType = ((CollectionMetadata) fmd).getCollectionCeilingEntity();
    }
    if (CollectionUtils.isEmpty(headerFields)) {
        String message = "There are no listgrid header fields configured for the class " + ceilingType + " and property '" + StringUtil.sanitize(field.getName()) + "'.";
        if (selectize && (type == ListGrid.Type.ADORNED || type == ListGrid.Type.ADORNED_WITH_FORM)) {
            message += " Please configure 'selectizeVisibleField' in your @AdminPresentationAdornedTargetCollection configuration";
        } else if (type == ListGrid.Type.ADORNED || type == ListGrid.Type.ADORNED_WITH_FORM) {
            message += " Please configure 'gridVisibleFields' in your @AdminPresentationAdornedTargetCollection configuration";
        } else if (selectize && type == ListGrid.Type.BASIC) {
            message += " Please configure 'selectizeVisibleField' in your @AdminPresentationCollection configuration";
        } else {
            message += " Please mark some @AdminPresentation fields with 'prominent = true'";
        }
        LOG.error(message);
    }
    ListGrid listGrid = createListGrid(ceilingType, headerFields, type, drs, sectionKey, fmd.getOrder(), idProperty, sectionCrumbs, sortProperty);
    listGrid.setSubCollectionFieldName(field.getName());
    listGrid.setFriendlyName(field.getMetadata().getFriendlyName());
    if (StringUtils.isEmpty(listGrid.getFriendlyName())) {
        listGrid.setFriendlyName(field.getName());
    }
    listGrid.setContainingEntityId(containingEntityId);
    listGrid.setIsReadOnly(readOnly);
    listGrid.setHideIdColumn(hideIdColumn);
    listGrid.setCanFilterAndSort(canFilterAndSort);
    // Set up the filter builder params
    Date c = new Date();
    String friendlyName = field.getMetadata().getFriendlyName();
    String jsonFriendlyName = friendlyName.replaceAll(" ", "_");
    listGrid.setJsonFieldName(jsonFriendlyName + c.getTime() + "Json");
    listGrid.setFriendlyName(friendlyName);
    listGrid.setFieldBuilder("RULE_SIMPLE");
    if (CollectionUtils.isEmpty(wrapper.getFields())) {
        wrapper.setFields(defaultWrapperFields);
    }
    listGrid.setFieldWrapper(wrapper);
    String blankJsonString = "{\"data\":[]}";
    listGrid.setJson(blankJsonString);
    DataWrapper dw = convertJsonToDataWrapper(blankJsonString);
    if (dw != null) {
        listGrid.setDataWrapper(dw);
    }
    if (editable) {
        listGrid.getRowActions().add(DefaultListGridActions.UPDATE);
    }
    if (readOnly) {
        listGrid.getRowActions().add(DefaultListGridActions.VIEW);
    }
    if (sortable) {
        listGrid.setCanFilterAndSort(false);
        listGrid.setIsSortable(true);
    }
    if (modalSingleSelectable) {
        if (readOnly) {
            listGrid.addModalRowAction(DefaultListGridActions.SINGLE_SELECT.clone().withForListGridReadOnly(true));
        } else {
            listGrid.addModalRowAction(DefaultListGridActions.SINGLE_SELECT);
        }
    }
    listGrid.setSelectType(ListGrid.SelectType.SINGLE_SELECT);
    if (selectize) {
        listGrid.setSelectizeUrl(buildSelectizeUrl(listGrid));
        listGrid.setSelectType(ListGrid.SelectType.SELECTIZE);
    }
    if (modalMultiSelectable) {
        listGrid.addModalRowAction(DefaultListGridActions.MULTI_SELECT);
        listGrid.setSelectType(ListGrid.SelectType.MULTI_SELECT);
    }
    listGrid.getRowActions().add(DefaultListGridActions.REMOVE);
    if (fmd.getManualFetch()) {
        listGrid.setManualFetch(true);
        listGrid.getToolbarActions().add(DefaultListGridActions.MANUAL_FETCH);
    }
    if (isMedia) {
        listGrid.setListGridType(ListGrid.Type.ASSET_GRID);
    }
    extensionManager.getProxy().modifyListGrid(listGrid.getClassName(), listGrid);
    // If someone has replaced RowLevelSecurityService, check here to make sure the replacement implements the expected interface
    if (rowLevelSecurityService instanceof ExceptionAwareRowLevelSecurityProvider) {
        EntityFormModifierConfiguration entityFormModifierConfiguration = ((ExceptionAwareRowLevelSecurityProvider) rowLevelSecurityService).getUpdateDenialExceptions();
        for (EntityFormModifierData<EntityFormModifierDataPoint> data : entityFormModifierConfiguration.getData()) {
            for (EntityFormModifier modifier : entityFormModifierConfiguration.getModifier()) {
                if (modifier.isQualified(data.getModifierType())) {
                    modifier.modifyListGrid(new EntityFormModifierRequest().withListGrid(listGrid).withConfiguration(data).withCurrentUser(adminRemoteSecurityService.getPersistentAdminUser()).withRowLevelSecurityService(rowLevelSecurityService));
                }
            }
        }
    }
    return listGrid;
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) ArrayList(java.util.ArrayList) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) EntityFormModifier(org.broadleafcommerce.openadmin.server.security.service.EntityFormModifier) ManyToOne(javax.persistence.ManyToOne) EntityFormModifierConfiguration(org.broadleafcommerce.openadmin.server.security.service.EntityFormModifierConfiguration) 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) OneToOne(javax.persistence.OneToOne) FieldWrapper(org.broadleafcommerce.openadmin.web.rulebuilder.dto.FieldWrapper) Property(org.broadleafcommerce.openadmin.dto.Property) AdornedTargetList(org.broadleafcommerce.openadmin.dto.AdornedTargetList) MapMetadata(org.broadleafcommerce.openadmin.dto.MapMetadata) FieldDTO(org.broadleafcommerce.openadmin.web.rulebuilder.dto.FieldDTO) BasicCollectionMetadata(org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata) AdornedTargetCollectionMetadata(org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata) CollectionMetadata(org.broadleafcommerce.openadmin.dto.CollectionMetadata) EntityFormModifierDataPoint(org.broadleafcommerce.openadmin.server.security.service.EntityFormModifierDataPoint) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid) Date(java.util.Date) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) EntityFormModifierRequest(org.broadleafcommerce.openadmin.server.security.service.EntityFormModifierRequest) ExceptionAwareRowLevelSecurityProvider(org.broadleafcommerce.openadmin.server.security.service.ExceptionAwareRowLevelSecurityProvider) BasicCollectionMetadata(org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata) AdornedTargetCollectionMetadata(org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)

Example 5 with FieldDTO

use of org.broadleafcommerce.openadmin.web.rulebuilder.dto.FieldDTO in project BroadleafCommerce by BroadleafCommerce.

the class FormBuilderServiceImpl method constructFieldDTOFromFieldData.

protected FieldDTO constructFieldDTOFromFieldData(Field field, BasicFieldMetadata fmd) {
    FieldDTO fieldDTO = new FieldDTO();
    // translate the label to display
    String label = field.getFriendlyName();
    BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
    MessageSource messages = context.getMessageSource();
    if (messages != null) {
        label = messages.getMessage(label, null, label, context.getJavaLocale());
    }
    fieldDTO.setLabel(label);
    fieldDTO.setId(field.getName());
    if (field.getFieldType().equals("STRING")) {
        fieldDTO.setOperators("blcFilterOperators_Text");
    } else if (field.getFieldType().equals("DATE")) {
        fieldDTO.setOperators("blcFilterOperators_Date");
    } else if (field.getFieldType().equals("NUMBER") || field.getFieldType().equals("MONEY") || field.getFieldType().equals("DECIMAL")) {
        fieldDTO.setOperators("blcFilterOperators_Numeric");
    } else if (field.getFieldType().equals("BOOLEAN")) {
        fieldDTO.setOperators("blcFilterOperators_Boolean");
    } else if (field.getFieldType().equals("BROADLEAF_ENUMERATION")) {
        fieldDTO.setOperators("blcFilterOperators_Enumeration");
        fieldDTO.setInput("select");
        fieldDTO.setType("string");
        String[][] enumerationValues = fmd.getEnumerationValues();
        Map<String, String> enumMap = new HashMap<>();
        for (int i = 0; i < enumerationValues.length; i++) {
            enumMap.put(enumerationValues[i][0], enumerationValues[i][1]);
        }
        fieldDTO.setValues(new JSONObject(enumMap).toString());
    } else if (field.getFieldType().equals("ADDITIONAL_FOREIGN_KEY")) {
        fieldDTO.setOperators("blcFilterOperators_Selectize");
        fieldDTO.setType("string");
        AdminSection section = adminNavigationService.findAdminSectionByClassAndSectionId(fmd.getForeignKeyClass(), null);
        if (section != null) {
            String sectionKey = section.getUrl().substring(1);
            fieldDTO.setSelectizeSectionKey(sectionKey);
        } else {
            fieldDTO.setSelectizeSectionKey(fmd.getForeignKeyClass());
        }
    } else {
        fieldDTO.setOperators("blcFilterOperators_Text");
    }
    return fieldDTO;
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) HashMap(java.util.HashMap) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) AdminSection(org.broadleafcommerce.openadmin.server.security.domain.AdminSection) MessageSource(org.springframework.context.MessageSource) EntityFormModifierDataPoint(org.broadleafcommerce.openadmin.server.security.service.EntityFormModifierDataPoint) FieldDTO(org.broadleafcommerce.openadmin.web.rulebuilder.dto.FieldDTO)

Aggregations

FieldDTO (org.broadleafcommerce.openadmin.web.rulebuilder.dto.FieldDTO)5 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 BroadleafRequestContext (org.broadleafcommerce.common.web.BroadleafRequestContext)2 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)2 Property (org.broadleafcommerce.openadmin.dto.Property)2 EntityFormModifierDataPoint (org.broadleafcommerce.openadmin.server.security.service.EntityFormModifierDataPoint)2 ListGrid (org.broadleafcommerce.openadmin.web.form.component.ListGrid)2 MediaField (org.broadleafcommerce.openadmin.web.form.component.MediaField)2 RuleBuilderField (org.broadleafcommerce.openadmin.web.form.component.RuleBuilderField)2 CodeField (org.broadleafcommerce.openadmin.web.form.entity.CodeField)2 ComboField (org.broadleafcommerce.openadmin.web.form.entity.ComboField)2 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)2 DataWrapper (org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper)2 FieldWrapper (org.broadleafcommerce.openadmin.web.rulebuilder.dto.FieldWrapper)2 MessageSource (org.springframework.context.MessageSource)2 HashMap (java.util.HashMap)1 ManyToOne (javax.persistence.ManyToOne)1 OneToOne (javax.persistence.OneToOne)1 SupportedFieldType (org.broadleafcommerce.common.presentation.client.SupportedFieldType)1