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