Search in sources :

Example 1 with ErrorType

use of com.archimatetool.hammer.validation.issues.ErrorType in project archi by archimatetool.

the class Validator method validate.

/**
 * @return The list of Issue Categories and Issues
 */
public List<Object> validate() {
    if (fModel == null) {
        return null;
    }
    // Collect interesting objects
    fElements = new ArrayList<IArchimateElement>();
    fRelations = new ArrayList<IArchimateRelationship>();
    fViews = new ArrayList<IArchimateDiagramModel>();
    for (Iterator<EObject> iter = fModel.eAllContents(); iter.hasNext(); ) {
        EObject eObject = iter.next();
        if (eObject instanceof IArchimateRelationship) {
            fRelations.add((IArchimateRelationship) eObject);
        } else if (eObject instanceof IArchimateElement) {
            fElements.add((IArchimateElement) eObject);
        } else if (eObject instanceof IArchimateDiagramModel) {
            fViews.add((IArchimateDiagramModel) eObject);
        }
    }
    // Analyse
    List<Object> result = new ArrayList<Object>();
    fErrorList = new ArrayList<ErrorType>();
    fWarningList = new ArrayList<WarningType>();
    fAdviceList = new ArrayList<AdviceType>();
    // ------------------ Checkers -----------------------------
    IPreferenceStore store = ArchiHammerPlugin.INSTANCE.getPreferenceStore();
    // Invalid Relations
    if (store.getBoolean(IPreferenceConstants.PREFS_HAMMER_CHECK_INVALID_RELATIONS)) {
        collectIssues(new InvalidRelationsChecker(getArchimateRelationships()));
    }
    // Unused Elements
    if (store.getBoolean(IPreferenceConstants.PREFS_HAMMER_CHECK_UNUSED_ELEMENTS)) {
        collectIssues(new UnusedElementsChecker(getArchimateElements()));
    }
    // Unused Relations
    if (store.getBoolean(IPreferenceConstants.PREFS_HAMMER_CHECK_UNUSED_RELATIONS)) {
        collectIssues(new UnusedRelationsChecker(getArchimateRelationships()));
    }
    // Empty Views
    if (store.getBoolean(IPreferenceConstants.PREFS_HAMMER_CHECK_EMPTY_VIEWS)) {
        collectIssues(new EmptyViewsChecker(getArchimateViews()));
    }
    // Components in wrong Viewpoints
    if (store.getBoolean(IPreferenceConstants.PREFS_HAMMER_CHECK_VIEWPOINT)) {
        collectIssues(new ViewpointChecker(getArchimateViews()));
    }
    // Nested elements
    if (store.getBoolean(IPreferenceConstants.PREFS_HAMMER_CHECK_NESTING)) {
        collectIssues(new NestedElementsChecker(getArchimateViews()));
    }
    // Possible Duplicates
    if (store.getBoolean(IPreferenceConstants.PREFS_HAMMER_CHECK_DUPLICATE_ELEMENTS)) {
        collectIssues(new DuplicateElementChecker(getArchimateElements()));
    }
    // Junctions
    if (store.getBoolean(IPreferenceConstants.PREFS_HAMMER_CHECK_JUNCTIONS)) {
        collectIssues(new JunctionsChecker(getArchimateElements()));
    }
    if (!fErrorList.isEmpty()) {
        IIssueCategory category = new ErrorsCategory(fErrorList);
        result.add(category);
    }
    if (!fWarningList.isEmpty()) {
        IIssueCategory category = new WarningsCategory(fWarningList);
        result.add(category);
    }
    if (!fAdviceList.isEmpty()) {
        IIssueCategory category = new AdviceCategory(fAdviceList);
        result.add(category);
    }
    if (result.isEmpty()) {
        result.add(new OKType());
    }
    return result;
}
Also used : UnusedElementsChecker(com.archimatetool.hammer.validation.checkers.UnusedElementsChecker) EmptyViewsChecker(com.archimatetool.hammer.validation.checkers.EmptyViewsChecker) AdviceCategory(com.archimatetool.hammer.validation.issues.AdviceCategory) ArrayList(java.util.ArrayList) DuplicateElementChecker(com.archimatetool.hammer.validation.checkers.DuplicateElementChecker) ErrorType(com.archimatetool.hammer.validation.issues.ErrorType) EObject(org.eclipse.emf.ecore.EObject) IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) ViewpointChecker(com.archimatetool.hammer.validation.checkers.ViewpointChecker) WarningsCategory(com.archimatetool.hammer.validation.issues.WarningsCategory) ErrorsCategory(com.archimatetool.hammer.validation.issues.ErrorsCategory) InvalidRelationsChecker(com.archimatetool.hammer.validation.checkers.InvalidRelationsChecker) IArchimateDiagramModel(com.archimatetool.model.IArchimateDiagramModel) UnusedRelationsChecker(com.archimatetool.hammer.validation.checkers.UnusedRelationsChecker) OKType(com.archimatetool.hammer.validation.issues.OKType) JunctionsChecker(com.archimatetool.hammer.validation.checkers.JunctionsChecker) WarningType(com.archimatetool.hammer.validation.issues.WarningType) NestedElementsChecker(com.archimatetool.hammer.validation.checkers.NestedElementsChecker) AdviceType(com.archimatetool.hammer.validation.issues.AdviceType) EObject(org.eclipse.emf.ecore.EObject) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) IIssueCategory(com.archimatetool.hammer.validation.issues.IIssueCategory)

Example 2 with ErrorType

use of com.archimatetool.hammer.validation.issues.ErrorType in project archi by archimatetool.

the class JunctionsChecker method findBogusJunctions.

List<IIssue> findBogusJunctions() {
    List<IIssue> issues = new ArrayList<IIssue>();
    for (IArchimateElement element : fArchimateElements) {
        if (element instanceof IJunction) {
            IArchimateRelationship rel = null;
            for (IArchimateRelationship relation : ArchimateModelUtils.getAllRelationshipsForConcept(element)) {
                if (rel != null && rel.eClass() != relation.eClass()) {
                    String name = ArchiLabelProvider.INSTANCE.getLabel(element);
                    String description = NLS.bind(DESCRIPTION, name);
                    String explanation = NLS.bind(EXPLANATION, name);
                    IIssue issue = new ErrorType(NAME, description, explanation, element);
                    issues.add(issue);
                    break;
                }
                rel = relation;
            }
        }
    }
    return issues;
}
Also used : ErrorType(com.archimatetool.hammer.validation.issues.ErrorType) ArrayList(java.util.ArrayList) IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IIssue(com.archimatetool.hammer.validation.issues.IIssue) IJunction(com.archimatetool.model.IJunction)

Example 3 with ErrorType

use of com.archimatetool.hammer.validation.issues.ErrorType in project archi by archimatetool.

the class InvalidRelationsChecker method findInvalidRelations.

// Invalid Relations
List<IIssue> findInvalidRelations() {
    List<IIssue> issues = new ArrayList<IIssue>();
    for (IArchimateRelationship relation : fRelations) {
        boolean valid = ArchimateModelUtils.isValidRelationship(relation.getSource(), relation.getTarget(), relation.eClass());
        if (!valid) {
            String className = ArchiLabelProvider.INSTANCE.getDefaultName(relation.eClass());
            String description = NLS.bind(fDescription, new Object[] { className, ArchiLabelProvider.INSTANCE.getLabel(relation.getSource()), ArchiLabelProvider.INSTANCE.getLabel(relation.getTarget()) });
            String explanation = NLS.bind(fExplanation, new Object[] { className, ArchiLabelProvider.INSTANCE.getDefaultName(relation.getSource().eClass()), ArchiLabelProvider.INSTANCE.getDefaultName(relation.getTarget().eClass()) });
            IIssue issue = new ErrorType(fName, description, explanation, relation);
            issues.add(issue);
        }
    }
    return issues;
}
Also used : ErrorType(com.archimatetool.hammer.validation.issues.ErrorType) ArrayList(java.util.ArrayList) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IIssue(com.archimatetool.hammer.validation.issues.IIssue)

Example 4 with ErrorType

use of com.archimatetool.hammer.validation.issues.ErrorType in project archi by archimatetool.

the class InvalidRelationsCheckerTests method testGetIssues.

@Test
public void testGetIssues() {
    List<IArchimateRelationship> relations = new ArrayList<IArchimateRelationship>();
    IArchimateRelationship relation = IArchimateFactory.eINSTANCE.createAssignmentRelationship();
    relation.setName("relation");
    relation.setSource(IArchimateFactory.eINSTANCE.createBusinessActor());
    relation.setTarget(IArchimateFactory.eINSTANCE.createBusinessRole());
    relations.add(relation);
    InvalidRelationsChecker checker = new InvalidRelationsChecker(relations);
    // Should be ok
    List<IIssue> issues = checker.getIssues();
    assertEquals(0, issues.size());
    // Now set bogus relationship
    relation.setTarget(IArchimateFactory.eINSTANCE.createNode());
    issues = checker.getIssues();
    assertEquals(1, issues.size());
    assertTrue(issues.get(0) instanceof ErrorType);
    assertSame(relation, issues.get(0).getObject());
}
Also used : ErrorType(com.archimatetool.hammer.validation.issues.ErrorType) ArrayList(java.util.ArrayList) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IIssue(com.archimatetool.hammer.validation.issues.IIssue) Test(org.junit.Test)

Aggregations

ErrorType (com.archimatetool.hammer.validation.issues.ErrorType)4 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)4 ArrayList (java.util.ArrayList)4 IIssue (com.archimatetool.hammer.validation.issues.IIssue)3 IArchimateElement (com.archimatetool.model.IArchimateElement)2 DuplicateElementChecker (com.archimatetool.hammer.validation.checkers.DuplicateElementChecker)1 EmptyViewsChecker (com.archimatetool.hammer.validation.checkers.EmptyViewsChecker)1 InvalidRelationsChecker (com.archimatetool.hammer.validation.checkers.InvalidRelationsChecker)1 JunctionsChecker (com.archimatetool.hammer.validation.checkers.JunctionsChecker)1 NestedElementsChecker (com.archimatetool.hammer.validation.checkers.NestedElementsChecker)1 UnusedElementsChecker (com.archimatetool.hammer.validation.checkers.UnusedElementsChecker)1 UnusedRelationsChecker (com.archimatetool.hammer.validation.checkers.UnusedRelationsChecker)1 ViewpointChecker (com.archimatetool.hammer.validation.checkers.ViewpointChecker)1 AdviceCategory (com.archimatetool.hammer.validation.issues.AdviceCategory)1 AdviceType (com.archimatetool.hammer.validation.issues.AdviceType)1 ErrorsCategory (com.archimatetool.hammer.validation.issues.ErrorsCategory)1 IIssueCategory (com.archimatetool.hammer.validation.issues.IIssueCategory)1 OKType (com.archimatetool.hammer.validation.issues.OKType)1 WarningType (com.archimatetool.hammer.validation.issues.WarningType)1 WarningsCategory (com.archimatetool.hammer.validation.issues.WarningsCategory)1