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()));
}
}
Aggregations