use of com.b2international.snowowl.core.request.io.ImportDefectAcceptor in project snow-owl by b2ihealthcare.
the class SnomedRf2ImportRequest method readFile.
private void readFile(ZipEntry entry, final InputStream in, final ObjectReader oReader, Rf2EffectiveTimeSlices effectiveTimeSlices, Rf2ValidationIssueReporter reporter) throws IOException, JsonProcessingException {
final String entryName = entry.getName();
final ImportDefectAcceptor defectAcceptor = reporter.getDefectAcceptor(entryName);
boolean header = true;
Rf2ContentType<?> resolver = null;
int lineNumber = 1;
MappingIterator<String[]> mi = oReader.readValues(in);
while (mi.hasNext()) {
String[] line = mi.next();
if (header) {
for (Rf2ContentType<?> contentType : Rf2Format.getContentTypes()) {
if (contentType.canResolve(line)) {
resolver = contentType;
break;
}
}
if (resolver == null) {
log.warn("Unrecognized RF2 file: {}", entryName);
break;
}
header = false;
} else {
final String effectiveTimeKey = getEffectiveTimeKey(line[1]);
final ImportDefectBuilder defectBuilder = defectAcceptor.on(Integer.toString(lineNumber));
resolver.register(line, effectiveTimeSlices.getOrCreate(effectiveTimeKey), defectBuilder);
}
lineNumber++;
}
}
use of com.b2international.snowowl.core.request.io.ImportDefectAcceptor 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());
}
}
Aggregations