use of com.b2international.snowowl.core.uri.ComponentURI in project snow-owl by b2ihealthcare.
the class ConceptMapSearchMappingRequestSnomedMapTypeReferenceSetTest method filterByComponentUriAndId.
@Test
public void filterByComponentUriAndId() {
final String refSetId = createSimpleMapTypeRefSet();
final String filterId = "12345";
final ComponentURI uri = ComponentURI.of(CODESYSTEM, SnomedConcept.TYPE, filterId);
final ComponentURI sourceUri = ComponentURI.of(CODESYSTEM, SnomedConcept.TYPE, REFERENCED_COMPONENT);
createSimpleMapTypeRefSetMember(refSetId, REFERENCED_COMPONENT, filterId);
createSimpleMapTypeRefSetMember(refSetId, REFERENCED_COMPONENT, "Random map target");
createSimpleMapTypeRefSetMember(refSetId, REFERENCED_COMPONENT, uri.toString());
final ConceptMapMappings conceptMaps = ConceptMapRequests.prepareSearchConceptMapMappings().all().filterByComponentIds(Set.of(uri.toString(), uri.identifier())).filterByConceptMap(ComponentURI.of(CODESYSTEM, SnomedConcept.REFSET_TYPE, refSetId).toString()).setLocales("en").buildAsync().execute(Services.bus()).getSync(1, TimeUnit.MINUTES);
assertEquals(2, conceptMaps.getTotal());
Set<ComponentURI> componentUris = getComponentUris(conceptMaps);
assertThat(componentUris).containsOnly(sourceUri, uri, ComponentURI.unspecified(filterId));
}
use of com.b2international.snowowl.core.uri.ComponentURI in project snow-owl by b2ihealthcare.
the class ConceptMapSearchMappingRequestSnomedMapTypeReferenceSetTest method filterByComponentUris.
@Test
public void filterByComponentUris() {
final String refSetId = createSimpleMapTypeRefSet();
final ComponentURI uri = ComponentURI.of(CODESYSTEM, SnomedConcept.TYPE, "12345");
final ComponentURI uri2 = ComponentURI.of(CODESYSTEM, SnomedConcept.TYPE, "54321");
final ComponentURI sourceUri = ComponentURI.of(CODESYSTEM, SnomedConcept.TYPE, REFERENCED_COMPONENT);
createSimpleMapTypeRefSetMember(refSetId, REFERENCED_COMPONENT, uri.toString());
createSimpleMapTypeRefSetMember(refSetId, REFERENCED_COMPONENT, uri2.toString());
createSimpleMapTypeRefSetMember(refSetId, REFERENCED_COMPONENT, "Random map target");
final ConceptMapMappings conceptMaps = ConceptMapRequests.prepareSearchConceptMapMappings().all().filterByComponentIds(Set.of(uri.toString(), uri2.toString())).filterByConceptMap(ComponentURI.of(CODESYSTEM, SnomedConcept.REFSET_TYPE, refSetId).toString()).setLocales("en").buildAsync().execute(Services.bus()).getSync(1, TimeUnit.MINUTES);
assertEquals(2, conceptMaps.getTotal());
Set<ComponentURI> componentUris = getComponentUris(conceptMaps);
assertThat(componentUris).containsOnly(sourceUri, uri, uri2);
}
use of com.b2international.snowowl.core.uri.ComponentURI in project snow-owl by b2ihealthcare.
the class GenericValidationRuleTest method affectedComponentURI.
@Test
public void affectedComponentURI() throws Exception {
final String ruleId = "45a";
indexRule(ruleId);
// index invalid hierarchical relationship to group 1
final SnomedRelationshipIndexEntry relationship = relationship(Concepts.FINDING_SITE, Concepts.IS_A, Concepts.MODULE_SCT_MODEL_COMPONENT).relationshipGroup(1).build();
indexRevision(MAIN, relationship);
ValidationIssues issues = validate(ruleId);
ComponentURI componentURI = issues.stream().map(issue -> issue.getAffectedComponentURI()).findFirst().orElse(null);
assertThat(componentURI).isEqualTo(ComponentURI.of(CodeSystem.uri(CODESYSTEM), SnomedRelationship.TYPE, relationship.getId()));
}
use of com.b2international.snowowl.core.uri.ComponentURI in project snow-owl by b2ihealthcare.
the class SnomedRf2ImportRequest method doImport.
ImportResponse doImport(final BranchContext context, final File rf2Archive, final Rf2ImportConfiguration importconfig) throws Exception {
final ResourceURI codeSystemUri = context.service(ResourceURI.class);
final Rf2ValidationIssueReporter reporter = new Rf2ValidationIssueReporter();
String latestVersionEffectiveTime = EffectiveTimes.format(ResourceRequests.prepareSearchVersion().one().filterByResource(codeSystemUri.withoutPath()).sortBy("effectiveTime:desc").buildAsync().execute(context).first().map(Version::getEffectiveTime).orElse(LocalDate.EPOCH), DateFormats.SHORT);
try (final DB db = createDb()) {
// Read effective time slices from import files
final Rf2EffectiveTimeSlices effectiveTimeSlices = new Rf2EffectiveTimeSlices(db, isLoadOnDemandEnabled(), latestVersionEffectiveTime, importUntil == null ? null : EffectiveTimes.format(importUntil, DateFormats.SHORT));
Stopwatch w = Stopwatch.createStarted();
read(rf2Archive, effectiveTimeSlices, reporter);
log.info("Preparing RF2 import took: {}", w);
w.reset().start();
// Log issues with rows from the import files
logValidationIssues(reporter);
if (reporter.hasErrors()) {
return ImportResponse.defects(reporter.getDefects());
}
// Run validation that takes current terminology content into account
final List<Rf2EffectiveTimeSlice> orderedEffectiveTimeSlices = effectiveTimeSlices.consumeInOrder();
final Rf2GlobalValidator globalValidator = new Rf2GlobalValidator(log, ignoreMissingReferencesIn);
/*
* TODO: Use Attachment to get the release file name and/or track file and line number sources for each row
* so that they can be referenced in this stage as well
*/
final ImportDefectAcceptor globalDefectAcceptor = reporter.getDefectAcceptor("RF2 release");
globalValidator.validateTerminologyComponents(orderedEffectiveTimeSlices, globalDefectAcceptor, context);
// globalValidator.validateMembers(orderedEffectiveTimeSlices, globalDefectAcceptor, context);
// Log validation issues (but just the ones found during global validation)
logValidationIssues(globalDefectAcceptor);
if (reporter.hasErrors()) {
return ImportResponse.defects(reporter.getDefects());
}
// Import effective time slices in chronological order
final ImmutableSet.Builder<ComponentURI> visitedComponents = ImmutableSet.builder();
// if not a dryRun, perform import
if (!dryRun) {
// Import effective time slices in chronological order
for (Rf2EffectiveTimeSlice slice : orderedEffectiveTimeSlices) {
slice.doImport(context, codeSystemUri, importconfig, visitedComponents);
}
// Update locales registered on the code system
updateCodeSystemSettings(context, codeSystemUri);
}
return ImportResponse.success(visitedComponents.build(), reporter.getDefects());
}
}
use of com.b2international.snowowl.core.uri.ComponentURI in project snow-owl by b2ihealthcare.
the class ImportRequest method doExecute.
@Override
public final ImportResponse doExecute(TransactionContext context) {
context.log().info("Importing components from source file '{}'.", this.attachment.getFileName());
InternalAttachmentRegistry iar = null;
try {
iar = (InternalAttachmentRegistry) context.service(AttachmentRegistry.class);
File attachment = iar.getAttachment(this.attachment.getAttachmentId());
ImportDefectAcceptor defectsAcceptor = new ImportDefectAcceptor(this.attachment.getFileName());
doValidate(context, attachment, defectsAcceptor, context.service(IProgressMonitor.class));
final ImportResponse validationResponse = ImportResponse.defects(defectsAcceptor.getDefects());
if (!validationResponse.getErrors().isEmpty()) {
return validationResponse;
} else {
final Set<ComponentURI> visitedComponents = Sets.newHashSet();
doImport(context, attachment, visitedComponents::add, context.service(IProgressMonitor.class));
context.log().info("Finished importing components from source file '{}'.", this.attachment.getFileName());
return ImportResponse.success(visitedComponents, validationResponse.getDefects());
}
} catch (ApiException e) {
throw e;
} catch (Exception e) {
String error = "Unexpected error happened during the import of the source file: " + attachment.getFileName();
context.log().error(error, e);
return ImportResponse.error(error);
} finally {
if (attachment != null && iar != null) {
iar.delete(attachment.getAttachmentId());
}
}
}
Aggregations