Search in sources :

Example 11 with Module

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

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

Example 13 with Module

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

the class SelectorTest method testMatch.

@Test
public void testMatch() throws ParseException {
    Project project = new Project("test");
    Module app = project.getApplication();
    Module mod = new Module("mod", project.getModules());
    DataElementUtils.save(mod);
    Entity appTable = new Entity("appTable", app, EntityType.TABLE);
    DataElementUtils.save(appTable);
    DataElementUtils.save(new Query("All records", appTable));
    Entity appDict = new Entity("appDict", app, EntityType.DICTIONARY);
    DataElementUtils.save(appDict);
    Query dictRecords = new Query("All records", appDict);
    dictRecords.setInvisible(true);
    DataElementUtils.save(dictRecords);
    Entity modTable = new Entity("modTable", mod, EntityType.DICTIONARY);
    DataElementUtils.save(modTable);
    DataElementUtils.save(new Query("All records", modTable));
    SelectorRule rule1 = UnionSelectorRule.create("Query[invisible=true]");
    assertEquals("Query[invisible=true]", rule1.toString());
    checkRule(rule1, "test/application/Entities/appDict/Queries/All records", project);
    SelectorRule rule2 = UnionSelectorRule.create(".table Query[name=\"All records\"]");
    assertEquals(".table Query[name=\"All records\"]", rule2.toString());
    checkRule(rule2, "test/application/Entities/appTable/Queries/All records", project);
    SelectorRule rule3 = UnionSelectorRule.create("Module#mod Query[name=\"All records\"]");
    assertEquals("Module#mod Query[name=\"All records\"]", rule3.toString());
    checkRule(rule3, "test/Modules/mod/Entities/modTable/Queries/All records", project);
    SelectorRule rule4 = UnionSelectorRule.create("Entity:not(.dictionary)");
    assertEquals("Entity:not(.dictionary)", rule4.toString());
    checkRule(rule4, "test/application/Entities/appTable", project);
}
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) Test(org.junit.Test)

Example 14 with Module

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

the class AppData method execute.

@Override
public void execute() throws MojoFailureException {
    init();
    PrintStream ps = null;
    try {
        if (logPath != null) {
            logPath.mkdirs();
            ps = new PrintStream(new File(logPath, be5Project.getName() + "_scripts_" + script.replace(';', '_').replace(':', '.') + ".sql"), "UTF-8");
        }
        ModuleLoader2.addModuleScripts(be5Project);
        List<FreemarkerScript> scripts = new ArrayList<>();
        for (String scriptName : script.split(";")) {
            int pos = scriptName.indexOf(':');
            FreemarkerCatalog scriptsCatalog = be5Project.getApplication().getFreemarkerScripts();
            if (pos > 0) {
                String moduleName = scriptName.substring(0, pos);
                scriptName = scriptName.substring(pos + 1);
                if (moduleName.equals("all")) {
                    for (Module module : be5Project.getModules()) {
                        scriptsCatalog = module.getFreemarkerScripts();
                        if (scriptsCatalog == null)
                            continue;
                        FreemarkerScript script = scriptsCatalog.optScript(scriptName);
                        if (script == null)
                            continue;
                        scripts.add(script);
                    }
                    FreemarkerScript script = be5Project.getApplication().getFreemarkerScripts().optScript(scriptName);
                    if (script != null) {
                        scripts.add(script);
                    }
                    continue;
                } else {
                    Module module = be5Project.getModule(moduleName);
                    if (module == null) {
                        if (ignoreMissing) {
                            System.err.println("Warning: module '" + moduleName + "' not found");
                            continue;
                        } else
                            throw new MojoFailureException("Module '" + moduleName + "' not found");
                    }
                    scriptsCatalog = module.getFreemarkerScripts();
                }
            }
            FreemarkerScript freemarkerScript = scriptsCatalog == null ? null : scriptsCatalog.optScript(scriptName);
            if (freemarkerScript == null) {
                if (ignoreMissing) {
                    System.err.println("Warning: FTL script " + scriptName + " not found");
                    continue;
                } else
                    throw new MojoFailureException("FTL script " + scriptName + " not found");
            }
            scripts.add(freemarkerScript);
        }
        SqlExecutor sqlExecutor = new BeSqlExecutor(connector, ps);
        for (FreemarkerScript freemarkerScript : scripts) {
            executeScript(sqlExecutor, freemarkerScript);
        }
        DatabaseUtils.clearAllCache(sqlExecutor);
    } catch (ProjectElementException | FreemarkerSqlException e) {
        throw new MojoFailureException(e.getMessage(), e);
    } catch (Exception e) {
        throw new MojoFailureException(e.getMessage(), e);
    } finally {
        if (ps != null) {
            ps.close();
        }
    }
}
Also used : FreemarkerSqlException(com.developmentontheedge.be5.metadata.exception.FreemarkerSqlException) PrintStream(java.io.PrintStream) ProjectElementException(com.developmentontheedge.be5.metadata.exception.ProjectElementException) ArrayList(java.util.ArrayList) MojoFailureException(org.apache.maven.plugin.MojoFailureException) FreemarkerCatalog(com.developmentontheedge.be5.metadata.model.FreemarkerCatalog) FreemarkerSqlException(com.developmentontheedge.be5.metadata.exception.FreemarkerSqlException) ProjectElementException(com.developmentontheedge.be5.metadata.exception.ProjectElementException) IOException(java.io.IOException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) BeSqlExecutor(com.developmentontheedge.be5.metadata.sql.BeSqlExecutor) SqlExecutor(com.developmentontheedge.dbms.SqlExecutor) BeSqlExecutor(com.developmentontheedge.be5.metadata.sql.BeSqlExecutor) FreemarkerScript(com.developmentontheedge.be5.metadata.model.FreemarkerScript) Module(com.developmentontheedge.be5.metadata.model.Module) File(java.io.File)

Example 15 with Module

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

the class AppDb method execute.

private void execute(final Module module) throws ProjectElementException {
    boolean started = false;
    for (Entity entity : module.getOrCreateEntityCollection().getAvailableElements()) {
        DdlElement scheme = entity.getScheme();
        if (scheme instanceof TableDef) {
            if (scheme.withoutDbScheme()) {
                if (!started) {
                    logger.setOperationName("[A] " + module.getCompletePath());
                    started = true;
                }
                processDdl(scheme);
                createdTables++;
            } else {
                logger.setOperationName("Skip table with schema: " + scheme.getEntityName());
            }
        }
    }
    // Define views after tables as there might be dependencies
    for (Entity entity : module.getOrCreateEntityCollection().getAvailableElements()) {
        DdlElement scheme = entity.getScheme();
        if (scheme instanceof ViewDef) {
            if (scheme.withoutDbScheme()) {
                if (!started) {
                    logger.setOperationName("[A] " + module.getCompletePath());
                    started = true;
                }
                processDdl(scheme);
                createdViews++;
            } else {
                logger.setOperationName("Skip table with schema: " + scheme.getEntityName());
            }
        }
    }
}
Also used : Entity(com.developmentontheedge.be5.metadata.model.Entity) DdlElement(com.developmentontheedge.be5.metadata.model.DdlElement) ViewDef(com.developmentontheedge.be5.metadata.model.ViewDef) TableDef(com.developmentontheedge.be5.metadata.model.TableDef)

Aggregations

Module (com.developmentontheedge.be5.metadata.model.Module)26 Project (com.developmentontheedge.be5.metadata.model.Project)21 Entity (com.developmentontheedge.be5.metadata.model.Entity)19 Query (com.developmentontheedge.be5.metadata.model.Query)12 Test (org.junit.Test)9 Path (java.nio.file.Path)8 ArrayList (java.util.ArrayList)6 Operation (com.developmentontheedge.be5.metadata.model.Operation)5 YamlDeserializer (com.developmentontheedge.be5.metadata.serialization.yaml.YamlDeserializer)5 HashMap (java.util.HashMap)5 ProjectElementException (com.developmentontheedge.be5.metadata.exception.ProjectElementException)4 TableDef (com.developmentontheedge.be5.metadata.model.TableDef)4 Map (java.util.Map)4 FreemarkerCatalog (com.developmentontheedge.be5.metadata.model.FreemarkerCatalog)3 FreemarkerScript (com.developmentontheedge.be5.metadata.model.FreemarkerScript)3 BeModelElement (com.developmentontheedge.be5.metadata.model.base.BeModelElement)3 List (java.util.List)3 FreemarkerSqlException (com.developmentontheedge.be5.metadata.exception.FreemarkerSqlException)2 ReadException (com.developmentontheedge.be5.metadata.exception.ReadException)2 ColumnDef (com.developmentontheedge.be5.metadata.model.ColumnDef)2