Search in sources :

Example 16 with LoadContext

use of com.developmentontheedge.be5.metadata.serialization.LoadContext in project be5 by DevelopmentOnTheEdge.

the class TestUtils method setUp.

@Before
public void setUp() throws Exception {
    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 moduleProject = createModule(project, "testModule", modulePath);
    Serialization.save(project, tpmProjectPath);
    ArrayList<URL> urls = new ArrayList<>();
    urls.add(modulePath.resolve("project.yaml").toUri().toURL());
    urls.add(tpmProjectPath.resolve("project.yaml").toUri().toURL());
    ModuleLoader2.loadAllProjects(urls);
    LoadContext ctx = new LoadContext();
    ModuleLoader2.mergeAllModules(project, Collections.singletonList(moduleProject), ctx);
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) LoadContext(com.developmentontheedge.be5.metadata.serialization.LoadContext) URL(java.net.URL) Before(org.junit.Before)

Example 17 with LoadContext

use of com.developmentontheedge.be5.metadata.serialization.LoadContext in project be5 by DevelopmentOnTheEdge.

the class ModuleUtilsTest method testMergeAllModules.

@Test
public void testMergeAllModules() throws Exception {
    Project module = getModule();
    Project app = getProject();
    LoadContext ctx = new LoadContext();
    ModuleLoader2.mergeAllModules(app, Collections.singletonList(module), ctx);
    ctx.check();
    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 : Project(com.developmentontheedge.be5.metadata.model.Project) Query(com.developmentontheedge.be5.metadata.model.Query) LoadContext(com.developmentontheedge.be5.metadata.serialization.LoadContext) Test(org.junit.Test)

Example 18 with LoadContext

use of com.developmentontheedge.be5.metadata.serialization.LoadContext 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 19 with LoadContext

use of com.developmentontheedge.be5.metadata.serialization.LoadContext in project be5 by DevelopmentOnTheEdge.

the class Templates method getTemplatesProject.

public static Project getTemplatesProject() throws ReadException {
    Project prj = new Project(TEMPLATES_PROJECT_NAME, true);
    LoadContext lc = new LoadContext();
    for (String template : TEMPLATES) {
        URL url = Templates.class.getResource("templates/" + template + ".yaml");
        Node content;
        try (InputStream is = url.openStream()) {
            content = new Yaml().compose(new InputStreamReader(is, StandardCharsets.UTF_8));
        } catch (MarkedYAMLException e) {
            throw new ReadException(new Exception((e.getProblemMark().getLine() + 1) + ":" + (e.getProblemMark().getColumn() + 1) + ": " + e.getMessage()), getPath(url), ReadException.LEE_INVALID_STRUCTURE);
        } catch (YAMLException | IOException e) {
            throw new ReadException(new Exception(e.getMessage()), getPath(url), ReadException.LEE_INVALID_STRUCTURE);
        }
        try {
            Object obj = Serialization.derepresent(content);
            @SuppressWarnings("unchecked") Map<String, Object> root = (Map<String, Object>) obj;
            @SuppressWarnings("unchecked") Map<String, Object> entityContent = (Map<String, Object>) root.get(template);
            DataElementUtils.saveQuiet(YamlDeserializer.readEntity(lc, template, entityContent, prj.getApplication()));
        } catch (RuntimeException e) {
            throw new ReadException(e, getPath(url), ReadException.LEE_INTERNAL_ERROR);
        }
        lc.check();
    }
    return prj;
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Node(org.yaml.snakeyaml.nodes.Node) MarkedYAMLException(org.yaml.snakeyaml.error.MarkedYAMLException) YAMLException(org.yaml.snakeyaml.error.YAMLException) MarkedYAMLException(org.yaml.snakeyaml.error.MarkedYAMLException) IOException(java.io.IOException) URL(java.net.URL) Yaml(org.yaml.snakeyaml.Yaml) FileSystemNotFoundException(java.nio.file.FileSystemNotFoundException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ReadException(com.developmentontheedge.be5.metadata.exception.ReadException) MarkedYAMLException(org.yaml.snakeyaml.error.MarkedYAMLException) YAMLException(org.yaml.snakeyaml.error.YAMLException) ReadException(com.developmentontheedge.be5.metadata.exception.ReadException) LoadContext(com.developmentontheedge.be5.metadata.serialization.LoadContext) Map(java.util.Map)

Example 20 with LoadContext

use of com.developmentontheedge.be5.metadata.serialization.LoadContext in project be5 by DevelopmentOnTheEdge.

the class Serialization method reloadEntity.

public static Entity reloadEntity(final Entity oldEntity) throws ReadException {
    checkProject(oldEntity.getProject());
    turnOffAutomaticSerialization();
    try {
        return new YamlDeserializer(new LoadContext()).reloadEntity(oldEntity);
    } finally {
        turnOnAutomaticSerialization();
    }
}
Also used : YamlDeserializer(com.developmentontheedge.be5.metadata.serialization.yaml.YamlDeserializer)

Aggregations

YamlDeserializer (com.developmentontheedge.be5.metadata.serialization.yaml.YamlDeserializer)10 Project (com.developmentontheedge.be5.metadata.model.Project)9 LoadContext (com.developmentontheedge.be5.metadata.serialization.LoadContext)7 ProjectLoadException (com.developmentontheedge.be5.metadata.exception.ProjectLoadException)5 ReadException (com.developmentontheedge.be5.metadata.exception.ReadException)5 URL (java.net.URL)4 Path (java.nio.file.Path)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 BeConnectionProfile (com.developmentontheedge.be5.metadata.model.BeConnectionProfile)3 Query (com.developmentontheedge.be5.metadata.model.Query)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 Yaml (org.yaml.snakeyaml.Yaml)3 Entity (com.developmentontheedge.be5.metadata.model.Entity)2 Module (com.developmentontheedge.be5.metadata.model.Module)2 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 Before (org.junit.Before)2