Search in sources :

Example 26 with Query

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

the class MoreRowsGenerator method generate.

/**
 * Generates more rows for a table.
 * @throws IllegalArgumentException
 */
public MoreRows generate(Request req) {
    String entityName = req.getNonEmpty(RestApiConstants.ENTITY);
    String queryName = req.getNonEmpty(RestApiConstants.QUERY);
    Map<String, String> parametersMap = req.getValuesFromJsonAsStrings(RestApiConstants.VALUES);
    String startStr = req.getNonEmpty(RestApiConstants.START);
    String lengthStr = req.getNonEmpty(RestApiConstants.LENGTH);
    String drawStr = req.getNonEmpty(RestApiConstants.DRAW);
    String selectableStr = req.getNonEmpty(RestApiConstants.SELECTABLE);
    String totalNumberOfRowsStr = req.getNonEmpty(RestApiConstants.TOTAL_NUMBER_OF_ROWS);
    int draw;
    int start;
    int totalNumberOfRows;
    int length;
    try {
        draw = Integer.parseInt(drawStr);
        start = Integer.parseInt(startStr);
        length = Integer.parseInt(lengthStr);
        totalNumberOfRows = Integer.parseInt(totalNumberOfRowsStr);
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException();
    }
    boolean selectable = Boolean.parseBoolean(selectableStr);
    Query query = injector.get(UserAwareMeta.class).getQuery(entityName, queryName);
    return generateMoreRows(query, req, parametersMap, selectable, draw, start, length, totalNumberOfRows);
}
Also used : Query(com.developmentontheedge.be5.metadata.model.Query) UserAwareMeta(com.developmentontheedge.be5.api.helpers.UserAwareMeta)

Example 27 with Query

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

the class QueryBuilder method select.

private void select(String sql, Request req, Injector injector) {
    DocumentGenerator documentGenerator = injector.get(DocumentGenerator.class);
    String userQBuilderQueryName = UserInfoHolder.getUserName() + "Query";
    Map<String, String> parametersMap = req.getValuesFromJsonAsStrings(RestApiConstants.VALUES);
    Entity entity = new Entity(entityName, injector.getProject().getApplication(), EntityType.TABLE);
    DataElementUtils.save(entity);
    Query query = new Query(userQBuilderQueryName, entity);
    query.setType(QueryType.D1_UNKNOWN);
    if (sql != null) {
        query.setQuery(sql);
    }
    DataElementUtils.save(query);
    try {
        resourceDataList.add(new ResourceData("finalSql", FrontendConstants.STATIC_ACTION, new StaticPagePresentation("Final sql", new Be5QueryExecutor(query, parametersMap, injector).getFinalSql()), null));
    } catch (Be5Exception e) {
        errorModelList.add(new ErrorModel(e));
    }
    try {
        JsonApiModel document = documentGenerator.getDocument(query, parametersMap);
        // todo refactor documentGenerator
        document.getData().setId("result");
        resourceDataList.add(document.getData());
        resourceDataList.addAll(Arrays.asList(document.getIncluded()));
    } catch (Be5Exception e) {
        errorModelList.add(new ErrorModel(e));
    }
    entity.getOrigin().remove(entityName);
}
Also used : Be5Exception(com.developmentontheedge.be5.api.exceptions.Be5Exception) Entity(com.developmentontheedge.be5.metadata.model.Entity) ResourceData(com.developmentontheedge.be5.model.jsonapi.ResourceData) StaticPagePresentation(com.developmentontheedge.be5.model.StaticPagePresentation) Query(com.developmentontheedge.be5.metadata.model.Query) SqlQuery(com.developmentontheedge.sql.model.SqlQuery) DocumentGenerator(com.developmentontheedge.be5.query.DocumentGenerator) ErrorModel(com.developmentontheedge.be5.model.jsonapi.ErrorModel) Be5QueryExecutor(com.developmentontheedge.be5.query.impl.model.Be5QueryExecutor) JsonApiModel(com.developmentontheedge.be5.model.jsonapi.JsonApiModel)

Example 28 with Query

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

the class PageCustomization method getErrors.

@Override
public List<ProjectElementException> getErrors() {
    List<ProjectElementException> result = new ArrayList<>();
    try {
        ModelValidationUtils.checkValueInSet(this, "domain", domain, getDomains());
    } catch (ProjectElementException e) {
        result.add(e);
    }
    try {
        ModelValidationUtils.checkValueInSet(this, "type", type, TYPES);
    } catch (ProjectElementException e) {
        result.add(e);
    }
    ProjectElementException error = getResult().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) ArrayList(java.util.ArrayList)

Example 29 with Query

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

the class ReadModelFromXmlTest method testWriteReadCustomizedModule.

@Test
public void testWriteReadCustomizedModule() throws Exception {
    final Project project = new Project("TestProject");
    final Module module = new Module("testmodule", project.getModules());
    DataElementUtils.saveQuiet(module);
    final Entity table = new Entity("customizedtable", module, EntityType.TABLE);
    DataElementUtils.saveQuiet(table);
    final Operation op1 = Operation.createOperation("normop", Operation.OPERATION_TYPE_JAVA, table);
    assertFalse(module.isCustomized());
    DataElementUtils.saveQuiet(op1);
    final Operation op2 = Operation.createOperation("custop", Operation.OPERATION_TYPE_JAVA, table);
    op2.setOriginModuleName(Project.APPLICATION);
    DataElementUtils.saveQuiet(op2);
    final Query q1 = new Query("normq", table);
    DataElementUtils.saveQuiet(q1);
    final Query q2 = new Query("custq", table);
    q2.setOriginModuleName(Project.APPLICATION);
    DataElementUtils.saveQuiet(q2);
    assertTrue(module.isCustomized());
    final Path tempFolder = Files.createTempDirectory("be4-temp");
    Serialization.save(project, tempFolder);
    final Project project2 = Serialization.load(tempFolder);
    final Module readModule = project2.getModule("testmodule");
    assertNotNull(readModule);
    assertTrue(readModule.isCustomized());
    final Entity readTable = readModule.getEntity("customizedtable");
    assertNotNull(readTable);
    assertTrue(readTable.isCustomized());
    assertEquals(1, readTable.getOperations().getSize());
    assertNotNull(readTable.getOperations().get("custop"));
    assertEquals(1, readTable.getQueries().getSize());
    assertNotNull(readTable.getQueries().get("custq"));
    FileUtils.deleteRecursively(tempFolder);
}
Also used : Path(java.nio.file.Path) Project(com.developmentontheedge.be5.metadata.model.Project) Entity(com.developmentontheedge.be5.metadata.model.Entity) Query(com.developmentontheedge.be5.metadata.model.Query) Operation(com.developmentontheedge.be5.metadata.model.Operation) Module(com.developmentontheedge.be5.metadata.model.Module) Test(org.junit.Test)

Example 30 with Query

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

the class ReadModelFromXmlTest method testWriteReadQueryFilters.

@Test
public void testWriteReadQueryFilters() throws Exception {
    final Project project = new Project("TestProject");
    final Module module = project.getApplication();
    DataElementUtils.saveQuiet(module);
    final Entity table = new Entity("table", module, EntityType.TABLE);
    DataElementUtils.saveQuiet(table);
    final Query query = new Query("q", table);
    DataElementUtils.saveQuiet(query);
    final Query query2 = new Query("q2", table);
    DataElementUtils.saveQuiet(query2);
    final Query filterQuery = new Query("filter query", table);
    DataElementUtils.saveQuiet(filterQuery);
    final QuickFilter qf1 = new QuickFilter("filter1", query);
    qf1.setTargetQueryName(filterQuery.getName());
    qf1.setQueryParam("param");
    qf1.setFilteringClass("test.class");
    DataElementUtils.saveQuiet(qf1);
    final QuickFilter qf2 = new QuickFilter("filter2", query2);
    qf2.setTargetQueryName(filterQuery.getName());
    qf2.setQueryParam("param2");
    DataElementUtils.saveQuiet(qf2);
    final Path tempFolder = Files.createTempDirectory("be4-temp");
    Serialization.save(project, tempFolder);
    final Project readProject = Serialization.load(tempFolder);
    final Entity readEntity = readProject.getApplication().getEntity("table");
    assertEquals("filter1", readEntity.getQueries().get("q").getQuickFilters()[0].getName());
    assertEquals("param", readEntity.getQueries().get("q").getQuickFilters()[0].getQueryParam());
    assertEquals("test.class", readEntity.getQueries().get("q").getQuickFilters()[0].getFilteringClass());
    assertSame(readEntity.getQueries().get("filter query"), readEntity.getQueries().get("q").getQuickFilters()[0].getTargetQuery());
    assertEquals("filter2", readEntity.getQueries().get("q2").getQuickFilters()[0].getName());
    assertEquals("param2", readEntity.getQueries().get("q2").getQuickFilters()[0].getQueryParam());
    assertNull(readEntity.getQueries().get("q2").getQuickFilters()[0].getFilteringClass());
    assertSame(readEntity.getQueries().get("filter query"), readEntity.getQueries().get("q2").getQuickFilters()[0].getTargetQuery());
    FileUtils.deleteRecursively(tempFolder);
}
Also used : Path(java.nio.file.Path) Project(com.developmentontheedge.be5.metadata.model.Project) Entity(com.developmentontheedge.be5.metadata.model.Entity) Query(com.developmentontheedge.be5.metadata.model.Query) Module(com.developmentontheedge.be5.metadata.model.Module) QuickFilter(com.developmentontheedge.be5.metadata.model.QuickFilter) Test(org.junit.Test)

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