Search in sources :

Example 31 with Query

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

the class ReadModelFromXmlTest method testWriteReadQuerySettings.

@Test
public void testWriteReadQuerySettings() throws Exception {
    final Project project = new Project("TestProject");
    project.setRoles(Arrays.asList("Admin", "Guest", "User"));
    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 QuerySettings set1 = new QuerySettings(query);
    set1.setColorSchemeID(1L);
    set1.getRoles().setValues(project.getRoles());
    set1.setBeautifier("my.beautifier");
    query.setQuerySettings(new QuerySettings[] { set1 });
    final QuerySettings set2 = new QuerySettings(query2);
    set2.setColorSchemeID(null);
    set2.setAutoRefresh(30);
    set2.getRoles().setValues(Arrays.asList("Admin", "Guest"));
    final QuerySettings set3 = new QuerySettings(query2);
    set3.setColorSchemeID(1L);
    set3.getRoles().setValues(Arrays.asList("User"));
    query2.setQuerySettings(new QuerySettings[] { set2, set3 });
    final Path tempFolder = Files.createTempDirectory("be4-temp");
    Serialization.save(project, tempFolder);
    final Project readProject = Serialization.load(tempFolder);
    final Entity readEntity = readProject.getApplication().getEntity("table");
    QuerySettings[] querySettings = readEntity.getQueries().get("q").getQuerySettings();
    assertEquals(1, querySettings.length);
    assertEquals((Long) 1L, querySettings[0].getColorSchemeID());
    assertEquals("my.beautifier", querySettings[0].getBeautifier());
    assertEquals(new HashSet<>(project.getRoles()), querySettings[0].getRoles().getFinalRoles());
    querySettings = readEntity.getQueries().get("q2").getQuerySettings();
    assertEquals(2, querySettings.length);
    assertEquals(null, querySettings[0].getColorSchemeID());
    // TODO assertEquals(null, querySettings[0].getBeautifier());
    assertEquals(30, querySettings[0].getAutoRefresh());
    assertEquals(new HashSet<>(Arrays.asList("Admin", "Guest")), querySettings[0].getRoles().getFinalRoles());
    assertEquals((Long) 1L, querySettings[1].getColorSchemeID());
    // TODO assertEquals(null, querySettings[1].getBeautifier());
    assertEquals(0, querySettings[1].getAutoRefresh());
    assertEquals(new HashSet<>(Arrays.asList("User")), querySettings[1].getRoles().getFinalRoles());
    FileUtils.deleteRecursively(tempFolder);
}
Also used : Path(java.nio.file.Path) Project(com.developmentontheedge.be5.metadata.model.Project) Entity(com.developmentontheedge.be5.metadata.model.Entity) QuerySettings(com.developmentontheedge.be5.metadata.model.QuerySettings) Query(com.developmentontheedge.be5.metadata.model.Query) Module(com.developmentontheedge.be5.metadata.model.Module) Test(org.junit.Test)

Example 32 with Query

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

the class ReadModelFromXmlTest method testWriteReadCompareXmlProject.

@Test
public void testWriteReadCompareXmlProject() throws Exception {
    final Project project = new Project("TestProject");
    project.setRoles(Arrays.asList("Admin", "Guest"));
    final Module module = project.getApplication();
    final Entity table = new Entity("testTable", module, EntityType.TABLE);
    DataElementUtils.saveQuiet(table);
    table.setDisplayName("$project.Name/$module.Name/$entity.Name");
    final Operation op = Operation.createOperation("Insert", Operation.OPERATION_TYPE_JAVA, table);
    DataElementUtils.saveQuiet(op);
    final Query query = new Query("All records", table);
    DataElementUtils.saveQuiet(query);
    query.setQuery("<@distinct \"name\"/>");
    query.setParametrizingOperation(op);
// TODO
// project.getMacroCollection().optScript( FreemarkerCatalog.MAIN_MACRO_LIBRARY )
// .setSource( "<#macro distinct column>SELECT DISTINCT ${column} FROM ${entity.getName()}</#macro>" );
// final BeModelCollection<TableRef> tableRefs = table.getOrCreateTableReferences();
// final TableRef tableRef = new TableRef("ref1", "user", tableRefs);
// tableRef.setTableTo("users");
// tableRef.setColumnsTo("userName");
// DataElementUtils.saveQuiet(tableRef);
// 
// final Path tempFolder = Files.createTempDirectory("be4-temp");
// Serialization.save( project, tempFolder );
// 
// final Project project2 = Serialization.load( tempFolder );
// assertEquals(new HashSet<>(Arrays.asList( "Admin", "Guest" )), project2.getRoles());
// assertEquals( project.getMacroCollection().optScript( FreemarkerCatalog.MAIN_MACRO_LIBRARY ).getSource(),
// project2.getMacroCollection().optScript( FreemarkerCatalog.MAIN_MACRO_LIBRARY ).getSource() );
// final Entity table2 = project2.getApplication().getEntity( "testTable" );
// assertNotNull(table2);
// assertEquals(table, table2);
// assertEquals(table2, table);
// final Query query2 = table2.getQueries().get("All records");
// assertNotNull(query2);
// assertEquals("<@distinct \"name\"/>", query2.getQuery());
// final Operation op2 = table2.getOperations().get("Insert");
// assertNotNull(op2);
// assertEquals(op, op2);
// assertSame(op2, query2.getParametrizingOperation());
// 
// final BeModelCollection<TableRef> tableReferences = project.getEntity("testTable").getOrCreateTableReferences();
// final BeModelCollection<TableRef> tableReferences2 = project2.getEntity("testTable").getOrCreateTableReferences();
// assertEquals(tableReferences.getSize(), tableReferences2.getSize());
// assertEquals(tableReferences.iterator().next().getColumnsFrom(), tableReferences2.iterator().next().getColumnsFrom());
// 
// FileUtils.deleteRecursively( tempFolder );
}
Also used : 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 33 with Query

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

the class ModuleUtilsTest method testMergeAllModulesWithLoadRead.

@Test
public void testMergeAllModulesWithLoadRead() throws Exception {
    Path tpmProjectPath = tmp.newFolder().toPath();
    Path tpmModulePath = tmp.newFolder().toPath();
    Project module = getModule();
    Serialization.save(module, tpmModulePath);
    Project app = getProject();
    Serialization.save(app, tpmProjectPath);
    ArrayList<URL> urls = new ArrayList<>();
    urls.add(tpmModulePath.resolve("project.yaml").toUri().toURL());
    urls.add(tpmProjectPath.resolve("project.yaml").toUri().toURL());
    ModuleLoader2.loadAllProjects(urls);
    assertNotNull(ModuleLoader2.getModulePath("app").resolve("project.yaml"));
    app = ModuleLoader2.getModulesMap().get("app");
    ModuleLoader2.mergeModules(app, new NullLogger());
    assertEquals(Collections.singleton("mentity"), app.getEntityNames());
    assertEquals(EntityType.DICTIONARY, app.getEntity("mentity").getType());
    BeModelCollection<Query> queries = app.getEntity("mentity").getQueries();
    assertEquals("QUERY1 customized", queries.get("q1").getQuery());
    assertEquals("Query1 title", queries.get("q1").getTitleName());
    assertEquals("QUERY2", queries.get("q2").getQuery());
    assertEquals("Query2 title", queries.get("q2").getTitleName());
    assertEquals("QUERY3", queries.get("q3").getQuery());
    assertEquals("Query3 title", queries.get("q3").getTitleName());
}
Also used : Path(java.nio.file.Path) Project(com.developmentontheedge.be5.metadata.model.Project) Query(com.developmentontheedge.be5.metadata.model.Query) ArrayList(java.util.ArrayList) URL(java.net.URL) Test(org.junit.Test)

Example 34 with Query

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

the class ModuleUtilsTest method getProject.

private Project getProject() throws ProjectSaveException {
    Project app = new Project("app");
    Module appModule = new Module("module", app.getModules());
    DataElementUtils.save(appModule);
    Entity appEntity = new Entity("mentity", appModule, EntityType.DICTIONARY);
    DataElementUtils.save(appEntity);
    Query appQ1 = new Query("q1", appEntity);
    appQ1.setQuery("QUERY1 customized");
    DataElementUtils.save(appQ1);
    Query appQ3 = new Query("q3", appEntity);
    appQ3.setQuery("QUERY3");
    appQ3.setTitleName("Query3 title");
    DataElementUtils.save(appQ3);
    return app;
}
Also used : 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)

Example 35 with Query

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

the class SerializationTest method testSerializationBasics.

@Test
public void testSerializationBasics() throws IOException, ProjectSaveException, ProjectLoadException {
    Path path = tmp.newFolder().toPath();
    Project project = ProjectTestUtils.getProject("test");
    Entity entity = ProjectTestUtils.createEntity(project, "entity", "ID");
    TableDef scheme = ProjectTestUtils.createScheme(entity);
    // only for test SqlColumnType getType( Collection<ColumnDef> stack )
    ColumnDef column3 = new ColumnDef("column3", scheme.getColumns());
    column3.setTableTo(entity.getName());
    column3.setColumnsTo("ID");
    DataElementUtils.save(column3);
    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);
    Serialization.save(project, path);
    assertEquals(path, project.getLocation());
    LoadContext lc = new LoadContext();
    Project project2 = Serialization.load(path, lc);
    project2.setDatabaseSystem(Rdbms.POSTGRESQL);
    lc.check();
    Entity entity2 = project2.getEntity("entity");
    assertEquals(entity, entity2);
    assertTrue(entity2.isBesql());
    assertEquals("VARCHAR(20)", entity2.findTableDefinition().getColumns().get("name").getTypeString());
    assertEquals(StreamEx.of("Administrator", "Operator").toSet(), entity2.getQueries().get("All records").getRoles().getFinalValues());
    assertEquals("op", entity2.getQueries().get("All records").getOperationNames().getFinalValuesString());
}
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) ColumnDef(com.developmentontheedge.be5.metadata.model.ColumnDef) TableDef(com.developmentontheedge.be5.metadata.model.TableDef) 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