Search in sources :

Example 6 with BeModelCollection

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

the class ReadModelFromXmlTest method testWriteReadOperationExtender.

@Test
public void testWriteReadOperationExtender() 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 Operation op = Operation.createOperation("op", Operation.OPERATION_TYPE_JAVA, table);
    DataElementUtils.saveQuiet(op);
    final OperationExtender ex1 = new OperationExtender(op, module.getName());
    DataElementUtils.saveQuiet(ex1);
    ex1.setClassName("test.class.name");
    ex1.setInvokeOrder(1);
    final JavaScriptOperationExtender ex2 = new JavaScriptOperationExtender(op, module.getName());
    DataElementUtils.saveQuiet(ex2);
    ex2.setFileName("MyExtender.js");
    ex2.setCode("Hello world!");
    final Path tempFolder = Files.createTempDirectory("be4-temp");
    Serialization.save(project, tempFolder);
    final Project readProject = Serialization.load(tempFolder);
    final Entity readEntity = readProject.getApplication().getEntity("table");
    final BeModelCollection<OperationExtender> extenders = readEntity.getOperations().get("op").getExtenders();
    assertEquals(2, extenders.getSize());
    final OperationExtender readEx1 = extenders.get("application - 0001");
    assertEquals("test.class.name", readEx1.getClassName());
    assertEquals(1, readEx1.getInvokeOrder());
    final JavaScriptOperationExtender readEx2 = (JavaScriptOperationExtender) extenders.get("application - 0002");
    assertEquals(0, readEx2.getInvokeOrder());
    assertEquals("MyExtender.js", readEx2.getFileName());
    assertEquals("Hello world!", readEx2.getCode());
    FileUtils.deleteRecursively(tempFolder);
}
Also used : Path(java.nio.file.Path) Project(com.developmentontheedge.be5.metadata.model.Project) Entity(com.developmentontheedge.be5.metadata.model.Entity) JavaScriptOperationExtender(com.developmentontheedge.be5.metadata.model.JavaScriptOperationExtender) OperationExtender(com.developmentontheedge.be5.metadata.model.OperationExtender) JavaScriptOperationExtender(com.developmentontheedge.be5.metadata.model.JavaScriptOperationExtender) Operation(com.developmentontheedge.be5.metadata.model.Operation) Module(com.developmentontheedge.be5.metadata.model.Module) Test(org.junit.Test)

Example 7 with BeModelCollection

use of com.developmentontheedge.be5.metadata.model.base.BeModelCollection 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 8 with BeModelCollection

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

the class YamlSerializer method serializeModules.

private Object serializeModules(final BeModelCollection<Module> modules, boolean serializeReferencedFiles) throws WriteException {
    final List<Object> serializedModules = list();
    for (final Module module : modules) {
        final Map<String, Object> serializedModule = map();
        final Map<String, Object> serializedModuleContent = map();
        final List<Object> serializedEntities = list();
        final Iterable<Entity> entities = module.getEntities();
        for (final Entity entity : entities) if (entity.isCustomized()) {
            if (serializeReferencedFiles)
                new EntitySerializer().serialize(entity);
            serializedEntities.add(entity.getName());
        }
        serializedModuleContent.put(TAG_ENTITIES, serializedEntities);
        final List<Object> serializedExtras = list();
        for (String extra : module.getExtras()) {
            serializedExtras.add(extra);
        }
        if (!serializedExtras.isEmpty()) {
            serializedModuleContent.put(TAG_EXTRAS, serializedExtras);
        }
        serializedModule.put(module.getName(), serializedModuleContent);
        serializedModules.add(serializedModule);
    }
    return serializedModules;
}
Also used : Entity(com.developmentontheedge.be5.metadata.model.Entity) Module(com.developmentontheedge.be5.metadata.model.Module)

Example 9 with BeModelCollection

use of com.developmentontheedge.be5.metadata.model.base.BeModelCollection 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 10 with BeModelCollection

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

the class ModuleLoader2MergeModulesTest method setRoleGroups.

private void setRoleGroups(Project project, String name) {
    BeModelCollection<RoleGroup> groups = project.getRoleGroups();
    RoleGroup management = new RoleGroup(name, groups);
    management.getRoleSet().addInclusionAll(Collections.singletonList(name));
    DataElementUtils.save(management);
    project.fireCodeChanged();
}
Also used : RoleGroup(com.developmentontheedge.be5.metadata.model.RoleGroup)

Aggregations

Entity (com.developmentontheedge.be5.metadata.model.Entity)4 Project (com.developmentontheedge.be5.metadata.model.Project)4 Test (org.junit.Test)4 Module (com.developmentontheedge.be5.metadata.model.Module)3 Query (com.developmentontheedge.be5.metadata.model.Query)3 BeModelCollection (com.developmentontheedge.be5.metadata.model.base.BeModelCollection)3 BeModelElement (com.developmentontheedge.be5.metadata.model.base.BeModelElement)3 Operation (com.developmentontheedge.be5.metadata.model.Operation)2 Path (java.nio.file.Path)2 JavaScriptOperationExtender (com.developmentontheedge.be5.metadata.model.JavaScriptOperationExtender)1 OperationExtender (com.developmentontheedge.be5.metadata.model.OperationExtender)1 PageCustomization (com.developmentontheedge.be5.metadata.model.PageCustomization)1 RoleGroup (com.developmentontheedge.be5.metadata.model.RoleGroup)1 LoadContext (com.developmentontheedge.be5.metadata.serialization.LoadContext)1 ProjectFileSystem (com.developmentontheedge.be5.metadata.serialization.ProjectFileSystem)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1