Search in sources :

Example 11 with BeModelElement

use of com.developmentontheedge.be5.metadata.model.base.BeModelElement in project be5 by DevelopmentOnTheEdge.

the class YamlSerializer method serializeFields.

static void serializeFields(final BeModelElement model, final List<Field> fields, final Map<String, Object> target) {
    final Collection<String> inheritedProperties;
    final Collection<String> customizedProperties;
    inheritedProperties = new HashSet<>(model.getCustomizableProperties());
    customizedProperties = model.getCustomizedProperties();
    inheritedProperties.removeAll(customizedProperties);
    for (final Field field : fields) {
        // Remove 'name' field.
        if (inheritedProperties.contains(field.name) || field.name.equals(ATTR_NAME))
            continue;
        try {
            final Object fieldValue = Beans.getBeanPropertyValue(model, field.name);
            if (fieldValue != null && (!fieldValue.equals(field.defaultValue) || customizedProperties.contains(field.name))) {
                if (fieldValue instanceof Integer || fieldValue instanceof Boolean || fieldValue instanceof String)
                    target.put(field.name, fieldValue);
                else
                    target.put(field.name, String.valueOf(fieldValue));
            }
        } catch (final Exception e) {
            throw new RuntimeException("Unexpected error when serializing '" + field.name + "' of " + model.getCompletePath(), e);
        }
    }
}
Also used : Field(com.developmentontheedge.be5.metadata.serialization.Field) ReadException(com.developmentontheedge.be5.metadata.exception.ReadException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) WriteException(com.developmentontheedge.be5.metadata.exception.WriteException)

Example 12 with BeModelElement

use of com.developmentontheedge.be5.metadata.model.base.BeModelElement in project be5 by DevelopmentOnTheEdge.

the class DpsHelper method getDeleteSpecialValues.

public Object[] getDeleteSpecialValues(BeModelElement modelElements) {
    Map<String, ColumnDef> columns = meta.getColumns(getEntity(modelElements));
    Timestamp currentTime = new Timestamp(new Date().getTime());
    List<Object> list = new ArrayList<>();
    if (columns.containsKey(IS_DELETED_COLUMN_NAME)) {
        list.add("yes");
        if (columns.containsKey(WHO_MODIFIED_COLUMN_NAME))
            list.add(UserInfoHolder.getUserName());
        if (columns.containsKey(MODIFICATION_DATE_COLUMN_NAME))
            list.add(currentTime);
        if (columns.containsKey(IP_MODIFIED_COLUMN_NAME))
            list.add(UserInfoHolder.getRemoteAddr());
    }
    return list.toArray();
}
Also used : ArrayList(java.util.ArrayList) ColumnDef(com.developmentontheedge.be5.metadata.model.ColumnDef) Timestamp(java.sql.Timestamp) Date(java.util.Date)

Example 13 with BeModelElement

use of com.developmentontheedge.be5.metadata.model.base.BeModelElement in project be5 by DevelopmentOnTheEdge.

the class DpsHelper method getDynamicPropertyWithoutTags.

public DynamicProperty getDynamicPropertyWithoutTags(ColumnDef columnDef, BeModelElement modelElements) {
    DynamicProperty dp = new DynamicProperty(columnDef.getName(), meta.getColumnType(columnDef));
    if (modelElements.getClass() == Query.class) {
        dp.setDisplayName(userAwareMeta.getColumnTitle(columnDef.getEntity().getName(), modelElements.getName(), columnDef.getName()));
    } else if (modelElements.getClass() == Entity.class) {
        dp.setDisplayName(userAwareMeta.getColumnTitle(columnDef.getEntity().getName(), columnDef.getName()));
    } else if (modelElements.getClass() == JavaOperation.class || modelElements.getClass() == GroovyOperation.class) {
        dp.setDisplayName(userAwareMeta.getLocalizedOperationField(columnDef.getEntity().getName(), modelElements.getName(), columnDef.getName()));
    }
    if (columnDef.getDefaultValue() != null) {
        dp.setValue(meta.getColumnDefaultValue(columnDef));
    }
    if (columnDef.isCanBeNull() || (columnDef.getTypeString().equals(SqlColumnType.TYPE_BOOL) && columnDef.getDefaultValue() != null)) {
        dp.setCanBeNull(true);
    }
    if (SqlColumnType.TYPE_VARCHAR.equals(columnDef.getType().getTypeName()) || SqlColumnType.TYPE_CHAR.equals(columnDef.getType().getTypeName())) {
        dp.setAttribute(BeanInfoConstants.COLUMN_SIZE_ATTR, columnDef.getType().getSize());
    }
    if (SqlColumnType.TYPE_DECIMAL.equals(columnDef.getType().getTypeName())) {
        int size = columnDef.getType().getSize();
        dp.setAttribute(BeanInfoConstants.VALIDATION_RULES, Arrays.asList(getRange(size, false), step(getPrecision(columnDef.getType().getPrecision()))));
    }
    if (SqlColumnType.TYPE_CURRENCY.equals(columnDef.getType().getTypeName())) {
        dp.setAttribute(BeanInfoConstants.VALIDATION_RULES, Arrays.asList(getRange(columnDef.getType().getSize(), false), step(0.01)));
    }
    if (SqlColumnType.TYPE_INT.equals(columnDef.getType().getTypeName()) || SqlColumnType.TYPE_UINT.equals(columnDef.getType().getTypeName())) {
        boolean unsigned = SqlColumnType.TYPE_UINT.equals(columnDef.getType().getTypeName());
        dp.setAttribute(BeanInfoConstants.VALIDATION_RULES, Arrays.asList(range(unsigned ? 0 : Integer.MIN_VALUE, Integer.MAX_VALUE), step(1)));
    }
    if (SqlColumnType.TYPE_BIGINT.equals(columnDef.getType().getTypeName()) || SqlColumnType.TYPE_UBIGINT.equals(columnDef.getType().getTypeName())) {
        boolean unsigned = SqlColumnType.TYPE_UBIGINT.equals(columnDef.getType().getTypeName());
        dp.setAttribute(BeanInfoConstants.VALIDATION_RULES, Arrays.asList(range(unsigned ? 0 : Long.MIN_VALUE, Long.MAX_VALUE), step(1)));
    }
    if (columnDef.getName().endsWith(HIDDEN_COLUMN_PREFIX))
        dp.setHidden(true);
    return dp;
}
Also used : Entity(com.developmentontheedge.be5.metadata.model.Entity) DynamicProperty(com.developmentontheedge.beans.DynamicProperty) GroovyOperation(com.developmentontheedge.be5.metadata.model.GroovyOperation) JavaOperation(com.developmentontheedge.be5.metadata.model.JavaOperation)

Example 14 with BeModelElement

use of com.developmentontheedge.be5.metadata.model.base.BeModelElement 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 15 with BeModelElement

use of com.developmentontheedge.be5.metadata.model.base.BeModelElement 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)

Aggregations

BeModelElement (com.developmentontheedge.be5.metadata.model.base.BeModelElement)9 ColumnDef (com.developmentontheedge.be5.metadata.model.ColumnDef)8 DynamicProperty (com.developmentontheedge.beans.DynamicProperty)7 BeModelCollection (com.developmentontheedge.be5.metadata.model.base.BeModelCollection)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 ReadException (com.developmentontheedge.be5.metadata.exception.ReadException)2 Entity (com.developmentontheedge.be5.metadata.model.Entity)2 Project (com.developmentontheedge.be5.metadata.model.Project)2 BeElementWithOriginModule (com.developmentontheedge.be5.metadata.model.base.BeElementWithOriginModule)2 Timestamp (java.sql.Timestamp)2 Date (java.util.Date)2 Map (java.util.Map)2 ProjectElementException (com.developmentontheedge.be5.metadata.exception.ProjectElementException)1 WriteException (com.developmentontheedge.be5.metadata.exception.WriteException)1 GroovyOperation (com.developmentontheedge.be5.metadata.model.GroovyOperation)1 JavaOperation (com.developmentontheedge.be5.metadata.model.JavaOperation)1 BeCaseInsensitiveCollection (com.developmentontheedge.be5.metadata.model.base.BeCaseInsensitiveCollection)1 Field (com.developmentontheedge.be5.metadata.serialization.Field)1