Search in sources :

Example 1 with DynamicPropertyBuilder

use of com.developmentontheedge.beans.DynamicPropertyBuilder in project be5 by DevelopmentOnTheEdge.

the class FilterHelper method processFilterParams.

public <T extends DynamicPropertySet> T processFilterParams(T dps, Map<String, Object> presetValues, Map<String, String> operationParams) {
    Map<String, Object> filterPresetValues = new HashMap<>(operationParams);
    filterPresetValues.putAll(presetValues);
    List<String> searchPresets = new ArrayList<>();
    if (!filterPresetValues.containsKey(SEARCH_PARAM)) {
        searchPresets.addAll(presetValues.entrySet().stream().filter(x -> x.getValue() != null).map(Map.Entry::getKey).collect(Collectors.toList()));
    } else {
        if (filterPresetValues.get(SEARCH_PRESETS_PARAM) != null) {
            searchPresets.addAll(Arrays.asList(((String) filterPresetValues.get(SEARCH_PRESETS_PARAM)).split(",")));
        }
    }
    for (DynamicProperty property : dps) {
        if (!property.getBooleanAttribute(BeanInfoConstants.LABEL_FIELD)) {
            // remove defaultValue
            property.setValue(null);
        }
    }
    dpsHelper.setValues(dps, filterPresetValues);
    for (DynamicProperty property : dps) {
        property.setCanBeNull(true);
        if (searchPresets.contains(property.getName()))
            property.setReadOnly(true);
    }
    dps.add(new DynamicPropertyBuilder(SEARCH_PRESETS_PARAM, String.class).value(searchPresets.size() > 0 ? String.join(",", searchPresets) : null).readonly().nullable().hidden().get());
    dps.add(new DynamicPropertyBuilder(SEARCH_PARAM, Boolean.class).value(true).readonly().nullable().hidden().get());
    return dps;
}
Also used : DynamicProperty(com.developmentontheedge.beans.DynamicProperty) Arrays(java.util.Arrays) DynamicPropertySet(com.developmentontheedge.beans.DynamicPropertySet) FilterApplier(com.developmentontheedge.sql.format.FilterApplier) DynamicPropertyBuilder(com.developmentontheedge.beans.DynamicPropertyBuilder) DocumentGenerator(com.developmentontheedge.be5.query.DocumentGenerator) Set(java.util.Set) HashMap(java.util.HashMap) Query(com.developmentontheedge.be5.metadata.model.Query) AstStart(com.developmentontheedge.sql.model.AstStart) EntryStream(one.util.streamex.EntryStream) Collectors(java.util.stream.Collectors) JsonApiModel(com.developmentontheedge.be5.model.jsonapi.JsonApiModel) ArrayList(java.util.ArrayList) BeanInfoConstants(com.developmentontheedge.beans.BeanInfoConstants) List(java.util.List) SEARCH_PRESETS_PARAM(com.developmentontheedge.be5.api.FrontendConstants.SEARCH_PRESETS_PARAM) AstBeParameterTag(com.developmentontheedge.sql.model.AstBeParameterTag) Map(java.util.Map) ColumnRef(com.developmentontheedge.sql.format.ColumnRef) SEARCH_PARAM(com.developmentontheedge.be5.api.FrontendConstants.SEARCH_PARAM) DynamicPropertyBuilder(com.developmentontheedge.beans.DynamicPropertyBuilder) DynamicProperty(com.developmentontheedge.beans.DynamicProperty) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Aggregations

SEARCH_PARAM (com.developmentontheedge.be5.api.FrontendConstants.SEARCH_PARAM)1 SEARCH_PRESETS_PARAM (com.developmentontheedge.be5.api.FrontendConstants.SEARCH_PRESETS_PARAM)1 Query (com.developmentontheedge.be5.metadata.model.Query)1 JsonApiModel (com.developmentontheedge.be5.model.jsonapi.JsonApiModel)1 DocumentGenerator (com.developmentontheedge.be5.query.DocumentGenerator)1 BeanInfoConstants (com.developmentontheedge.beans.BeanInfoConstants)1 DynamicProperty (com.developmentontheedge.beans.DynamicProperty)1 DynamicPropertyBuilder (com.developmentontheedge.beans.DynamicPropertyBuilder)1 DynamicPropertySet (com.developmentontheedge.beans.DynamicPropertySet)1 ColumnRef (com.developmentontheedge.sql.format.ColumnRef)1 FilterApplier (com.developmentontheedge.sql.format.FilterApplier)1 AstBeParameterTag (com.developmentontheedge.sql.model.AstBeParameterTag)1 AstStart (com.developmentontheedge.sql.model.AstStart)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1