use of com.b2international.snowowl.core.version.Version in project snow-owl by b2ihealthcare.
the class SnomedExtensionCreationTest method createExtensionVersion01.
@Test
public void createExtensionVersion01() {
String conceptId = createNewConcept(branchPath);
getComponent(branchPath, SnomedComponentType.CONCEPT, conceptId).statusCode(200).body("released", equalTo(false));
String codeSystemId = "SNOMEDCT-CV1";
createCodeSystem(branchPath, codeSystemId).statusCode(201);
getComponent(branchPath, SnomedComponentType.CONCEPT, conceptId).statusCode(200).body("released", equalTo(false));
String versionId = "v1";
LocalDate effectiveTime = LocalDate.now();
createVersion(codeSystemId, versionId, effectiveTime).statusCode(201);
Version version = getVersion(codeSystemId, versionId);
assertThat(version.getEffectiveTime()).isEqualTo(effectiveTime);
getComponent(branchPath, SnomedComponentType.CONCEPT, conceptId).statusCode(200).body("released", equalTo(true)).body("effectiveTime", equalTo(effectiveTime.format(DateTimeFormatter.BASIC_ISO_DATE)));
getComponent(version.getBranchPath(), SnomedComponentType.CONCEPT, conceptId).statusCode(200).body("released", equalTo(true)).body("effectiveTime", equalTo(effectiveTime.format(DateTimeFormatter.BASIC_ISO_DATE)));
}
use of com.b2international.snowowl.core.version.Version in project snow-owl by b2ihealthcare.
the class SnomedRf2NextReleaseImportTest method doImport.
private void doImport(final String importFile, final String importUntil) {
Attachment attachment = Attachment.upload(Services.context(), PlatformUtil.toAbsolutePathBundleEntry(SnomedContentRule.class, importFile));
String jobId = SnomedRequests.rf2().prepareImport().setRf2Archive(attachment).setReleaseType(Rf2ReleaseType.FULL).setCreateVersions(true).setImportUntil(importUntil).build(SnomedContentRule.SNOMEDCT).runAsJobWithRestart(SnomedRf2Requests.importJobKey(SnomedContentRule.SNOMEDCT), String.format("Import %s release", importFile)).execute(Services.bus()).getSync(1, TimeUnit.MINUTES);
RemoteJobEntry job = JobRequests.waitForJob(Services.bus(), jobId, 2000);
assertTrue("Failed to import RF2 archive", job.isSuccessful());
// assert that the version for importUntil is present in the system
Version latestVersion = CodeSystemVersionRestRequests.getLatestVersion(SnomedContentRule.SNOMEDCT_ID).get();
assertEquals(importUntil, EffectiveTimes.format(latestVersion.getEffectiveTime(), DateFormats.SHORT));
}
use of com.b2international.snowowl.core.version.Version in project snow-owl by b2ihealthcare.
the class SnomedRf2ExportRequest method execute.
@Override
public Attachment execute(final BranchContext context) {
final String referenceBranch = context.path();
if (referenceBranch.contains(RevisionIndex.AT_CHAR) && !Rf2ReleaseType.SNAPSHOT.equals(releaseType)) {
throw new BadRequestException("Only snapshot export is allowed for point-in-time branch path '%s'.", referenceBranch);
}
if (referenceBranch.contains(RevisionIndex.REV_RANGE)) {
if (!Rf2ReleaseType.DELTA.equals(releaseType) || needsVersionBranchesForDeltaExport()) {
throw new BadRequestException("Only unpublished delta export is allowed for branch path range '%s'.", referenceBranch);
}
}
// register export start time for later use
final long exportStartTime = Instant.now().toEpochMilli();
// Step 1: check if the export reference branch is a working branch path descendant
final CodeSystem referenceCodeSystem = (CodeSystem) context.service(TerminologyResource.class);
if (!CompareUtils.isEmpty(referenceCodeSystem.getSettings())) {
if (Strings.isNullOrEmpty(countryNamespaceElement)) {
if (maintainerType == null) {
String maintainerType = (String) referenceCodeSystem.getSettings().get(SnomedTerminologyComponentConstants.CODESYSTEM_MAINTAINER_TYPE_CONFIG_KEY);
String nrcCountryCode = (String) referenceCodeSystem.getSettings().get(SnomedTerminologyComponentConstants.CODESYSTEM_NRC_COUNTRY_CODE_CONFIG_KEY);
if (!Strings.isNullOrEmpty(maintainerType)) {
String customCountryNamespaceElement = getCountryNamespaceElement(context, referenceCodeSystem, Rf2MaintainerType.getByNameIgnoreCase(maintainerType), Strings.nullToEmpty(nrcCountryCode));
countryNamespaceElement = customCountryNamespaceElement;
}
} else {
countryNamespaceElement = getCountryNamespaceElement(context, referenceCodeSystem, maintainerType, Strings.nullToEmpty(nrcCountryCode));
}
}
if (refSetExportLayout == null && referenceCodeSystem.getSettings().containsKey(SnomedTerminologyComponentConstants.CODESYSTEM_RF2_EXPORT_LAYOUT_CONFIG_KEY)) {
String refSetLayout = (String) referenceCodeSystem.getSettings().get(SnomedTerminologyComponentConstants.CODESYSTEM_RF2_EXPORT_LAYOUT_CONFIG_KEY);
Rf2RefSetExportLayout rf2RefSetExportLayout = Rf2RefSetExportLayout.getByNameIgnoreCase(refSetLayout);
refSetExportLayout = rf2RefSetExportLayout;
}
}
if (Strings.isNullOrEmpty(countryNamespaceElement)) {
countryNamespaceElement = getCountryNamespaceElement(context, referenceCodeSystem, DEFAULT_MAINTAINER_TYPE, "");
}
if (refSetExportLayout == null) {
refSetExportLayout = DEFAULT_RF2_EXPORT_LAYOUT;
}
// Step 2: retrieve code system versions that are visible from the reference branch
final TreeSet<Version> versionsToExport = getAllExportableCodeSystemVersions(context, referenceCodeSystem);
// Step 3: compute branches to export
final List<String> branchesToExport = computeBranchesToExport(referenceBranch, versionsToExport);
// Step 4: compute possible language codes
Multimap<String, String> availableLanguageCodes = getLanguageCodes(context, branchesToExport);
Path exportDirectory = null;
try {
final UUID exportId = UUID.randomUUID();
// create temporary export directory
exportDirectory = createExportDirectory(exportId);
// get archive effective time based on latest version effective / transient effective time / current date
final LocalDateTime archiveEffectiveDate = getArchiveEffectiveTime(context, versionsToExport);
final String archiveEffectiveDateShort = EffectiveTimes.format(archiveEffectiveDate.toLocalDate(), DateFormats.SHORT);
// create main folder including release status and archive effective date
final Path releaseDirectory = createReleaseDirectory(exportDirectory, archiveEffectiveDate);
final Set<String> visitedComponentEffectiveTimes = newHashSet();
final long effectiveTimeStart = startEffectiveTime != null ? EffectiveTimes.getEffectiveTime(startEffectiveTime) : 0;
final long effectiveTimeEnd = endEffectiveTime != null ? EffectiveTimes.getEffectiveTime(endEffectiveTime) : Long.MAX_VALUE;
// export content from the pre-computed version branches
for (String branch : branchesToExport) {
exportBranch(releaseDirectory, context, branch, archiveEffectiveDateShort, effectiveTimeStart, effectiveTimeEnd, visitedComponentEffectiveTimes, availableLanguageCodes.get(branch));
}
// export content from reference branch
if (includePreReleaseContent) {
// If a special branch path was given, use it directly
final String referenceBranchToExport = containsSpecialCharacter(referenceBranch) ? referenceBranch : RevisionIndex.toBranchAtPath(referenceBranch, exportStartTime);
exportBranch(releaseDirectory, context, referenceBranchToExport, archiveEffectiveDateShort, EffectiveTimes.UNSET_EFFECTIVE_TIME, EffectiveTimes.UNSET_EFFECTIVE_TIME, visitedComponentEffectiveTimes, availableLanguageCodes.get(referenceBranch));
}
// Step 6: compress to archive and upload to the file registry
final AttachmentRegistry fileRegistry = context.service(AttachmentRegistry.class);
registerResult(fileRegistry, exportId, exportDirectory);
final String fileName = releaseDirectory.getFileName() + ".zip";
return new Attachment(exportId, fileName);
} catch (final Exception e) {
throw new SnowowlRuntimeException("Failed to export terminology content to RF2.", e);
} finally {
if (exportDirectory != null) {
FileUtils.deleteDirectory(exportDirectory.toFile());
}
}
}
use of com.b2international.snowowl.core.version.Version in project snow-owl by b2ihealthcare.
the class CodeSystemConverter method expandAvailableUpgrades.
private void expandAvailableUpgrades(List<CodeSystem> results) {
if (!expand().containsKey(CodeSystem.Expand.AVAILABLE_UPGRADES)) {
return;
}
final Set<ResourceURI> parentResources = results.stream().map(CodeSystem::getExtensionOf).filter(uri -> uri != null).collect(Collectors.toSet());
final Versions parentVersions = ResourceRequests.prepareSearchVersion().all().filterByResources(parentResources.stream().map(ResourceURI::withoutPath).map(ResourceURI::toString).collect(Collectors.toSet())).build().execute(context());
final TreeMultimap<ResourceURI, Version> versionsByResource = TreeMultimap.create(Comparator.naturalOrder(), Comparator.comparing(Version::getEffectiveTime));
versionsByResource.putAll(Multimaps.index(parentVersions, Version::getResource));
for (final CodeSystem result : results) {
final ResourceURI extensionOf = result.getExtensionOf();
// or the CodeSystem already has an upgrade
if (extensionOf == null || result.getUpgradeOf() != null || hasUpgrade(result, results)) {
// always set the field if user expands it
result.setAvailableUpgrades(List.of());
continue;
}
final ResourceURI resource = extensionOf.withoutPath();
final String version = extensionOf.getPath();
final NavigableSet<Version> candidates = versionsByResource.get(resource);
final Optional<Version> currentExtensionVersion = candidates.stream().filter(v -> v.getVersion().equals(version)).findFirst();
final Optional<List<ResourceURI>> upgradeUris = currentExtensionVersion.map(currentVersion -> {
final SortedSet<Version> upgradeVersions = candidates.tailSet(currentVersion, false);
return upgradeVersions.stream().map(upgradeVersion -> upgradeVersion.getVersionResourceURI()).collect(Collectors.toList());
});
result.setAvailableUpgrades(upgradeUris.orElseGet(List::of));
}
}
use of com.b2international.snowowl.core.version.Version in project snow-owl by b2ihealthcare.
the class VersionSearchRequest method toResource.
private Version toResource(VersionDocument doc) {
Version version = new Version();
version.setId(doc.getId());
version.setVersion(doc.getVersion());
version.setDescription(doc.getDescription());
version.setEffectiveTime(doc.getEffectiveTimeAsLocalDate());
version.setResource(doc.getResource());
version.setBranchPath(doc.getBranchPath());
version.setCreatedAt(doc.getCreatedAt());
version.setAuthor(doc.getAuthor());
return version;
}
Aggregations