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);
}
}
}
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();
}
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;
}
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);
}
}
}
}
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;
}
Aggregations