Search in sources :

Example 1 with ProjectElementException

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);
}
Also used : Query(com.developmentontheedge.be5.metadata.model.Query) Test(org.junit.Test) Be5ProjectTest(com.developmentontheedge.be5.test.Be5ProjectTest)

Example 2 with ProjectElementException

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

Example 3 with ProjectElementException

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

Example 4 with ProjectElementException

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());
}
Also used : Project(com.developmentontheedge.be5.metadata.model.Project) FreemarkerScript(com.developmentontheedge.be5.metadata.model.FreemarkerScript) Test(org.junit.Test)

Example 5 with ProjectElementException

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

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