use of org.eclipse.winery.model.tosca.extensions.OTStayMapping in project winery by eclipse.
the class PatternRefinementTest method redirectStayMappings.
// endregion
// region ********** redirectStayMappings **********
@Test
void redirectStayMappings() {
setUp();
/*
input:
####### (1) #######
# (1) # <----- # (2) #
####### #######
| (2)
\/
#######
# (4) #
#######
expected output:
####### (1) ######## ########
# (1) # <----- # (10) # # (11) #
####### ######## ########
| (2) | (2)
+-------|------+
\/
#######
# (4) #
#######
*/
// region *** add stay mapping to PRM ***
TTopologyTemplate refinementTopology = candidateForTopology.getRefinementModel().getRefinementTopology();
TTopologyTemplate detector = candidateForTopology.getRefinementModel().getDetector();
refinementTopology.getNodeTemplateOrRelationshipTemplate().removeIf(template -> template.getId().equals("13") || template.getId().equals("1213"));
TNodeTemplate nt12 = refinementTopology.getNodeTemplate("12");
assertNotNull(nt12);
nt12.setType("{http://ex.org}nodeType_4");
TNodeTemplate nt4 = detector.getNodeTemplate("8");
OTStayMapping nt4staysAsNt12 = new OTStayMapping.Builder("stay1").setDetectorElement(nt4).setRefinementElement(nt12).build();
((OTPatternRefinementModel) candidateForTopology.getRefinementModel()).setStayMappings(Collections.singletonList(nt4staysAsNt12));
// endregion
// recreate the candidate
ToscaGraph topologyGraph = ToscaTransformer.createTOSCAGraph(topology2);
ToscaGraph detectorGraph = ToscaTransformer.createTOSCAGraph(detector);
GraphMapping<ToscaNode, ToscaEdge> mapping = new ToscaIsomorphismMatcher().findMatches(detectorGraph, topologyGraph, new ToscaTypeMatcher()).next();
candidateForTopology = new RefinementCandidate(candidateForTopology.getRefinementModel(), mapping, detectorGraph, 1);
PatternRefinement patternRefinement = new PatternRefinement();
patternRefinement.applyRefinement(candidateForTopology, topology2);
// region *** assertions ***
assertNotNull(topology2.getNodeTemplate("4"));
TRelationshipTemplate relation1012 = topology2.getRelationshipTemplate("1012");
assertNotNull(relation1012);
assertEquals("4", relation1012.getTargetElement().getRef().getId());
assertEquals("10", relation1012.getSourceElement().getRef().getId());
TRelationshipTemplate relation1112 = topology2.getRelationshipTemplate("1112");
assertNotNull(relation1112);
assertEquals("4", relation1112.getTargetElement().getRef().getId());
assertEquals("11", relation1112.getSourceElement().getRef().getId());
TRelationshipTemplate relation21 = topology2.getRelationshipTemplate("21");
assertNotNull(relation21);
assertEquals("1", relation21.getTargetElement().getRef().getId());
assertEquals("10", relation21.getSourceElement().getRef().getId());
// endregion
}
use of org.eclipse.winery.model.tosca.extensions.OTStayMapping 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);
}
use of org.eclipse.winery.model.tosca.extensions.OTStayMapping 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.OTStayMapping 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.OTStayMapping in project winery by eclipse.
the class PermutationGenerator method addNodeFromRefinementStructureToDetector.
private TNodeTemplate addNodeFromRefinementStructureToDetector(TNodeTemplate refinementElement, OTTopologyFragmentRefinementModel permutation, Map<String, String> alreadyAdded) {
TNodeTemplate clone = SerializationUtils.clone(refinementElement);
ModelUtilities.generateNewIdOfTemplate(clone, permutation.getDetector());
permutation.getDetector().addNodeTemplate(clone);
alreadyAdded.put(refinementElement.getId(), clone.getId());
if (permutation.getStayMappings() == null) {
permutation.setStayMappings(new ArrayList<>());
}
permutation.getStayMappings().add(new OTStayMapping(clone, refinementElement));
return clone;
}
Aggregations