use of com.developmentontheedge.be5.api.helpers.UserAwareMeta in project be5 by DevelopmentOnTheEdge.
the class Document method generate.
@Override
public void generate(Request req, Response res, Injector injector) {
DocumentGenerator documentGenerator = injector.get(DocumentGenerator.class);
UserAwareMeta userAwareMeta = injector.get(UserAwareMeta.class);
String entityName = req.getNonEmpty(RestApiConstants.ENTITY);
String queryName = req.getNonEmpty(RestApiConstants.QUERY);
int sortColumn = req.getInt("order[0][column]", -1);
boolean sortDesc = "desc".equals(req.get("order[0][dir]"));
Map<String, String> parametersMap = req.getValuesFromJsonAsStrings(RestApiConstants.VALUES);
HashUrl url = new HashUrl(TABLE_ACTION, entityName, queryName).named(parametersMap);
Query query;
try {
query = userAwareMeta.getQuery(entityName, queryName);
} catch (Be5Exception e) {
sendError(req, res, url, e);
return;
}
try {
switch(req.getRequestUri()) {
case "":
JsonApiModel document = documentGenerator.getDocument(query, parametersMap, sortColumn, sortDesc);
document.setMeta(req.getDefaultMeta());
res.sendAsJson(document);
return;
case "moreRows":
res.sendAsRawJson(new MoreRowsGenerator(injector).generate(req));
return;
default:
res.sendUnknownActionError();
}
} catch (Be5Exception e) {
sendError(req, res, url, e);
} catch (Throwable e) {
sendError(req, res, url, Be5Exception.internalInQuery(e, query));
}
}
use of com.developmentontheedge.be5.api.helpers.UserAwareMeta 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.api.helpers.UserAwareMeta in project be5 by DevelopmentOnTheEdge.
the class TemplateProcessor method generate.
@Override
public void generate(Request req, Response res, Injector injector) {
UserAwareMeta userAwareMeta = injector.get(UserAwareMeta.class);
String title = userAwareMeta.getColumnTitle("index", "page", "title");
String description = userAwareMeta.getColumnTitle("index", "page", "description");
Context context = new Context();
context.setVariable("lang", UserInfoHolder.getLanguage());
context.setVariable("title", title);
context.setVariable("description", description);
String reqWithoutContext = req.getRequestUri().replaceFirst(req.getContextPath(), "");
if (!reqWithoutContext.endsWith("/"))
reqWithoutContext += "/";
context.setVariable("baseUrl", req.getContextPath() + reqWithoutContext);
context.setVariable("baseUrlWithoutContext", reqWithoutContext);
res.sendHtml(templateEngine.process(reqWithoutContext + "index", context));
}
use of com.developmentontheedge.be5.api.helpers.UserAwareMeta 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.api.helpers.UserAwareMeta in project be5 by DevelopmentOnTheEdge.
the class Menu method generateMenu.
private MenuResponse generateMenu(Injector injector, boolean withIds, EntityType entityType) {
UserAwareMeta userAwareMeta = injector.get(UserAwareMeta.class);
List<String> roles = UserInfoHolder.getCurrentRoles();
String language = UserInfoHolder.getLanguage();
List<RootNode> entities = collectEntities(injector.getMeta(), userAwareMeta, language, roles, withIds, entityType);
return new MenuResponse(entities);
}
Aggregations