Search in sources :

Example 1 with UserAwareMeta

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));
    }
}
Also used : Be5Exception(com.developmentontheedge.be5.api.exceptions.Be5Exception) MoreRowsGenerator(com.developmentontheedge.be5.query.impl.MoreRowsGenerator) Query(com.developmentontheedge.be5.metadata.model.Query) DocumentGenerator(com.developmentontheedge.be5.query.DocumentGenerator) UserAwareMeta(com.developmentontheedge.be5.api.helpers.UserAwareMeta) HashUrl(com.developmentontheedge.be5.util.HashUrl) JsonApiModel(com.developmentontheedge.be5.model.jsonapi.JsonApiModel)

Example 2 with UserAwareMeta

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));
    }
}
Also used : Action(com.developmentontheedge.be5.model.Action) Query(com.developmentontheedge.be5.metadata.model.Query)

Example 3 with UserAwareMeta

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));
}
Also used : ServletContext(javax.servlet.ServletContext) Context(org.thymeleaf.context.Context) UserAwareMeta(com.developmentontheedge.be5.api.helpers.UserAwareMeta)

Example 4 with UserAwareMeta

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;
}
Also used : Action(com.developmentontheedge.be5.model.Action) Query(com.developmentontheedge.be5.metadata.model.Query) ArrayList(java.util.ArrayList) Operation(com.developmentontheedge.be5.metadata.model.Operation)

Example 5 with UserAwareMeta

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);
}
Also used : UserAwareMeta(com.developmentontheedge.be5.api.helpers.UserAwareMeta)

Aggregations

UserAwareMeta (com.developmentontheedge.be5.api.helpers.UserAwareMeta)4 Query (com.developmentontheedge.be5.metadata.model.Query)3 Action (com.developmentontheedge.be5.model.Action)2 Be5Exception (com.developmentontheedge.be5.api.exceptions.Be5Exception)1 Operation (com.developmentontheedge.be5.metadata.model.Operation)1 JsonApiModel (com.developmentontheedge.be5.model.jsonapi.JsonApiModel)1 DocumentGenerator (com.developmentontheedge.be5.query.DocumentGenerator)1 MoreRowsGenerator (com.developmentontheedge.be5.query.impl.MoreRowsGenerator)1 HashUrl (com.developmentontheedge.be5.util.HashUrl)1 ArrayList (java.util.ArrayList)1 ServletContext (javax.servlet.ServletContext)1 Context (org.thymeleaf.context.Context)1