Search in sources :

Example 1 with MoreRowsGenerator

use of com.developmentontheedge.be5.query.impl.MoreRowsGenerator 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)

Aggregations

Be5Exception (com.developmentontheedge.be5.api.exceptions.Be5Exception)1 UserAwareMeta (com.developmentontheedge.be5.api.helpers.UserAwareMeta)1 Query (com.developmentontheedge.be5.metadata.model.Query)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