Search in sources :

Example 11 with Project

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

the class ModuleLoader2 method foldModules.

private static Project foldModules(final Project model, final List<Project> modules, LoadContext context) {
    if (modules.isEmpty()) {
        return null;
    }
    Project compositeModule = null;
    for (Project module : modules) {
        if (compositeModule != null) {
            module.getModules().merge(compositeModule.getModules(), true, true);
            module.getApplication().merge(compositeModule.getModule(module.getProjectOrigin()), true, true);
        }
        module.applyMassChanges(context);
        compositeModule = module;
        if (compositeModule.isModuleProject()) {
            DataElementUtils.addQuiet(module.getModules(), module.getApplication());
            module.setApplication(new Module(model.getProjectOrigin(), model));
        }
    }
    return compositeModule;
}
Also used : Project(com.developmentontheedge.be5.metadata.model.Project) Module(com.developmentontheedge.be5.metadata.model.Module)

Example 12 with Project

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

the class SqlMacroTest method testMacro.

@Test
public void testMacro() throws ProjectElementException {
    Project project = new Project("test");
    project.setDatabaseSystem(Rdbms.POSTGRESQL);
    FreemarkerScript script = new FreemarkerScript("script", project.getApplication().getFreemarkerScripts());
    DataElementUtils.save(script);
    script.setSource("SELECT ${concat('a'?asDate, 'b', 'c'?str)} FROM test");
    assertEquals("SELECT ( TO_DATE(a,'YYYY-MM-DD') || b || 'c' ) FROM test", project.mergeTemplate(script).validate());
    script.setSource("<#macro _sql>${project.enterSQL()}<#assign nested><#nested></#assign>${project.translateSQL(nested)}</#macro>" + "<@_sql>SELECT TO_DATE(a) || b || 'c' FROM test</@>");
    assertEquals("SELECT TO_DATE(a, 'YYYY-MM-DD') || b || 'c' FROM test", project.mergeTemplate(script).validate());
    script.setSource("<#macro _sql>${project.enterSQL()}<#assign nested><#nested></#assign>${project.translateSQL(nested)}</#macro>" + "<@_sql>SELECT ${'a'?asDate} || b || 'c' FROM test</@>");
    assertEquals("SELECT TO_DATE(a, 'YYYY-MM-DD') || b || 'c' FROM test", project.mergeTemplate(script).validate());
}
Also used : Project(com.developmentontheedge.be5.metadata.model.Project) FreemarkerScript(com.developmentontheedge.be5.metadata.model.FreemarkerScript) Test(org.junit.Test)

Example 13 with Project

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

the class MassChangeTest method testMassChange.

@Test
public void testMassChange() {
    Project project = new Project("test");
    Entity entity = new Entity("entity", project.getApplication(), EntityType.TABLE);
    DataElementUtils.save(entity);
    Query queryToChange = new Query("queryToChange", entity);
    DataElementUtils.save(queryToChange);
    Query query = new Query("query", entity);
    DataElementUtils.save(query);
    MassChange mc = new MassChange("Query[name*=\"Change\"]", project.getApplication().getMassChangeCollection(), Collections.singletonMap("type", QueryType.D2));
    assertEquals("type", mc.getPropertiesString());
    assertEquals("Query[name*=Change]", mc.getSelectorString());
    DataElementUtils.save(mc);
    assertEquals(QueryType.D1, queryToChange.getType());
    assertEquals(QueryType.D1, query.getType());
    LoadContext context = new LoadContext();
    project.applyMassChanges(context);
    context.check();
    assertEquals(QueryType.D2, entity.getQueries().get("queryToChange").getType());
    assertEquals(QueryType.D1, entity.getQueries().get("query").getType());
}
Also used : LoadContext(com.developmentontheedge.be5.metadata.serialization.LoadContext) Test(org.junit.Test)

Example 14 with Project

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

the class ReadModelFromXmlTest method testWriteReadConnectionProfile.

/**
 * Unexpected error when serializing 'connectionUrl' of TestProject/Connection profiles/Local/test
 * on windows
 * @throws Exception
 */
@Test
public void testWriteReadConnectionProfile() throws Exception {
    Assume.assumeFalse(System.getProperty("os.name").toLowerCase().startsWith("win"));
    final Project project = new Project("TestProject");
    BeConnectionProfile profile = new BeConnectionProfile("test", project.getConnectionProfiles().getLocalProfiles());
    profile.setConnectionUrl("jdbc:db2://localhost:50000/housing:retrieveMessagesFromServerOnGetMessage=true;");
    profile.setUsername("test");
    profile.setPassword("password");
    LinkedHashMap<String, Object> serializedProfiles = new LinkedHashMap<>();
    serializedProfiles.put(profile.getName(), YamlSerializer.serializeProfile(profile));
    String serialized = new Yaml().dump(serializedProfiles);
    LoadContext loadContext = new LoadContext();
    BeConnectionProfile createdProfile = YamlDeserializer.deserializeConnectionProfile(loadContext, serialized, project);
    assertNotNull(createdProfile);
    if (!loadContext.getWarnings().isEmpty())
        throw loadContext.getWarnings().get(0);
    assertEquals(profile.getConnectionUrl(), createdProfile.getConnectionUrl());
    assertEquals(profile.getUsername(), createdProfile.getUsername());
}
Also used : Project(com.developmentontheedge.be5.metadata.model.Project) BeConnectionProfile(com.developmentontheedge.be5.metadata.model.BeConnectionProfile) LoadContext(com.developmentontheedge.be5.metadata.serialization.LoadContext) Yaml(org.yaml.snakeyaml.Yaml) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 15 with Project

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

the class ReadModelFromXmlTest method testWriteReadQueryOperation.

@Test
public void testWriteReadQueryOperation() 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 Query query = new Query("q", table);
    DataElementUtils.saveQuiet(query);
    query.getOperationNames().add("op");
    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("op", readEntity.getQueries().get("q").getOperationNames().getValuesArray()[0]);
    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)

Aggregations

Project (com.developmentontheedge.be5.metadata.model.Project)40 Module (com.developmentontheedge.be5.metadata.model.Module)19 Test (org.junit.Test)19 Entity (com.developmentontheedge.be5.metadata.model.Entity)14 Path (java.nio.file.Path)13 Query (com.developmentontheedge.be5.metadata.model.Query)12 LoadContext (com.developmentontheedge.be5.metadata.serialization.LoadContext)7 ArrayList (java.util.ArrayList)7 ProjectLoadException (com.developmentontheedge.be5.metadata.exception.ProjectLoadException)6 FreemarkerScript (com.developmentontheedge.be5.metadata.model.FreemarkerScript)5 URL (java.net.URL)5 Map (java.util.Map)5 ReadException (com.developmentontheedge.be5.metadata.exception.ReadException)4 BeConnectionProfile (com.developmentontheedge.be5.metadata.model.BeConnectionProfile)4 Operation (com.developmentontheedge.be5.metadata.model.Operation)4 IOException (java.io.IOException)4 MojoFailureException (org.apache.maven.plugin.MojoFailureException)4 WriteException (com.developmentontheedge.be5.metadata.exception.WriteException)3 FreemarkerCatalog (com.developmentontheedge.be5.metadata.model.FreemarkerCatalog)3 Localizations (com.developmentontheedge.be5.metadata.model.Localizations)3