Search in sources :

Example 11 with ProjectElementException

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;
}
Also used : ProjectElementException(com.developmentontheedge.be5.metadata.exception.ProjectElementException) DataElementPath(com.developmentontheedge.be5.metadata.model.base.DataElementPath)

Example 12 with ProjectElementException

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;
}
Also used : ProjectElementException(com.developmentontheedge.be5.metadata.exception.ProjectElementException)

Example 13 with ProjectElementException

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;
}
Also used : ProjectElementException(com.developmentontheedge.be5.metadata.exception.ProjectElementException) DataElementPath(com.developmentontheedge.be5.metadata.model.base.DataElementPath) ArrayList(java.util.ArrayList)

Example 14 with ProjectElementException

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"));
}
Also used : PrintStream(java.io.PrintStream) SqlExecutor(com.developmentontheedge.dbms.SqlExecutor) WriterLogger(com.developmentontheedge.be5.metadata.util.WriterLogger) Project(com.developmentontheedge.be5.metadata.model.Project) FreemarkerScript(com.developmentontheedge.be5.metadata.model.FreemarkerScript) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 15 with ProjectElementException

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);
}
Also used : DataElementPath(com.developmentontheedge.be5.metadata.model.base.DataElementPath) FreemarkerSqlHandler(com.developmentontheedge.be5.metadata.freemarker.FreemarkerSqlHandler)

Aggregations

ProjectElementException (com.developmentontheedge.be5.metadata.exception.ProjectElementException)13 DataElementPath (com.developmentontheedge.be5.metadata.model.base.DataElementPath)6 ArrayList (java.util.ArrayList)6 MojoFailureException (org.apache.maven.plugin.MojoFailureException)6 FreemarkerSqlException (com.developmentontheedge.be5.metadata.exception.FreemarkerSqlException)3 FreemarkerScript (com.developmentontheedge.be5.metadata.model.FreemarkerScript)3 Project (com.developmentontheedge.be5.metadata.model.Project)3 PrintStream (java.io.PrintStream)3 Test (org.junit.Test)3 Module (com.developmentontheedge.be5.metadata.model.Module)2 BeSqlExecutor (com.developmentontheedge.be5.metadata.sql.BeSqlExecutor)2 SqlExecutor (com.developmentontheedge.dbms.SqlExecutor)2 File (java.io.File)2 IOException (java.io.IOException)2 ProjectLoadException (com.developmentontheedge.be5.metadata.exception.ProjectLoadException)1 ProjectSaveException (com.developmentontheedge.be5.metadata.exception.ProjectSaveException)1 FreemarkerSqlHandler (com.developmentontheedge.be5.metadata.freemarker.FreemarkerSqlHandler)1 DdlElement (com.developmentontheedge.be5.metadata.model.DdlElement)1 Entity (com.developmentontheedge.be5.metadata.model.Entity)1 FreemarkerCatalog (com.developmentontheedge.be5.metadata.model.FreemarkerCatalog)1