use of com.b2international.snowowl.core.ResourceURI in project snow-owl by b2ihealthcare.
the class SnomedExtensionUpgradeTest method upgrade17UpgradeFromCodeSystemVersionWithPublishedChanges.
@Test
public void upgrade17UpgradeFromCodeSystemVersionWithPublishedChanges() {
// create extension on the latest SI VERSION
CodeSystem extension = createExtension(latestInternationalVersion, branchPath.lastSegment());
// new SI concept
String newConceptId = createConcept(SnomedContentRule.SNOMEDCT, createConceptRequestBody(Concepts.ROOT_CONCEPT, Concepts.MODULE_SCT_CORE));
// create a new INT version
LocalDate effectiveDate = getNextAvailableEffectiveDate(SNOMEDCT);
createVersion(SNOMEDCT, effectiveDate).statusCode(201);
ResourceURI upgradeVersion = CodeSystem.uri(SNOMEDCT, effectiveDate.toString());
// new SE concept
String extensionModuleId = createModule(extension);
String newConceptId2 = createConcept(extension.getResourceURI(), createConceptRequestBody(Concepts.ROOT_CONCEPT, extensionModuleId));
// version extension
LocalDate effectiveDate2 = getNextAvailableEffectiveDate(extension.getId());
createVersion(extension.getId(), effectiveDate2).statusCode(201);
ResourceURI extensionVersion = CodeSystem.uri(extension.getId(), effectiveDate2.toString());
// start upgrade to the new available upgrade version
CodeSystem upgradeCodeSystem = createExtensionUpgrade(extensionVersion, upgradeVersion);
assertEquals(upgradeVersion, upgradeCodeSystem.getExtensionOf());
getComponent(upgradeCodeSystem.getResourceURI(), SnomedComponentType.CONCEPT, newConceptId).statusCode(200);
getComponent(upgradeCodeSystem.getResourceURI(), SnomedComponentType.CONCEPT, newConceptId2).statusCode(200);
}
use of com.b2international.snowowl.core.ResourceURI in project snow-owl by b2ihealthcare.
the class SnomedExtensionUpgradeTest method upgrade20ExpandUpgradeInfo.
@Test
public void upgrade20ExpandUpgradeInfo() throws Exception {
// create extension on the latest SI VERSION
CodeSystem extension = createExtension(latestInternationalVersion, branchPath.lastSegment());
// new SI concept
createConcept(SnomedContentRule.SNOMEDCT, createConceptRequestBody(Concepts.ROOT_CONCEPT, Concepts.MODULE_SCT_CORE));
// create a new INT version
LocalDate effectiveDate = getNextAvailableEffectiveDate(SNOMEDCT);
createVersion(SNOMEDCT, effectiveDate).statusCode(201);
ResourceURI upgradeVersion = CodeSystem.uri(SNOMEDCT, effectiveDate.toString());
// new SE concept
String extensionModuleId = createModule(extension);
createConcept(extension.getResourceURI(), createConceptRequestBody(Concepts.ROOT_CONCEPT, extensionModuleId));
// version extension
LocalDate effectiveDate2 = LocalDate.now();
createVersion(extension.getId(), effectiveDate2).statusCode(201);
ResourceURI extensionVersion = CodeSystem.uri(extension.getId(), effectiveDate2.toString());
// new SE concept
createConcept(extension.getResourceURI(), createConceptRequestBody(Concepts.ROOT_CONCEPT, extensionModuleId));
// version extension
LocalDate effectiveDate3 = getNextAvailableEffectiveDate(extension.getId());
createVersion(extension.getId(), effectiveDate3).statusCode(201);
ResourceURI extensionVersion2 = CodeSystem.uri(extension.getId(), effectiveDate3.toString());
// start upgrade to the new available upgrade version
CodeSystem upgradeCodeSystem = createExtensionUpgrade(extensionVersion, upgradeVersion);
CodeSystems expandedCodeSystems = CodeSystemRestRequests.search(upgradeCodeSystem.getId(), CodeSystem.Expand.UPGRADE_INFO + "()");
assertEquals(upgradeVersion, upgradeCodeSystem.getExtensionOf());
assertThat(expandedCodeSystems.first().get().getUpgradeInfo().getAvailableVersions()).doesNotContainSequence(extensionVersion);
assertThat(expandedCodeSystems.first().get().getUpgradeInfo().getAvailableVersions()).contains(extensionVersion2);
}
use of com.b2international.snowowl.core.ResourceURI in project snow-owl by b2ihealthcare.
the class SnomedVersioningApiTest method forceCreateVersionShouldUpdateEffectiveTime.
@Test
public void forceCreateVersionShouldUpdateEffectiveTime() {
final String versionName = "forceCreateVersionShouldUpdateEffectiveTime";
ResourceURI codeSystemVersionURI = SnomedContentRule.SNOMEDCT.withPath(versionName);
LocalDate versionEffectiveDate = getNextAvailableEffectiveDate(INT_CODESYSTEM);
createVersion(INT_CODESYSTEM, versionName, versionEffectiveDate).statusCode(201);
String conceptId = createConcept(SnomedContentRule.SNOMEDCT, SnomedRestFixtures.childUnderRootWithDefaults());
SnomedConcept afterFailedVersioning = getConcept(SnomedContentRule.SNOMEDCT, conceptId);
assertEquals(null, afterFailedVersioning.getEffectiveTime());
// Should succeed to recreate version with the force flag set
createVersion(INT_CODESYSTEM, versionName, versionEffectiveDate, true).statusCode(201);
SnomedConcept afterForceVersioning = getConcept(codeSystemVersionURI, conceptId);
assertEquals(versionEffectiveDate, afterForceVersioning.getEffectiveTime());
}
use of com.b2international.snowowl.core.ResourceURI in project snow-owl by b2ihealthcare.
the class SnomedRf2ExportRequest method collectExportableCodeSystemVersions.
private void collectExportableCodeSystemVersions(final RepositoryContext context, final Set<Version> versionsToExport, final TerminologyResource codeSystem, final String referenceBranch) {
final List<Version> candidateVersions = newArrayList(getCodeSystemVersions(context, codeSystem.getResourceURI()));
if (candidateVersions.isEmpty()) {
return;
}
final Set<String> versionPaths = candidateVersions.stream().map(Version::getBranchPath).collect(Collectors.toSet());
final Branches versionBranches = getBranches(context, versionPaths);
final Map<String, Branch> versionBranchesByPath = Maps.uniqueIndex(versionBranches, Branch::path);
// cutoff timestamp represents the timestamp on the current referenceBranch segments, cutting off any versions created after this timestamp
final Branch cutoffBranch = getBranch(context, referenceBranch);
final String latestVersionParentBranch = candidateVersions.stream().findFirst().map(v -> BranchPathUtils.createPath(v.getBranchPath()).getParentPath()).get();
final long cutoffBaseTimestamp = getCutoffBaseTimestamp(context, cutoffBranch, latestVersionParentBranch);
// Remove all code system versions which were created after the cut-off date, or don't have a corresponding branch
candidateVersions.removeIf(v -> false || !versionBranchesByPath.containsKey(v.getBranchPath()) || versionBranchesByPath.get(v.getBranchPath()).baseTimestamp() > cutoffBaseTimestamp);
versionsToExport.addAll(candidateVersions);
// Exit early if only an extension code system should be exported, or we are already at the "base" code system
final ResourceURI extensionOfUri = codeSystem.getExtensionOf();
if (extensionOnly || extensionOfUri == null) {
return;
}
// Otherwise, collect applicable versions using this code system's working path
final CodeSystem extensionOfCodeSystem = CodeSystemRequests.prepareGetCodeSystem(extensionOfUri.getResourceId()).buildAsync().execute(context);
collectExportableCodeSystemVersions(context, versionsToExport, extensionOfCodeSystem, codeSystem.getBranchPath());
}
use of com.b2international.snowowl.core.ResourceURI 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