Search in sources :

Example 16 with RepositoryContext

use of com.b2international.snowowl.core.domain.RepositoryContext in project snow-owl by b2ihealthcare.

the class SnomedRepositoryPreCommitHook method postUpdateDocuments.

@Override
protected void postUpdateDocuments(StagingArea staging, RevisionSearcher index) throws IOException {
    final RepositoryContext context = ClassUtils.checkAndCast(staging.getContext(), RepositoryContext.class);
    if (canRestoreEffectiveTime(context) && !staging.isMerge()) {
        final long branchBaseTimestamp = index.get(RevisionBranch.class, staging.getBranchPath()).getBaseTimestamp();
        // XXX effective time restore should be the last processing unit before we send the changes to commit
        doProcess(Collections.singleton(new ComponentEffectiveTimeRestoreChangeProcessor(log, branchBaseTimestamp)), staging, index);
    }
}
Also used : RepositoryContext(com.b2international.snowowl.core.domain.RepositoryContext) RevisionBranch(com.b2international.index.revision.RevisionBranch)

Example 17 with RepositoryContext

use of com.b2international.snowowl.core.domain.RepositoryContext in project snow-owl by b2ihealthcare.

the class SnomedRepositoryPreCommitHook method preUpdateDocuments.

@Override
protected void preUpdateDocuments(StagingArea staging, RevisionSearcher index) throws IOException {
    final RepositoryContext context = ClassUtils.checkAndCast(staging.getContext(), RepositoryContext.class);
    if (!(context instanceof Rf2TransactionContext)) {
        final ImmutableList.Builder<ChangeSetProcessor> processors = ImmutableList.builder();
        processors.add(new DetachedContainerChangeProcessor());
        if (!staging.isMerge()) {
            processors.add(new ComponentInactivationChangeProcessor());
        }
        doProcess(processors.build(), staging, index);
    }
}
Also used : RepositoryContext(com.b2international.snowowl.core.domain.RepositoryContext) ImmutableList(com.google.common.collect.ImmutableList) ChangeSetProcessor(com.b2international.snowowl.core.repository.ChangeSetProcessor) Rf2TransactionContext(com.b2international.snowowl.snomed.datastore.request.rf2.importer.Rf2TransactionContext)

Example 18 with RepositoryContext

use of com.b2international.snowowl.core.domain.RepositoryContext in project snow-owl by b2ihealthcare.

the class ComponentEffectiveTimeRestoreChangeProcessor method process.

@Override
public void process(StagingArea staging, RevisionSearcher searcher) throws IOException {
    final Multimap<Class<? extends SnomedDocument>, SnomedDocument> componentsByType = ArrayListMultimap.create();
    staging.getChangedObjects().filter(SnomedDocument.class::isInstance).map(SnomedDocument.class::cast).filter(doc -> doc.isReleased() && EffectiveTimes.isUnset(doc.getEffectiveTime())).forEach(doc -> componentsByType.put(doc.getClass(), doc));
    if (componentsByType.isEmpty()) {
        return;
    }
    final RepositoryContext context = ClassUtils.checkAndCast(staging.getContext(), RepositoryContext.class);
    final List<String> branchesForPreviousVersion = getAvailableVersionPaths(context, staging.getBranchPath());
    if (branchesForPreviousVersion.isEmpty()) {
        return;
    }
    final Multimap<Class<? extends SnomedDocument>, String> componentHadPreviousVersionOnAnyBranch = ArrayListMultimap.create();
    for (String branchToCheck : branchesForPreviousVersion) {
        for (Class<? extends SnomedDocument> componentType : ImmutableSet.copyOf(componentsByType.keySet())) {
            final Set<String> componentIds = componentsByType.get(componentType).stream().map(SnomedDocument::getId).collect(Collectors.toSet());
            final Map<String, ? extends SnomedDocument> previousVersions = Maps.uniqueIndex(fetchPreviousComponentRevisions(staging.getIndex(), branchToCheck, componentType, componentIds), SnomedDocument::getId);
            for (SnomedDocument changedRevision : ImmutableList.copyOf(componentsByType.get(componentType))) {
                final SnomedDocument previousVersion = previousVersions.get(changedRevision.getId());
                if (previousVersion != null) {
                    if (canRestoreEffectiveTime(changedRevision, previousVersion)) {
                        SnomedDocument restoredRevision = toBuilder(changedRevision).effectiveTime(previousVersion.getEffectiveTime()).build();
                        stageChange(changedRevision, restoredRevision);
                        // successfully restored, remove from remaining item list
                        componentsByType.remove(componentType, changedRevision);
                    } else {
                        // register as a component that had an earlier version and can be ignored from the warning message beneath even if there were no prev versions to restore ET from
                        componentHadPreviousVersionOnAnyBranch.put(componentType, changedRevision.getId());
                    }
                }
            }
        }
    }
    // after checking all branches, clear everything that had at least one previous version, report anything that remains as released content without previous version
    componentHadPreviousVersionOnAnyBranch.forEach((componentType, changedRevisionId) -> {
        componentsByType.remove(componentType, changedRevisionId);
    });
    if (!componentsByType.isEmpty()) {
        log.warn("There were components which could not be restored, {}.", componentsByType.values().stream().map(SnomedDocument::getId).collect(Collectors.toSet()));
    }
}
Also used : UnexpectedTypeException(javax.validation.UnexpectedTypeException) EffectiveTimes(com.b2international.snowowl.core.date.EffectiveTimes) ChangeSetProcessorBase(com.b2international.snowowl.core.repository.ChangeSetProcessorBase) java.util(java.util) TerminologyResource(com.b2international.snowowl.core.TerminologyResource) Logger(org.slf4j.Logger) RepositoryContext(com.b2international.snowowl.core.domain.RepositoryContext) ResourceRequests(com.b2international.snowowl.core.request.ResourceRequests) ClassUtils(com.b2international.commons.ClassUtils) ResourceURIPathResolver(com.b2international.snowowl.core.uri.ResourceURIPathResolver) IOException(java.io.IOException) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) SearchResourceRequest(com.b2international.snowowl.core.request.SearchResourceRequest) VersionDocument(com.b2international.snowowl.core.version.VersionDocument) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) StagingArea(com.b2international.index.revision.StagingArea) RevisionIndex(com.b2international.index.revision.RevisionIndex) com.b2international.snowowl.snomed.datastore.index.entry(com.b2international.snowowl.snomed.datastore.index.entry) com.google.common.collect(com.google.common.collect) ResourceURI(com.b2international.snowowl.core.ResourceURI) Version(com.b2international.snowowl.core.version.Version) RepositoryContext(com.b2international.snowowl.core.domain.RepositoryContext)

Aggregations

RepositoryContext (com.b2international.snowowl.core.domain.RepositoryContext)18 Request (com.b2international.snowowl.core.events.Request)8 Collectors (java.util.stream.Collectors)8 CompareUtils (com.b2international.commons.CompareUtils)5 BadRequestException (com.b2international.commons.exceptions.BadRequestException)5 Branch (com.b2international.snowowl.core.branch.Branch)5 EffectiveTimes (com.b2international.snowowl.core.date.EffectiveTimes)5 Permission (com.b2international.snowowl.core.identity.Permission)5 IOException (java.io.IOException)5 ResourceURI (com.b2international.snowowl.core.ResourceURI)4 TerminologyResource (com.b2international.snowowl.core.TerminologyResource)4 AccessControl (com.b2international.snowowl.core.authorization.AccessControl)4 RepositoryRequests (com.b2international.snowowl.core.repository.RepositoryRequests)4 SnomedRf2Headers (com.b2international.snowowl.snomed.common.SnomedRf2Headers)4 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)4 LocalDate (java.time.LocalDate)4 java.util (java.util)4 List (java.util.List)4 Stream (java.util.stream.Stream)4 NotNull (javax.validation.constraints.NotNull)4