Skip to content

Commit

Permalink
Exclude merge sectors from auto blocking in regular syncs. Fixes Cata…
Browse files Browse the repository at this point in the history
  • Loading branch information
mdoering committed Nov 1, 2024
1 parent 0674e07 commit 5aa3e90
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ abstract class SectorRunnable implements Runnable {
// maps keyed on taxon ids from this sector
final Map<String, EditorialDecision> decisions = new HashMap<>();
List<Sector> childSectors;
// map with foreign child id to original parent name
Map<String, Name> foreignChildrenParents = new HashMap<>();
private final UsageMatcherGlobal matcher;
private final boolean clearMatcherCache;
private final Consumer<SectorRunnable> successCallback;
Expand Down Expand Up @@ -283,7 +281,8 @@ private void loadAttachedSectors() {
SectorMapper sm = session.getMapper(SectorMapper.class);
childSectors=sm.listChildSectors(sectorKey);
}
LOG.info("Loaded {} sectors targeting taxa from sector {}", childSectors.size(), sectorKey);
long mergeCnt = childSectors.stream().filter(s -> s.getMode() == Sector.Mode.MERGE).count();
LOG.info("Loaded {} sectors incl {} merge sectors targeting taxa from sector {}", childSectors.size(), mergeCnt, sectorKey);
}

abstract void doWork() throws Exception;
Expand Down
11 changes: 9 additions & 2 deletions webservice/src/main/java/life/catalogue/assembly/SectorSync.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import life.catalogue.matching.decision.RematchRequest;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -57,6 +58,8 @@ public class SectorSync extends SectorRunnable {
private final int targetDatasetKey; // dataset to sync into
private @Nullable TreeMergeHandlerConfig mergeCfg;
private List<SimpleName> foreignChildren;
// map with foreign child id to original parent name
private final Map<String, Name> foreignChildrenParents = new HashMap<>();
private final UsageIdGen usageIdGen;
private final Supplier<String> nameIdGen;
private final Supplier<String> typeMaterialIdGen;
Expand Down Expand Up @@ -145,13 +148,17 @@ void init() throws Exception {
super.init(true);
loadForeignChildren();
if (!disableAutoBlocking) {
// also load all sector subjects to auto block them
// also load all sector subjects of non merge sources to auto block them
try (SqlSession session = factory.openSession()) {
AtomicInteger counter = new AtomicInteger();
PgUtils.consume(
() -> session.getMapper(SectorMapper.class).processSectors(sectorKey.getDatasetKey(), subjectDatasetKey),
s -> {
if (!s.getId().equals(sectorKey.getId()) && s.getSubject() != null && s.getSubject().getId() != null) {
if (!s.getId().equals(sectorKey.getId())
&& s.getSubject() != null
&& s.getSubject().getId() != null
&& s.getMode() != Sector.Mode.MERGE
) {
EditorialDecision d = new EditorialDecision();
d.setSubject(s.getSubject());
d.setDatasetKey(sectorKey.getDatasetKey());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public class SectorSyncMergeIT extends SectorSyncTestBase {
@Parameterized.Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] {
{"myosotis", List.of("taxref", "uksi", "pbdb", "bavaria")},
{"tetralobus", List.of("wfo", "bouchard", "plazi")},
{"cactus", List.of("wfo", "wcvp", "grin", "taxref", "tpl", "pbdb")},
{"aphanizomenon", List.of("worms","ncbi","dyntaxa")}, // https://github.com/CatalogueOfLife/xcol/issues/146
Expand Down

0 comments on commit 5aa3e90

Please sign in to comment.