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();
}
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();
}
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;
}
}
}
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);
}
}
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();
}
Aggregations