Search in sources :

Example 1 with Version

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)));
}
Also used : CodeSystemVersionRestRequests.createVersion(com.b2international.snowowl.test.commons.codesystem.CodeSystemVersionRestRequests.createVersion) CodeSystemVersionRestRequests.getVersion(com.b2international.snowowl.test.commons.codesystem.CodeSystemVersionRestRequests.getVersion) Version(com.b2international.snowowl.core.version.Version) LocalDate(java.time.LocalDate) Test(org.junit.Test) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)

Example 2 with Version

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));
}
Also used : SnomedContentRule(com.b2international.snowowl.test.commons.SnomedContentRule) Version(com.b2international.snowowl.core.version.Version) Attachment(com.b2international.snowowl.core.attachments.Attachment) RemoteJobEntry(com.b2international.snowowl.core.jobs.RemoteJobEntry)

Example 3 with Version

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());
        }
    }
}
Also used : Path(java.nio.file.Path) LocalDateTime(java.time.LocalDateTime) AttachmentRegistry(com.b2international.snowowl.core.attachments.AttachmentRegistry) Attachment(com.b2international.snowowl.core.attachments.Attachment) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) BadRequestException(com.b2international.commons.exceptions.BadRequestException) IOException(java.io.IOException) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) Version(com.b2international.snowowl.core.version.Version) BadRequestException(com.b2international.commons.exceptions.BadRequestException) TerminologyResource(com.b2international.snowowl.core.TerminologyResource)

Example 4 with Version

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));
    }
}
Also used : BaseRevisionBranching(com.b2international.index.revision.BaseRevisionBranching) java.util(java.util) BranchState(com.b2international.index.revision.RevisionBranch.BranchState) RepositoryContext(com.b2international.snowowl.core.domain.RepositoryContext) ResourceRequests(com.b2international.snowowl.core.request.ResourceRequests) RepositoryManager(com.b2international.snowowl.core.RepositoryManager) RevisionBranch(com.b2international.index.revision.RevisionBranch) BranchInfo(com.b2international.snowowl.core.branch.BranchInfo) ResourceURIPathResolver(com.b2international.snowowl.core.uri.ResourceURIPathResolver) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) Multimaps(com.google.common.collect.Multimaps) ResourceDocument(com.b2international.snowowl.core.internal.ResourceDocument) Strings(com.google.common.base.Strings) ExtendedLocale(com.b2international.commons.http.ExtendedLocale) Options(com.b2international.commons.options.Options) Lists(com.google.common.collect.Lists) TreeMultimap(com.google.common.collect.TreeMultimap) Versions(com.b2international.snowowl.core.version.Versions) ResourceURI(com.b2international.snowowl.core.ResourceURI) BaseResourceConverter(com.b2international.snowowl.core.request.BaseResourceConverter) Version(com.b2international.snowowl.core.version.Version) ResourceURI(com.b2international.snowowl.core.ResourceURI) Versions(com.b2international.snowowl.core.version.Versions) Version(com.b2international.snowowl.core.version.Version)

Example 5 with Version

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;
}
Also used : Version(com.b2international.snowowl.core.version.Version)

Aggregations

Version (com.b2international.snowowl.core.version.Version)11 LocalDate (java.time.LocalDate)5 BadRequestException (com.b2international.commons.exceptions.BadRequestException)4 ResourceURI (com.b2international.snowowl.core.ResourceURI)4 RepositoryContext (com.b2international.snowowl.core.domain.RepositoryContext)4 java.util (java.util)4 Collectors (java.util.stream.Collectors)4 TerminologyResource (com.b2international.snowowl.core.TerminologyResource)3 EffectiveTimes (com.b2international.snowowl.core.date.EffectiveTimes)3 VersionDocument (com.b2international.snowowl.core.version.VersionDocument)3 IOException (java.io.IOException)3 CompareUtils (com.b2international.commons.CompareUtils)2 RevisionBranch (com.b2international.index.revision.RevisionBranch)2 RevisionIndex (com.b2international.index.revision.RevisionIndex)2 Attachment (com.b2international.snowowl.core.attachments.Attachment)2 AccessControl (com.b2international.snowowl.core.authorization.AccessControl)2 Branch (com.b2international.snowowl.core.branch.Branch)2 Request (com.b2international.snowowl.core.events.Request)2 Permission (com.b2international.snowowl.core.identity.Permission)2 RepositoryRequests (com.b2international.snowowl.core.repository.RepositoryRequests)2