Search in sources :

Example 6 with DynamicPropertySet

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

the class DpsRecordAdapter method createDps.

public static DynamicPropertySet createDps(ResultSet resultSet, MetaProcessor metaProcessor) {
    try {
        DynamicProperty[] schema = createSchema(resultSet.getMetaData());
        DynamicPropertySet row = new DynamicPropertySetSupport();
        for (int i = 0; i < schema.length; i++) {
            DynamicProperty dp = schema[i];
            Object refIdxObj = dp.getAttribute(COLUMN_REF_IDX_PROPERTY);
            if (refIdxObj instanceof Integer) {
                int refIdx = (int) refIdxObj;
                if (refIdx >= 0) {
                    Map<String, Map<String, String>> tags = new TreeMap<>();
                    BeTagParser.parseTags(tags, resultSet.getString(i + 1));
                    DynamicPropertyMeta.add(schema[refIdx], tags);
                    dp.setAttribute(COLUMN_REF_IDX_PROPERTY, -1);
                }
                continue;
            }
            Object val = getSqlValue(dp.getType(), resultSet, i + 1);
            // todo test Map<String, Map<String, String>> metaInfo = DynamicPropertyMeta.get(dp);
            // metaProcessor.process(val, metaInfo);
            DynamicProperty property = DynamicPropertySetSupport.cloneProperty(dp);
            property.setValue(val);
            row.add(property);
        }
        return row;
    } catch (Exception e) {
        throw Be5Exception.internal(e);
    }
}
Also used : DynamicPropertySet(com.developmentontheedge.beans.DynamicPropertySet) DynamicProperty(com.developmentontheedge.beans.DynamicProperty) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map) SQLException(java.sql.SQLException) Be5Exception(com.developmentontheedge.be5.api.exceptions.Be5Exception) DynamicPropertySetSupport(com.developmentontheedge.beans.DynamicPropertySetSupport)

Example 7 with DynamicPropertySet

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

the class FilterOperation method getParameters.

@Override
public Object getParameters(Map<String, Object> presetValues) throws Exception {
    DynamicPropertySet dps = new DynamicPropertySetSupport();
    dpsHelper.addDpExcludeAutoIncrement(dps, getInfo().getModel());
    return filterHelper.processFilterParams(dps, presetValues, context.getOperationParams());
}
Also used : DynamicPropertySet(com.developmentontheedge.beans.DynamicPropertySet) DynamicPropertySetSupport(com.developmentontheedge.beans.DynamicPropertySetSupport)

Example 8 with DynamicPropertySet

use of com.developmentontheedge.beans.DynamicPropertySet 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)

Example 9 with DynamicPropertySet

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

the class Be5QueryExecutor method executeSubQuery.

@Override
public List<DynamicPropertySet> executeSubQuery(String subqueryName, CellFormatter.VarResolver varResolver) {
    AstBeSqlSubQuery subQuery = contextApplier.applyVars(subqueryName, varResolver::resolve);
    if (subQuery.getQuery() == null) {
        return Collections.emptyList();
    }
    String finalSql = new Formatter().format(subQuery.getQuery(), context, parserContext);
    List<DynamicPropertySet> dynamicPropertySets;
    try {
        dynamicPropertySets = listDps(finalSql);
    } catch (Throwable e) {
        // TODO only for Document presentation, for operations must be error throw
        Be5Exception be5Exception = Be5Exception.internalInQuery(e, query);
        log.log(Level.SEVERE, be5Exception.toString() + " Final SQL: " + finalSql, be5Exception);
        DynamicPropertySetSupport dynamicProperties = new DynamicPropertySetSupport();
        dynamicProperties.add(new DynamicProperty("___ID", String.class, "-1"));
        dynamicProperties.add(new DynamicProperty("error", String.class, UserInfoHolder.isSystemDeveloper() ? Be5Exception.getMessage(e) : "error"));
        dynamicPropertySets = Collections.singletonList(dynamicProperties);
    }
    // return Collections.singletonList(dynamicProperties);
    return dynamicPropertySets;
}
Also used : DynamicPropertySet(com.developmentontheedge.beans.DynamicPropertySet) Be5Exception(com.developmentontheedge.be5.api.exceptions.Be5Exception) DynamicProperty(com.developmentontheedge.beans.DynamicProperty) Formatter(com.developmentontheedge.sql.format.Formatter) AstBeSqlSubQuery(com.developmentontheedge.sql.model.AstBeSqlSubQuery) DynamicPropertySetSupport(com.developmentontheedge.beans.DynamicPropertySetSupport)

Example 10 with DynamicPropertySet

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

the class CellFormatter method toTable.

/**
 * Returns a two-dimensional listDps of processed content. Each element is either a string or a table.
 */
private List<List<Object>> toTable(String subquery, VarResolver varResolver) {
    List<DynamicPropertySet> list = queryExecutor.executeSubQuery(subquery, varResolver);
    List<List<Object>> lists = new ArrayList<>();
    for (DynamicPropertySet dps : list) {
        List<Object> objects = toRow(dps, varResolver);
        lists.add(objects);
    }
    return lists;
}
Also used : DynamicPropertySet(com.developmentontheedge.beans.DynamicPropertySet) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList)

Aggregations

DynamicPropertySet (com.developmentontheedge.beans.DynamicPropertySet)17 DynamicPropertySetSupport (com.developmentontheedge.beans.DynamicPropertySetSupport)11 DynamicProperty (com.developmentontheedge.beans.DynamicProperty)7 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3 Be5Exception (com.developmentontheedge.be5.api.exceptions.Be5Exception)2 HashMap (java.util.HashMap)2 SEARCH_PARAM (com.developmentontheedge.be5.api.FrontendConstants.SEARCH_PARAM)1 SEARCH_PRESETS_PARAM (com.developmentontheedge.be5.api.FrontendConstants.SEARCH_PRESETS_PARAM)1 Entity (com.developmentontheedge.be5.metadata.model.Entity)1 Query (com.developmentontheedge.be5.metadata.model.Query)1 JsonApiModel (com.developmentontheedge.be5.model.jsonapi.JsonApiModel)1 DocumentGenerator (com.developmentontheedge.be5.query.DocumentGenerator)1 SqlMockOperationTest (com.developmentontheedge.be5.test.SqlMockOperationTest)1 BeanInfoConstants (com.developmentontheedge.beans.BeanInfoConstants)1 DynamicPropertyBuilder (com.developmentontheedge.beans.DynamicPropertyBuilder)1 ColumnRef (com.developmentontheedge.sql.format.ColumnRef)1 FilterApplier (com.developmentontheedge.sql.format.FilterApplier)1 Formatter (com.developmentontheedge.sql.format.Formatter)1