Search in sources :

Example 11 with Version

use of com.b2international.snowowl.core.version.Version 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

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