Search in sources :

Example 1 with OTBehaviorPatternMapping

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

the class BehaviorPatternDetectionTest method addCompatibleBehaviorPatterns.

@Test
public void addCompatibleBehaviorPatterns() {
    List<TPolicy> behaviorPatterns = new ArrayList<>();
    behaviorPatterns.add(new TPolicy(new TPolicy.Builder(QName.valueOf("{patternNs}oneProp")).setName("oneProp")));
    TNodeTemplate detectorElement = new TNodeTemplate(new TNodeTemplate.Builder("detectorElement", QName.valueOf("{ns}patternType")).setPolicies(behaviorPatterns).setX("1").setY("1"));
    TNodeTemplate refinementElement = new TNodeTemplate(new TNodeTemplate.Builder("refinementElement", QName.valueOf("{ns}concreteType")).setX("1").setY("1"));
    LinkedHashMap<String, String> refinementProps = new LinkedHashMap<>();
    refinementProps.put("oneProp", "true");
    ModelUtilities.setPropertiesKV(refinementElement, refinementProps);
    List<TPolicy> stayingPolicies = new ArrayList<>();
    stayingPolicies.add(new TPolicy(new TPolicy.Builder(QName.valueOf("{ns}normalPolicy")).setName("normalPolicy")));
    TNodeTemplate stayingElement = new TNodeTemplate(new TNodeTemplate.Builder("stayingElement", QName.valueOf("{ns}concreteType")).setPolicies(stayingPolicies).setX("1").setY("1"));
    LinkedHashMap<String, String> stayingProps = new LinkedHashMap<>();
    stayingProps.put("oneProp", "false");
    ModelUtilities.setPropertiesKV(stayingElement, stayingProps);
    List<OTStayMapping> stayMappings = Collections.singletonList(new OTStayMapping(new OTStayMapping.Builder().setDetectorElement(detectorElement).setRefinementElement(refinementElement)));
    List<OTBehaviorPatternMapping> behaviorPatternMappings = Collections.singletonList(new OTBehaviorPatternMapping(new OTBehaviorPatternMapping.Builder("behaviorPatternMap0").setDetectorElement(detectorElement).setRefinementElement(refinementElement).setBehaviorPattern("oneProp").setProperty(new OTPropertyKV("oneProp", "true"))));
    TTopologyTemplate detector = new TTopologyTemplate();
    detector.addNodeTemplate(detectorElement);
    TTopologyTemplate refinementStructure = new TTopologyTemplate();
    refinementStructure.addNodeTemplate(refinementElement);
    OTPatternRefinementModel prm = new OTPatternRefinementModel(new OTPatternRefinementModel.Builder().setDetector(detector).setRefinementStructure(refinementStructure).setStayMappings(stayMappings).setBehaviorPatternMappings(behaviorPatternMappings));
    // needs to be swapped manually as only PRMs retrieved from repo are swapped automatically
    PatternDetectionUtils.swapDetectorWithRefinement(prm);
    TTopologyTemplate topology = new TTopologyTemplate();
    topology.addNodeTemplate(stayingElement);
    ToscaGraph topologyGraph = ToscaTransformer.createTOSCAGraph(topology);
    ToscaGraph detectorGraph = ToscaTransformer.createTOSCAGraph(prm.getDetector());
    IToscaMatcher matcher = new ToscaBehaviorPatternMatcher(prm, namespaceManager());
    ToscaIsomorphismMatcher isomorphismMatcher = new ToscaIsomorphismMatcher();
    Iterator<GraphMapping<ToscaNode, ToscaEdge>> matches = isomorphismMatcher.findMatches(detectorGraph, topologyGraph, matcher);
    RefinementCandidate refinementCandidate = new RefinementCandidate(prm, matches.next(), detectorGraph, 1);
    // 'normalPolicy' is not removed because not behavior pattern, 'oneProp' not present behavior pattern mapping doesn't match
    BehaviorPatternDetection behaviorPatternDetection = new BehaviorPatternDetection(new DefaultRefinementChooser());
    behaviorPatternDetection.applyRefinement(refinementCandidate, topology);
    assertEquals(topology.getNodeTemplateOrRelationshipTemplate().size(), 1);
    assertEquals(topology.getNodeTemplates().get(0).getId(), "stayingElement");
    List<TPolicy> policies = topology.getNodeTemplates().get(0).getPolicies();
    assertEquals(policies.size(), 1);
    assertEquals(policies.get(0).getName(), "normalPolicy");
    // 'normalPolicy' is not removed because not behavior pattern, 'oneProp' present behavior pattern mapping matches
    stayingProps.put("oneProp", "true");
    topology.getNodeTemplateOrRelationshipTemplate().clear();
    topology.addNodeTemplate(stayingElement);
    behaviorPatternDetection.applyRefinement(refinementCandidate, topology);
    assertEquals(topology.getNodeTemplateOrRelationshipTemplate().size(), 1);
    assertEquals(topology.getNodeTemplates().get(0).getId(), "stayingElement");
    policies = topology.getNodeTemplates().get(0).getPolicies();
    assertEquals(policies.size(), 2);
    assertTrue(policies.stream().anyMatch(policy -> policy.getName().equals("normalPolicy")));
    assertTrue(policies.stream().anyMatch(policy -> policy.getName().equals("oneProp")));
}
Also used : TPolicy(org.eclipse.winery.model.tosca.TPolicy) PatternDetectionUtils(org.eclipse.winery.topologygraph.matching.patterndetection.PatternDetectionUtils) GraphMapping(org.jgrapht.GraphMapping) IToscaMatcher(org.eclipse.winery.topologygraph.matching.IToscaMatcher) ToscaEdge(org.eclipse.winery.topologygraph.model.ToscaEdge) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) NamespaceProperties(org.eclipse.winery.repository.backend.filebased.NamespaceProperties) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) OTBehaviorPatternMapping(org.eclipse.winery.model.tosca.extensions.OTBehaviorPatternMapping) ToscaIsomorphismMatcher(org.eclipse.winery.topologygraph.matching.ToscaIsomorphismMatcher) Nullable(org.eclipse.jdt.annotation.Nullable) Map(java.util.Map) ToscaBehaviorPatternMatcher(org.eclipse.winery.topologygraph.matching.patterndetection.ToscaBehaviorPatternMatcher) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) OTStayMapping(org.eclipse.winery.model.tosca.extensions.OTStayMapping) Iterator(java.util.Iterator) DefaultRefinementChooser(org.eclipse.winery.model.adaptation.substitution.refinement.DefaultRefinementChooser) Collection(java.util.Collection) Test(org.junit.jupiter.api.Test) List(java.util.List) ToscaNode(org.eclipse.winery.topologygraph.model.ToscaNode) NamespaceManager(org.eclipse.winery.repository.backend.NamespaceManager) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) ToscaGraph(org.eclipse.winery.topologygraph.model.ToscaGraph) QName(javax.xml.namespace.QName) OTPropertyKV(org.eclipse.winery.model.tosca.extensions.kvproperties.OTPropertyKV) Collections(java.util.Collections) RefinementCandidate(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementCandidate) ToscaTransformer(org.eclipse.winery.topologygraph.transformation.ToscaTransformer) NonNull(org.eclipse.jdt.annotation.NonNull) ToscaGraph(org.eclipse.winery.topologygraph.model.ToscaGraph) RefinementCandidate(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementCandidate) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) ToscaIsomorphismMatcher(org.eclipse.winery.topologygraph.matching.ToscaIsomorphismMatcher) ToscaBehaviorPatternMatcher(org.eclipse.winery.topologygraph.matching.patterndetection.ToscaBehaviorPatternMatcher) IToscaMatcher(org.eclipse.winery.topologygraph.matching.IToscaMatcher) DefaultRefinementChooser(org.eclipse.winery.model.adaptation.substitution.refinement.DefaultRefinementChooser) OTStayMapping(org.eclipse.winery.model.tosca.extensions.OTStayMapping) TPolicy(org.eclipse.winery.model.tosca.TPolicy) OTPropertyKV(org.eclipse.winery.model.tosca.extensions.kvproperties.OTPropertyKV) OTBehaviorPatternMapping(org.eclipse.winery.model.tosca.extensions.OTBehaviorPatternMapping) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) GraphMapping(org.jgrapht.GraphMapping) Test(org.junit.jupiter.api.Test)

Example 2 with OTBehaviorPatternMapping

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

the class TopologyFragmentRefinementModelResource method savePrmMappingTopology.

@PUT
@Path("graphicPrmTopology")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Override
public TopologyTemplateResource savePrmMappingTopology(TTopologyTemplate topologyTemplate) {
    this.getTRefinementModel().resetAllMappings();
    RestUtils.persist(this);
    for (TRelationshipTemplate relTemplate : topologyTemplate.getRelationshipTemplates()) {
        String mappingId;
        // necessary for topologymodeler to create the IDs
        if (relTemplate.getId().startsWith("con")) {
            mappingId = relTemplate.getId().substring(relTemplate.getId().indexOf("_") + 1);
        } else {
            mappingId = relTemplate.getId();
        }
        if (relTemplate.getType().getLocalPart().startsWith("PermutationMapping")) {
            this.getPermutationMappings().addMapping(new OTPermutationMapping(new OTPermutationMapping.Builder(mappingId).setDetectorElement(relTemplate.getSourceElement().getRef()).setRefinementElement(relTemplate.getTargetElement().getRef())));
        }
        if (relTemplate.getType().getLocalPart().startsWith("RelationshipMapping")) {
            Map<String, String> propertiesMap = ((TEntityTemplate.WineryKVProperties) relTemplate.getProperties()).getKVProperties();
            this.getRelationMappings().addMapping(new OTRelationMapping(new OTRelationMapping.Builder(mappingId).setDetectorElement(relTemplate.getSourceElement().getRef()).setRefinementElement(relTemplate.getTargetElement().getRef()).setDirection(OTRelationDirection.fromValue(propertiesMap.get("direction"))).setRelationType(QName.valueOf(propertiesMap.get("applicableRelationshipType"))).setValidSourceOrTarget(QName.valueOf(propertiesMap.get("validEndpointType")))));
        }
        if (relTemplate.getType().getLocalPart().startsWith("StayMapping")) {
            this.getStayMappings().addMapping(new OTStayMapping(new OTStayMapping.Builder(mappingId).setDetectorElement(relTemplate.getSourceElement().getRef()).setRefinementElement(relTemplate.getTargetElement().getRef())));
        }
        if (relTemplate.getType().getLocalPart().startsWith("AttributeMapping")) {
            Map<String, String> propertiesMap = ((TEntityTemplate.WineryKVProperties) relTemplate.getProperties()).getKVProperties();
            this.getAttributeMappings().addMapping(new OTAttributeMapping(new OTAttributeMapping.Builder(mappingId).setDetectorElement(relTemplate.getSourceElement().getRef()).setRefinementElement(relTemplate.getTargetElement().getRef()).setType(OTAttributeMappingType.fromValue(propertiesMap.get("type"))).setDetectorProperty(propertiesMap.get("detectorProperty")).setRefinementProperty(propertiesMap.get("refinementProperty"))));
        }
        if (relTemplate.getType().getLocalPart().startsWith("DeploymentArtifactMapping")) {
            Map<String, String> propertiesMap = ((TEntityTemplate.WineryKVProperties) relTemplate.getProperties()).getKVProperties();
            this.getDeploymentArtifactMappings().addMapping(new OTDeploymentArtifactMapping(new OTDeploymentArtifactMapping.Builder(mappingId).setDetectorElement(relTemplate.getSourceElement().getRef()).setRefinementElement(relTemplate.getTargetElement().getRef()).setArtifactType(QName.valueOf(propertiesMap.get("requiredDeploymentArtifactType")))));
        }
        if (relTemplate.getType().getLocalPart().startsWith("BehaviorPatternMapping")) {
            Map<String, String> propertiesMap = ((TEntityTemplate.WineryKVProperties) relTemplate.getProperties()).getKVProperties();
            ((PatternRefinementModelResource) this).getBehaviorPatternMappings().addMapping(new OTBehaviorPatternMapping(new OTBehaviorPatternMapping.Builder(mappingId).setDetectorElement(relTemplate.getSourceElement().getRef()).setRefinementElement(relTemplate.getTargetElement().getRef()).setProperty(new OTPropertyKV(propertiesMap.get("refinementProperty"), propertiesMap.get("refinementPropertyValue"))).setBehaviorPattern(propertiesMap.get("behaviorPattern"))));
        }
    }
    return new RefinementTopologyTemplateResource(this, this.getTRefinementModel(), GRAFIC_PRM_MODEL);
}
Also used : OTDeploymentArtifactMapping(org.eclipse.winery.model.tosca.extensions.OTDeploymentArtifactMapping) RefinementTopologyTemplateResource(org.eclipse.winery.repository.rest.resources.servicetemplates.topologytemplates.RefinementTopologyTemplateResource) OTAttributeMapping(org.eclipse.winery.model.tosca.extensions.OTAttributeMapping) OTRelationMapping(org.eclipse.winery.model.tosca.extensions.OTRelationMapping) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) 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) OTPermutationMapping(org.eclipse.winery.model.tosca.extensions.OTPermutationMapping) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 3 with OTBehaviorPatternMapping

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

the class ToscaBehaviorPatternMatcherTest method propertiesCompatible.

@Test
public void propertiesCompatible() {
    LinkedHashMap<String, String> refinementProps = new LinkedHashMap<>();
    refinementProps.put("null", null);
    refinementProps.put("empty", "");
    refinementProps.put("star", "*");
    refinementProps.put("match", "this has to match");
    refinementProps.put("ignoreCase", "THIS HAS TO MATCH INDEPENDENT OF CASE");
    LinkedHashMap<String, String> candidateProps = new LinkedHashMap<>();
    candidateProps.put("null", "does not have to be null");
    candidateProps.put("empty", "does not have to be empty");
    candidateProps.put("star", "this has to be non-null and non-empty");
    candidateProps.put("match", "this has to match");
    candidateProps.put("ignoreCase", "this has to match independent of case");
    TNodeTemplate refinement = new TNodeTemplate();
    refinement.setId("refinement");
    ModelUtilities.setPropertiesKV(refinement, refinementProps);
    ToscaNode refinementNode = new ToscaNode();
    refinementNode.setNodeTemplate(refinement);
    TNodeTemplate candidate = new TNodeTemplate();
    candidate.setId("candidate");
    ModelUtilities.setPropertiesKV(candidate, candidateProps);
    ToscaNode candidateNode = new ToscaNode();
    candidateNode.setNodeTemplate(candidate);
    OTPatternRefinementModel prm = new OTPatternRefinementModel();
    prm.setRefinementTopology(new TTopologyTemplate(new TTopologyTemplate.Builder().addNodeTemplate(refinement)));
    // needs to be swapped manually as only prms retrieved from repo are swapped automatically
    PatternDetectionUtils.swapDetectorWithRefinement(prm);
    ToscaBehaviorPatternMatcher matcher = new ToscaBehaviorPatternMatcher(prm, null);
    assertTrue(matcher.propertiesCompatible(refinementNode, candidateNode));
    refinementProps.put("doesNotMatch", "something");
    candidateProps.put("doesNotMatch", "something else");
    assertFalse(matcher.propertiesCompatible(refinementNode, candidateNode));
    // props with behavior pattern mappings can be ignored
    List<OTBehaviorPatternMapping> behaviorPatternMappings = new ArrayList<>();
    OTBehaviorPatternMapping behaviorPatternMapping = new OTBehaviorPatternMapping(new OTBehaviorPatternMapping.Builder("behaviorPatternMap0").setRefinementElement(refinement).setProperty(new OTPropertyKV("doesNotMatch", "")));
    behaviorPatternMappings.add((OTBehaviorPatternMapping) PatternDetectionUtils.swapDetectorWithRefinement(behaviorPatternMapping));
    prm.setBehaviorPatternMappings(behaviorPatternMappings);
    assertTrue(matcher.propertiesCompatible(refinementNode, candidateNode));
    candidateProps.put("empty", "");
    assertTrue(matcher.propertiesCompatible(refinementNode, candidateNode));
    candidateProps.put("star", null);
    assertFalse(matcher.propertiesCompatible(refinementNode, candidateNode));
    candidateProps.put("star", "");
    assertFalse(matcher.propertiesCompatible(refinementNode, candidateNode));
}
Also used : ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ToscaNode(org.eclipse.winery.topologygraph.model.ToscaNode) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) OTPropertyKV(org.eclipse.winery.model.tosca.extensions.kvproperties.OTPropertyKV) OTBehaviorPatternMapping(org.eclipse.winery.model.tosca.extensions.OTBehaviorPatternMapping) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) Test(org.junit.jupiter.api.Test)

Example 4 with OTBehaviorPatternMapping

use of org.eclipse.winery.model.tosca.extensions.OTBehaviorPatternMapping 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 5 with OTBehaviorPatternMapping

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

the class RefinementTopologyTemplateResource method createRelationshipsForMappings.

/**
 * convert mappings into Relationship for use in grafic prm modeling
 */
private void createRelationshipsForMappings(OTRefinementModel refinementModel) {
    for (OTPrmMapping mapping : getAllMappings(refinementModel)) {
        TRelationshipTemplate.Builder builder = new TRelationshipTemplate.Builder("con_" + mapping.getId(), QName.valueOf("{http://opentosca.org/prmMappingTypes}" + mapping.getId().substring(0, mapping.getId().indexOf("_"))), new TNodeTemplate(mapping.getDetectorElement().getId()), new TNodeTemplate(mapping.getRefinementElement().getId()));
        if (mapping instanceof OTPermutationMapping) {
            builder.setName("PermutationMapping");
        }
        if (mapping instanceof OTRelationMapping) {
            builder.setName("RelationshipMapping");
            LinkedHashMap<String, String> kvproperties = new LinkedHashMap<>();
            kvproperties.put("direction", ((OTRelationMapping) mapping).getDirection().value());
            kvproperties.put("applicableRelationshipType", ((OTRelationMapping) mapping).getRelationType().toString());
            kvproperties.put("validEndpointType", ((OTRelationMapping) mapping).getValidSourceOrTarget().toString());
            TEntityTemplate.WineryKVProperties properties = new TEntityTemplate.WineryKVProperties();
            properties.setKVProperties(kvproperties);
            builder.setProperties(properties);
        }
        if (mapping instanceof OTStayMapping) {
            builder.setName("StayMapping");
        }
        if (mapping instanceof OTAttributeMapping) {
            builder.setName("AttributeMapping");
            LinkedHashMap<String, String> kvproperties = new LinkedHashMap<>();
            kvproperties.put("type", ((OTAttributeMapping) mapping).getType().value());
            kvproperties.put("detectorProperty", ((OTAttributeMapping) mapping).getDetectorProperty());
            kvproperties.put("refinementProperty", ((OTAttributeMapping) mapping).getRefinementProperty());
            TEntityTemplate.WineryKVProperties properties = new TEntityTemplate.WineryKVProperties();
            properties.setKVProperties(kvproperties);
            builder.setProperties(properties);
        }
        if (mapping instanceof OTDeploymentArtifactMapping) {
            builder.setName("DeploymentArtifactMapping");
            LinkedHashMap<String, String> kvproperties = new LinkedHashMap<>();
            kvproperties.put("requiredDeploymentArtifactType", ((OTDeploymentArtifactMapping) mapping).getArtifactType().toString());
            TEntityTemplate.WineryKVProperties properties = new TEntityTemplate.WineryKVProperties();
            properties.setKVProperties(kvproperties);
            builder.setProperties(properties);
        }
        if (mapping instanceof OTBehaviorPatternMapping) {
            builder.setName("BehaviorPatternMapping");
            LinkedHashMap<String, String> kvproperties = new LinkedHashMap<>();
            kvproperties.put("refinementProperty", ((OTBehaviorPatternMapping) mapping).getProperty().getKey());
            kvproperties.put("refinementPropertyValue", ((OTBehaviorPatternMapping) mapping).getProperty().getValue());
            kvproperties.put("behaviorPattern", ((OTBehaviorPatternMapping) mapping).getBehaviorPattern());
            TEntityTemplate.WineryKVProperties properties = new TEntityTemplate.WineryKVProperties();
            properties.setKVProperties(kvproperties);
            builder.setProperties(properties);
        }
        TRelationshipTemplate templateForMapping = new TRelationshipTemplate(builder);
        prmModellingTopologyTemplate.addRelationshipTemplate(templateForMapping);
    }
}
Also used : OTDeploymentArtifactMapping(org.eclipse.winery.model.tosca.extensions.OTDeploymentArtifactMapping) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) OTPrmMapping(org.eclipse.winery.model.tosca.extensions.OTPrmMapping) LinkedHashMap(java.util.LinkedHashMap) OTAttributeMapping(org.eclipse.winery.model.tosca.extensions.OTAttributeMapping) OTRelationMapping(org.eclipse.winery.model.tosca.extensions.OTRelationMapping) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) OTStayMapping(org.eclipse.winery.model.tosca.extensions.OTStayMapping) OTBehaviorPatternMapping(org.eclipse.winery.model.tosca.extensions.OTBehaviorPatternMapping) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) OTPermutationMapping(org.eclipse.winery.model.tosca.extensions.OTPermutationMapping)

Aggregations

OTBehaviorPatternMapping (org.eclipse.winery.model.tosca.extensions.OTBehaviorPatternMapping)6 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)5 OTStayMapping (org.eclipse.winery.model.tosca.extensions.OTStayMapping)5 OTPropertyKV (org.eclipse.winery.model.tosca.extensions.kvproperties.OTPropertyKV)5 LinkedHashMap (java.util.LinkedHashMap)4 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)4 OTPatternRefinementModel (org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)4 ArrayList (java.util.ArrayList)3 OTAttributeMapping (org.eclipse.winery.model.tosca.extensions.OTAttributeMapping)3 OTDeploymentArtifactMapping (org.eclipse.winery.model.tosca.extensions.OTDeploymentArtifactMapping)3 OTPermutationMapping (org.eclipse.winery.model.tosca.extensions.OTPermutationMapping)3 OTRelationMapping (org.eclipse.winery.model.tosca.extensions.OTRelationMapping)3 ToscaNode (org.eclipse.winery.topologygraph.model.ToscaNode)3 Test (org.junit.jupiter.api.Test)3 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Map (java.util.Map)2 QName (javax.xml.namespace.QName)2