Search in sources :

Example 1 with IArchimateRelationship

use of com.archimatetool.model.IArchimateRelationship 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 IArchimateRelationship

use of com.archimatetool.model.IArchimateRelationship 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 IArchimateRelationship

use of com.archimatetool.model.IArchimateRelationship in project archi by archimatetool.

the class TreeViewpointFilterProvider method getTextColor.

/**
 * If the element is disallowed in a Viewpoint grey it out
 * @param element
 * @return Color or null
 */
Color getTextColor(Object element) {
    if (isActive() && fActiveDiagramModel != null && element instanceof IArchimateConcept) {
        String id = fActiveDiagramModel.getViewpoint();
        IViewpoint viewpoint = ViewpointManager.INSTANCE.getViewpoint(id);
        if (viewpoint != null) {
            // From same model as active diagram
            IArchimateModel model = ((IArchimateConcept) element).getArchimateModel();
            if (model == fActiveDiagramModel.getArchimateModel()) {
                if (element instanceof IArchimateRelationship) {
                    IArchimateConcept source = ((IArchimateRelationship) element).getSource();
                    IArchimateConcept target = ((IArchimateRelationship) element).getTarget();
                    if (!viewpoint.isAllowedConcept(source.eClass()) || !viewpoint.isAllowedConcept(target.eClass())) {
                        return ColorFactory.get(128, 128, 128);
                    }
                } else if (element instanceof IArchimateElement) {
                    if (!viewpoint.isAllowedConcept(((IArchimateElement) element).eClass())) {
                        return ColorFactory.get(128, 128, 128);
                    }
                }
            }
        }
    }
    return null;
}
Also used : IArchimateConcept(com.archimatetool.model.IArchimateConcept) IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IViewpoint(com.archimatetool.model.viewpoints.IViewpoint) IArchimateModel(com.archimatetool.model.IArchimateModel)

Example 4 with IArchimateRelationship

use of com.archimatetool.model.IArchimateRelationship in project archi by archimatetool.

the class UnusedRelationsChecker method findUnusedRelations.

List<IIssue> findUnusedRelations() {
    List<IIssue> issues = new ArrayList<IIssue>();
    for (IArchimateRelationship relation : fRelations) {
        if (!DiagramModelUtils.isArchimateConceptReferencedInDiagrams(relation)) {
            String name = ArchiLabelProvider.INSTANCE.getLabel(relation);
            String description = NLS.bind(DESCRIPTION, name);
            String explanation = NLS.bind(EXPLANATION, name);
            IIssue issue = new WarningType(NAME, description, explanation, relation);
            issues.add(issue);
        }
    }
    return issues;
}
Also used : ArrayList(java.util.ArrayList) WarningType(com.archimatetool.hammer.validation.issues.WarningType) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IIssue(com.archimatetool.hammer.validation.issues.IIssue)

Example 5 with IArchimateRelationship

use of com.archimatetool.model.IArchimateRelationship in project archi by archimatetool.

the class ArchimateModelUtilsTests method testHasDirectRelationship.

/*
     * NOTE - Tests for ArchimateModelUtils.isValidRelationshipStart() and ArchimateModelUtils.isValidRelationship() are in ViewpointTests
     */
@Test
public void testHasDirectRelationship() {
    IArchimateConcept sourceConcept = IArchimateFactory.eINSTANCE.createBusinessActor();
    IArchimateConcept someTarget = IArchimateFactory.eINSTANCE.createBusinessRole();
    IArchimateRelationship relationship = IArchimateFactory.eINSTANCE.createAssociationRelationship();
    assertFalse(ArchimateModelUtils.hasDirectRelationship(sourceConcept, relationship));
    assertFalse(ArchimateModelUtils.hasDirectRelationship(relationship, sourceConcept));
    relationship.connect(sourceConcept, someTarget);
    assertTrue(ArchimateModelUtils.hasDirectRelationship(sourceConcept, relationship));
    assertTrue(ArchimateModelUtils.hasDirectRelationship(relationship, sourceConcept));
    relationship.connect(someTarget, sourceConcept);
    assertTrue(ArchimateModelUtils.hasDirectRelationship(sourceConcept, relationship));
    assertTrue(ArchimateModelUtils.hasDirectRelationship(relationship, sourceConcept));
}
Also used : IArchimateConcept(com.archimatetool.model.IArchimateConcept) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) Test(org.junit.Test)

Aggregations

IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)74 Test (org.junit.Test)39 IArchimateElement (com.archimatetool.model.IArchimateElement)33 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)22 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)15 ArrayList (java.util.ArrayList)15 IArchimateConcept (com.archimatetool.model.IArchimateConcept)14 IDiagramModel (com.archimatetool.model.IDiagramModel)12 IArchimateModel (com.archimatetool.model.IArchimateModel)9 EObject (org.eclipse.emf.ecore.EObject)9 IIssue (com.archimatetool.hammer.validation.issues.IIssue)7 IDiagramModelConnection (com.archimatetool.model.IDiagramModelConnection)7 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)7 IDiagramModelArchimateComponent (com.archimatetool.model.IDiagramModelArchimateComponent)5 ArchimateTestModel (com.archimatetool.testingtools.ArchimateTestModel)5 ErrorType (com.archimatetool.hammer.validation.issues.ErrorType)4 IFolder (com.archimatetool.model.IFolder)4 EClass (org.eclipse.emf.ecore.EClass)4 Command (org.eclipse.gef.commands.Command)4 NoteEditPart (com.archimatetool.editor.diagram.editparts.diagram.NoteEditPart)3