All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.structurizr.inspection.model.DisconnectedElementInspection Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
package com.structurizr.inspection.model;

import com.structurizr.inspection.Inspector;
import com.structurizr.inspection.Violation;
import com.structurizr.model.DeploymentNode;
import com.structurizr.model.Element;
import com.structurizr.model.Relationship;

import java.util.HashSet;
import java.util.Set;

public class DisconnectedElementInspection extends AbstractElementInspection {

    private final Set elementsWithRelationships = new HashSet<>();

    public DisconnectedElementInspection(Inspector inspector) {
        super(inspector);

        for (Relationship relationship : getWorkspace().getModel().getRelationships()) {
            elementsWithRelationships.add(relationship.getSourceId());
            elementsWithRelationships.add(relationship.getDestinationId());
        }
    }

    @Override
    protected Violation inspect(Element element) {
        if (element instanceof DeploymentNode) {
            // deployment nodes typically won't have relationships to/from them
            return noViolation();
        }

        if (!elementsWithRelationships.contains(element.getId())) {
            return violation("The " + terminologyFor(element).toLowerCase() + " \"" + nameOf(element) + "\" is disconnected - add a relationship to/from it, or consider removing it from the model.");
        }

        return noViolation();
    }

    @Override
    protected String getType() {
        return "model.element.disconnected";
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy