Search in sources :

Example 6 with DynamicProperty

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

the class DpsHelper method getLabel.

public DynamicProperty getLabel(String name, String text) {
    DynamicProperty label = new DynamicProperty(name, String.class, text);
    label.setAttribute(BeanInfoConstants.LABEL_FIELD, true);
    label.setAttribute(BeanInfoConstants.CAN_BE_NULL, true);
    return label;
}
Also used : DynamicProperty(com.developmentontheedge.beans.DynamicProperty)

Example 7 with DynamicProperty

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

the class DpsHelper method getLabelRaw.

public DynamicProperty getLabelRaw(String name, String text) {
    DynamicProperty label = getLabel(name, text);
    label.setAttribute(BeanInfoConstants.RAW_VALUE, true);
    return label;
}
Also used : DynamicProperty(com.developmentontheedge.beans.DynamicProperty)

Example 8 with DynamicProperty

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

the class OperationHelper method readAsList.

public List<List<Object>> readAsList(String sql, Object... params) {
    List<List<Object>> vals = new ArrayList<>();
    List<DynamicPropertySet> list = readAsRecords(sql, params);
    for (int i = 0; i < list.size(); i++) {
        List<Object> propertyList = new ArrayList<>();
        for (DynamicProperty property : list.get(i)) {
            propertyList.add(property.getValue());
        }
        vals.add(propertyList);
    }
    return vals;
}
Also used : DynamicPropertySet(com.developmentontheedge.beans.DynamicPropertySet) DynamicProperty(com.developmentontheedge.beans.DynamicProperty) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 9 with DynamicProperty

use of com.developmentontheedge.beans.DynamicProperty 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 10 with DynamicProperty

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

the class DpsRecordAdapter method createSchema.

public static DynamicProperty[] createSchema(ResultSetMetaData metaData) {
    try {
        int count = metaData.getColumnCount();
        DynamicProperty[] schema = new DynamicProperty[count];
        Set<String> names = new HashSet<>();
        // TODO: support ";ColumnName" declarations
        for (int i = 1; i <= count; i++) {
            String columnLabel = metaData.getColumnLabel(i);
            if (columnLabel.startsWith(";")) {
                String refName = columnLabel.substring(1);
                int refId = IntStreamEx.ofIndices(schema, dp -> dp != null && dp.getName().equals(refName)).findAny().orElseThrow(() -> Be5Exception.internal("no previous column with name " + refName));
                DynamicProperty dp = new DynamicProperty(columnLabel, String.class);
                dp.setAttribute(COLUMN_REF_IDX_PROPERTY, refId);
                dp.setHidden(true);
                schema[i - 1] = dp;
                continue;
            }
            String[] parts = columnLabel.split(";", 2);
            String name = getUniqueName(names, parts[0]);
            Class<?> clazz = getTypeClass(metaData.getColumnType(i));
            DynamicProperty dp = new DynamicProperty(name, clazz);
            if (name.startsWith(DatabaseConstants.HIDDEN_COLUMN_PREFIX)) {
                dp.setHidden(true);
            }
            Map<String, Map<String, String>> tags = new TreeMap<>();
            if (parts.length == 2)
                BeTagParser.parseTags(tags, parts[1]);
            DynamicPropertyMeta.set(dp, tags);
            // TODO: support various types, attributes, tags, meta
            schema[i - 1] = dp;
        }
        return schema;
    } catch (SQLException e) {
        throw Be5Exception.internal(e);
    }
}
Also used : DynamicProperty(com.developmentontheedge.beans.DynamicProperty) SQLException(java.sql.SQLException) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

DynamicProperty (com.developmentontheedge.beans.DynamicProperty)27 DynamicPropertySet (com.developmentontheedge.beans.DynamicPropertySet)7 ColumnDef (com.developmentontheedge.be5.metadata.model.ColumnDef)6 Map (java.util.Map)6 HashMap (java.util.HashMap)5 DynamicPropertySetSupport (com.developmentontheedge.beans.DynamicPropertySetSupport)4 SQLException (java.sql.SQLException)4 ArrayList (java.util.ArrayList)4 LinkedHashMap (java.util.LinkedHashMap)3 Be5Exception (com.developmentontheedge.be5.api.exceptions.Be5Exception)2 Formatter (com.developmentontheedge.sql.format.Formatter)2 List (java.util.List)2 TreeMap (java.util.TreeMap)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 GroovyOperation (com.developmentontheedge.be5.metadata.model.GroovyOperation)1 JavaOperation (com.developmentontheedge.be5.metadata.model.JavaOperation)1 Query (com.developmentontheedge.be5.metadata.model.Query)1 JsonApiModel (com.developmentontheedge.be5.model.jsonapi.JsonApiModel)1