Search in sources :

Example 16 with Query

use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.

the class ModuleLoader2MergeModulesTest method setUp.

@Before
public void setUp() throws Exception {
    Path tpmProjectPath = tmp.newFolder().toPath();
    project = ProjectTestUtils.getProject("test");
    // Entity entity = ProjectTestUtils.createEntity( project, "entity", "ID" );
    // ProjectTestUtils.createScheme( entity );
    // ProjectTestUtils.createScript( project, "delete from entity;\nINSERT INTO entity (name) VALUES ('foo')" );
    ProjectTestUtils.createH2Profile(project, "profileTestMavenPlugin");
    // Query query = ProjectTestUtils.createQuery(entity, "All records", Arrays.asList('@' + SpecialRoleGroup.ALL_ROLES_EXCEPT_GUEST_GROUP, "-User"));
    // query.getOperationNames().setValues( Collections.singleton( "op" ) );
    // ProjectTestUtils.createOperation( entity );
    Path modulePath = tmp.newFolder().toPath();
    Project moduleProject1 = createModuleWithQueryRoles(project, null, "testModule1", "testQuery1", "testRole1", modulePath);
    Path modulePath2 = tmp.newFolder().toPath();
    Project moduleProject2 = createModuleWithQueryRoles(project, moduleProject1, "testModule2", "testQuery2", "testRole2", modulePath2);
    project.setRoles(Arrays.asList("testRole1", "testRole2"));
    Serialization.save(project, tpmProjectPath);
    ArrayList<URL> urls = new ArrayList<>();
    urls.add(modulePath.resolve("project.yaml").toUri().toURL());
    urls.add(modulePath2.resolve("project.yaml").toUri().toURL());
    urls.add(tpmProjectPath.resolve("project.yaml").toUri().toURL());
    ModuleLoader2.loadAllProjects(urls);
    LoadContext ctx = new LoadContext();
    ModuleLoader2.mergeAllModules(project, Arrays.asList(moduleProject1, moduleProject2), ctx);
}
Also used : Path(java.nio.file.Path) Project(com.developmentontheedge.be5.metadata.model.Project) ArrayList(java.util.ArrayList) URL(java.net.URL) Before(org.junit.Before)

Example 17 with Query

use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.

the class Project method getContext.

/**
 * Creates and returns FreeMarker context for given element
 * @param element to create context for (can be null)
 * @return
 */
public Map<String, Object> getContext(TemplateElement element) {
    Map<String, Object> context = new HashMap<>();
    BeModelElement parent = element;
    while (parent != null) {
        if (parent instanceof PageCustomization) {
            context.put("customization", parent);
        } else if (parent instanceof Query) {
            context.put("query", parent);
        } else if (parent instanceof Operation) {
            context.put("operation", parent);
        } else if (parent instanceof Entity) {
            context.put("entity", parent);
        } else if (parent instanceof Module) {
            context.put("module", parent);
        }
        parent = parent.getOrigin();
    }
    for (String name : getPropertyNames()) {
        context.put(name, getProperty(name));
    }
    BeConnectionProfile profile = getConnectionProfile();
    if (profile != null) {
        for (String name : profile.getPropertyNames()) {
            context.put(name, profile.getProperty(name));
        }
    }
    return context;
}
Also used : BeModelElement(com.developmentontheedge.be5.metadata.model.base.BeModelElement) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 18 with Query

use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.

the class Query method getErrors.

@Override
public List<ProjectElementException> getErrors() {
    List<ProjectElementException> result = super.getErrors();
    try {
        ModelValidationUtils.checkValueInSet(this, "type", getType().getName(), getQueryTypes());
    } catch (ProjectElementException e) {
        result.add(e);
    }
    String templateQueryName = getTemplateQueryName();
    if (!templateQueryName.isEmpty()) {
        int pos = templateQueryName.indexOf('.');
        if (pos < 0) {
            result.add(new ProjectElementException(getCompletePath(), "templateQueryName", new IllegalArgumentException("templateQueryName must have format <entity>:<query>")));
        }
    }
    Set<String> missingEntries = getRoles().getMissingEntries();
    if (!missingEntries.isEmpty()) {
        result.add(new ProjectElementException(getCompletePath(), "roles", "Unknown role(s): " + missingEntries));
    }
    ProjectElementException error = getQueryCompiled().getError();
    if (error != null && !error.isNoError()) {
        DataElementPath path = getCompletePath();
        if (error.getPath().equals(path.toString()))
            result.add(error);
        else
            result.add(new ProjectElementException(path, "query", error));
    }
    return result;
}
Also used : ProjectElementException(com.developmentontheedge.be5.metadata.exception.ProjectElementException) DataElementPath(com.developmentontheedge.be5.metadata.model.base.DataElementPath)

Example 19 with Query

use of com.developmentontheedge.be5.metadata.model.Query 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 20 with Query

use of com.developmentontheedge.be5.metadata.model.Query 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)

Aggregations

Query (com.developmentontheedge.be5.metadata.model.Query)29 Entity (com.developmentontheedge.be5.metadata.model.Entity)16 ArrayList (java.util.ArrayList)15 Test (org.junit.Test)15 Project (com.developmentontheedge.be5.metadata.model.Project)12 Module (com.developmentontheedge.be5.metadata.model.Module)8 Path (java.nio.file.Path)8 Operation (com.developmentontheedge.be5.metadata.model.Operation)6 HashMap (java.util.HashMap)6 Be5Exception (com.developmentontheedge.be5.api.exceptions.Be5Exception)4 ProjectElementException (com.developmentontheedge.be5.metadata.exception.ProjectElementException)4 Be5ProjectTest (com.developmentontheedge.be5.test.Be5ProjectTest)4 Map (java.util.Map)4 UserAwareMeta (com.developmentontheedge.be5.api.helpers.UserAwareMeta)3 ReadException (com.developmentontheedge.be5.metadata.exception.ReadException)3 DataElementPath (com.developmentontheedge.be5.metadata.model.base.DataElementPath)3 LoadContext (com.developmentontheedge.be5.metadata.serialization.LoadContext)3 LinkedHashMap (java.util.LinkedHashMap)3 BeModelElement (com.developmentontheedge.be5.metadata.model.base.BeModelElement)2 Action (com.developmentontheedge.be5.model.Action)2