Search in sources :

Example 6 with NotFoundException

use of com.b2international.commons.exceptions.NotFoundException in project snow-owl by b2ihealthcare.

the class AbstractBranchChangeRequest method execute.

@Override
public Merge execute(RepositoryContext context) {
    try {
        final Branch source = RepositoryRequests.branching().prepareGet(sourcePath).build().execute(context);
        final Branch target = RepositoryRequests.branching().prepareGet(targetPath).build().execute(context);
        Merge merge = Merge.builder().source(sourcePath).target(targetPath).build();
        try {
            Commit commit = applyChanges(context, source, target);
            if (commit != null) {
                context.service(RepositoryCommitNotificationSender.class).publish(context, commit);
            }
            return merge.completed();
        } catch (BranchMergeConflictException e) {
            return merge.failedWithConflicts(e.getMessage(), toMergeConflicts(e.getConflicts()));
        } catch (ApiException e) {
            return merge.failed(e.toApiError());
        } catch (RuntimeException e) {
            context.log().error("Failed to merge {} into {}", sourcePath, targetPath, e);
            return merge.failed(ApiError.of(e.getMessage()));
        }
    } catch (NotFoundException e) {
        throw e.toBadRequestException();
    }
}
Also used : Merge(com.b2international.snowowl.core.merge.Merge) RepositoryCommitNotificationSender(com.b2international.snowowl.core.repository.RepositoryCommitNotificationSender) NotFoundException(com.b2international.commons.exceptions.NotFoundException) ApiException(com.b2international.commons.exceptions.ApiException)

Example 7 with NotFoundException

use of com.b2international.commons.exceptions.NotFoundException in project snow-owl by b2ihealthcare.

the class CodeSystemRestService method delete.

@Operation(summary = "Delete a CodeSystem", description = "Deletes a CodeSystem permanently from the server")
@ApiResponses({ @ApiResponse(responseCode = "204", description = "No content"), @ApiResponse(responseCode = "400", description = "Bad Request"), @ApiResponse(responseCode = "409", description = "CodeSystem cannot be deleted") })
@DeleteMapping(value = "/{codeSystemId}")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void delete(@Parameter(description = "The code system identifier") @PathVariable(value = "codeSystemId") final String codeSystemId, @RequestHeader(value = X_AUTHOR, required = false) final String author) {
    try {
        final CodeSystem codeSystem = CodeSystemRequests.prepareGetCodeSystem(codeSystemId).buildAsync().execute(getBus()).getSync(1, TimeUnit.MINUTES);
        ResourceRequests.prepareDelete(codeSystemId).build(author, String.format("Deleted Code System %s", codeSystem.getTitle())).execute(getBus()).getSync(COMMIT_TIMEOUT, TimeUnit.MINUTES);
    } catch (NotFoundException e) {
    // already deleted, ignore error
    }
}
Also used : NotFoundException(com.b2international.commons.exceptions.NotFoundException) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 8 with NotFoundException

use of com.b2international.commons.exceptions.NotFoundException in project snow-owl by b2ihealthcare.

the class CodeSystemUpgradeRestService method complete.

@Operation(summary = "Complete a codesystem upgrade (EXPERIMENTAL)", description = "Completes the upgrade process of a Code System to the newer extensionOf Code System dependency.")
@ApiResponses({ @ApiResponse(responseCode = "204", description = "Code system upgrade completed"), @ApiResponse(responseCode = "400", description = "Code System upgrade cannot be completed") })
@PostMapping("/{id}/complete")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void complete(@Parameter(description = "Code System identifier", required = true) @PathVariable("id") final String codeSystemId) {
    CodeSystemRequests.prepareSearchCodeSystem().filterById(codeSystemId).buildAsync().execute(getBus()).getSync(1, TimeUnit.MINUTES).first().orElseThrow(() -> new NotFoundException("Code System", codeSystemId));
    CodeSystemRequests.prepareComplete(codeSystemId).buildAsync().execute(getBus());
}
Also used : NotFoundException(com.b2international.commons.exceptions.NotFoundException) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 9 with NotFoundException

use of com.b2international.commons.exceptions.NotFoundException in project snow-owl by b2ihealthcare.

the class CodeSystemUpgradeRestService method sync.

@Operation(summary = "Synchronize upgrade codesystem with the original codesystem (EXPERIMENTAL)", description = "Synchronize any changes on the original code system with the upgrade code system.")
@ApiResponses({ @ApiResponse(responseCode = "204", description = "Upgrade code system synchronized"), @ApiResponse(responseCode = "400", description = "Code system could not be synchronized with the downstream code system") })
@PostMapping(value = "/sync/", consumes = { AbstractRestService.JSON_MEDIA_TYPE })
@ResponseStatus(HttpStatus.NO_CONTENT)
public void sync(@RequestBody final CodeSystemUpgradeSyncRestInput body) {
    final String codeSystemId = body.getCodeSystemId();
    final ResourceURI source = body.getSource();
    final CodeSystem codeSystem = CodeSystemRequests.prepareSearchCodeSystem().filterById(codeSystemId).buildAsync().execute(getBus()).getSync(1, TimeUnit.MINUTES).first().orElseThrow(() -> new NotFoundException("Code System", codeSystemId));
    CodeSystemRequests.prepareUpgradeSynchronization(codeSystem.getResourceURI(), source).buildAsync().execute(getBus());
}
Also used : ResourceURI(com.b2international.snowowl.core.ResourceURI) NotFoundException(com.b2international.commons.exceptions.NotFoundException) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 10 with NotFoundException

use of com.b2international.commons.exceptions.NotFoundException in project snow-owl by b2ihealthcare.

the class AttachmentRegistryTest method delete.

@Test
public void delete() throws Exception {
    final UUID id = UUID.randomUUID();
    upload(id, "file-reg-upload.zip");
    assertTrue(exists(id));
    registry.delete(id);
    try {
        registry.getAttachment(id);
        fail("Expected exception " + NotFoundException.class.getName());
    } catch (NotFoundException e) {
    // expected
    }
}
Also used : NotFoundException(com.b2international.commons.exceptions.NotFoundException) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

NotFoundException (com.b2international.commons.exceptions.NotFoundException)18 Operation (io.swagger.v3.oas.annotations.Operation)5 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)5 BadRequestException (com.b2international.commons.exceptions.BadRequestException)3 Branch (com.b2international.snowowl.core.branch.Branch)3 Bundle (com.b2international.snowowl.core.bundle.Bundle)3 Json (com.b2international.commons.json.Json)2 RevisionBranch (com.b2international.index.revision.RevisionBranch)2 ResourceURI (com.b2international.snowowl.core.ResourceURI)2 Bundles (com.b2international.snowowl.core.bundle.Bundles)2 CodeSystem (com.b2international.snowowl.core.codesystem.CodeSystem)2 BaseResourceApiTest (com.b2international.snowowl.core.rest.BaseResourceApiTest)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 Test (org.junit.Test)2 CompareUtils (com.b2international.commons.CompareUtils)1 AlreadyExistsException (com.b2international.commons.exceptions.AlreadyExistsException)1 ApiException (com.b2international.commons.exceptions.ApiException)1 ConflictException (com.b2international.commons.exceptions.ConflictException)1 CycleDetectedException (com.b2international.commons.exceptions.CycleDetectedException)1 BaseRevisionBranching (com.b2international.index.revision.BaseRevisionBranching)1