Search in sources :

Example 16 with DynamicProperty

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

the class DpsHelper method addSpecialColumns.

private void addSpecialColumns(BeModelElement modelElements, DynamicPropertySet dps, List<String> specialColumns) {
    Map<String, ColumnDef> columns = meta.getColumns(getEntity(modelElements));
    Timestamp currentTime = new Timestamp(new Date().getTime());
    for (String propertyName : specialColumns) {
        ColumnDef columnDef = columns.get(propertyName);
        if (columnDef != null) {
            Object value = getSpecialColumnsValue(propertyName, currentTime);
            if (dps.getProperty(propertyName) == null) {
                DynamicProperty newProperty = new DynamicProperty(propertyName, value.getClass(), value);
                newProperty.setHidden(true);
                dps.add(newProperty);
            } else {
                dps.setValue(propertyName, value);
            }
        }
    }
}
Also used : DynamicProperty(com.developmentontheedge.beans.DynamicProperty) ColumnDef(com.developmentontheedge.be5.metadata.model.ColumnDef) Timestamp(java.sql.Timestamp) Date(java.util.Date)

Example 17 with DynamicProperty

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

the class DpsHelper method setValueIfOneTag.

public void setValueIfOneTag(DynamicPropertySet dps, List<String> propertyNames) {
    for (String name : propertyNames) {
        DynamicProperty property = dps.getProperty(name);
        Objects.requireNonNull(property);
        String[][] tags = (String[][]) property.getAttribute(BeanInfoConstants.TAG_LIST_ATTR);
        if (tags.length == 1) {
            property.setValue(tags[0][0]);
        }
    }
}
Also used : DynamicProperty(com.developmentontheedge.beans.DynamicProperty)

Example 18 with DynamicProperty

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

the class DpsHelper method addDynamicProperties.

public <T extends DynamicPropertySet> T addDynamicProperties(T dps, BeModelElement modelElements, Collection<String> propertyNames) {
    Map<String, ColumnDef> columns = meta.getColumns(getEntity(modelElements));
    for (String propertyName : propertyNames) {
        ColumnDef columnDef = columns.get(propertyName);
        DynamicProperty dynamicProperty = getDynamicPropertyWithoutTags(columnDef, modelElements);
        addTags(dynamicProperty, columnDef);
        dps.add(dynamicProperty);
    }
    return dps;
}
Also used : DynamicProperty(com.developmentontheedge.beans.DynamicProperty) ColumnDef(com.developmentontheedge.be5.metadata.model.ColumnDef)

Example 19 with DynamicProperty

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

the class DpsHelper method addDpsExcludedColumnsWithoutTags.

public <T extends DynamicPropertySet> T addDpsExcludedColumnsWithoutTags(T dps, BeModelElement modelElements, Collection<String> excludedColumns) {
    Map<String, ColumnDef> columns = meta.getColumns(getEntity(modelElements));
    ArrayList<String> excludedColumnsList = new ArrayList<>(excludedColumns);
    for (Map.Entry<String, ColumnDef> entry : columns.entrySet()) {
        if (!excludedColumnsList.contains(entry.getKey())) {
            DynamicProperty dynamicProperty = getDynamicPropertyWithoutTags(entry.getValue(), modelElements);
            dps.add(dynamicProperty);
        }
        excludedColumnsList.remove(entry.getKey());
    }
    for (String propertyName : excludedColumnsList) {
        log.warning("Column " + propertyName + " not found in " + modelElements.getName());
    }
    return dps;
}
Also used : DynamicProperty(com.developmentontheedge.beans.DynamicProperty) ArrayList(java.util.ArrayList) ColumnDef(com.developmentontheedge.be5.metadata.model.ColumnDef) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 20 with DynamicProperty

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

the class DpsHelper method checkDpsColumns.

public void checkDpsColumns(BeModelElement modelElements, DynamicPropertySet dps) {
    StringBuilder errorMsg = new StringBuilder();
    Map<String, ColumnDef> columns = meta.getColumns(getEntity(modelElements));
    for (ColumnDef column : columns.values()) {
        if (!column.isCanBeNull() && !column.isAutoIncrement() && column.getDefaultValue() == null && !dps.hasProperty(column.getName())) {
            errorMsg.append("Dps not contain notNull column '").append(column.getName()).append("'\n");
        }
    }
    for (DynamicProperty property : dps) {
        if (!columns.keySet().contains(property.getName())) {
            errorMsg.append("Entity not contain column '").append(property.getName()).append("'\n");
        }
    }
    if (!errorMsg.toString().isEmpty()) {
        throw Be5Exception.internal("Dps columns errors for modelElements '" + modelElements.getName() + "'\n" + errorMsg);
    }
}
Also used : DynamicProperty(com.developmentontheedge.beans.DynamicProperty) ColumnDef(com.developmentontheedge.be5.metadata.model.ColumnDef)

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