use of com.b2international.commons.exceptions.ApiErrorException 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.");
}
}
Aggregations