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;
}
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);
}
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);
}
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();
}
}
}
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());
}
}
}
}
Aggregations