@Test public void ensureThatEnrichedPropertiesAreLinked() throws NodeFactoryException { this.taxonService = new ResolvingTaxonIndex(new PropertyEnricher() { @Override public Map<String, String> enrichFirstMatch(Map<String, String> properties) throws PropertyEnricherException { return enrichAllMatches(properties).get(0); } @Override public List<Map<String, String>> enrichAllMatches(Map<String, String> properties) throws PropertyEnricherException { Taxon taxon1 = enrichTaxonWithSuffix(properties, "1"); Taxon taxon2 = enrichTaxonWithSuffix(properties, "2"); return Arrays.asList( TaxonUtil.taxonToMap(taxon1), TaxonUtil.taxonToMap(taxon2) ); } Taxon enrichTaxonWithSuffix(Map<String, String> properties, String suffix) { Taxon taxon = TaxonUtil.mapToTaxon(properties); taxon.setPathNames("kingdom" + suffix + CharsetConstant.SEPARATOR + "phylum" + CharsetConstant.SEPARATOR + "etc" + CharsetConstant.SEPARATOR); taxon.setPath("a kingdom name" + suffix + CharsetConstant.SEPARATOR + "a phylum name" + CharsetConstant.SEPARATOR + "a etc name" + CharsetConstant.SEPARATOR); taxon.setPathIds("a kingdom id" + suffix + CharsetConstant.SEPARATOR + "a phylum id" + CharsetConstant.SEPARATOR + "a etc id" + CharsetConstant.SEPARATOR); taxon.setExternalId("anExternalId" + suffix); taxon.setCommonNames(EXPECTED_COMMON_NAMES); return taxon; } @Override public void shutdown() { } }, getGraphDb() ); Transaction transaction = getGraphDb().beginTx(); assertThat(getGraphDb().index().existsForNodes("taxons"), is(true)); assertThat(getGraphDb().index().existsForNodes("thisDoesnoTExist"), is(false)); transaction.success(); transaction.close(); TaxonNode indexedTaxonNode = taxonService.getOrCreateTaxon(new TaxonImpl("some name1")); assertEnrichedPropertiesSet(indexedTaxonNode, "1"); TaxonNode someFoundTaxonNode = taxonService.findTaxonByName("some name1"); assertThat(someFoundTaxonNode.getNodeID(), is(indexedTaxonNode.getNodeID())); assertEnrichedPropertiesSet(someFoundTaxonNode, "1"); try (Transaction ignored = getGraphDb().beginTx()) { Index<Node> ids = getGraphDb().index().forNodes(INDEX_TAXON_NAMES_AND_IDS, MapUtil.stringMap(IndexManager.PROVIDER, "lucene", "type", "fulltext")); assertThat( ids.query("path:\"some name2\"").size(), is(0) ); } LinkerTaxonIndex linkerTaxonIndex = new LinkerTaxonIndex(); linkerTaxonIndex.index(new GraphServiceFactoryProxy(getGraphDb())); try (Transaction ignored = getGraphDb().beginTx()) { Index<Node> ids = getGraphDb().index().forNodes(INDEX_TAXON_NAMES_AND_IDS, MapUtil.stringMap(IndexManager.PROVIDER, "lucene", "type", "fulltext")); IndexHits<Node> hits = ids.query("path:\"a kingdom name2\""); assertThat(hits.size(), is(1)); for (Node hit : hits) { TaxonNode taxonHit = new TaxonNode(hit); assertNotNull(taxonHit); assertThat(taxonHit.getNodeID(), is(indexedTaxonNode.getNodeID())); } } TaxonNode someOtherFoundTaxonNodeTake2 = taxonService.findTaxonByName("some name2"); assertNull(someOtherFoundTaxonNodeTake2); }
@Override public TaxonNode getOrCreateTaxon(Taxon taxon) throws NodeFactoryException { if (StringUtils.isBlank(taxon.getExternalId()) && StringUtils.length(taxon.getName()) < 3) { throw new NodeFactoryException("taxon name [" + taxon.getName() + "] too short and no externalId is provided"); } TaxonNode taxonNode = findTaxon(taxon); return taxonNode == null ? createTaxon(taxon) : taxonNode; }
ResolvingTaxonIndex extends NonResolvingTaxonIndex { @Override public TaxonNode getOrCreateTaxon(Taxon taxon) throws NodeFactoryException { if (StringUtils.isBlank(taxon.getExternalId()) && StringUtils.length(taxon.getName()) < 3) { throw new NodeFactoryException("taxon name [" + taxon.getName() + "] too short and no externalId is provided"); } TaxonNode taxonNode = findTaxon(taxon); return taxonNode == null ? createTaxon(taxon) : taxonNode; } }
ResolvingTaxonIndex extends NonResolvingTaxonIndex { @Override public TaxonNode getOrCreateTaxon(Taxon taxon) throws NodeFactoryException { if (StringUtils.isBlank(taxon.getExternalId()) && StringUtils.length(taxon.getName()) < 3) { throw new NodeFactoryException("taxon name [" + taxon.getName() + "] too short and no externalId is provided"); } TaxonNode taxonNode = findTaxon(taxon); return taxonNode == null ? createTaxon(taxon) : taxonNode; } ResolvingTaxonIndex(PropertyEnricher enricher, GraphDatabaseService graphDbService); }
ResolvingTaxonIndex extends NonResolvingTaxonIndex { @Override public TaxonNode getOrCreateTaxon(Taxon taxon) throws NodeFactoryException { if (StringUtils.isBlank(taxon.getExternalId()) && StringUtils.length(taxon.getName()) < 3) { throw new NodeFactoryException("taxon name [" + taxon.getName() + "] too short and no externalId is provided"); } TaxonNode taxonNode = findTaxon(taxon); return taxonNode == null ? createTaxon(taxon) : taxonNode; } ResolvingTaxonIndex(PropertyEnricher enricher, GraphDatabaseService graphDbService); @Override TaxonNode getOrCreateTaxon(Taxon taxon); TaxonNode indexFirstAndConnectRemaining(List<Map<String, String>> taxonMatches, Taxon origTaxon); Taxon selectPrimaryTaxon(List<Map<String, String>> taxonMatches); TaxonNode indexAndConnect(List<Map<String, String>> taxonMatches, Taxon origTaxon, Taxon primaryTaxon); void setEnricher(PropertyEnricher enricher); void setIndexResolvedTaxaOnly(boolean indexResolvedOnly); boolean isIndexResolvedOnly(); }
ResolvingTaxonIndex extends NonResolvingTaxonIndex { @Override public TaxonNode getOrCreateTaxon(Taxon taxon) throws NodeFactoryException { if (StringUtils.isBlank(taxon.getExternalId()) && StringUtils.length(taxon.getName()) < 3) { throw new NodeFactoryException("taxon name [" + taxon.getName() + "] too short and no externalId is provided"); } TaxonNode taxonNode = findTaxon(taxon); return taxonNode == null ? createTaxon(taxon) : taxonNode; } ResolvingTaxonIndex(PropertyEnricher enricher, GraphDatabaseService graphDbService); @Override TaxonNode getOrCreateTaxon(Taxon taxon); TaxonNode indexFirstAndConnectRemaining(List<Map<String, String>> taxonMatches, Taxon origTaxon); Taxon selectPrimaryTaxon(List<Map<String, String>> taxonMatches); TaxonNode indexAndConnect(List<Map<String, String>> taxonMatches, Taxon origTaxon, Taxon primaryTaxon); void setEnricher(PropertyEnricher enricher); void setIndexResolvedTaxaOnly(boolean indexResolvedOnly); boolean isIndexResolvedOnly();  }