use of org.eclipse.winery.model.tosca.TEntityTemplate in project winery by eclipse.
the class PropertyMappingsResource method onPost.
@ApiOperation(value = "Creates or updates a property mapping with the given fields")
@POST
@Consumes(MediaType.APPLICATION_JSON)
public // @formatter:off
Response onPost(PropertyMapping apiPropertyMapping) {
// @formatter:on
if (StringUtils.isEmpty(apiPropertyMapping.serviceTemplatePropertyRef)) {
return Response.status(Status.BAD_REQUEST).entity("serviceTemplatePropertyRef must not be empty").build();
}
if (StringUtils.isEmpty(apiPropertyMapping.targetObjectRef)) {
return Response.status(Status.BAD_REQUEST).entity("targetObjectRef must not be empty").build();
}
if (StringUtils.isEmpty(apiPropertyMapping.targetPropertyRef)) {
return Response.status(Status.BAD_REQUEST).entity("targetPropertyRef must not be empty").build();
}
TEntityTemplate template = ModelUtilities.findNodeTemplateOrRequirementOfNodeTemplateOrCapabilityOfNodeTemplateOrRelationshipTemplate(this.res.getServiceTemplate().getTopologyTemplate(), apiPropertyMapping.targetObjectRef);
if (template == null) {
return Response.status(Status.BAD_REQUEST).entity("targetObjectRef " + apiPropertyMapping.targetObjectRef + " could not be resolved.").build();
}
// replace propertyMapping if it exists
for (TPropertyMapping propertyMapping : this.propertyMappings) {
if (propertyMapping.getServiceTemplatePropertyRef().equals(apiPropertyMapping.serviceTemplatePropertyRef)) {
// we found a property with the same mapping
// just update it ...
this.updatePropertyMapping(propertyMapping, apiPropertyMapping.serviceTemplatePropertyRef, template, apiPropertyMapping.targetPropertyRef);
// ... and finish processing
return RestUtils.persist(this.res);
}
}
// the property mapping didn't exist,
// we create a new one
this.propertyMappings.add(new TPropertyMapping(apiPropertyMapping.serviceTemplatePropertyRef, template, apiPropertyMapping.targetPropertyRef));
return RestUtils.persist(this.res);
}
use of org.eclipse.winery.model.tosca.TEntityTemplate in project winery by eclipse.
the class PermutationMappingsResource method addPermutationMapping.
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public List<OTPermutationMapping> addPermutationMapping(PrmPermutationMappingApiData mapping) {
TEntityTemplate detectorElement = this.res.getDetectorResource().getTopologyTemplate().getNodeTemplate(mapping.detectorElement);
TEntityTemplate refinementElement = this.res.getRefinementTopologyResource().getTopologyTemplate().getNodeTemplate(mapping.refinementElement);
return this.addMapping(mapping.createPermutationMapping(detectorElement, refinementElement));
}
use of org.eclipse.winery.model.tosca.TEntityTemplate in project winery by eclipse.
the class StayMappingsResource method addPropertyMappingFromApi.
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public List<OTStayMapping> addPropertyMappingFromApi(PrmStayMappingApiData mapping) {
TEntityTemplate detectorElement = this.res.getDetectorResource().getTopologyTemplate().getNodeTemplateOrRelationshipTemplate().stream().filter(element -> element.getId().equals(mapping.detectorElement)).findFirst().orElseThrow(IllegalArgumentException::new);
TEntityTemplate refinementElement = this.res.getRefinementTopologyResource().getTopologyTemplate().getNodeTemplateOrRelationshipTemplate().stream().filter(element -> element.getId().equals(mapping.refinementElement)).findFirst().orElseThrow(IllegalArgumentException::new);
return this.addMapping(mapping.createOTPrmStayMapping(detectorElement, refinementElement));
}
use of org.eclipse.winery.model.tosca.TEntityTemplate in project winery by eclipse.
the class BehaviorPatternMappingsResource method addPropertyMappingFromApi.
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public List<OTBehaviorPatternMapping> addPropertyMappingFromApi(PrmBehaviorPatternMappingApiData mapping) {
TEntityTemplate detectorElement = this.res.getDetectorResource().getTopologyTemplate().getNodeTemplateOrRelationshipTemplate().stream().filter(entityTemplate -> entityTemplate.getId().equals(mapping.detectorElement)).findFirst().orElse(null);
TEntityTemplate refinementElement = this.res.getRefinementTopologyResource().getTopologyTemplate().getNodeTemplateOrRelationshipTemplate().stream().filter(entityTemplate -> entityTemplate.getId().equals(mapping.refinementElement)).findFirst().orElse(null);
return this.addMapping(mapping.createBehaviorPatternMapping(detectorElement, mapping.behaviorPattern, refinementElement));
}
use of org.eclipse.winery.model.tosca.TEntityTemplate in project winery by eclipse.
the class ModelUtilities method patchAnyAttributes.
/**
* When sending JSON to the server, the content of "any" is a String and not some JSON data structure. To be able to
* save it as XML, we have to "objectize" the content of Any
*
* @param templates The templates (node, relationship) to update. The content of the given collection is modified.
* @throws IllegalStateException if DocumentBuilder could not initialize
* @throws IOException if something goes wrong during parsing
*/
public static void patchAnyAttributes(Collection<? extends TEntityTemplate> templates) throws IOException {
Map<QName, String> tempConvertedOtherAttributes = new HashMap<>();
for (TEntityTemplate template : templates) {
// Convert the wrong QName created by the JSON serialization back to a right QName
for (Map.Entry<QName, String> otherAttribute : template.getOtherAttributes().entrySet()) {
QName qName;
String localPart = otherAttribute.getKey().getLocalPart();
if (localPart.startsWith("{")) {
// QName is stored as plain string - this is the case when nested in "any"
qName = QName.valueOf(localPart);
} else {
// sometimes, the QName is retrieved properly. So, we just keep it.
// This is the case when directly nested in nodetemplate JSON.
qName = new QName(otherAttribute.getKey().getNamespaceURI(), localPart);
}
tempConvertedOtherAttributes.put(qName, otherAttribute.getValue());
}
template.getOtherAttributes().clear();
template.getOtherAttributes().putAll(tempConvertedOtherAttributes);
tempConvertedOtherAttributes.clear();
// Convert the String created by the JSON serialization back to an XML dom document
TEntityTemplate.Properties properties = template.getProperties();
if (properties instanceof TEntityTemplate.XmlProperties) {
TEntityTemplate.XmlProperties props = (TEntityTemplate.XmlProperties) properties;
props.setAny(patchAnyItem(props.getAny()));
}
}
}
Aggregations