Search in sources :

Example 1 with DynamicProperty

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

the class DynamicPropertySetMetaClass method leftShift.

// todo refactoring duplicate code
public static DynamicPropertySet leftShift(DynamicPropertySet dps, Map<String, Object> properties) {
    Map<String, Object> map = new HashMap<>();
    map.putAll(properties);
    String name = asString(removeFromMap(map, "name"));
    if (name == null) {
        name = "null";
    }
    Object value = removeFromMap(map, "value");
    if (value != null && value.getClass() == GStringImpl.class) {
        value = value.toString();
    }
    String displayName = asString(removeFromMap(map, "DISPLAY_NAME"));
    Boolean isHidden = (Boolean) removeFromMap(map, "HIDDEN");
    Class type = (Class) removeFromMap(map, "TYPE");
    if (type == java.sql.Date.class && value != null) {
        value = Utils.changeType(value, java.sql.Date.class);
    }
    DynamicProperty dp = dps.getProperty(name);
    if (dp == null) {
        dp = new DynamicProperty(name, type != null ? type : value != null ? value.getClass() : String.class);
        dps.add(dp);
    }
    dp.setValue(value);
    if (displayName != null)
        dp.setDisplayName(displayName);
    if (isHidden == Boolean.TRUE)
        dp.setHidden(true);
    for (String key : map.keySet()) {
        String attributeName = beanInfoConstants.get(key);
        if (attributeName != null) {
            dp.setAttribute(attributeName, map.get(key));
        } else {
            log.warning("Not found attribute: " + key + " in BeanInfoConstants");
        }
    }
    return dps;
}
Also used : DynamicProperty(com.developmentontheedge.beans.DynamicProperty) HashMap(java.util.HashMap) GStringImpl(org.codehaus.groovy.runtime.GStringImpl)

Example 2 with DynamicProperty

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

the class GDynamicPropertySetSupport method add.

// may be add
// public DynamicProperty setAt(String name, String value)
// {
// DynamicProperty property = new DynamicProperty(name, String.class, value);
// super.add(property);
// return property;
// }
public DynamicProperty add(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = DPSAttributes.class) Closure cl) {
    DPSAttributes builder = getBuilder(cl);
    Objects.requireNonNull(builder.getName());
    DynamicProperty property = new DynamicProperty(builder.getName(), builder.getTYPE());
    add(property);
    return DynamicPropertyMetaClass.leftShift(property, builder.getMap());
}
Also used : DynamicProperty(com.developmentontheedge.beans.DynamicProperty)

Example 3 with DynamicProperty

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

the class TestOperationProperty method getParameters.

@Override
public Object getParameters(Map<String, Object> presetValues) throws Exception {
    DynamicPropertySet dps = new DynamicPropertySetSupport();
    dps.add(new DynamicProperty("simple", "Name", String.class));
    dps.add(new DynamicProperty("simpleNumber", "Number", Long.class));
    dps.add(new DynamicProperty("getOrDefault", "Name", String.class, presetValues.getOrDefault("getOrDefault", "defaultValue")));
    dps.add(new DynamicProperty("getOrDefaultNumber", "Name", Long.class, presetValues.getOrDefault("getOrDefaultNumber", "3")));
    return dpsHelper.setValues(dps, presetValues);
}
Also used : DynamicPropertySet(com.developmentontheedge.beans.DynamicPropertySet) DynamicProperty(com.developmentontheedge.beans.DynamicProperty) DynamicPropertySetSupport(com.developmentontheedge.beans.DynamicPropertySetSupport)

Example 4 with DynamicProperty

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

the class DpsHelper method addTags.

private <T extends DynamicPropertySet> T addTags(T dps, BeModelElement modelElements, Collection<String> columnNames) {
    Map<String, ColumnDef> columns = meta.getColumns(getEntity(modelElements));
    for (String propertyName : columnNames) {
        DynamicProperty property = dps.getProperty(propertyName);
        ColumnDef columnDef = columns.get(property.getName());
        if (columnDef != null)
            addTags(property, columnDef);
    }
    return dps;
}
Also used : DynamicProperty(com.developmentontheedge.beans.DynamicProperty) ColumnDef(com.developmentontheedge.be5.metadata.model.ColumnDef)

Example 5 with DynamicProperty

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

the class DpsHelper method setValues.

public <T extends DynamicPropertySet> T setValues(T dps, ResultSet resultSet) {
    try {
        ResultSetMetaData metaData = resultSet.getMetaData();
        for (int i = 1; i <= metaData.getColumnCount(); i++) {
            String name = metaData.getColumnName(i);
            DynamicProperty property = dps.getProperty(name);
            if (property != null) {
                property.setValue(DpsRecordAdapter.getSqlValue(property.getType(), resultSet, i));
            }
        }
    } catch (SQLException e) {
        throw Be5Exception.internal(e);
    }
    return dps;
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) DynamicProperty(com.developmentontheedge.beans.DynamicProperty) SQLException(java.sql.SQLException)

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