Search in sources :

Example 16 with ValidationResult

use of org.apache.cayenne.validation.ValidationResult 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 17 with ValidationResult

use of org.apache.cayenne.validation.ValidationResult 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)

Example 18 with ValidationResult

use of org.apache.cayenne.validation.ValidationResult in project cayenne by apache.

the class SaveAsAction method performAction.

public void performAction() {
    ProjectValidator projectValidator = getApplication().getInjector().getInstance(ProjectValidator.class);
    ValidationResult validationResult = projectValidator.validate(getCurrentProject().getRootNode());
    getProjectController().fireProjectOnSaveEvent(new ProjectOnSaveEvent(SaveAsAction.class));
    try {
        if (!saveAll()) {
            return;
        }
    } catch (Exception ex) {
        throw new CayenneRuntimeException("Error on save", ex);
    }
    getApplication().getFrameController().projectSavedAction();
    // If there were errors or warnings at validation, display them
    if (validationResult.getFailures().size() > 0) {
        ValidatorDialog.showDialog(Application.getFrame(), validationResult.getFailures());
    }
}
Also used : CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) ProjectValidator(org.apache.cayenne.project.validation.ProjectValidator) ProjectOnSaveEvent(org.apache.cayenne.modeler.event.ProjectOnSaveEvent) ValidationResult(org.apache.cayenne.validation.ValidationResult) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException)

Aggregations

ValidationResult (org.apache.cayenne.validation.ValidationResult)18 Test (org.junit.Test)7 ValidationFailure (org.apache.cayenne.validation.ValidationFailure)6 ProjectValidator (org.apache.cayenne.project.validation.ProjectValidator)4 Artist (org.apache.cayenne.testdo.testmap.Artist)3 BeanValidationFailure (org.apache.cayenne.validation.BeanValidationFailure)3 ArrayList (java.util.ArrayList)2 DbEntity (org.apache.cayenne.map.DbEntity)2 ObjEntity (org.apache.cayenne.map.ObjEntity)2 MeaningfulFK (org.apache.cayenne.testdo.relationships.MeaningfulFK)2 SimpleValidationFailure (org.apache.cayenne.validation.SimpleValidationFailure)2 ValidationException (org.apache.cayenne.validation.ValidationException)2 File (java.io.File)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)1 Persistent (org.apache.cayenne.Persistent)1 Validating (org.apache.cayenne.Validating)1