Splitting { public TTopologyTemplate split(TTopologyTemplate topologyTemplate) throws SplittingException { if (!checkValidTopology(topologyTemplate)) { throw new SplittingException("Topology is not valid"); } TTopologyTemplate topologyTemplateCopy = BackendUtils.clone(topologyTemplate); HashSet<TNodeTemplate> nodeTemplatesWhichPredecessorsHasNoPredecessors = new HashSet<>(getNodeTemplatesWhichPredecessorsHasNoPredecessors(topologyTemplateCopy)); while (!nodeTemplatesWhichPredecessorsHasNoPredecessors.isEmpty()) { for (TNodeTemplate currentNode : nodeTemplatesWhichPredecessorsHasNoPredecessors) { List<TNodeTemplate> predecessors = getHostedOnPredecessorsOfNodeTemplate(topologyTemplateCopy, currentNode); Set<String> predecessorsTargetLabel = new HashSet<>(); for (TNodeTemplate predecessor : predecessors) { Optional<String> targetLabel = ModelUtilities.getTargetLabel(predecessor); if (!targetLabel.isPresent()) { LOGGER.error("No target label present"); LOGGER.error("id " + predecessor.getId()); } predecessorsTargetLabel.add(targetLabel.get().toLowerCase()); } if (predecessorsTargetLabel.size() == 1) { ModelUtilities.setTargetLabel(currentNode, ModelUtilities.getTargetLabel(predecessors.get(0)).get()); } else { List<TRelationshipTemplate> incomingRelationships = ModelUtilities.getIncomingRelationshipTemplates(topologyTemplateCopy, currentNode); List<TRelationshipTemplate> outgoingRelationships = ModelUtilities.getOutgoingRelationshipTemplates(topologyTemplateCopy, currentNode); for (String targetLabel : predecessorsTargetLabel) { TNodeTemplate duplicatedNode = BackendUtils.clone(currentNode); duplicatedNode.setId(Util.makeNCName(currentNode.getId() + "-" + targetLabel)); duplicatedNode.setName(Util.makeNCName(currentNode.getName() + "-" + targetLabel)); topologyTemplate.getNodeTemplateOrRelationshipTemplate().add(duplicatedNode); topologyTemplateCopy.getNodeTemplateOrRelationshipTemplate().add(duplicatedNode); ModelUtilities.setTargetLabel(duplicatedNode, targetLabel); for (TRelationshipTemplate incomingRelationship : incomingRelationships) { Object sourceElementIncommingRel = incomingRelationship.getSourceElement().getRef(); TNodeTemplate sourceNodeTemplate = ModelUtilities.getSourceNodeTemplateOfRelationshipTemplate(topologyTemplateCopy, incomingRelationship); if (((ModelUtilities.getTargetLabel(sourceNodeTemplate).get() .equalsIgnoreCase(ModelUtilities.getTargetLabel(duplicatedNode).get()) && getBasisRelationshipType(incomingRelationship.getType()).getValidTarget().getTypeRef().getLocalPart().equalsIgnoreCase("Container")) || !predecessors.contains(sourceNodeTemplate))) { List<TRelationshipTemplate> reassignRelationship = new ArrayList<>(); reassignRelationship.add(incomingRelationship); List<TRelationshipTemplate> reassignedRelationship = reassignIncomingRelationships(reassignRelationship, duplicatedNode); topologyTemplate.getNodeTemplateOrRelationshipTemplate().addAll(reassignedRelationship); topologyTemplateCopy.getNodeTemplateOrRelationshipTemplate().addAll(reassignedRelationship); } } List<TRelationshipTemplate> newOutgoingRelationships = reassignOutgoingRelationships(outgoingRelationships, duplicatedNode); topologyTemplate.getNodeTemplateOrRelationshipTemplate().addAll(newOutgoingRelationships); topologyTemplateCopy.getNodeTemplateOrRelationshipTemplate().addAll(newOutgoingRelationships); } topologyTemplate.getNodeTemplateOrRelationshipTemplate().remove(currentNode); topologyTemplate.getNodeTemplateOrRelationshipTemplate().removeAll(outgoingRelationships); topologyTemplate.getNodeTemplateOrRelationshipTemplate().removeAll(incomingRelationships); topologyTemplateCopy.getNodeTemplateOrRelationshipTemplate().remove(currentNode); topologyTemplateCopy.getNodeTemplateOrRelationshipTemplate().removeAll(outgoingRelationships); topologyTemplateCopy.getNodeTemplateOrRelationshipTemplate().removeAll(incomingRelationships); } topologyTemplateCopy.getNodeTemplateOrRelationshipTemplate().removeAll(predecessors); List<TRelationshipTemplate> removingRelationships = topologyTemplateCopy.getRelationshipTemplates().stream() .filter(rt -> predecessors.contains(ModelUtilities.getSourceNodeTemplateOfRelationshipTemplate(topologyTemplateCopy, rt)) || predecessors.contains(ModelUtilities.getTargetNodeTemplateOfRelationshipTemplate(topologyTemplateCopy, rt))) .collect(Collectors.toList()); topologyTemplateCopy.getNodeTemplateOrRelationshipTemplate().removeAll(removingRelationships); } nodeTemplatesWhichPredecessorsHasNoPredecessors.clear(); nodeTemplatesWhichPredecessorsHasNoPredecessors.addAll(getNodeTemplatesWhichPredecessorsHasNoPredecessors(topologyTemplateCopy)); } return topologyTemplate; }  ServiceTemplateId splitTopologyOfServiceTemplate(ServiceTemplateId id); ServiceTemplateId matchTopologyOfServiceTemplate(ServiceTemplateId id); ServiceTemplateId composeServiceTemplates(String composedSolutionServiceTemplateID, List<ServiceTemplateId> serviceTemplateIds); void resolveTopologyTemplate(ServiceTemplateId serviceTemplateId); boolean checkValidTopology(TTopologyTemplate topologyTemplate); TTopologyTemplate split(TTopologyTemplate topologyTemplate); Map<String, List<TTopologyTemplate>> getHostingInjectionOptions(TTopologyTemplate topologyTemplate); Map<String, List<TTopologyTemplate>> getHostingMatchingOptionsWithDefaultLabeling(TTopologyTemplate topologyTemplate); TTopologyTemplate hostMatchingWithDefaultHostSelection(TTopologyTemplate topologyTemplate); TTopologyTemplate connectionMatchingWithDefaultConnectorSelection(TTopologyTemplate topologyTemplate); TTopologyTemplate injectNodeTemplates(TTopologyTemplate topologyTemplate, Map<String, TTopologyTemplate> injectNodes, InjectRemoval removal); Map<String, List<TTopologyTemplate>> getConnectionInjectionOptions(TTopologyTemplate topologyTemplate); TTopologyTemplate injectConnectionNodeTemplates(TTopologyTemplate topologyTemplate, Map<String, TTopologyTemplate> selectedConnectionFragments); Map<TNodeTemplate, Set<TNodeTemplate>> computeTransitiveClosure(TTopologyTemplate topologyTemplate); Map<TRequirement, String> getOpenRequirementsAndMatchingBasisCapabilityTypeNames(TTopologyTemplate topologyTemplate); List<TRequirement> getOpenRequirements(TTopologyTemplate topologyTemplate); TRelationshipType getBasisRelationshipType(QName relationshipTypeQName);  }
@Test public void splitSmallTopology() throws Exception { List<String> expectedIds = Arrays.asList("NT1", "NT1_2", "NT1_3-A", "NT1_3-B", "NT1_4-A", "NT1_4-B", "NT1_5-A", "NT1_5-B", "con37", "con45", "con_91-A-A", "con_57-B-B"); List<TEntityTemplate> NodeTemplates = splitting.split(topologyTemplate).getNodeTemplateOrRelationshipTemplate(); List<String> Ids = new ArrayList<>(); for (TEntityTemplate nodeTemplate : NodeTemplates) { Ids.add(nodeTemplate.getId()); } assertEquals(expectedIds, Ids); }