Search in sources :

Example 11 with OTPermutationMapping

use of org.eclipse.winery.model.tosca.extensions.OTPermutationMapping in project winery by eclipse.

the class PatternDetectionUtilsTest method swapDetectorWithRefinement.

@Test
public void swapDetectorWithRefinement() {
    TTopologyTemplate detector = new TTopologyTemplate();
    TTopologyTemplate refinementStructure = new TTopologyTemplate();
    TEntityTemplate detectorElement = new TNodeTemplate();
    TEntityTemplate refinementElement = new TNodeTemplate();
    OTRelationMapping relationMapping = new OTRelationMapping(new OTRelationMapping.Builder().setDetectorElement(detectorElement).setRefinementElement(refinementElement).setDirection(OTRelationDirection.INGOING).setRelationType("relationType").setValidSourceOrTarget(QName.valueOf("validSourceOrTarget")));
    OTPermutationMapping permutationMapping = new OTPermutationMapping(new OTPermutationMapping.Builder().setDetectorElement(detectorElement).setRefinementElement(refinementElement));
    OTAttributeMapping attributeMapping = new OTAttributeMapping(new OTAttributeMapping.Builder().setDetectorElement(detectorElement).setRefinementElement(refinementElement).setDetectorProperty("detectorProperty").setRefinementProperty("refinementProperty"));
    OTStayMapping stayMapping = new OTStayMapping(new OTStayMapping.Builder().setDetectorElement(detectorElement).setRefinementElement(refinementElement));
    OTDeploymentArtifactMapping deploymentArtifactMapping = new OTDeploymentArtifactMapping(new OTDeploymentArtifactMapping.Builder().setDetectorElement(detectorElement).setRefinementElement(refinementElement).setArtifactType(QName.valueOf("artifactType")));
    OTBehaviorPatternMapping behaviorPatternMapping = new OTBehaviorPatternMapping(new OTBehaviorPatternMapping.Builder("behaviorPatternMap0").setDetectorElement(detectorElement).setRefinementElement(refinementElement).setBehaviorPattern("behaviorPattern").setProperty(new OTPropertyKV("key", "value")));
    OTPatternRefinementModel prm = new OTPatternRefinementModel(new OTPatternRefinementModel.Builder().setDetector(detector).setRefinementStructure(refinementStructure).setRelationMappings(Collections.singletonList(relationMapping)).setPermutationMappings(Collections.singletonList(permutationMapping)).setAttributeMappings(Collections.singletonList(attributeMapping)).setStayMappings(Collections.singletonList(stayMapping)).setDeploymentArtifactMappings(Collections.singletonList(deploymentArtifactMapping)).setBehaviorPatternMappings(Collections.singletonList(behaviorPatternMapping)));
    PatternDetectionUtils.swapDetectorWithRefinement(prm);
    assertEquals(prm.getDetector(), refinementStructure);
    assertEquals(prm.getRefinementStructure(), detector);
    assertEquals(relationMapping.getDetectorElement(), refinementElement);
    assertEquals(relationMapping.getRefinementElement(), detectorElement);
    assertEquals(relationMapping.getDirection(), OTRelationDirection.INGOING);
    assertEquals(relationMapping.getRelationType(), QName.valueOf("relationType"));
    assertEquals(relationMapping.getValidSourceOrTarget(), QName.valueOf("validSourceOrTarget"));
    assertEquals(permutationMapping.getDetectorElement(), refinementElement);
    assertEquals(permutationMapping.getRefinementElement(), detectorElement);
    assertEquals(attributeMapping.getDetectorElement(), refinementElement);
    assertEquals(attributeMapping.getRefinementElement(), detectorElement);
    assertEquals(attributeMapping.getDetectorProperty(), "refinementProperty");
    assertEquals(attributeMapping.getRefinementProperty(), "detectorProperty");
    assertEquals(stayMapping.getDetectorElement(), refinementElement);
    assertEquals(stayMapping.getRefinementElement(), detectorElement);
    assertEquals(deploymentArtifactMapping.getDetectorElement(), refinementElement);
    assertEquals(deploymentArtifactMapping.getRefinementElement(), detectorElement);
    assertEquals(deploymentArtifactMapping.getArtifactType(), QName.valueOf("artifactType"));
    assertEquals(behaviorPatternMapping.getDetectorElement(), refinementElement);
    assertEquals(behaviorPatternMapping.getRefinementElement(), detectorElement);
    assertEquals(behaviorPatternMapping.getBehaviorPattern(), "behaviorPattern");
    assertEquals(behaviorPatternMapping.getProperty(), new OTPropertyKV("key", "value"));
}
Also used : OTDeploymentArtifactMapping(org.eclipse.winery.model.tosca.extensions.OTDeploymentArtifactMapping) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) OTAttributeMapping(org.eclipse.winery.model.tosca.extensions.OTAttributeMapping) OTRelationMapping(org.eclipse.winery.model.tosca.extensions.OTRelationMapping) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) OTStayMapping(org.eclipse.winery.model.tosca.extensions.OTStayMapping) OTPropertyKV(org.eclipse.winery.model.tosca.extensions.kvproperties.OTPropertyKV) OTBehaviorPatternMapping(org.eclipse.winery.model.tosca.extensions.OTBehaviorPatternMapping) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) OTPermutationMapping(org.eclipse.winery.model.tosca.extensions.OTPermutationMapping) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) Test(org.junit.jupiter.api.Test)

Example 12 with OTPermutationMapping

use of org.eclipse.winery.model.tosca.extensions.OTPermutationMapping in project winery by eclipse.

the class ToscaComponentPatternMatcher method componentPatternsCompatible.

protected boolean componentPatternsCompatible(ToscaEntity left, ToscaEntity right) {
    // By convention, the left node is always the element to search in right.
    TEntityTemplate detectorElement = left.getTemplate();
    TEntityTemplate candidateElement = right.getTemplate();
    if (!(detectorElement instanceof TNodeTemplate) || !(candidateElement instanceof TNodeTemplate)) {
        return false;
    }
    if (prm.getPermutationMappings() == null || prm.getPermutationMappings().isEmpty()) {
        return false;
    }
    List<OTPermutationMapping> detectorMappings = prm.getPermutationMappings().stream().filter(mapping -> isOneToOne(mapping, prm) && mapping.getDetectorElement().getId().equals(detectorElement.getId())).collect(Collectors.toList());
    if (detectorMappings.isEmpty()) {
        return false;
    }
    TEntityTemplate refinementElement = detectorMappings.get(0).getRefinementElement();
    return refinementModels.stream().map(OTPatternRefinementModel.class::cast).filter(otherPrm -> otherPrm.getPermutationMappings() != null && !otherPrm.getPermutationMappings().isEmpty()).anyMatch(otherPrm -> {
        List<OTPermutationMapping> matchingDetectorMappings = otherPrm.getPermutationMappings().stream().filter(mapping -> isOneToOne(mapping, otherPrm) && super.isCompatible(mapping.getDetectorElement(), candidateElement) && mapping.getRefinementElement().getType().equals(refinementElement.getType())).collect(Collectors.toList());
        if (!matchingDetectorMappings.isEmpty()) {
            componentPatternCandidates.get(prm).add(new ComponentPatternCandidate((TNodeTemplate) detectorElement, (TNodeTemplate) refinementElement, otherPrm, (TNodeTemplate) matchingDetectorMappings.get(0).getDetectorElement()));
            return true;
        }
        return false;
    });
}
Also used : TEntityType(org.eclipse.winery.model.tosca.TEntityType) Set(java.util.Set) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) ToscaEdge(org.eclipse.winery.topologygraph.model.ToscaEdge) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) List(java.util.List) ToscaNode(org.eclipse.winery.topologygraph.model.ToscaNode) NamespaceManager(org.eclipse.winery.repository.backend.NamespaceManager) ToscaEntity(org.eclipse.winery.topologygraph.model.ToscaEntity) Map(java.util.Map) OTPermutationMapping(org.eclipse.winery.model.tosca.extensions.OTPermutationMapping) OTRefinementModel(org.eclipse.winery.model.tosca.extensions.OTRefinementModel) QName(javax.xml.namespace.QName) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) OTPermutationMapping(org.eclipse.winery.model.tosca.extensions.OTPermutationMapping) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)

Example 13 with OTPermutationMapping

use of org.eclipse.winery.model.tosca.extensions.OTPermutationMapping in project winery by eclipse.

the class PermutationGenerator method generatePermutations.

public Map<String, OTTopologyFragmentRefinementModel> generatePermutations(OTTopologyFragmentRefinementModel refinementModel) {
    Map<String, OTTopologyFragmentRefinementModel> permutations = new HashMap<>();
    IRepository repository = RepositoryFactory.getRepository();
    if (!checkMutability(refinementModel)) {
        throw new RuntimeException("The refinement model cannot be permuted!");
    }
    QName refinementModelQName = new QName(refinementModel.getTargetNamespace(), refinementModel.getName());
    DefinitionsChildId refinementModelId = new TopologyFragmentRefinementModelId(refinementModelQName);
    if (refinementModel instanceof OTPatternRefinementModel) {
        refinementModelId = new PatternRefinementModelId(refinementModelQName);
    }
    for (OTStringList options : refinementModel.getPermutationOptions()) {
        String permutationName = VersionSupport.getNewComponentVersionId(refinementModelId, "permutation-" + String.join("-", options.getValues()).replaceAll("_", "-"));
        QName permutationQName = new QName(refinementModel.getTargetNamespace(), permutationName);
        DefinitionsChildId permutationModelId = new TopologyFragmentRefinementModelId(permutationQName);
        if (refinementModel instanceof OTPatternRefinementModel) {
            permutationModelId = new PatternRefinementModelId(permutationQName);
        }
        try {
            // To ensure that the permutationMaps are duplicated correctly, save the permutation first
            repository.setElement(refinementModelId, refinementModel);
            repository.setElement(permutationModelId, refinementModel);
        } catch (IOException e) {
            logger.error("Error while creating permutation!", e);
            break;
        }
        OTTopologyFragmentRefinementModel permutation = repository.getElement(permutationModelId);
        permutation.setName(permutationName);
        permutations.put(permutationName, permutation);
        Map<String, String> alreadyAdded = new HashMap<>();
        for (String option : options.getValues()) {
            permutation.getPermutationMappings().stream().filter(permutationMap -> permutationMap.getDetectorElement().getId().equals(option)).map(OTPrmMapping::getRefinementElement).filter(refinementElement -> refinementElement instanceof TNodeTemplate).map(refinementElement -> (TNodeTemplate) refinementElement).forEach(refinementElement -> {
                TNodeTemplate addedDetectorElement = alreadyAdded.containsKey(refinementElement.getId()) ? permutation.getDetector().getNodeTemplate(alreadyAdded.get(refinementElement.getId())) : addNodeFromRefinementStructureToDetector(refinementElement, permutation, alreadyAdded);
                // region outgoing relations of the currently permuted refinementElement
                ModelUtilities.getOutgoingRelationshipTemplates(permutation.getRefinementStructure(), refinementElement).forEach(relation -> {
                    // Using the permutation maps defined in the original model as we remove them in the permutation
                    refinementModel.getPermutationMappings().stream().filter(permutationMap -> permutationMap.getRefinementElement().getId().equals(relation.getTargetElement().getRef().getId())).filter(permutationMap -> permutationMap.getDetectorElement() instanceof TNodeTemplate).forEach(permutationMap -> {
                        // to be mutated, add it the component and create the relation.
                        if (permutationMap.getDetectorElement().getId().equals(option) || options.getValues().contains(permutationMap.getDetectorElement().getId())) {
                            String alreadyAddedElement = alreadyAdded.get(relation.getTargetElement().getRef().getId());
                            TNodeTemplate target = alreadyAddedElement == null ? addNodeFromRefinementStructureToDetector((TNodeTemplate) relation.getTargetElement().getRef(), permutation, alreadyAdded) : permutation.getDetector().getNodeTemplate(alreadyAddedElement);
                            ModelUtilities.createRelationshipTemplateAndAddToTopology(addedDetectorElement, target, relation.getType(), permutation.getDetector());
                        } else if (!options.getValues().contains(permutationMap.getDetectorElement().getId())) {
                            // Else if the target is part of the detector, add the relation between the
                            // added element and the detector element.
                            // No need to check instance of again, as we filter them in line 383.
                            TNodeTemplate target = (TNodeTemplate) permutationMap.getDetectorElement();
                            ModelUtilities.createRelationshipTemplateAndAddToTopology(addedDetectorElement, target, relation.getType(), permutation.getDetector());
                        }
                    });
                });
                // region handle ingoing relations in the detector
                for (TRelationshipTemplate relation : permutation.getDetector().getRelationshipTemplates()) {
                    if (relation.getTargetElement().getRef().getId().equals(option)) {
                        Optional<OTPermutationMapping> relationTarget = permutation.getPermutationMappings().stream().filter(permutationMap -> permutationMap.getDetectorElement().getId().equals(relation.getId())).filter(permutationMap -> permutationMap.getRefinementElement().getId().equals(refinementElement.getId())).findFirst();
                        long refinementEquivalents = permutation.getPermutationMappings().stream().filter(permutationMap -> permutationMap.getDetectorElement().getId().equals(option)).map(OTPrmMapping::getRefinementElement).distinct().count();
                        if (relationTarget.isPresent() || refinementEquivalents == 1) {
                            ModelUtilities.createRelationshipTemplateAndAddToTopology((TNodeTemplate) relation.getSourceElement().getRef(), addedDetectorElement, relation.getType(), permutation.getDetector());
                        }
                    }
                }
            // endregion
            });
            // region remove permuted
            if (permutation.getAttributeMappings() != null) {
                permutation.getRelationMappings().removeIf(map -> map.getDetectorElement().getId().equals(option));
            }
            if (permutation.getAttributeMappings() != null) {
                permutation.getAttributeMappings().removeIf(map -> map.getDetectorElement().getId().equals(option));
            }
            if (permutation.getDeploymentArtifactMappings() != null) {
                permutation.getDeploymentArtifactMappings().removeIf(map -> map.getDetectorElement().getId().equals(option));
            }
            permutation.getPermutationMappings().removeIf(permMap -> permMap.getDetectorElement().getId().equals(option) || permMap.getDetectorElement() instanceof TRelationshipTemplate && (((TRelationshipTemplate) permMap.getDetectorElement()).getSourceElement().getRef().getId().equals(option) || ((TRelationshipTemplate) permMap.getDetectorElement()).getTargetElement().getRef().getId().equals(option)));
            permutation.getDetector().getNodeTemplateOrRelationshipTemplate().removeIf(template -> template instanceof TRelationshipTemplate && (((TRelationshipTemplate) template).getSourceElement().getRef().getId().equals(option) || ((TRelationshipTemplate) template).getTargetElement().getRef().getId().equals(option)) || template.getId().equals(option));
        // endregion
        }
        try {
            RepositoryFactory.getRepository().setElement(permutationModelId, permutation);
        } catch (IOException e) {
            logger.error("Error while saving permutation!", e);
            break;
        }
    }
    return permutations;
}
Also used : Arrays(java.util.Arrays) RefinementUtils.getAllContentMappingsForRefinementNodeWithoutDetectorNode(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementUtils.getAllContentMappingsForRefinementNodeWithoutDetectorNode) TopologyFragmentRefinementModelId(org.eclipse.winery.model.ids.extensions.TopologyFragmentRefinementModelId) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) SerializationUtils(org.apache.commons.lang3.SerializationUtils) RefinementUtils.isStayPlaceholder(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementUtils.isStayPlaceholder) OTTopologyFragmentRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) RefinementUtils.addMutabilityMapping(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementUtils.addMutabilityMapping) RefinementUtils.getAllMappingsForDetectorNode(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementUtils.getAllMappingsForDetectorNode) PatternRefinementModelId(org.eclipse.winery.model.ids.extensions.PatternRefinementModelId) VersionSupport(org.eclipse.winery.model.version.VersionSupport) Map(java.util.Map) OTPermutationMapping(org.eclipse.winery.model.tosca.extensions.OTPermutationMapping) RefinementUtils.noMappingExistsForRefinementNodeExeptForGivenDetectorNode(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementUtils.noMappingExistsForRefinementNodeExeptForGivenDetectorNode) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) OTStayMapping(org.eclipse.winery.model.tosca.extensions.OTStayMapping) RefinementUtils.getStayAndPermutationMappings(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementUtils.getStayAndPermutationMappings) RefinementUtils.isStayingRefinementElement(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementUtils.isStayingRefinementElement) Logger(org.slf4j.Logger) Set(java.util.Set) IOException(java.io.IOException) RefinementUtils.permutabilityMappingExistsForDetectorElement(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementUtils.permutabilityMappingExistsForDetectorElement) TNodeType(org.eclipse.winery.model.tosca.TNodeType) Collectors(java.util.stream.Collectors) HasId(org.eclipse.winery.model.tosca.HasId) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) RefinementUtils.permutabilityMappingExistsForRefinementNode(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementUtils.permutabilityMappingExistsForRefinementNode) List(java.util.List) IRepository(org.eclipse.winery.repository.backend.IRepository) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) Sets(org.eclipse.collections.impl.factory.Sets) Optional(java.util.Optional) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) OTPrmMapping(org.eclipse.winery.model.tosca.extensions.OTPrmMapping) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) QName(javax.xml.namespace.QName) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) OTStringList(org.eclipse.winery.model.tosca.extensions.OTStringList) OTTopologyFragmentRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel) HashMap(java.util.HashMap) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) QName(javax.xml.namespace.QName) OTPrmMapping(org.eclipse.winery.model.tosca.extensions.OTPrmMapping) IOException(java.io.IOException) PatternRefinementModelId(org.eclipse.winery.model.ids.extensions.PatternRefinementModelId) OTStringList(org.eclipse.winery.model.tosca.extensions.OTStringList) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TopologyFragmentRefinementModelId(org.eclipse.winery.model.ids.extensions.TopologyFragmentRefinementModelId) IRepository(org.eclipse.winery.repository.backend.IRepository) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) OTPermutationMapping(org.eclipse.winery.model.tosca.extensions.OTPermutationMapping)

Example 14 with OTPermutationMapping

use of org.eclipse.winery.model.tosca.extensions.OTPermutationMapping in project winery by eclipse.

the class PermutationHelper method addSomePermutationMappings.

static void addSomePermutationMappings(OTPatternRefinementModel refinementModel) {
    OTPermutationMapping pattern2_to_node14 = new OTPermutationMapping.Builder("pm-2--14").setDetectorElement(refinementModel.getDetector().getNodeTemplate("2")).setRefinementElement(refinementModel.getRefinementStructure().getNodeTemplate("14")).build();
    OTPermutationMapping pattern3_to_node15 = new OTPermutationMapping.Builder("pm-3--15").setDetectorElement(refinementModel.getDetector().getNodeTemplate("3")).setRefinementElement(refinementModel.getRefinementStructure().getNodeTemplate("15")).build();
    OTPermutationMapping pattern3_to_node16 = new OTPermutationMapping.Builder("pm-3--16").setDetectorElement(refinementModel.getDetector().getNodeTemplate("3")).setRefinementElement(refinementModel.getRefinementStructure().getNodeTemplate("16")).build();
    ArrayList<OTPermutationMapping> permutationMaps = new ArrayList<>(Arrays.asList(pattern2_to_node14, pattern3_to_node15, pattern3_to_node16));
    refinementModel.setPermutationMappings(permutationMaps);
}
Also used : ArrayList(java.util.ArrayList) OTPermutationMapping(org.eclipse.winery.model.tosca.extensions.OTPermutationMapping)

Example 15 with OTPermutationMapping

use of org.eclipse.winery.model.tosca.extensions.OTPermutationMapping in project winery by eclipse.

the class PermutationHelper method generatePrmWithComplexRelationMaps2.

static OTPatternRefinementModel generatePrmWithComplexRelationMaps2() {
    /*
        ########                 ########        ######## 
        #  (1) #---------------> # (11) # -----> # (12) # 
        ########                 ########        ######## 
            |                    (2) |______________| (2)
            | (2)                   \/    
            |                    ########
            |                    # (13) #
            |                    ########
            |                       | (2)
           \/                      \/   
        ########---------------> ########
        #  (2) #                 # (14) #
        ########                 ########
                                     | (2)
                                    \/   
                                 ########
                                 # (15) #
                                 ########
         */
    TTopologyTemplate detector = generateDetectorWithTwoPatterns();
    // region refinement structure
    TNodeTemplate refinementNode_11 = new TNodeTemplate();
    refinementNode_11.setType("{http://ex.org}nodeType_11");
    refinementNode_11.setId("11");
    TNodeTemplate refinementNode_12 = new TNodeTemplate();
    refinementNode_12.setType("{http://ex.org}nodeType_12");
    refinementNode_12.setId("12");
    TNodeTemplate refinementNode_13 = new TNodeTemplate();
    refinementNode_13.setType("{http://ex.org}nodeType_13");
    refinementNode_13.setId("13");
    TNodeTemplate refinementNode_14 = new TNodeTemplate();
    refinementNode_14.setType("{http://ex.org}nodeType_14");
    refinementNode_14.setId("14");
    TNodeTemplate refinementNode_15 = new TNodeTemplate();
    refinementNode_15.setType("{http://ex.org}nodeType_15");
    refinementNode_15.setId("15");
    TRelationshipTemplate node11_hostedOn_node13 = ModelUtilities.createRelationshipTemplate(refinementNode_11, refinementNode_13, QName.valueOf("{http://ex.org}relType_hostedOn"));
    TRelationshipTemplate node12_hostedOn_node13 = ModelUtilities.createRelationshipTemplate(refinementNode_12, refinementNode_13, QName.valueOf("{http://ex.org}relType_hostedOn"));
    TRelationshipTemplate node13_hostedOn_node14 = ModelUtilities.createRelationshipTemplate(refinementNode_13, refinementNode_14, QName.valueOf("{http://ex.org}relType_hostedOn"));
    TRelationshipTemplate node14_hostedOn_node15 = ModelUtilities.createRelationshipTemplate(refinementNode_14, refinementNode_15, QName.valueOf("{http://ex.org}relType_hostedOn"));
    TRelationshipTemplate node11_connectsTo_node12 = ModelUtilities.createRelationshipTemplate(refinementNode_11, refinementNode_12, QName.valueOf("{http://ex.org}relType_connectsTo"));
    TTopologyTemplate refinementStructure = new TTopologyTemplate.Builder().addNodeTemplate(refinementNode_11).addNodeTemplate(refinementNode_12).addNodeTemplate(refinementNode_13).addNodeTemplate(refinementNode_14).addNodeTemplate(refinementNode_15).addRelationshipTemplate(node11_hostedOn_node13).addRelationshipTemplate(node12_hostedOn_node13).addRelationshipTemplate(node13_hostedOn_node14).addRelationshipTemplate(node14_hostedOn_node15).addRelationshipTemplate(node11_connectsTo_node12).build();
    // endregion
    // region mappings
    OTPermutationMapping pattern1_to_node11 = new OTPermutationMapping.Builder("pm-1--11").setRefinementElement(refinementNode_11).setDetectorElement(detector.getNodeTemplate("1")).build();
    OTPermutationMapping pattern2_to_node14 = new OTPermutationMapping.Builder("pm-2--14").setDetectorElement(detector.getNodeTemplate("2")).setRefinementElement(refinementNode_14).build();
    // endregion
    // region permutation mapping
    List<OTPermutationMapping> list = new ArrayList<>();
    list.add(pattern1_to_node11);
    list.add(pattern2_to_node14);
    return new OTPatternRefinementModel.Builder().setName("PrmWithComplexRelationMappings2").setTargetNamespace("http://ex.org").setDetector(detector).setRefinementStructure(refinementStructure).setPermutationMappings(list).build();
}
Also used : TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) ArrayList(java.util.ArrayList) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) OTPermutationMapping(org.eclipse.winery.model.tosca.extensions.OTPermutationMapping)

Aggregations

OTPermutationMapping (org.eclipse.winery.model.tosca.extensions.OTPermutationMapping)18 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)12 ArrayList (java.util.ArrayList)11 OTPatternRefinementModel (org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)10 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)9 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)9 OTStayMapping (org.eclipse.winery.model.tosca.extensions.OTStayMapping)7 OTRelationMapping (org.eclipse.winery.model.tosca.extensions.OTRelationMapping)6 Test (org.junit.jupiter.api.Test)6 List (java.util.List)5 OTAttributeMapping (org.eclipse.winery.model.tosca.extensions.OTAttributeMapping)5 Arrays (java.util.Arrays)4 QName (javax.xml.namespace.QName)4 OTStringList (org.eclipse.winery.model.tosca.extensions.OTStringList)4 OTTopologyFragmentRefinementModel (org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel)4 LinkedHashMap (java.util.LinkedHashMap)3 PermutationHelper.addAllPermutationMappings (org.eclipse.winery.model.adaptation.substitution.refinement.PermutationHelper.addAllPermutationMappings)3 PermutationHelper.addSomePermutationMappings (org.eclipse.winery.model.adaptation.substitution.refinement.PermutationHelper.addSomePermutationMappings)3 PermutationHelper.generateComplexPrmWithPatternSet (org.eclipse.winery.model.adaptation.substitution.refinement.PermutationHelper.generateComplexPrmWithPatternSet)3 PermutationHelper.generatePrmWithComplexRelationMaps (org.eclipse.winery.model.adaptation.substitution.refinement.PermutationHelper.generatePrmWithComplexRelationMaps)3