Search in sources :

Example 11 with ValidationFailure

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;
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) BeanValidationFailure(org.apache.cayenne.validation.BeanValidationFailure) SimpleValidationFailure(org.apache.cayenne.validation.SimpleValidationFailure) ValidationFailure(org.apache.cayenne.validation.ValidationFailure) BeanValidationFailure(org.apache.cayenne.validation.BeanValidationFailure)

Example 12 with ValidationFailure

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;
}
Also used : SimpleValidationFailure(org.apache.cayenne.validation.SimpleValidationFailure) ValidationFailure(org.apache.cayenne.validation.ValidationFailure) BeanValidationFailure(org.apache.cayenne.validation.BeanValidationFailure)

Example 13 with ValidationFailure

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;
}
Also used : SimpleValidationFailure(org.apache.cayenne.validation.SimpleValidationFailure) ValidationFailure(org.apache.cayenne.validation.ValidationFailure) BeanValidationFailure(org.apache.cayenne.validation.BeanValidationFailure)

Example 14 with ValidationFailure

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();
}
Also used : Project(org.apache.cayenne.project.Project) DbEntity(org.apache.cayenne.map.DbEntity) DbRelationship(org.apache.cayenne.map.DbRelationship) DbAttribute(org.apache.cayenne.map.DbAttribute) ProjectValidator(org.apache.cayenne.project.validation.ProjectValidator) ValidationResult(org.apache.cayenne.validation.ValidationResult) DataMap(org.apache.cayenne.map.DataMap) ValidationFailure(org.apache.cayenne.validation.ValidationFailure)

Example 15 with ValidationFailure

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());
    }
}
Also used : ArrayList(java.util.ArrayList) ProjectValidator(org.apache.cayenne.project.validation.ProjectValidator) EditorView(org.apache.cayenne.modeler.editor.EditorView) ValidationResult(org.apache.cayenne.validation.ValidationResult) File(java.io.File) ValidationFailure(org.apache.cayenne.validation.ValidationFailure)

Aggregations

ValidationFailure (org.apache.cayenne.validation.ValidationFailure)17 BeanValidationFailure (org.apache.cayenne.validation.BeanValidationFailure)11 SimpleValidationFailure (org.apache.cayenne.validation.SimpleValidationFailure)7 ValidationResult (org.apache.cayenne.validation.ValidationResult)6 ObjEntity (org.apache.cayenne.map.ObjEntity)4 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 DbAttribute (org.apache.cayenne.map.DbAttribute)2 DbEntity (org.apache.cayenne.map.DbEntity)2 DbRelationship (org.apache.cayenne.map.DbRelationship)2 ProjectValidator (org.apache.cayenne.project.validation.ProjectValidator)2 Artist (org.apache.cayenne.testdo.testmap.Artist)2 File (java.io.File)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 MergerContext (org.apache.cayenne.dbsync.merge.context.MergerContext)1 MergerToken (org.apache.cayenne.dbsync.merge.token.MergerToken)1 ObjectNameGenerator (org.apache.cayenne.dbsync.naming.ObjectNameGenerator)1 ModelMergeDelegate (org.apache.cayenne.dbsync.reverse.dbload.ModelMergeDelegate)1