Search in sources :

Example 1 with RefinementTopologyTemplateResource

use of org.eclipse.winery.repository.rest.resources.servicetemplates.topologytemplates.RefinementTopologyTemplateResource 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 2 with RefinementTopologyTemplateResource

use of org.eclipse.winery.repository.rest.resources.servicetemplates.topologytemplates.RefinementTopologyTemplateResource in project winery by eclipse.

the class TestRefinementModelResource method savePrmMappingTopology.

@PUT
@Path("graphicPrmTopology")
@Consumes(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("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")))));
        }
    }
    return new RefinementTopologyTemplateResource(this, this.getTRefinementModel(), GRAFIC_PRM_MODEL);
}
Also used : OTRelationMapping(org.eclipse.winery.model.tosca.extensions.OTRelationMapping) RefinementTopologyTemplateResource(org.eclipse.winery.repository.rest.resources.servicetemplates.topologytemplates.RefinementTopologyTemplateResource) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Aggregations

Consumes (javax.ws.rs.Consumes)2 PUT (javax.ws.rs.PUT)2 Path (javax.ws.rs.Path)2 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)2 OTRelationMapping (org.eclipse.winery.model.tosca.extensions.OTRelationMapping)2 RefinementTopologyTemplateResource (org.eclipse.winery.repository.rest.resources.servicetemplates.topologytemplates.RefinementTopologyTemplateResource)2 Produces (javax.ws.rs.Produces)1 OTAttributeMapping (org.eclipse.winery.model.tosca.extensions.OTAttributeMapping)1 OTBehaviorPatternMapping (org.eclipse.winery.model.tosca.extensions.OTBehaviorPatternMapping)1 OTDeploymentArtifactMapping (org.eclipse.winery.model.tosca.extensions.OTDeploymentArtifactMapping)1 OTPermutationMapping (org.eclipse.winery.model.tosca.extensions.OTPermutationMapping)1 OTStayMapping (org.eclipse.winery.model.tosca.extensions.OTStayMapping)1 OTPropertyKV (org.eclipse.winery.model.tosca.extensions.kvproperties.OTPropertyKV)1