Search in sources :

Example 6 with ProjectElementException

use of com.developmentontheedge.be5.metadata.exception.ProjectElementException 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());
            }
        }
    }
}
Also used : Entity(com.developmentontheedge.be5.metadata.model.Entity) DdlElement(com.developmentontheedge.be5.metadata.model.DdlElement) ViewDef(com.developmentontheedge.be5.metadata.model.ViewDef) TableDef(com.developmentontheedge.be5.metadata.model.TableDef)

Example 7 with ProjectElementException

use of com.developmentontheedge.be5.metadata.exception.ProjectElementException in project be5 by DevelopmentOnTheEdge.

the class AppValidate method saveProject.

// private List<ProjectElementException> validateDeps( List<Project> moduleProjects )
// {
// List<ProjectElementException> moduleErrors = new ArrayList<>();
// Map<String, String> entityToModule = new HashMap<>();
// for(Project prj : moduleProjects)
// {
// for(Entity entity : prj.getApplication().getEntities())
// entityToModule.put( entity.getName(), prj.getName() );
// }
// for(Project prj : moduleProjects)
// {
// for(Entity entity : prj.getApplication().getEntities())
// {
// for(TableReference ref : entity.getAllReferences())
// {
// String moduleTo = entityToModule.get( ref.getTableTo() );
// if(moduleTo != null && prj.getModule( moduleTo ) == null)
// {
// moduleErrors.add( new ProjectElementException( ref, "Reference to entity '" + ref.getTableTo()
// + "' which is defined in module '" + moduleTo + "' which is not specified in dependencies of module '"
// + prj.getName() + "'" ) );
// }
// }
// }
// }
// return moduleErrors;
// }
private void saveProject() throws MojoFailureException {
    if (saveProject) {
        try {
            getLog().info("Saving...");
            Serialization.save(be5Project, be5Project.getLocation());
        } catch (ProjectSaveException e) {
            throw new MojoFailureException("Can not save project.", e);
        }
    }
}
Also used : MojoFailureException(org.apache.maven.plugin.MojoFailureException) ProjectSaveException(com.developmentontheedge.be5.metadata.exception.ProjectSaveException)

Example 8 with ProjectElementException

use of com.developmentontheedge.be5.metadata.exception.ProjectElementException in project be5 by DevelopmentOnTheEdge.

the class AppValidate method validateProject.

private void validateProject() throws MojoFailureException {
    List<ProjectElementException> errors = new ArrayList<>();
    if (skipValidation) {
        getLog().info("Validation skipped");
    } else {
        getLog().info("Validating...");
        errors.addAll(be5Project.getErrors());
        int count = 0;
        for (ProjectElementException error : errors) {
            if (error.getPath().equals(be5Project.getName()) && error.getProperty().equals("connectionProfileName"))
                continue;
            count++;
            displayError(error);
        }
        if (count > 0) {
            throw new MojoFailureException("Project has " + count + " errors.");
        }
        getLog().info("Project is valid.");
        skipValidation = true;
    }
}
Also used : ProjectElementException(com.developmentontheedge.be5.metadata.exception.ProjectElementException) ArrayList(java.util.ArrayList) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 9 with ProjectElementException

use of com.developmentontheedge.be5.metadata.exception.ProjectElementException in project be5 by DevelopmentOnTheEdge.

the class FreemarkerUtils method translateException.

public static ProjectElementException translateException(String templateName, Exception ex) {
    Exception result;
    int row = 1;
    int column = 1;
    if (ex instanceof TemplateException) {
        String[] stack = ((TemplateException) ex).getFTLInstructionStack().split("\n");
        Throwable cause = ex.getCause();
        result = new Exception(((TemplateException) ex).getMessageWithoutStackTop());
        if (cause != null) {
            result = new Exception(cause.getMessage());
        }
        for (String stackItem : stack) {
            try {
                stackItem = stackItem.trim();
                int openBracketPos = stackItem.lastIndexOf("[in template");
                if (openBracketPos <= 0)
                    continue;
                int nameStartPos = stackItem.indexOf('"', openBracketPos);
                if (nameStartPos <= 0)
                    continue;
                int nameEndPos = stackItem.indexOf('"', nameStartPos + 1);
                if (nameEndPos <= 0)
                    continue;
                // TODO: make parsing more robust
                String name = stackItem.substring(nameStartPos + 1, nameEndPos);
                int linePos = stackItem.lastIndexOf("line");
                if (linePos <= 0)
                    continue;
                linePos += "line".length() + 1;
                int lineEndPos = stackItem.indexOf(',', linePos);
                if (lineEndPos <= 0)
                    continue;
                row = Integer.parseInt(stackItem.substring(linePos, lineEndPos));
                int columnPos = stackItem.lastIndexOf("column");
                if (columnPos <= 0)
                    continue;
                columnPos += "column".length() + 1;
                int columnEndPos = stackItem.indexOf(']', columnPos);
                if (columnEndPos <= 0)
                    continue;
                column = Integer.parseInt(stackItem.substring(columnPos, columnEndPos));
                String property = null;
                int propertyPos = name.lastIndexOf(':');
                if (propertyPos > 0) {
                    property = name.substring(propertyPos + 1);
                    name = name.substring(0, propertyPos);
                }
                result = new ProjectElementException(DataElementPath.create(name), property, row, column, result);
            } catch (NumberFormatException e) {
            // Ignore
            }
        }
        if (result instanceof ProjectElementException) {
            return (ProjectElementException) result;
        }
    } else if (ex instanceof ParseException) {
        result = new Exception(ex.getMessage());
        row = ((ParseException) ex).getLineNumber();
        column = ((ParseException) ex).getColumnNumber();
        templateName = ((ParseException) ex).getTemplateName();
    } else {
        result = new Exception(ex.getMessage(), ex.getCause());
    }
    String name = templateName;
    String property = null;
    int propertyPos = name.lastIndexOf(':');
    if (propertyPos > 0) {
        property = name.substring(propertyPos + 1);
        name = name.substring(0, propertyPos);
    }
    return new ProjectElementException(DataElementPath.create(name), property, row, column, result);
}
Also used : ProjectElementException(com.developmentontheedge.be5.metadata.exception.ProjectElementException) TemplateException(freemarker.template.TemplateException) ParseException(freemarker.core.ParseException) TemplateModelException(freemarker.template.TemplateModelException) ProjectElementException(com.developmentontheedge.be5.metadata.exception.ProjectElementException) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException) ParseException(freemarker.core.ParseException)

Example 10 with ProjectElementException

use of com.developmentontheedge.be5.metadata.exception.ProjectElementException in project be5 by DevelopmentOnTheEdge.

the class TableDef method getErrors.

@Override
public List<ProjectElementException> getErrors() {
    List<ProjectElementException> errors = super.getErrors();
    if (isFromApplication() && getColumnsCount() == 0) {
        errors.add(new ProjectElementException(this, "Table must have at least one column"));
    }
    String startValue = null;
    try {
        startValue = getStartId();
    } catch (Exception e1) {
        errors.add(new ProjectElementException(getCompletePath(), "startIdVariable", "Unable to calculate start value"));
    }
    if (startValue != null) {
        try {
            Long.parseLong(startValue);
        } catch (NumberFormatException e) {
            errors.add(new ProjectElementException(getCompletePath(), "startIdVariable", "Invalid start id value (must be number): " + startValue));
        }
    }
    return errors;
}
Also used : ProjectElementException(com.developmentontheedge.be5.metadata.exception.ProjectElementException) ProjectElementException(com.developmentontheedge.be5.metadata.exception.ProjectElementException) ExtendedSqlException(com.developmentontheedge.dbms.ExtendedSqlException)

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