Search in sources :

Example 1 with Branches

use of com.b2international.snowowl.core.branch.Branches in project snow-owl by b2ihealthcare.

the class ClassificationTaskConverter method expand.

@Override
public void expand(final List<ClassificationTask> results) {
    final Multimap<String, ClassificationTask> tasksByBranch = Multimaps.index(results, ClassificationTask::getBranch);
    final Branches branches = RepositoryRequests.branching().prepareSearch().setLimit(tasksByBranch.keySet().size()).filterByIds(tasksByBranch.keySet()).build().execute(context());
    final Map<String, Long> headTimestamps = branches.stream().collect(Collectors.toMap(Branch::path, Branch::headTimestamp));
    // Overwrite stored status if the branch has moved forward in the meantime, except if the task is saved
    for (final ClassificationTask task : results) {
        if (SAVE_AND_SCHEDULED_STATUSES.contains(task.getStatus())) {
            continue;
        }
        if (task.getTimestamp() < headTimestamps.get(task.getBranch())) {
            task.setStatus(ClassificationStatus.STALE);
        }
    }
    if (expand().isEmpty()) {
        return;
    }
    final Set<String> classificationTaskIds = results.stream().map(ClassificationTask::getId).collect(Collectors.toSet());
    expandEquivalentConceptSets(results, classificationTaskIds);
    expandRelationshipChanges(results, classificationTaskIds);
    expandConcreteDomainChanges(results, classificationTaskIds);
}
Also used : ClassificationTask(com.b2international.snowowl.snomed.reasoner.domain.ClassificationTask) Branches(com.b2international.snowowl.core.branch.Branches)

Example 2 with Branches

use of com.b2international.snowowl.core.branch.Branches 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());
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) SnomedConceptSearchRequestBuilder(com.b2international.snowowl.snomed.datastore.request.SnomedConceptSearchRequestBuilder) SnomedRelationshipIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry) SnomedReferenceSets(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSets) RepositoryRequests(com.b2international.snowowl.core.repository.RepositoryRequests) Sets.newTreeSet(com.google.common.collect.Sets.newTreeSet) Collections.singleton(java.util.Collections.singleton) AccessControl(com.b2international.snowowl.core.authorization.AccessControl) LocalTime(java.time.LocalTime) RevisionIndex(com.b2international.index.revision.RevisionIndex) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) AttachmentRegistry(com.b2international.snowowl.core.attachments.AttachmentRegistry) Branches(com.b2international.snowowl.core.branch.Branches) Permission(com.b2international.snowowl.core.identity.Permission) CompareUtils(com.b2international.commons.CompareUtils) Path(java.nio.file.Path) com.google.common.collect(com.google.common.collect) Collectors.toSet(java.util.stream.Collectors.toSet) ResourceURI(com.b2international.snowowl.core.ResourceURI) com.b2international.snowowl.core.request(com.b2international.snowowl.core.request) Version(com.b2international.snowowl.core.version.Version) RepositoryContext(com.b2international.snowowl.core.domain.RepositoryContext) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) Request(com.b2international.snowowl.core.events.Request) IEventBus(com.b2international.snowowl.eventbus.IEventBus) Instant(java.time.Instant) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Stream(java.util.stream.Stream) VersionDocument(com.b2international.snowowl.core.version.VersionDocument) LocalDate(java.time.LocalDate) Sort(com.b2international.snowowl.core.request.SearchResourceRequest.Sort) Entry(java.util.Map.Entry) CodeSystemRequests(com.b2international.snowowl.core.codesystem.CodeSystemRequests) SnomedDescriptionIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionIndexEntry) BranchContext(com.b2international.snowowl.core.domain.BranchContext) Builder(com.google.common.collect.ImmutableList.Builder) FileUtils(com.b2international.commons.FileUtils) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) EffectiveTimes(com.b2international.snowowl.core.date.EffectiveTimes) java.util(java.util) TerminologyResource(com.b2international.snowowl.core.TerminologyResource) LocalDateTime(java.time.LocalDateTime) com.b2international.snowowl.snomed.datastore.request.rf2.exporter(com.b2international.snowowl.snomed.datastore.request.rf2.exporter) com.b2international.snowowl.snomed.core.domain(com.b2international.snowowl.snomed.core.domain) Branch(com.b2international.snowowl.core.branch.Branch) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) Strings(com.google.common.base.Strings) SnomedRequests(com.b2international.snowowl.snomed.datastore.request.SnomedRequests) Attachment(com.b2international.snowowl.core.attachments.Attachment) SnomedRefSetMemberSearchRequestBuilder(com.b2international.snowowl.snomed.datastore.request.SnomedRefSetMemberSearchRequestBuilder) BadRequestException(com.b2international.commons.exceptions.BadRequestException) BranchPathUtils(com.b2international.snowowl.core.branch.BranchPathUtils) DateFormats(com.b2international.snowowl.core.date.DateFormats) Files(java.nio.file.Files) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) SnomedTerminologyComponentConstants(com.b2international.snowowl.snomed.common.SnomedTerminologyComponentConstants) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) ChronoUnit(java.time.temporal.ChronoUnit) SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) NotEmpty(org.hibernate.validator.constraints.NotEmpty) DateTimeFormatter(java.time.format.DateTimeFormatter) IComponent(com.b2international.snowowl.core.domain.IComponent) SnomedRf2Headers(com.b2international.snowowl.snomed.common.SnomedRf2Headers) Versions(com.b2international.snowowl.core.version.Versions) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType) ResourceURI(com.b2international.snowowl.core.ResourceURI) Version(com.b2international.snowowl.core.version.Version) Branches(com.b2international.snowowl.core.branch.Branches) Branch(com.b2international.snowowl.core.branch.Branch) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem)

Aggregations

Branches (com.b2international.snowowl.core.branch.Branches)2 CompareUtils (com.b2international.commons.CompareUtils)1 FileUtils (com.b2international.commons.FileUtils)1 BadRequestException (com.b2international.commons.exceptions.BadRequestException)1 RevisionIndex (com.b2international.index.revision.RevisionIndex)1 ResourceURI (com.b2international.snowowl.core.ResourceURI)1 TerminologyResource (com.b2international.snowowl.core.TerminologyResource)1 SnowowlRuntimeException (com.b2international.snowowl.core.api.SnowowlRuntimeException)1 Attachment (com.b2international.snowowl.core.attachments.Attachment)1 AttachmentRegistry (com.b2international.snowowl.core.attachments.AttachmentRegistry)1 AccessControl (com.b2international.snowowl.core.authorization.AccessControl)1 Branch (com.b2international.snowowl.core.branch.Branch)1 BranchPathUtils (com.b2international.snowowl.core.branch.BranchPathUtils)1 CodeSystem (com.b2international.snowowl.core.codesystem.CodeSystem)1 CodeSystemRequests (com.b2international.snowowl.core.codesystem.CodeSystemRequests)1 DateFormats (com.b2international.snowowl.core.date.DateFormats)1 EffectiveTimes (com.b2international.snowowl.core.date.EffectiveTimes)1 BranchContext (com.b2international.snowowl.core.domain.BranchContext)1 IComponent (com.b2international.snowowl.core.domain.IComponent)1 RepositoryContext (com.b2international.snowowl.core.domain.RepositoryContext)1