Search in sources :

Example 1 with HiddenResources

use of org.opentosca.toscana.api.docs.HiddenResources in project TOSCAna by StuPro-TOSCAna.

the class PlatformController method getPlatforms.

/**
 *     Lists all Supported Platforms (HTTP Response Method).
 *     <p>
 *     It handles the <code>/platforms</code> Request
 *     <p>
 *     Always responds with HTTP-Code 200 (application/hal+json)
 */
@ApiOperation(value = "List all supported Platforms", notes = "Returns a HAL resource (_embedded) containing all " + "Platforms supported by this transformer", code = 200, response = PlatformResources.class)
@RequestMapping(path = "", method = RequestMethod.GET, produces = "application/hal+json")
public ResponseEntity<Resources<PlatformResponse>> getPlatforms() {
    Link selfLink = linkTo(methodOn(PlatformController.class).getPlatforms()).withSelfRel();
    ArrayList<PlatformResponse> responses = new ArrayList<>();
    for (Platform platform : platformService.getSupportedPlatforms()) {
        logger.info("Adding Platform {} to response ", platform.id);
        PlatformResponse res = getPlatformResource(platform);
        responses.add(res);
    }
    Resources<PlatformResponse> resources = new HiddenResources<>(responses, selfLink);
    return ResponseEntity.ok(resources);
}
Also used : HiddenResources(org.opentosca.toscana.api.docs.HiddenResources) Platform(org.opentosca.toscana.core.transformation.platform.Platform) ArrayList(java.util.ArrayList) PlatformResponse(org.opentosca.toscana.api.model.PlatformResponse) Link(org.springframework.hateoas.Link) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with HiddenResources

use of org.opentosca.toscana.api.docs.HiddenResources in project TOSCAna by StuPro-TOSCAna.

the class CsarController method listCSARs.

/**
 *     Responds with a list of csars stored on the transformer.
 *     <p>
 *     This always responds with HTTP-Code 200 (application/hal+json)
 */
@ApiOperation(value = "List all CSARs stored on the server", notes = "Returns a Hypermedia Resource containing all CSARs" + " that have been uploaded to the server and did not get removed", response = CsarResources.class, produces = "application/hal+json")
@RequestMapping(path = "", method = RequestMethod.GET, produces = "application/hal+json")
public ResponseEntity<Resources<CsarResponse>> listCSARs() {
    Link selfLink = linkTo(methodOn(CsarController.class).listCSARs()).withSelfRel();
    List<CsarResponse> responses = new ArrayList<>();
    for (Csar csar : csarService.getCsars()) {
        responses.add(new CsarResponse(csar.getIdentifier(), csar.getLifecyclePhases()));
    }
    Resources<CsarResponse> csarResources = new HiddenResources<>(responses, selfLink);
    return ResponseEntity.ok().body(csarResources);
}
Also used : Csar(org.opentosca.toscana.core.csar.Csar) HiddenResources(org.opentosca.toscana.api.docs.HiddenResources) ArrayList(java.util.ArrayList) CsarResponse(org.opentosca.toscana.api.model.CsarResponse) Link(org.springframework.hateoas.Link) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with HiddenResources

use of org.opentosca.toscana.api.docs.HiddenResources in project TOSCAna by StuPro-TOSCAna.

the class TransformationController method getCSARTransformations.

/**
 *     This Request Returns a list of all transformations belonging to a csar.
 *     <p>
 *     Accessed with http call <code>GET /csars/{csar}/transformations/</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 the resource (list) of all transformations that belong to this given csar</td>
 *     </tr>
 *     <tr>
 *     <td>404</td>
 *     <td>application/json</td>
 *     <td>Returns a error message if the csar is not found (see returned error message for details)</td>
 *     </tr>
 *     </table>
 */
@RequestMapping(path = "", method = RequestMethod.GET, produces = "application/hal+json")
@ApiOperation(value = "List all transformations of a CSAR", tags = { "transformations", "csars" }, notes = "Returns a HAL-Resources list containing all Transformations for a specific CSAR")
@ApiResponses({ @ApiResponse(code = 200, message = "The operation was executed successfully", response = TransformationResources.class), @ApiResponse(code = 404, message = "There is no CSAR for the given identifier", response = RestErrorResponse.class) })
public ResponseEntity<Resources<TransformationResponse>> getCSARTransformations(@ApiParam(value = "The unique identifier for the CSAR", required = true, example = "test") @PathVariable(name = "csarId") String name) {
    Csar csar = findByCsarId(name);
    Link selfLink = linkTo(methodOn(TransformationController.class).getCSARTransformations(name)).withSelfRel().expand(name);
    List<TransformationResponse> transformations = new ArrayList<>();
    for (Map.Entry<String, Transformation> entry : csar.getTransformations().entrySet()) {
        transformations.add(new TransformationResponse(entry.getValue().getLifecyclePhases(), entry.getValue().getState(), entry.getKey(), csar.getIdentifier()));
    }
    Resources<TransformationResponse> resources = new HiddenResources<>(transformations, selfLink);
    return ResponseEntity.ok(resources);
}
Also used : Csar(org.opentosca.toscana.core.csar.Csar) Transformation(org.opentosca.toscana.core.transformation.Transformation) HiddenResources(org.opentosca.toscana.api.docs.HiddenResources) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) Link(org.springframework.hateoas.Link) TransformationResponse(org.opentosca.toscana.api.model.TransformationResponse) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)3 ArrayList (java.util.ArrayList)3 HiddenResources (org.opentosca.toscana.api.docs.HiddenResources)3 Link (org.springframework.hateoas.Link)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 Csar (org.opentosca.toscana.core.csar.Csar)2 ApiResponses (io.swagger.annotations.ApiResponses)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CsarResponse (org.opentosca.toscana.api.model.CsarResponse)1 PlatformResponse (org.opentosca.toscana.api.model.PlatformResponse)1 TransformationResponse (org.opentosca.toscana.api.model.TransformationResponse)1 Transformation (org.opentosca.toscana.core.transformation.Transformation)1 Platform (org.opentosca.toscana.core.transformation.platform.Platform)1