Search in sources :

Example 11 with NotFoundException

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

the class FhirLookupRequest method doExecute.

@Override
protected LookupResult doExecute(ServiceProvider context, CodeSystem codeSystem) {
    validateRequestedProperties(codeSystem);
    final String acceptLanguage = extractLocales(request.getDisplayLanguage());
    FhirCodeSystemLookupConverter converter = context.service(RepositoryManager.class).get(codeSystem.getToolingId()).optionalService(FhirCodeSystemLookupConverter.class).orElse(FhirCodeSystemLookupConverter.DEFAULT);
    final String conceptExpand = converter.configureConceptExpand(request);
    Concept concept = CodeSystemRequests.prepareSearchConcepts().one().filterByCodeSystemUri(codeSystem.getResourceURI()).filterById(request.getCode()).setLocales(acceptLanguage).setExpand(conceptExpand).buildAsync().execute(context).first().orElseThrow(() -> new NotFoundException("Concept", request.getCode()));
    return LookupResult.builder().name(codeSystem.getName()).display(concept.getTerm()).version(codeSystem.getVersion()).designation(converter.expandDesignations(context, codeSystem, concept, request, acceptLanguage)).property(converter.expandProperties(context, codeSystem, concept, request)).build();
}
Also used : Concept(com.b2international.snowowl.core.domain.Concept) NotFoundException(com.b2international.commons.exceptions.NotFoundException) RepositoryManager(com.b2international.snowowl.core.RepositoryManager)

Example 12 with NotFoundException

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

the class SnomedImportRowValidatorTest method importArchive.

private ImportResponse importArchive(String archiveFilePath, Rf2ReleaseType releaseType) throws FileNotFoundException {
    final String codeSystemId = branchPath.lastSegment();
    try {
        CodeSystemRequests.prepareGetCodeSystem(codeSystemId).buildAsync().execute(getBus()).getSync(1L, TimeUnit.MINUTES);
    } catch (NotFoundException e) {
        CodeSystemRequests.prepareNewCodeSystem().setBranchPath(branchPath.getPath()).setId(codeSystemId).setToolingId(SnomedTerminologyComponentConstants.TOOLING_ID).setUrl(SnomedTerminologyComponentConstants.SNOMED_URI_SCT + "/" + codeSystemId).setTitle(codeSystemId).build("info@b2international.com", "Created new code system " + codeSystemId).execute(getBus()).getSync(1L, TimeUnit.MINUTES);
    }
    Attachment attachment = Attachment.upload(Services.context(), PlatformUtil.toAbsolutePath(this.getClass(), archiveFilePath));
    return SnomedRequests.rf2().prepareImport().setCreateVersions(false).setReleaseType(releaseType).setRf2Archive(attachment).build(branchPath.getPath()).execute(getBus()).getSync();
}
Also used : FileNotFoundException(java.io.FileNotFoundException) NotFoundException(com.b2international.commons.exceptions.NotFoundException) Attachment(com.b2international.snowowl.core.attachments.Attachment)

Example 13 with NotFoundException

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

the class BranchesCommand method run.

@Override
public void run(CommandLineStream out) {
    if (isValidRepositoryName(repositoryId, out)) {
        if (!branchPath.startsWith(Branch.MAIN_PATH)) {
            out.println("Specify branch with full path. i.e. MAIN/PROJECT/TASK1. Got: '%s'", branchPath);
            return;
        }
        try {
            Branch parentBranch = RepositoryRequests.branching().prepareGet(branchPath).setExpand("children(direct:false)").build(repositoryId).execute(getBus()).getSync(1, TimeUnit.MINUTES);
            out.println("Branch hierarchy for '%s' in repository '%s':", branchPath, repositoryId);
            print(parentBranch, getDepthOfBranch(parentBranch), parentBranch.getChildren().getItems(), out);
        } catch (NotFoundException e) {
            out.println("Unable to find branch '%s'", branchPath);
            return;
        }
    }
}
Also used : Branch(com.b2international.snowowl.core.branch.Branch) NotFoundException(com.b2international.commons.exceptions.NotFoundException)

Example 14 with NotFoundException

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

the class TerminologyResourceRequest method initialize.

private void initialize(ServiceProvider context) {
    if (resourcePath.startsWith(Branch.MAIN_PATH)) {
        context.log().warn("Reflective access of terminology resources ('{}/{}') is not the recommended way of accessing resources. Consider using Resource IDs and relative branch path expressions.", toolingId, resourcePath);
        this.resource = context.service(PathTerminologyResourceResolver.class).resolve(context, toolingId, resourcePath);
        this.resourceUri = resource.getResourceURI(resourcePath);
        this.branchPath = resourcePath;
    } else {
        // resourcePaths are just ID/PATH style expressions to reference content in a terminology repository
        final ResourceURI referenceResourceUri = ResourceURI.of("any", resourcePath);
        Resource resource = ResourceRequests.prepareGet(referenceResourceUri).buildAsync().getRequest().execute(context);
        if (!(resource instanceof TerminologyResource)) {
            throw new NotFoundException("Terminology Resource", referenceResourceUri.getResourceId());
        }
        this.resource = (TerminologyResource) resource;
        this.resourceUri = this.resource.getResourceURI().withPath(referenceResourceUri.getPath()).withTimestampPart(referenceResourceUri.getTimestampPart());
        this.branchPath = context.service(ResourceURIPathResolver.class).resolve(context, referenceResourceUri, resource);
    }
}
Also used : ResourceURI(com.b2international.snowowl.core.ResourceURI) TerminologyResource(com.b2international.snowowl.core.TerminologyResource) Resource(com.b2international.snowowl.core.Resource) TerminologyResource(com.b2international.snowowl.core.TerminologyResource) NotFoundException(com.b2international.commons.exceptions.NotFoundException)

Example 15 with NotFoundException

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

the class BaseResourceUpdateRequest method getBundleAncestorIds.

private List<String> getBundleAncestorIds(final TransactionContext context, final String resourceId) {
    if (IComponent.ROOT_ID.equals(bundleId)) {
        return List.of(bundleId);
    }
    final Bundles bundles = ResourceRequests.bundles().prepareSearch().filterById(bundleId).one().build().execute(context);
    if (bundles.getTotal() == 0) {
        throw new NotFoundException("Bundle parent", bundleId).toBadRequestException();
    }
    final Bundle parentBundle = bundles.first().get();
    if (parentBundle.getBundleId().equals(resourceId) || parentBundle.getBundleAncestorIds().contains(resourceId)) {
        throw new CycleDetectedException("Setting parent bundle ID to '" + bundleId + "' would create a loop.");
    }
    return parentBundle.getResourcePathSegments();
}
Also used : Bundle(com.b2international.snowowl.core.bundle.Bundle) CycleDetectedException(com.b2international.commons.exceptions.CycleDetectedException) NotFoundException(com.b2international.commons.exceptions.NotFoundException) Bundles(com.b2international.snowowl.core.bundle.Bundles)

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