Search in sources :

Example 1 with Meta

use of com.developmentontheedge.be5.api.services.Meta in project be5 by DevelopmentOnTheEdge.

the class DateTimeTest method testOperation.

@Test
public void testOperation() {
    Operation operation = createOperation("dateTime", "All records", "Insert", "0");
    ImmutableMap<String, Object> values = ImmutableMap.of("activeFrom", "1901-02-03");
    Either<Object, OperationResult> generate = generateOperation(operation, values);
    Object parameters = generate.getFirst();
    assertEquals("{" + "'values':{'activeFrom':'1901-02-03'}," + "'meta':{'/activeFrom':{'displayName':'activeFrom','type':'Date'}}," + "'order':['/activeFrom']" + "}", oneQuotes(JsonFactory.bean(parameters)));
    OperationResult result = executeOperation(operation, values).getSecond();
    assertEquals(OperationResult.redirect("table/dateTime/All records"), result);
}
Also used : OperationResult(com.developmentontheedge.be5.operation.OperationResult) Operation(com.developmentontheedge.be5.operation.Operation) Test(org.junit.Test) SqlMockOperationTest(com.developmentontheedge.be5.test.SqlMockOperationTest)

Example 2 with Meta

use of com.developmentontheedge.be5.api.services.Meta in project be5 by DevelopmentOnTheEdge.

the class ResponseImpl method sendError.

// @Override
// public void sendErrorsAsJson(Object[] errors, Object meta)
// {
// throw new RuntimeException("");
// //TODO create ErrorObject, sendAsRawJson(new JsonApiModel(errors, meta, links));
// }
@Override
public void sendError(Be5Exception e) {
    ErrorModel errorModel;
    if (UserInfoHolder.isSystemDeveloper()) {
        errorModel = new ErrorModel(e);
    } else {
        errorModel = new ErrorModel(e.getHttpStatusCode(), "");
    }
    sendErrorAsJson(errorModel, null);
}
Also used : ErrorModel(com.developmentontheedge.be5.model.jsonapi.ErrorModel)

Example 3 with Meta

use of com.developmentontheedge.be5.api.services.Meta in project be5 by DevelopmentOnTheEdge.

the class GdslGenegator method createService.

private void createService(String generatedSourcesPath, String packageName, String serviceClassName, Configuration cfg) throws IOException {
    Template serviceTpl = cfg.getTemplate("gdsl/entities.ftl");
    Meta meta = injector.getMeta();
    List<Entity> entities = meta.getOrderedEntities("ru");
    Map<String, Object> input = new HashMap<>();
    // input.put("serviceClassName", serviceClassName);
    // input.put("packageName", packageName);
    List<String> entityNames = new ArrayList<>();
    entityCount = entities.size();
    for (Entity entity : entities) {
        if (entity.getName().startsWith("_"))
            continue;
        // groovy have getProperties()
        if (entity.getName().equals("properties"))
            continue;
        entityNames.add(entity.getName());
    }
    input.put("entityNames", entityNames);
    Utils.createFile(generatedSourcesPath, packageName, serviceClassName + ".gdsl", serviceTpl, input);
}
Also used : Meta(com.developmentontheedge.be5.api.services.Meta) Entity(com.developmentontheedge.be5.metadata.model.Entity) Template(freemarker.template.Template)

Example 4 with Meta

use of com.developmentontheedge.be5.api.services.Meta in project be5 by DevelopmentOnTheEdge.

the class Menu method generateEntityQueries.

private List<QueryNode> generateEntityQueries(List<Query> permittedQueries, String language, Meta meta, boolean withIds) {
    List<OrderedQuery> queries = new ArrayList<>();
    for (Query permittedQuery : permittedQueries) {
        queries.add(new OrderedQuery(permittedQuery, meta.getTitle(permittedQuery, language)));
    }
    Collections.sort(queries);
    List<QueryNode> children = new ArrayList<>();
    for (OrderedQuery query : queries) {
        Query permittedQuery = query.query;
        Id id = null;
        if (withIds) {
            id = new Id(permittedQuery.getEntity().getName(), permittedQuery.getName());
        }
        children.add(new QueryNode(id, query.title, ActionUtils.toAction(permittedQuery), permittedQuery.isDefaultView()));
    }
    return children;
}
Also used : Query(com.developmentontheedge.be5.metadata.model.Query) ArrayList(java.util.ArrayList)

Example 5 with Meta

use of com.developmentontheedge.be5.api.services.Meta 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)

Aggregations

Entity (com.developmentontheedge.be5.metadata.model.Entity)4 ArrayList (java.util.ArrayList)4 Meta (com.developmentontheedge.be5.api.services.Meta)3 Query (com.developmentontheedge.be5.metadata.model.Query)3 Template (freemarker.template.Template)3 Test (org.junit.Test)3 Action (com.developmentontheedge.be5.model.Action)2 HashMap (java.util.HashMap)2 ColumnDef (com.developmentontheedge.be5.metadata.model.ColumnDef)1 Operation (com.developmentontheedge.be5.metadata.model.Operation)1 Project (com.developmentontheedge.be5.metadata.model.Project)1 ErrorModel (com.developmentontheedge.be5.model.jsonapi.ErrorModel)1 JsonApiModel (com.developmentontheedge.be5.model.jsonapi.JsonApiModel)1 ResourceData (com.developmentontheedge.be5.model.jsonapi.ResourceData)1 Operation (com.developmentontheedge.be5.operation.Operation)1 OperationResult (com.developmentontheedge.be5.operation.OperationResult)1 Be5ProjectTest (com.developmentontheedge.be5.test.Be5ProjectTest)1 SqlMockOperationTest (com.developmentontheedge.be5.test.SqlMockOperationTest)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1