Search in sources :

Example 81 with RequestBody

use of io.swagger.v3.oas.models.parameters.RequestBody in project snow-owl by b2ihealthcare.

the class VersionRestService method createVersion.

@Operation(summary = "Create a new resource version", description = "Creates a new resource version. " + "The version tag (represented by an empty branch) is created on the resource's current working branch. " + "Where applicable, effective times are set on the unpublished content as part of this operation.")
@ApiResponses({ @ApiResponse(responseCode = "201", description = "Created"), @ApiResponse(responseCode = "404", description = "Not found"), @ApiResponse(responseCode = "409", description = "Code system version conflicts with existing branch") })
@PostMapping(consumes = { AbstractRestService.JSON_MEDIA_TYPE })
@ResponseStatus(value = HttpStatus.CREATED)
public ResponseEntity<Void> createVersion(@Parameter(description = "Version parameters") @RequestBody final ResourceRequest<VersionRestInput> input) {
    final VersionRestInput change = input.getChange();
    ApiValidation.checkInput(change);
    String newVersionUri = String.join(Branch.SEPARATOR, change.getResource().toString(), change.getVersion());
    String jobId = ResourceRequests.prepareNewVersion().setResource(change.getResource()).setVersion(change.getVersion()).setDescription(change.getDescription()).setEffectiveTime(change.getEffectiveTime()).setForce(change.isForce()).setCommitComment(input.getCommitComment()).buildAsync().runAsJobWithRestart(ResourceRequests.versionJobKey(change.getResource()), "Creating version " + newVersionUri).execute(getBus()).getSync(1, TimeUnit.MINUTES);
    RemoteJobEntry job = JobRequests.waitForJob(getBus(), jobId, 500);
    if (job.isSuccessful()) {
        final URI location = MvcUriComponentsBuilder.fromMethodName(VersionRestService.class, "getVersion", newVersionUri).build().toUri();
        return ResponseEntity.created(location).build();
    } else if (!Strings.isNullOrEmpty(job.getResult())) {
        ApiError error = job.getResultAs(ApplicationContext.getServiceForClass(ObjectMapper.class), ApiError.class);
        throw new ApiErrorException(error.withMessage(error.getMessage().replace("Branch name", "Version")));
    } else {
        throw new SnowowlRuntimeException("Version creation failed.");
    }
}
Also used : ApiError(com.b2international.commons.exceptions.ApiError) URI(java.net.URI) ApiErrorException(com.b2international.commons.exceptions.ApiErrorException) RemoteJobEntry(com.b2international.snowowl.core.jobs.RemoteJobEntry) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 82 with RequestBody

use of io.swagger.v3.oas.models.parameters.RequestBody in project snow-owl by b2ihealthcare.

the class SnomedRelationshipRestService method update.

@Operation(summary = "Update Relationship", description = "Updates properties of the specified Relationship.")
@ApiResponses({ @ApiResponse(responseCode = "204", description = "No content"), @ApiResponse(responseCode = "404", description = "Branch or Relationship not found") })
@PutMapping(value = "/{relationshipId}", consumes = { AbstractRestService.JSON_MEDIA_TYPE })
@ResponseStatus(HttpStatus.NO_CONTENT)
public void update(@Parameter(description = "The resource path", required = true) @PathVariable("path") final String path, @Parameter(description = "The Relationship identifier") @PathVariable("relationshipId") final String relationshipId, @Parameter(description = "Update Relationship parameters") @RequestBody final SnomedResourceRequest<SnomedRelationshipRestUpdate> body, @Parameter(description = "Force update flag") @RequestParam(defaultValue = "false", required = false) final Boolean force, @RequestHeader(value = X_AUTHOR, required = false) final String author) {
    final String commitComment = body.getCommitComment();
    final SnomedRelationshipRestUpdate update = body.getChange();
    final String defaultModuleId = body.getDefaultModuleId();
    update.toRequestBuilder(relationshipId).force(force).commit().setDefaultModuleId(defaultModuleId).setAuthor(author).setCommitComment(commitComment).build(path).execute(getBus()).getSync(COMMIT_TIMEOUT, TimeUnit.MINUTES);
}
Also used : SnomedRelationshipRestUpdate(com.b2international.snowowl.snomed.core.rest.domain.SnomedRelationshipRestUpdate) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 83 with RequestBody

use of io.swagger.v3.oas.models.parameters.RequestBody in project snow-owl by b2ihealthcare.

the class SnomedRelationshipRestService method create.

@Operation(summary = "Create Relationship", description = "Creates a new Relationship directly on a version path.")
@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("path") final String path, @Parameter(description = "Relationship parameters") @RequestBody final SnomedResourceRequest<SnomedRelationshipRestInput> body, @RequestHeader(value = X_AUTHOR, required = false) final String author) {
    final SnomedRelationshipRestInput change = body.getChange();
    final String commitComment = body.getCommitComment();
    final String defaultModuleId = body.getDefaultModuleId();
    final String createdRelationshipId = 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, createdRelationshipId)).build();
}
Also used : SnomedRelationshipRestInput(com.b2international.snowowl.snomed.core.rest.domain.SnomedRelationshipRestInput) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 84 with RequestBody

use of io.swagger.v3.oas.models.parameters.RequestBody in project snow-owl by b2ihealthcare.

the class SnomedConceptRestService method update.

@Operation(summary = "Update Concept", description = "Updates properties of the specified Concept, also managing inactivation indicator and association reference set " + "membership in case of inactivation." + "<p>The following properties are allowed to change:" + "<p>" + "&bull; module identifier<br>" + "&bull; subclass definition status<br>" + "&bull; definition status<br>" + "&bull; associated Concepts<br>" + "" + "<p>The following properties, when changed, will trigger inactivation:" + "<p>" + "&bull; inactivation indicator<br>")
@ApiResponses({ @ApiResponse(responseCode = "204", description = "No Content"), @ApiResponse(responseCode = "404", description = "Branch or Concept not found") })
@PutMapping(value = "/{conceptId}", consumes = { AbstractRestService.JSON_MEDIA_TYPE })
@ResponseStatus(HttpStatus.NO_CONTENT)
public void update(@Parameter(description = "The resource path", required = true) @PathVariable(value = "path") final String path, @Parameter(description = "The Concept identifier") @PathVariable(value = "conceptId") final String conceptId, @Parameter(description = "Updated Concept parameters") @RequestBody final SnomedResourceRequest<SnomedConceptRestUpdate> body, @Parameter(description = "Force update flag") @RequestParam(defaultValue = "false", required = false) final Boolean force, @RequestHeader(value = X_AUTHOR, required = false) final String author) {
    final SnomedConceptRestUpdate change = body.getChange();
    final String commitComment = body.getCommitComment();
    final String defaultModuleId = body.getDefaultModuleId();
    change.toRequestBuilder(conceptId).force(force).commit().setDefaultModuleId(defaultModuleId).setAuthor(author).setCommitComment(commitComment).build(path).execute(getBus()).getSync(COMMIT_TIMEOUT, TimeUnit.MINUTES);
}
Also used : SnomedConceptRestUpdate(com.b2international.snowowl.snomed.core.rest.domain.SnomedConceptRestUpdate) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 85 with RequestBody

use of io.swagger.v3.oas.models.parameters.RequestBody in project snow-owl by b2ihealthcare.

the class CisAuthenticationService method authenticate.

@Operation(summary = "Validates a token, checking if it's assigned to a current session, and retrieves user data.")
@ApiResponses({ @ApiResponse(responseCode = "400", description = "Error"), @ApiResponse(responseCode = "401", description = "Unauthorized") })
@PostMapping(value = "/authenticate")
public UserData authenticate(@Parameter(description = "The security access token.", required = true) @RequestBody Token token) {
    String username = verify(token.getToken());
    if (Strings.isNullOrEmpty(username)) {
        throw new UnauthorizedException("Token does not validate.");
    } else {
        final UserData userData = new UserData();
        userData.setUsername(username);
        return userData;
    }
}
Also used : UserData(com.b2international.snowowl.snomed.cis.rest.model.UserData) UnauthorizedException(com.b2international.commons.exceptions.UnauthorizedException) PostMapping(org.springframework.web.bind.annotation.PostMapping) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Aggregations

Test (org.testng.annotations.Test)67 OpenAPI (io.swagger.v3.oas.models.OpenAPI)62 RequestBody (io.swagger.v3.oas.models.parameters.RequestBody)59 Schema (io.swagger.v3.oas.models.media.Schema)46 Operation (io.swagger.v3.oas.annotations.Operation)41 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)40 MediaType (io.swagger.v3.oas.models.media.MediaType)36 StringSchema (io.swagger.v3.oas.models.media.StringSchema)35 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)32 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)32 Content (io.swagger.v3.oas.models.media.Content)31 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)28 Operation (io.swagger.v3.oas.models.Operation)27 PathItem (io.swagger.v3.oas.models.PathItem)23 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)21 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)19 Parameter (io.swagger.v3.oas.models.parameters.Parameter)15 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)14 Components (io.swagger.v3.oas.models.Components)13 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)12