Search in sources :

Example 21 with DynamicProperty

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

the class DpsHelper method addDpForColumnsWithoutTags.

public <T extends DynamicPropertySet> T addDpForColumnsWithoutTags(T dps, BeModelElement modelElements, Collection<String> columnNames) {
    Map<String, ColumnDef> columns = meta.getColumns(getEntity(modelElements));
    for (String propertyName : columnNames) {
        ColumnDef columnDef = columns.get(propertyName);
        if (columnDef != null) {
            DynamicProperty dynamicProperty = getDynamicPropertyWithoutTags(columnDef, modelElements);
            dps.add(dynamicProperty);
        } else {
            throw Be5Exception.internal("Entity '" + modelElements.getName() + "' not contain column " + propertyName);
        }
    }
    return dps;
}
Also used : DynamicProperty(com.developmentontheedge.beans.DynamicProperty) ColumnDef(com.developmentontheedge.be5.metadata.model.ColumnDef)

Example 22 with DynamicProperty

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

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

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

the class PropertiesToRowTransformer method collectCells.

/**
 * Glues and constructs cells.
 * @see # preprocessProperties(DatabaseConnector, List<DynamicProperty>, Map<String, DynamicProperty>)
 */
List<RawCellModel> collectCells() {
    // TODO support: collect all values, GLUE_COLUMN_PREFIX
    // // mutable map of properties
    // Map<String, StringBuilder> temp = new LinkedHashMap<>();
    // 
    // // see RecordEx#preprocessProperties/3
    // for( DynamicProperty property : properties )
    // {
    // String name = property.getName();
    // if( name.startsWith( RecordEx.GLUE_COLUMN_PREFIX ) )
    // {
    // appendProperty( property, temp );
    // continue;
    // }
    // temp.put( name, new StringBuilder( toString( property ) ) );
    // }
    // 
    // List<RawCellModel> cells = new ArrayList<>();
    // 
    // // collect all values
    // for( Entry<String, StringBuilder> entry : temp.entrySet() )
    // {
    // String cellName = entry.getKey();
    // String cellContent = entry.getValue().toString();
    // boolean hidden = shouldBeSkipped( cellName );
    // cells.add( new RawCellModel( cellName, localizer.localize( cellContent ), null, hidden ) );
    // }
    List<RawCellModel> cells = new ArrayList<>();
    for (DynamicProperty property : properties) {
        String cellName = property.getName();
        Object cellContent = formatValue(property);
        boolean hidden = shouldBeSkipped(cellName);
        cells.add(new RawCellModel(cellName, cellContent, DynamicPropertyMeta.get(property), hidden));
    }
    return cells;
}
Also used : RawCellModel(com.developmentontheedge.be5.query.impl.model.TableModel.RawCellModel) DynamicProperty(com.developmentontheedge.beans.DynamicProperty) ArrayList(java.util.ArrayList)

Example 25 with DynamicProperty

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

the class DynamicPropertySetMetaClass method setProperty.

@Override
@SuppressWarnings("unchecked")
public void setProperty(Object object, String propertyName, Object value) {
    DynamicPropertySet dps = ((T) object);
    if (value instanceof Map) {
        Map map = (Map) value;
        map.put("name", propertyName);
        this.invokeMethod(object, "leftShift", new Object[] { map });
        return;
    }
    if (value == null) {
        DynamicProperty dp = new DynamicProperty(propertyName, String.class);
        dp.setValue(null);
        dps.add(dp);
        return;
    }
    if (dps.getProperty(propertyName) != null) {
        dps.setValue(propertyName, value);
        return;
    }
    DynamicProperty dp = new DynamicProperty(propertyName, value.getClass());
    dp.setValue(value);
    dps.add(dp);
}
Also used : DynamicPropertySet(com.developmentontheedge.beans.DynamicPropertySet) DynamicProperty(com.developmentontheedge.beans.DynamicProperty) Map(java.util.Map) HashMap(java.util.HashMap)

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