public ToscaNode getReferenceNode() { return vertexSet().stream().findAny().orElse(null); } }
public List<GraphMapping> extractViolatingMappings(ToscaGraph identifierGraph, List<GraphMapping> identifierMappings, List<GraphMapping> requiredStructureMappings) { List<GraphMapping> violatingMappings = new ArrayList<>(); // for all mappings in identifierMappings, we need to find the corresponding required Structure Mappings for (GraphMapping identifierMapping : identifierMappings) { boolean foundCorrespondence = false; for (GraphMapping requiredStructureMapping : requiredStructureMappings) { //get the corresponding ToscaNode from the searchInGraph ToscaNode identifierVertexCorrespondence = (ToscaNode) identifierMapping.getVertexCorrespondence(identifierGraph.getReferenceNode(), false); foundCorrespondence = (requiredStructureMapping.getVertexCorrespondence(identifierVertexCorrespondence, true) != null) ? true : false; } if (!foundCorrespondence) { violatingMappings.add(identifierMapping); } } return violatingMappings; }
public static ToscaGraph createTOSCAGraph(TTopologyTemplate topologyTemplate) { ToscaGraph graph = new ToscaGraph(new ToscaEdgeFactory()); @NonNull List<TRelationshipTemplate> relationshipTemplates = topologyTemplate.getRelationshipTemplates(); @NonNull List<TNodeTemplate> nodeTemplates = topologyTemplate.getNodeTemplates(); Map<TNodeTemplate, ToscaNode> nodes = new HashMap<>(); for (TNodeTemplate nodeTemplate : nodeTemplates) { ToscaNode node = createAndInitializeTOSCANode(nodeTemplate); nodes.put(nodeTemplate, node); graph.addVertex(node); } for (TRelationshipTemplate tRelationshipTemplate : relationshipTemplates) { ToscaNode source = nodes.get(tRelationshipTemplate.getSourceElement().getRef()); ToscaNode target = nodes.get(tRelationshipTemplate.getTargetElement().getRef()); ToscaEdge edge = graph.addEdge(source, target); initializeTOSCAEdge(tRelationshipTemplate, edge); } return graph; }
public Stream<TRelationshipTemplate> getExternalRelations(TNodeTemplate matchingNode, RefinementCandidate candidate, TTopologyTemplate topology) { return topology.getRelationshipTemplates().stream() .filter(relationship -> // all relationships which have the matchingNode as source or target // -> \pi_1(rm_x) = \pi_2(sgm_i) matchingNode.getId().equals(relationship.getSourceElement().getRef().getId()) || matchingNode.getId().equals(relationship.getTargetElement().getRef().getId()) ).filter(relationship -> { // ignore all relationships which are part of the sub-graph // \nexists sgm_y \in sgms : \pi_1(sgm_y) = r_j return candidate.getDetectorGraph().edgeSet() .stream() .noneMatch(toscaEdge -> { ToscaEdge edgeCorrespondence = candidate.getGraphMapping().getEdgeCorrespondence(toscaEdge, false); return edgeCorrespondence.getTemplate().equals(relationship); }); }); }
ToscaNode node = refinement.getDetectorGraph().getNode(relationMapping.getDetectorNode().getId()); String topologyNodeId = refinement.getGraphMapping().getVertexCorrespondence(node, false).getId();
public Map<ToscaNode, ToscaNode> getSubGraphMappingAsMap(GraphMapping mapping, ToscaGraph subGraph) { Map<ToscaNode, ToscaNode> result = new HashMap<>(); for (ToscaNode node : subGraph.vertexSet()) { Optional.of(mapping.getVertexCorrespondence(node, false)).map(vertex -> (ToscaNode) vertex).ifPresent(vertex -> result.put(node, vertex)); } return result; }
public ToscaNode getNode(String id) { return vertexSet().stream().filter(n -> StringUtils.equals(id, n.getId())).findFirst().orElse(null); }
public ArrayList<String> getNodeIdsToBeReplaced() { ArrayList<String> ids = new ArrayList<>(); this.detectorGraph.vertexSet().forEach(toscaNode -> ids.add(graphMapping.getVertexCorrespondence(toscaNode, false).getTemplate().getId()) ); return ids; } }
public boolean isApplicable(RefinementCandidate candidate, TTopologyTemplate topology) { return candidate.getDetectorGraph().vertexSet() .stream() .allMatch(vertex -> { TNodeTemplate matchingNode = candidate.getGraphMapping().getVertexCorrespondence(vertex, false).getTemplate(); return this.canRedirectExternalRelations(candidate, matchingNode, topology); }); }
private Map<String, Map<String, Integer>> calculateNewPositions(ToscaGraph detectorGraph, GraphMapping<ToscaNode, ToscaEdge> mapping, TTopologyTemplate refinementStructure) { HashMap<String, Map<String, Integer>> coordinates = new HashMap<>(); int[] topLeftOriginal = {-1, -1}; int[] topLeftReplacement = {-1, -1}; detectorGraph.vertexSet().forEach(toscaNode -> { ToscaNode node = mapping.getVertexCorrespondence(toscaNode, false); getTopLeft(node.getTemplate().getX(), node.getTemplate().getY(), topLeftOriginal); }); refinementStructure.getNodeTemplates().forEach( tNodeTemplate -> getTopLeft(tNodeTemplate.getX(), tNodeTemplate.getY(), topLeftReplacement) ); refinementStructure.getNodeTemplates().forEach(nodeTemplate -> { int x = Integer.parseInt(nodeTemplate.getX()); int y = Integer.parseInt(nodeTemplate.getY()); HashMap<String, Integer> newCoordinates = new HashMap<>(); newCoordinates.put("x", (x - topLeftReplacement[0]) + topLeftOriginal[0]); newCoordinates.put("y", (y - topLeftReplacement[1]) + topLeftOriginal[1]); coordinates.put(nodeTemplate.getId(), newCoordinates); }); return coordinates; }