Search in sources :

Example 1 with ProjectValidator

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

the class ValidateAction method performAction.

/**
 * Validates project for possible conflicts and incomplete mappings.
 */
public void performAction(ActionEvent e) {
    ProjectValidator projectValidator = getApplication().getInjector().getInstance(ProjectValidator.class);
    ValidationResult validationResult = projectValidator.validate(getCurrentProject().getRootNode());
    // If there were errors or warnings at validation, display them
    if (validationResult.getFailures().size() > 0) {
        ValidatorDialog.showDialog(Application.getFrame(), validationResult.getFailures());
    } else {
        ValidatorDialog.showValidationSuccess(Application.getFrame());
    }
}
Also used : ProjectValidator(org.apache.cayenne.project.validation.ProjectValidator) ValidationResult(org.apache.cayenne.validation.ValidationResult)

Example 2 with ProjectValidator

use of org.apache.cayenne.project.validation.ProjectValidator 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 3 with ProjectValidator

use of org.apache.cayenne.project.validation.ProjectValidator 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 4 with ProjectValidator

use of org.apache.cayenne.project.validation.ProjectValidator 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

ProjectValidator (org.apache.cayenne.project.validation.ProjectValidator)4 ValidationResult (org.apache.cayenne.validation.ValidationResult)4 ValidationFailure (org.apache.cayenne.validation.ValidationFailure)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)1 DataMap (org.apache.cayenne.map.DataMap)1 DbAttribute (org.apache.cayenne.map.DbAttribute)1 DbEntity (org.apache.cayenne.map.DbEntity)1 DbRelationship (org.apache.cayenne.map.DbRelationship)1 EditorView (org.apache.cayenne.modeler.editor.EditorView)1 ProjectOnSaveEvent (org.apache.cayenne.modeler.event.ProjectOnSaveEvent)1 Project (org.apache.cayenne.project.Project)1