use of org.eclipse.winery.model.tosca.extensions.OTAttributeMapping 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"));
}
use of org.eclipse.winery.model.tosca.extensions.OTAttributeMapping 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);
}
}
use of org.eclipse.winery.model.tosca.extensions.OTAttributeMapping in project winery by eclipse.
the class PermutationHelper method generateComplexPrmWithPatternSet.
static OTPatternRefinementModel generateComplexPrmWithPatternSet() {
/* +------------------------+
| \|
########----------+ ######## ########
# (1) #---------------> # (11) # -----> # (12) #
######## ######## ########
| | (2) | (2)
| (2) \/ \/
\/ ######## ########
########---------------> # (13) #-------># (14) #
# (2) # ######## ########
########--------+ | (2) |
| | \/ |
| (2) +------> ######## |
\/ # (15) # (2) |
########---------------> ######## |
# (3) # | (2) |
######## \/ |
######## |
# (16) #<-----------+
########
*/
TTopologyTemplate detector = generateDetectorWithThreePatterns();
// 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");
TNodeTemplate refinementNode_16 = new TNodeTemplate();
refinementNode_16.setType("{http://ex.org}nodeType_16");
refinementNode_16.setId("16");
TRelationshipTemplate node11_connectsTo_node12 = ModelUtilities.createRelationshipTemplate(refinementNode_11, refinementNode_12, QName.valueOf("{http://ex.org}relType_connectsTo"));
TRelationshipTemplate node11_hostedOn_node13 = ModelUtilities.createRelationshipTemplate(refinementNode_11, refinementNode_13, QName.valueOf("{http://ex.org}relType_hostedOn"));
TRelationshipTemplate node12_hostedOn_node14 = ModelUtilities.createRelationshipTemplate(refinementNode_12, refinementNode_14, QName.valueOf("{http://ex.org}relType_hostedOn"));
TRelationshipTemplate node13_connectsTo_node14 = ModelUtilities.createRelationshipTemplate(refinementNode_13, refinementNode_14, QName.valueOf("{http://ex.org}relType_connectsTo"));
TRelationshipTemplate node13_hostedOn_node15 = ModelUtilities.createRelationshipTemplate(refinementNode_13, refinementNode_15, QName.valueOf("{http://ex.org}relType_hostedOn"));
TRelationshipTemplate node14_hostedOn_node16 = ModelUtilities.createRelationshipTemplate(refinementNode_14, refinementNode_16, QName.valueOf("{http://ex.org}relType_hostedOn"));
TRelationshipTemplate node15_hostedOn_node16 = ModelUtilities.createRelationshipTemplate(refinementNode_15, refinementNode_16, QName.valueOf("{http://ex.org}relType_hostedOn"));
TTopologyTemplate refinementStructure = new TTopologyTemplate.Builder().addNodeTemplate(refinementNode_11).addNodeTemplate(refinementNode_12).addNodeTemplate(refinementNode_13).addNodeTemplate(refinementNode_14).addNodeTemplate(refinementNode_15).addNodeTemplate(refinementNode_16).addRelationshipTemplate(node11_connectsTo_node12).addRelationshipTemplate(node11_hostedOn_node13).addRelationshipTemplate(node12_hostedOn_node14).addRelationshipTemplate(node13_connectsTo_node14).addRelationshipTemplate(node13_hostedOn_node15).addRelationshipTemplate(node14_hostedOn_node16).addRelationshipTemplate(node15_hostedOn_node16).build();
// endregion
// region mappings
OTRelationMapping pattern1_to_node11 = new OTRelationMapping.Builder("rm-1--11").setRelationType("{http://ex.org}relType_connectsTo").setDirection(OTRelationDirection.INGOING).setDetectorElement(detector.getNodeTemplate("1")).setRefinementElement(refinementNode_11).build();
OTDeploymentArtifactMapping pattern1_to_node12 = new OTDeploymentArtifactMapping.Builder("dam-1--12").setDetectorElement(detector.getNodeTemplate("1")).setRefinementElement(refinementNode_12).setArtifactType(QName.valueOf("{http://ex.org}artType_war")).build();
OTAttributeMapping pattern2_to_node13 = new OTAttributeMapping.Builder("am-2--13").setType(OTAttributeMappingType.ALL).setDetectorElement(detector.getNodeTemplate("2")).setRefinementElement(refinementNode_13).build();
OTRelationMapping pattern2_to_node15 = new OTRelationMapping.Builder("rm-2--15").setRelationType("{http://ex.org}relType_connectsTo").setDirection(OTRelationDirection.INGOING).setDetectorElement(detector.getNodeTemplate("2")).setRefinementElement(refinementNode_15).build();
OTRelationMapping pattern3_to_node15 = new OTRelationMapping.Builder("rm-3--15").setRelationType(QName.valueOf("{http://ex.org}relType_connectsTo")).setDirection(OTRelationDirection.INGOING).setDetectorElement(detector.getNodeTemplate("3")).setRefinementElement(refinementNode_15).build();
// endregion
// region relation mappings
ArrayList<OTRelationMapping> relationMappings = new ArrayList<>();
relationMappings.add(pattern1_to_node11);
relationMappings.add(pattern2_to_node15);
relationMappings.add(pattern3_to_node15);
return new OTPatternRefinementModel.Builder().setName("ComplexPrmWithPatternSet").setTargetNamespace("http://ex.org").setDetector(detector).setRefinementStructure(refinementStructure).setAttributeMappings(Collections.singletonList(pattern2_to_node13)).setRelationMappings(relationMappings).setDeploymentArtifactMappings(Collections.singletonList(pattern1_to_node12)).build();
}
Aggregations