use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.
the class Menu method collectEntityContent.
private void collectEntityContent(Entity entity, String language, Meta meta, UserAwareMeta userAwareMeta, List<String> roles, boolean withIds, List<RootNode> out) {
List<Query> permittedQueries = meta.getQueries(entity, roles);
if (permittedQueries.isEmpty()) {
return;
}
String title = meta.getTitle(entity, language);
List<OperationNode> operations = generateEntityOperations(entity, meta, userAwareMeta, roles, withIds);
if (operations.isEmpty()) {
operations = null;
}
if (canBeMovedToRoot(permittedQueries, title, language, meta)) {
// Query in the root, contains an action.
Id id = null;
Action action = ActionUtils.toAction(permittedQueries.get(0));
boolean isDefault = permittedQueries.get(0).isDefaultView();
if (withIds) {
String queryTitle = getTitleOfRootQuery(permittedQueries, title, language, meta);
id = new Id(entity.getName(), queryTitle);
}
out.add(RootNode.action(id, title, isDefault, action, operations));
} else {
// No query in the root, just inner queries.
List<QueryNode> children = generateEntityQueries(permittedQueries, language, meta, withIds);
Id id = new Id(entity.getName(), null);
out.add(RootNode.container(id, title, children, operations));
}
}
use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.
the class DocumentGeneratorImpl method presentOperation.
private TableOperationPresentation presentOperation(Query query, Operation operation) {
String visibleWhen = Operations.determineWhenVisible(operation);
String title = userAwareMeta.getLocalizedOperationTitle(query.getEntity().getName(), operation.getName());
// boolean requiresConfirmation = operation.isConfirm();
boolean isClientSide = Operations.isClientSide(operation);
Action action = null;
if (isClientSide) {
action = Action.call(Operations.asClientSide(operation).toHashUrl());
}
return new TableOperationPresentation(operation.getName(), title, visibleWhen, false, isClientSide, action);
}
use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.
the class DocumentGeneratorImpl method collectOperations.
private List<TableOperationPresentation> collectOperations(Query query) {
List<TableOperationPresentation> operations = new ArrayList<>();
List<String> userRoles = UserInfoHolder.getCurrentRoles();
for (Operation operation : getQueryOperations(query)) {
if (Operations.isAllowed(operation, userRoles)) {
operations.add(presentOperation(query, operation));
}
}
operations.sort(Comparator.comparing(TableOperationPresentation::getTitle));
return operations;
}
use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.
the class DocumentGeneratorImpl method routeAndRun.
@Override
public Object routeAndRun(Query query, Map<String, String> parameters, int sortColumn, boolean sortDesc) {
switch(query.getType()) {
case STATIC:
if (ActionUtils.isStaticPage(query)) {
return getStatic(query);
} else {
throw Be5Exception.internalInQuery(new IllegalStateException("Unsupported static request"), query);
}
case D1:
case D1_UNKNOWN:
return getTable(query, parameters, sortColumn, sortDesc);
case D2:
case CONTAINER:
case CUSTOM:
case JAVASCRIPT:
throw Be5Exception.internal("Not support operation type: " + query.getType());
case GROOVY:
try {
Class aClass = groovyRegister.getClass(query.getEntity() + query.getName(), query.getQuery(), query.getFileName());
if (aClass != null) {
TableBuilder tableBuilder = (TableBuilder) aClass.newInstance();
tableBuilder.initialize(query, parameters);
injector.injectAnnotatedFields(tableBuilder);
return getTable(query, parameters, tableBuilder.getTableModel());
} else {
throw Be5Exception.internal("Class " + query.getQuery() + " is null.");
}
} catch (NoClassDefFoundError | IllegalAccessException | InstantiationException e) {
throw new UnsupportedOperationException("Groovy feature has been excluded", e);
}
default:
throw Be5Exception.internal("Unknown action type '" + query.getType() + "'");
}
}
use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.
the class DocumentGeneratorImpl method getQueryOperations.
private List<Operation> getQueryOperations(Query query) {
List<Operation> queryOperations = new ArrayList<>();
OperationSet operationNames = query.getOperationNames();
for (String operationName : operationNames.getFinalValues()) {
Operation op = query.getEntity().getOperations().get(operationName);
if (op != null)
queryOperations.add(op);
}
return queryOperations;
}
Aggregations