use of org.eclipse.winery.model.tosca.TExportedOperation in project winery by eclipse.
the class InterfacesResource method onPost.
/**
* A special handling for TExportedInterface is required as this object uses IDREF, which must not be a string, but
* the real object when persisting.
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response onPost(TExportedInterface[] exportedInterfacesList) {
if (exportedInterfacesList == null) {
return Response.status(Response.Status.BAD_REQUEST).entity("a valid XML/JSON element has to be posted").build();
}
for (TExportedInterface exportedInterface : exportedInterfacesList) {
for (TExportedOperation exportedOperation : exportedInterface.getOperation()) {
if (exportedOperation.getNodeOperation() != null) {
final String nodeRef = (String) exportedOperation.getNodeOperation().getNodeRef();
final TNodeTemplate nodeTemplate = ((ServiceTemplateResource) res).getServiceTemplate().getTopologyTemplate().getNodeTemplates().stream().filter(node -> node.getId().contentEquals(nodeRef)).findFirst().get();
exportedOperation.getNodeOperation().setNodeRef(nodeTemplate);
} else if (exportedOperation.getRelationshipOperation() != null) {
final String relationshipRef = (String) exportedOperation.getRelationshipOperation().getRelationshipRef();
final TRelationshipTemplate relationshipTemplate = ((ServiceTemplateResource) res).getServiceTemplate().getTopologyTemplate().getRelationshipTemplates().stream().filter(relationship -> relationship.getId().contentEquals(relationshipRef)).findFirst().get();
exportedOperation.getRelationshipOperation().setRelationshipRef(relationshipTemplate);
} else if (exportedOperation.getPlan() != null) {
final String planRef = (String) exportedOperation.getPlan().getPlanRef();
final TPlan planTemplate = ((ServiceTemplateResource) res).getServiceTemplate().getPlans().stream().filter(relationship -> relationship.getId().contentEquals(planRef)).findFirst().get();
exportedOperation.getPlan().setPlanRef(planTemplate);
} else {
return Response.status(Response.Status.BAD_REQUEST).entity("No linked operation provided").build();
}
}
}
this.list.clear();
this.list.addAll(Arrays.asList(exportedInterfacesList));
return RestUtils.persist(this.res);
}
use of org.eclipse.winery.model.tosca.TExportedOperation in project winery by eclipse.
the class ToCanonical method convert.
private TExportedOperation convert(XTExportedOperation xml) {
TExportedOperation canonical = new TExportedOperation(xml.getName());
if (xml.getNodeOperation() != null) {
canonical.setNodeOperation(convert(xml.getNodeOperation()));
}
if (xml.getRelationshipOperation() != null) {
canonical.setRelationshipOperation(convert(xml.getRelationshipOperation()));
}
if (xml.getPlan() != null) {
TExportedOperation.Plan plan = new TExportedOperation.Plan();
if (xml.getPlan().getPlanRef() instanceof String) {
plan.setPlanRef(xml.getPlan().getPlanRef());
} else {
plan.setPlanRef(convert((XTPlan) xml.getPlan().getPlanRef()));
}
canonical.setPlan(plan);
}
return canonical;
}
Aggregations