use of org.apache.cayenne.validation.ValidationFailure in project cayenne by apache.
the class GeneratorController method validateRelationship.
protected ValidationFailure validateRelationship(ObjRelationship relationship, boolean clientValidation) {
String name = relationship.getSourceEntity().getName();
ValidationFailure emptyName = BeanValidationFailure.validateNotEmpty(name, "relationship.name", relationship.getName());
if (emptyName != null) {
return emptyName;
}
ValidationFailure badName = CodeValidationUtil.validateJavaIdentifier(name, "relationship.name", relationship.getName());
if (badName != null) {
return badName;
}
if (!relationship.isToMany()) {
ObjEntity targetEntity = relationship.getTargetEntity();
if (clientValidation && targetEntity != null) {
targetEntity = targetEntity.getClientEntity();
}
if (targetEntity == null) {
return new BeanValidationFailure(name, "relationship.targetEntity", "No target entity");
} else if (!targetEntity.isGeneric()) {
ValidationFailure emptyClass = BeanValidationFailure.validateNotEmpty(name, "relationship.targetEntity.className", targetEntity.getClassName());
if (emptyClass != null) {
return emptyClass;
}
ValidationFailure badClass = BeanValidationFailure.validateJavaClassName(name, "relationship.targetEntity.className", targetEntity.getClassName());
if (badClass != null) {
return badClass;
}
}
}
return null;
}
use of org.apache.cayenne.validation.ValidationFailure in project cayenne by apache.
the class GeneratorController method validateAttribute.
protected ValidationFailure validateAttribute(ObjAttribute attribute) {
String name = attribute.getEntity().getName();
ValidationFailure emptyName = BeanValidationFailure.validateNotEmpty(name, "attribute.name", attribute.getName());
if (emptyName != null) {
return emptyName;
}
ValidationFailure badName = CodeValidationUtil.validateJavaIdentifier(name, "attribute.name", attribute.getName());
if (badName != null) {
return badName;
}
ValidationFailure emptyType = BeanValidationFailure.validateNotEmpty(name, "attribute.type", attribute.getType());
if (emptyType != null) {
return emptyType;
}
ValidationFailure badType = BeanValidationFailure.validateJavaClassName(name, "attribute.type", attribute.getType());
if (badType != null) {
return badType;
}
return null;
}
use of org.apache.cayenne.validation.ValidationFailure in project cayenne by apache.
the class GeneratorController method validateEmbeddedAttribute.
protected ValidationFailure validateEmbeddedAttribute(ObjAttribute attribute) {
String name = attribute.getEntity().getName();
// validate embeddedAttribute and attribute names
// embeddedAttribute returned attibute as
// [name_embeddedAttribute].[name_attribute]
String[] attributes = attribute.getName().split("\\.");
String nameEmbeddedAttribute = attributes[0];
int beginIndex = attributes[0].length();
String attr = attribute.getName().substring(beginIndex + 1);
ValidationFailure emptyEmbeddedName = BeanValidationFailure.validateNotEmpty(name, "attribute.name", nameEmbeddedAttribute);
if (emptyEmbeddedName != null) {
return emptyEmbeddedName;
}
ValidationFailure badEmbeddedName = CodeValidationUtil.validateJavaIdentifier(name, "attribute.name", nameEmbeddedAttribute);
if (badEmbeddedName != null) {
return badEmbeddedName;
}
ValidationFailure emptyName = BeanValidationFailure.validateNotEmpty(name, "attribute.name", attr);
if (emptyName != null) {
return emptyName;
}
ValidationFailure badName = CodeValidationUtil.validateJavaIdentifier(name, "attribute.name", attr);
if (badName != null) {
return badName;
}
ValidationFailure emptyType = BeanValidationFailure.validateNotEmpty(name, "attribute.type", attribute.getType());
if (emptyType != null) {
return emptyType;
}
ValidationFailure badType = BeanValidationFailure.validateJavaClassName(name, "attribute.type", attribute.getType());
if (badType != null) {
return badType;
}
return null;
}
use of org.apache.cayenne.validation.ValidationFailure in project cayenne by apache.
the class TableSelectorController method updateTables.
/**
* Performs validation of DbEntities in the current DataMap. Returns a collection of
* ValidationInfo objects describing the problems.
*/
public void updateTables(Collection<DataMap> dataMaps) {
this.tables = new ArrayList<DbEntity>();
for (DataMap dataMap : dataMaps) {
this.tables.addAll(dataMap.getDbEntities());
}
excludedTables.clear();
validationMessages.clear();
// if there were errors, filter out those related to
// non-derived DbEntities...
// TODO: this is inefficient.. we need targeted validation
// instead of doing it on the whole project
Project project = getApplication().getProject();
ProjectValidator projectValidator = getApplication().getInjector().getInstance(ProjectValidator.class);
ValidationResult validationResult = projectValidator.validate(project.getRootNode());
if (validationResult.getFailures().size() > 0) {
for (ValidationFailure nextProblem : validationResult.getFailures()) {
DbEntity failedEntity = null;
if (nextProblem.getSource() instanceof DbAttribute) {
DbAttribute failedAttribute = (DbAttribute) nextProblem.getSource();
failedEntity = (DbEntity) failedAttribute.getEntity();
} else if (nextProblem.getSource() instanceof DbRelationship) {
DbRelationship failedRelationship = (DbRelationship) nextProblem.getSource();
failedEntity = (DbEntity) failedRelationship.getSourceEntity();
} else if (nextProblem.getSource() instanceof DbEntity) {
failedEntity = (DbEntity) nextProblem.getSource();
}
if (failedEntity == null) {
continue;
}
excludedTables.put(failedEntity.getName(), failedEntity);
validationMessages.put(failedEntity.getName(), nextProblem.getDescription());
}
}
// Find selectable tables
permanentlyExcludedCount = excludedTables.size();
selectableTablesList.clear();
for (DbEntity table : tables) {
if (false == excludedTables.containsKey(table.getName())) {
selectableTablesList.add(table);
}
}
tableBinding.updateView();
tableSelectedAction();
}
use of org.apache.cayenne.validation.ValidationFailure in project cayenne by apache.
the class CayenneModelerController method projectOpenedAction.
/**
* Handles project opening control. Updates main frame, then delegates control to
* child controllers.
*/
public void projectOpenedAction(Project project) {
projectController.setProject(project);
editorView = new EditorView(projectController);
frame.setView(editorView);
projectController.projectOpened();
application.getActionManager().projectOpened();
// do status update AFTER the project is actually opened...
if (project.getConfigurationResource() == null) {
updateStatus("New project created...");
frame.setTitle("[New Project]");
} else {
updateStatus("Project opened...");
frame.setTitle(project.getConfigurationResource().getURL().getPath());
}
// update preferences
if (project.getConfigurationResource() != null) {
getLastDirectory().setDirectory(new File(project.getConfigurationResource().getURL().getPath()));
frame.fireRecentFileListChanged();
}
PROJECT_STATE_UTIL.fireLastState(projectController);
// for validation purposes combine load failures with post-load validation (not
// sure if that'll cause duplicate messages?).
List<ValidationFailure> allFailures = new ArrayList<>();
Collection<ValidationFailure> loadFailures = project.getConfigurationTree().getLoadFailures();
if (!loadFailures.isEmpty()) {
// mark project as unsaved
project.setModified(true);
projectController.setDirty(true);
allFailures.addAll(loadFailures);
}
ProjectValidator projectValidator = getApplication().getInjector().getInstance(ProjectValidator.class);
ValidationResult validationResult = projectValidator.validate(project.getRootNode());
allFailures.addAll(validationResult.getFailures());
if (!allFailures.isEmpty()) {
ValidatorDialog.showDialog(frame, validationResult.getFailures());
}
}
Aggregations