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