use of org.opentosca.toscana.api.exceptions.TransformationAlreadyPresentException in project TOSCAna by StuPro-TOSCAna.
the class TransformationController method addTransformation.
/**
* Creates a new transformation for the given platform and csar <p>
* <p>
* Accessed with http call <code>PUT or POST /csars/{csar}/transformations/{platform}/create</code>
* <table summary="">
* <tr>
* <td>HTTP-Code</td>
* <td>Mime-Type</td>
* <td>Description (Returned if)</td>
* </tr>
* <tr>
* <td>200</td>
* <td>application/hal+json</td>
* <td>Returns a empty body if the transformation has been created</td>
* </tr>
* <tr>
* <td>404</td>
* <td>application/json</td>
* <td>Returns a error message if the csar is not found or if the given platform name is not found (see returned error
* message for details)</td>
* </tr>
* </table>
*/
@RequestMapping(path = "/{platform}/create", method = { RequestMethod.POST, RequestMethod.PUT }, produces = "application/hal+json")
@ApiOperation(value = "Create a new Transformation", tags = { "transformations" }, notes = "Creates a new transformation for the given CSAR and Platform " + "(If the platform does not exist and there is no other transformation with the same CSAR and Platform, " + "you have to delete the old transformation in this case)")
@ApiResponses({ @ApiResponse(code = 200, message = "The operation was executed successfully"), @ApiResponse(code = 400, message = "The transfomation could not get created because there already is a Transformation" + " of this CSAR on the given Platform", response = RestErrorResponse.class), @ApiResponse(code = 404, message = "There is no CSAR for the given identifier or the platform is not known.", response = RestErrorResponse.class) })
public ResponseEntity<Void> addTransformation(@ApiParam(value = "The unique identifier for the CSAR", required = true, example = "test") @PathVariable(name = "csarId") String name, @ApiParam(value = "The identifier for the platform", required = true, example = "kubernetes") @PathVariable(name = "platform") String platform) {
logger.info("Creating transformation for csar '{}' on '{}'", name, platform);
Csar csar = findByCsarId(name);
// Return bad Request if a transformation for this platform is already present
if (csar.getTransformation(platform).isPresent()) {
throw new TransformationAlreadyPresentException();
}
// Return 404 if the platform does not exist
Optional<Platform> optionalPlatform = platformService.findPlatformById(platform);
Platform p = optionalPlatform.orElseThrow(PlatformNotFoundException::new);
transformationService.createTransformation(csar, p);
return ResponseEntity.ok().build();
}
Aggregations