use of com.developmentontheedge.be5.metadata.exception.ProjectElementException in project be5 by DevelopmentOnTheEdge.
the class ProjectTest method testQueryCompiledValidate.
@Test
public void testQueryCompiledValidate() throws ProjectElementException {
Query testQuery = projectProvider.getProject().getEntity("testtable").getQueries().get("All records");
String validatedQuery = testQuery.getQueryCompiled().validate().trim();
assertNotNull(validatedQuery);
assertEquals("SELECT\n" + " t.name AS \"Name\",\n" + " t.value AS \"Value\"\n" + "FROM\n" + " testtable t", validatedQuery);
}
use of com.developmentontheedge.be5.metadata.exception.ProjectElementException in project be5 by DevelopmentOnTheEdge.
the class Entity method getErrors.
@Override
public List<ProjectElementException> getErrors() {
final List<ProjectElementException> errors = new ArrayList<>();
if (getName().length() > Constants.MAX_ID_LENGTH) {
errors.add(new ProjectElementException(getCompletePath(), "name", "Entity name is too long."));
}
for (final Module module : getProject().getModulesAndApplication()) {
final Module thisModule = getModule();
if (module == thisModule)
break;
final Entity duplicate = module.getEntity(getName());
if (duplicate != null) {
errors.add(new ProjectElementException(getCompletePath(), "name", "Entity with name '" + getName() + "' already exists."));
break;
}
}
final TableDef tableDef = findTableDefinition();
if (tableDef != null) {
errors.addAll(tableDef.getErrors());
}
for (final Query query : getQueries()) {
errors.addAll(query.getErrors());
}
for (final Operation operation : getOperations()) {
errors.addAll(operation.getErrors());
}
return errors;
}
use of com.developmentontheedge.be5.metadata.exception.ProjectElementException in project be5 by DevelopmentOnTheEdge.
the class FreemarkerScript method getErrors.
@Override
public List<ProjectElementException> getErrors() {
List<ProjectElementException> result = new ArrayList<>();
ProjectElementException error = getResult().getError();
if (error != null && !error.isNoError()) {
DataElementPath path = getCompletePath();
if (error.getPath().equals(path.toString()))
result.add(error);
else
result.add(new ProjectElementException(path, "source", error));
}
return result;
}
use of com.developmentontheedge.be5.metadata.exception.ProjectElementException 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());
}
use of com.developmentontheedge.be5.metadata.exception.ProjectElementException 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();
}
}
}
Aggregations