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