use of com.developmentontheedge.be5.metadata.exception.ProjectElementException in project be5 by DevelopmentOnTheEdge.
the class Query method getErrors.
@Override
public List<ProjectElementException> getErrors() {
List<ProjectElementException> result = super.getErrors();
try {
ModelValidationUtils.checkValueInSet(this, "type", getType().getName(), getQueryTypes());
} catch (ProjectElementException e) {
result.add(e);
}
String templateQueryName = getTemplateQueryName();
if (!templateQueryName.isEmpty()) {
int pos = templateQueryName.indexOf('.');
if (pos < 0) {
result.add(new ProjectElementException(getCompletePath(), "templateQueryName", new IllegalArgumentException("templateQueryName must have format <entity>:<query>")));
}
}
Set<String> missingEntries = getRoles().getMissingEntries();
if (!missingEntries.isEmpty()) {
result.add(new ProjectElementException(getCompletePath(), "roles", "Unknown role(s): " + missingEntries));
}
ProjectElementException error = getQueryCompiled().getError();
if (error != null && !error.isNoError()) {
DataElementPath path = getCompletePath();
if (error.getPath().equals(path.toString()))
result.add(error);
else
result.add(new ProjectElementException(path, "query", error));
}
return result;
}
use of com.developmentontheedge.be5.metadata.exception.ProjectElementException in project be5 by DevelopmentOnTheEdge.
the class Operation method getErrors.
@Override
public List<ProjectElementException> getErrors() {
List<ProjectElementException> result = super.getErrors();
try {
ModelValidationUtils.checkValueInSet(this, "logging", logging, OPERATION_LOGGING);
} catch (ProjectElementException e) {
result.add(e);
}
try {
ModelValidationUtils.checkValueInSet(this, "records", records, VISIBILITY_OPTIONS);
} catch (ProjectElementException e) {
result.add(e);
}
Set<String> missingEntries = getRoles().getMissingEntries();
if (!missingEntries.isEmpty()) {
result.add(new ProjectElementException(getCompletePath(), "roles", "Unknown role(s): " + missingEntries));
}
// TODO: add more checks
return result;
}
use of com.developmentontheedge.be5.metadata.exception.ProjectElementException in project be5 by DevelopmentOnTheEdge.
the class PageCustomization method getErrors.
@Override
public List<ProjectElementException> getErrors() {
List<ProjectElementException> result = new ArrayList<>();
try {
ModelValidationUtils.checkValueInSet(this, "domain", domain, getDomains());
} catch (ProjectElementException e) {
result.add(e);
}
try {
ModelValidationUtils.checkValueInSet(this, "type", type, TYPES);
} catch (ProjectElementException e) {
result.add(e);
}
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, "query", error));
}
return result;
}
use of com.developmentontheedge.be5.metadata.exception.ProjectElementException in project be5 by DevelopmentOnTheEdge.
the class FreemarkerSqlHandlerTest method testHandler.
@Test
public void testHandler() throws UnsupportedEncodingException, IOException, FreemarkerSqlException, ProjectElementException {
ByteArrayOutputStream log = new ByteArrayOutputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(log, true, "UTF-8");
PrintStream psOut = new PrintStream(out, true, "UTF-8");
SqlExecutor executor = new SqlExecutor(new NullConnector(), ps, SqlExecutor.class.getResource("basesql.properties"));
FreemarkerSqlHandler handler = new FreemarkerSqlHandler(executor, true, new WriterLogger(psOut));
Project proj = new Project("test");
proj.setDatabaseSystem(Rdbms.POSTGRESQL);
FreemarkerScript sql = new FreemarkerScript("sql", proj.getApplication().getFreemarkerScripts());
DataElementUtils.save(sql);
FreemarkerScript sql2 = new FreemarkerScript("sql2", proj.getApplication().getFreemarkerScripts());
DataElementUtils.save(sql2);
sql2.setSource("UPDATE test SET b = 'c';");
sql.setSource("delete from test;-- hehehe\nINSERT INTO \"test\" VALUES('a','b','c');\nBEGIN update test SET a='a''b END;';END;\nDELETE FROM test;<#include 'sql2'/>");
handler.execute(sql);
String result = new String(log.toByteArray(), StandardCharsets.UTF_8);
String expected = "\n" + "-- Execute test/application/Scripts/sql\n" + "-- At test/application/Scripts/sql[1,1]-[1,17]\n" + "delete from test;\n" + "-- At test/application/Scripts/sql[2,1]-[2,39]\n" + "INSERT INTO \"test\" VALUES('a','b','c');\n" + "-- At test/application/Scripts/sql[3,1]-[3,40]\n" + "BEGIN update test SET a='a''b END;';END;\n" + "-- At test/application/Scripts/sql[4,1]-[4,17]\n" + "DELETE FROM test;\n" + "-- At test/application/Scripts/sql[4,18]-[4,35]\n" + "-- At test/application/Scripts/sql2[1,1]-[1,24]\n" + "\n" + "-- Start of included test/application/Scripts/sql2\n" + "UPDATE test SET b = 'c';\n" + "-- End of included test/application/Scripts/sql2\n";
assertEquals(expected, result.replace("\r", ""));
String outResult = new String(out.toByteArray(), StandardCharsets.UTF_8);
String outExpected = "xx:xx:xx: [>] test/application/Scripts/sql\n" + "xx:xx:xx: [>] test/application/Scripts/sql2\n";
assertEquals(outExpected, outResult.replace("\r", "").replaceAll("\\d\\d", "xx"));
}
use of com.developmentontheedge.be5.metadata.exception.ProjectElementException in project be5 by DevelopmentOnTheEdge.
the class AppData method executeScript.
protected void executeScript(final SqlExecutor sqlExecutor, FreemarkerScript freemarkerScript) throws ProjectElementException, IOException {
String compiled = freemarkerScript.getResult().validate();
if (logPath != null) {
Files.write(logPath.toPath().resolve(be5Project.getName() + "_script_" + freemarkerScript.getModule().getName() + "_" + freemarkerScript.getName() + ".compiled"), compiled.getBytes(StandardCharsets.UTF_8));
}
String sql = compiled.trim();
if (sql.isEmpty())
return;
DataElementPath path = freemarkerScript.getCompletePath();
if (debug)
System.err.println(sql);
sqlExecutor.comment("Execute " + path);
new FreemarkerSqlHandler(sqlExecutor, debug, logger).execute(freemarkerScript);
}
Aggregations