use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.
the class Menu method generateEntityOperations.
private List<OperationNode> generateEntityOperations(Entity entity, Meta meta, UserAwareMeta userAwareMeta, List<String> roles, boolean withIds) {
List<OperationNode> operations = new ArrayList<>();
Query allRecords = entity.getQueries().get(DatabaseConstants.ALL_RECORDS_VIEW);
String insertOperationName = INSERT_OPERATION;
if (allRecords != null && allRecords.getOperationNames().getFinalValues().contains(insertOperationName)) {
Operation insertOperation = entity.getOperations().get(insertOperationName);
if (insertOperation != null && meta.isAvailableFor(insertOperation, roles)) {
String title = userAwareMeta.getLocalizedOperationTitle(entity.getName(), insertOperationName);
Action action = ActionUtils.toAction(DatabaseConstants.ALL_RECORDS_VIEW, insertOperation);
OperationId id = withIds ? new OperationId(entity.getName(), insertOperationName) : null;
OperationNode operation = new OperationNode(id, title, action);
operations.add(operation);
}
}
return operations;
}
use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.
the class Be5QueryExecutor method hasColumnWithLabel.
private boolean hasColumnWithLabel(AstStart ast, String idColumnLabel) {
AstQuery query = ast.getQuery();
Optional<AstSelect> selectOpt = query.children().select(AstSelect.class).collect(MoreCollectors.onlyOne());
if (!selectOpt.isPresent())
return false;
AstSelect select = selectOpt.get();
return select.getSelectList().children().select(AstDerivedColumn.class).map(AstDerivedColumn::getAlias).nonNull().map(alias -> alias.replaceFirst("^\"(.+)\"$", "$1")).has(idColumnLabel);
}
use of com.developmentontheedge.be5.metadata.model.Query 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.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.
the class CellFormatter method format.
private Object format(TableModel.RawCellModel cell, VarResolver varResolver) {
// ImmutableList<Object> formattedParts = getFormattedPartsWithoutLink(cell, varResolver);
Object formattedContent = getFormattedPartsWithoutLink(cell, varResolver);
// formattedContent = StreamEx.of(formattedParts).map(this::print).joining();
if (formattedContent instanceof String) {
formattedContent = userAwareMeta.getLocalizedCell((String) formattedContent, query.getEntity().getName(), query.getName());
}
// TODO && extraQuery == Be5QueryExecutor.ExtraQuery.DEFAULT
Map<String, String> blankNullsProperties = cell.options.get(DatabaseConstants.COL_ATTR_BLANKNULLS);
if (blankNullsProperties != null) {
if (formattedContent == null || formattedContent.equals("null")) {
formattedContent = blankNullsProperties.getOrDefault("value", "");
}
}
Map<String, String> nullIfProperties = cell.options.get(DatabaseConstants.COL_ATTR_NULLIF);
if (nullIfProperties != null) {
if (formattedContent == null || formattedContent.equals(nullIfProperties.get("value"))) {
formattedContent = nullIfProperties.getOrDefault("result", "");
}
}
Map<String, String> linkProperties = cell.options.get(DatabaseConstants.COL_ATTR_LINK);
if (linkProperties != null) {
try {
HashUrl url = new HashUrl("table").positional(linkProperties.get("table")).positional(linkProperties.getOrDefault("queryName", DatabaseConstants.ALL_RECORDS_VIEW));
String cols = linkProperties.get("columns");
String vals = linkProperties.get("using");
if (cols != null && vals != null) {
String[] colsArr = cols.split(",");
String[] valuesArr = vals.split(",");
for (int i = 0; i < colsArr.length; i++) {
String resolveValue = varResolver.resolve(valuesArr[i]);
if (resolveValue != null)
url = url.named(colsArr[i], resolveValue);
}
}
cell.options.put(DatabaseConstants.COL_ATTR_LINK, Collections.singletonMap("url", url.toString()));
} catch (Throwable e) {
throw Be5Exception.internalInQuery(new RuntimeException("Error in process COL_ATTR_LINK: " + cell.name, e), query);
}
}
return formattedContent;
}
use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.
the class DocumentGeneratorImpl method getDocument.
@Override
public JsonApiModel getDocument(Query query, Map<String, String> parameters, int sortColumn, boolean sortDesc) {
Object data = routeAndRun(query, parameters, sortColumn, sortDesc);
HashUrl url = new HashUrl(TABLE_ACTION, query.getEntity().getName(), query.getName()).named(parameters);
List<ResourceData> included = new ArrayList<>();
String topForm = (String) ParseRequestUtils.getValuesFromJson(query.getLayout()).get(TOP_FORM);
if (topForm != null) {
com.developmentontheedge.be5.operation.Operation operation = operationExecutor.create(query.getEntity().getName(), query.getName(), topForm, new String[] {}, parameters);
Either<FormPresentation, OperationResult> dataTopForm = generateForm(operation, Collections.emptyMap());
included.add(new ResourceData(TOP_FORM, dataTopForm.isFirst() ? FORM_ACTION : OPERATION_RESULT, dataTopForm.get(), Collections.singletonMap(SELF_LINK, operation.getUrl().toString())));
}
return JsonApiModel.data(new ResourceData(TABLE_ACTION, data, Collections.singletonMap(SELF_LINK, url.toString())), included.toArray(new ResourceData[0]), null);
}
Aggregations