Search in sources :

Example 61 with ApiResponse

use of io.swagger.v3.oas.annotations.responses.ApiResponse in project oxTrust by GluuFederation.

the class PeopleWebResource method getPersonByInum.

@GET
@Path(ApiConstants.INUM_PARAM_PATH)
@Operation(summary = "Get person by inum", description = "Get a person by inum")
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = GluuPersonApi.class)), description = "Success"), @ApiResponse(responseCode = "500", description = "Server error") })
@ProtectedApi(scopes = { READ_ACCESS })
public Response getPersonByInum(@PathParam(ApiConstants.INUM) @NotNull String inum) {
    log(logger, "Get person " + inum);
    try {
        Objects.requireNonNull(inum, "inum should not be null");
        GluuCustomPerson person = personService.getPersonByInum(inum);
        if (person != null) {
            return Response.ok(convert(Arrays.asList(person)).get(0)).build();
        } else {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
    } catch (Exception e) {
        log(logger, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 62 with ApiResponse

use of io.swagger.v3.oas.annotations.responses.ApiResponse in project oxTrust by GluuFederation.

the class UmaResourceWebResource method addClientToUmaResource.

@POST
@Operation(summary = "Add UMA resource client", description = "add client to uma resource")
@ApiResponses(value = { @ApiResponse(responseCode = "201", content = @Content(schema = @Schema(implementation = UmaResource.class)), description = "Success"), @ApiResponse(responseCode = "500", description = "Server error") })
@Path(ApiConstants.ID_PARAM_PATH + ApiConstants.CLIENTS + ApiConstants.INUM_PARAM_PATH)
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response addClientToUmaResource(@PathParam(ApiConstants.ID) @NotNull String id, @PathParam(ApiConstants.INUM) @NotNull String clientInum) {
    try {
        log(logger, "Add client " + clientInum + " to uma resource " + id);
        Objects.requireNonNull(id, "Uma id should not be null");
        Objects.requireNonNull(clientInum, "Client inum should not be null");
        List<UmaResource> resources = umaResourcesService.findResourcesById(id);
        OxAuthClient client = clientService.getClientByInum(clientInum);
        if (resources != null && !resources.isEmpty() && client != null) {
            UmaResource umaResource = resources.get(0);
            List<String> clientsDn = new ArrayList<String>();
            if (umaResource.getClients() != null) {
                clientsDn.addAll(umaResource.getClients());
            }
            clientsDn.add(clientService.getDnForClient(clientInum));
            umaResource.setClients(clientsDn);
            umaResourcesService.updateResource(umaResource);
            return Response.status(Response.Status.CREATED).entity(umaResourcesService.findResourcesById(id).get(0)).build();
        } else {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
    } catch (Exception e) {
        log(logger, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : OxAuthClient(org.gluu.oxtrust.model.OxAuthClient) ArrayList(java.util.ArrayList) UmaResource(org.gluu.oxauth.model.uma.persistence.UmaResource) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 63 with ApiResponse

use of io.swagger.v3.oas.annotations.responses.ApiResponse in project oxTrust by GluuFederation.

the class UmaResourceWebResource method addScopeToUmaResource.

@POST
@Operation(summary = "Add UMA resource scope", description = "add scope to uma resource")
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = UmaResource.class)), description = "Success"), @ApiResponse(responseCode = "500", description = "Server error") })
@Path(ApiConstants.ID_PARAM_PATH + ApiConstants.SCOPES + ApiConstants.INUM_PARAM_PATH)
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response addScopeToUmaResource(@PathParam(ApiConstants.ID) @NotNull String id, @PathParam(ApiConstants.INUM) @NotNull String scopeInum) {
    log(logger, "Add scope " + scopeInum + " to uma resource " + id);
    try {
        Objects.requireNonNull(id, "Uma id should not be null");
        Objects.requireNonNull(scopeInum, "scope inum should not be null");
        List<UmaResource> resources = umaResourcesService.findResourcesById(id);
        Scope umaScope = scopeDescriptionService.getUmaScopeByInum(scopeInum);
        if (resources != null && !resources.isEmpty() && umaScope != null) {
            UmaResource umaResource = resources.get(0);
            List<String> scopesDn = new ArrayList<String>();
            if (umaResource.getScopes() != null) {
                scopesDn.addAll(umaResource.getScopes());
            }
            scopesDn.add(scopeDescriptionService.getDnForScope(scopeInum));
            umaResource.setScopes(scopesDn);
            umaResourcesService.updateResource(umaResource);
            return Response.ok(umaResourcesService.findResourcesById(id).get(0)).build();
        } else {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
    } catch (Exception e) {
        log(logger, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : Scope(org.oxauth.persistence.model.Scope) ArrayList(java.util.ArrayList) UmaResource(org.gluu.oxauth.model.uma.persistence.UmaResource) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 64 with ApiResponse

use of io.swagger.v3.oas.annotations.responses.ApiResponse in project snow-owl by b2ihealthcare.

the class SnomedClassificationRestService method beginClassification.

@Operation(summary = "Start a classification on a branch", description = "Classification runs are async jobs. The call to this method immediately returns with a unique URL " + "pointing to the classification run.<p>The URL can be used to fetch the state of the classification " + "to determine whether it's completed or not.")
@ApiResponses({ @ApiResponse(responseCode = "201", description = "Created"), @ApiResponse(responseCode = "404", description = "Branch not found") })
@PostMapping(consumes = { AbstractRestService.JSON_MEDIA_TYPE })
@ResponseStatus(value = HttpStatus.CREATED)
public Promise<ResponseEntity<?>> beginClassification(@Parameter(description = "Classification parameters") @RequestBody final ClassificationRunRestInput request, @RequestHeader(value = X_AUTHOR, required = false) final String author) {
    ApiValidation.checkInput(request);
    final UriComponentsBuilder linkTo = MvcUriComponentsBuilder.fromController(SnomedClassificationRestService.class);
    return ClassificationRequests.prepareCreateClassification().setReasonerId(request.getReasonerId()).setUserId(author).build(request.getPath()).execute(getBus()).then(id -> {
        final URI resourceUri = linkTo.pathSegment(id).build().toUri();
        return ResponseEntity.created(resourceUri).build();
    });
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) MvcUriComponentsBuilder(org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder) URI(java.net.URI) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 65 with ApiResponse

use of io.swagger.v3.oas.annotations.responses.ApiResponse in project snow-owl by b2ihealthcare.

the class SnomedDescriptionRestService method create.

@Operation(summary = "Create Description", description = "Creates a new Description directly on a version.")
@ApiResponses({ @ApiResponse(responseCode = "201", description = "Created"), @ApiResponse(responseCode = "404", description = "Branch not found") })
@PostMapping(consumes = { AbstractRestService.JSON_MEDIA_TYPE })
@ResponseStatus(HttpStatus.CREATED)
public ResponseEntity<Void> create(@Parameter(description = "The resource path", required = true) @PathVariable(value = "path") final String path, @Parameter(description = "Description parameters") @RequestBody final SnomedResourceRequest<SnomedDescriptionRestInput> body, @RequestHeader(value = X_AUTHOR, required = false) final String author) {
    final SnomedDescriptionRestInput change = body.getChange();
    final String commitComment = body.getCommitComment();
    final String defaultModuleId = body.getDefaultModuleId();
    final String createdDescriptionId = change.toRequestBuilder().commit().setDefaultModuleId(defaultModuleId).setAuthor(author).setCommitComment(commitComment).build(path).execute(getBus()).getSync(COMMIT_TIMEOUT, TimeUnit.MINUTES).getResultAs(String.class);
    return ResponseEntity.created(getResourceLocationURI(path, createdDescriptionId)).build();
}
Also used : SnomedDescriptionRestInput(com.b2international.snowowl.snomed.core.rest.domain.SnomedDescriptionRestInput) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Aggregations

Operation (io.swagger.v3.oas.annotations.Operation)113 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)99 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)85 Test (org.testng.annotations.Test)53 Operation (io.swagger.v3.oas.models.Operation)51 OpenAPI (io.swagger.v3.oas.models.OpenAPI)48 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)48 ApiResponses (io.swagger.v3.oas.models.responses.ApiResponses)44 PathItem (io.swagger.v3.oas.models.PathItem)41 Schema (io.swagger.v3.oas.models.media.Schema)38 MediaType (io.swagger.v3.oas.models.media.MediaType)31 Path (javax.ws.rs.Path)30 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)29 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)27 StringSchema (io.swagger.v3.oas.models.media.StringSchema)27 Content (io.swagger.v3.oas.models.media.Content)26 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)25 ArrayList (java.util.ArrayList)25 Components (io.swagger.v3.oas.models.Components)19 Parameter (io.swagger.v3.oas.models.parameters.Parameter)19