Search in sources :

Example 36 with Entity

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

the class YamlSerializer method serializeApplication.

private Object serializeApplication(final Module application, boolean serializeReferencedFiles) throws WriteException {
    final List<Object> serializedEntities = list();
    final Iterable<Entity> entities = application.getEntities();
    for (final Entity entity : entities) {
        if (serializeReferencedFiles)
            new EntitySerializer().serialize(entity);
        serializedEntities.add(entity.getName());
    }
    return serializedEntities;
}
Also used : Entity(com.developmentontheedge.be5.metadata.model.Entity)

Example 37 with Entity

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

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

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

the class ModuleLoader2MergeModulesTest method createModuleWithQueryRoles.

private Project createModuleWithQueryRoles(Project project, Project entityOwner, String moduleName, String queryName, String roleName, Path path) throws Exception {
    Project moduleProject = new Project(moduleName, true);
    Entity entity;
    if (entityOwner == null) {
        entity = ProjectTestUtils.createEntity(moduleProject, "moduleEntity", "ID");
    } else {
        Module appModule = new Module(entityOwner.getName(), moduleProject.getModules());
        DataElementUtils.save(appModule);
        entity = new Entity("moduleEntity", appModule, EntityType.TABLE);
        DataElementUtils.save(entity);
    }
    ProjectTestUtils.createScheme(entity);
    ProjectTestUtils.createQuery(entity, queryName, Collections.singletonList('@' + roleName));
    moduleProject.setRoles(Collections.singletonList(roleName));
    setRoleGroups(moduleProject, roleName);
    Module appModule = new Module(moduleName, project.getModules());
    DataElementUtils.save(appModule);
    Serialization.save(moduleProject, path);
    return moduleProject;
}
Also used : Project(com.developmentontheedge.be5.metadata.model.Project) Entity(com.developmentontheedge.be5.metadata.model.Entity) Module(com.developmentontheedge.be5.metadata.model.Module)

Example 40 with Entity

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

Entity (com.developmentontheedge.be5.metadata.model.Entity)36 Query (com.developmentontheedge.be5.metadata.model.Query)19 Module (com.developmentontheedge.be5.metadata.model.Module)16 Project (com.developmentontheedge.be5.metadata.model.Project)16 Test (org.junit.Test)11 Path (java.nio.file.Path)9 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)8 ColumnDef (com.developmentontheedge.be5.metadata.model.ColumnDef)7 Operation (com.developmentontheedge.be5.metadata.model.Operation)7 TableDef (com.developmentontheedge.be5.metadata.model.TableDef)7 Meta (com.developmentontheedge.be5.api.services.Meta)4 ReadException (com.developmentontheedge.be5.metadata.exception.ReadException)4 BeModelElement (com.developmentontheedge.be5.metadata.model.base.BeModelElement)4 Map (java.util.Map)4 ProjectElementException (com.developmentontheedge.be5.metadata.exception.ProjectElementException)3 DdlElement (com.developmentontheedge.be5.metadata.model.DdlElement)3 Localizations (com.developmentontheedge.be5.metadata.model.Localizations)3 LinkedHashMap (java.util.LinkedHashMap)3 Be5Exception (com.developmentontheedge.be5.api.exceptions.Be5Exception)2