@Test public void testGetAdditionalData() throws BaleenException { MongoGazetteer gaz = new MongoGazetteer(); gaz.init(sfr, Collections.emptyMap()); Map<String, Object> helloData = gaz.getAdditionalData(EN_HELLO2); Map<String, Object> gutentagData = gaz.getAdditionalData(DE_HELLO); Map<String, Object> konnbanwaData = gaz.getAdditionalData(JP_HELLO); assertEquals(0, helloData.size()); assertEquals(2, gutentagData.size()); assertEquals(1, konnbanwaData.size()); assertTrue(gutentagData.containsKey(LANGUAGE)); assertEquals("de", gutentagData.get(LANGUAGE)); assertTrue(gutentagData.containsKey(TRANSLATION)); assertEquals("good day", gutentagData.get(TRANSLATION)); assertTrue(konnbanwaData.containsKey(LANGUAGE)); assertEquals("jp", konnbanwaData.get(LANGUAGE)); gaz.destroy(); }
@Override public Map<String, Object> getAdditionalData(String key) { ObjectId id = getId(key); if (id == null) { return Collections.emptyMap(); } Document doc = coll.find(new Document("_id", id)) .projection(new Document(valueField, 0).append("_id", 0)) .first(); if (doc == null) { return Collections.emptyMap(); } Map<String, Object> ret = new HashMap<>(); for (Entry<String, Object> mongoEntry : doc.entrySet()) { ret.put(mongoEntry.getKey(), mongoEntry.getValue()); } return ret; }
MongoGazetteer extends AbstractMultiMapGazetteer<ObjectId> { @Override public Map<String, Object> getAdditionalData(String key) { ObjectId id = getId(key); if (id == null) { return Collections.emptyMap(); } Document doc = coll.find(new Document("_id", id)) .projection(new Document(valueField, 0).append("_id", 0)) .first(); if (doc == null) { return Collections.emptyMap(); } Map<String, Object> ret = new HashMap<>(); for (Entry<String, Object> mongoEntry : doc.entrySet()) { ret.put(mongoEntry.getKey(), mongoEntry.getValue()); } return ret; } }
MongoGazetteer extends AbstractMultiMapGazetteer<ObjectId> { @Override public Map<String, Object> getAdditionalData(String key) { ObjectId id = getId(key); if (id == null) { return Collections.emptyMap(); } Document doc = coll.find(new Document("_id", id)) .projection(new Document(valueField, 0).append("_id", 0)) .first(); if (doc == null) { return Collections.emptyMap(); } Map<String, Object> ret = new HashMap<>(); for (Entry<String, Object> mongoEntry : doc.entrySet()) { ret.put(mongoEntry.getKey(), mongoEntry.getValue()); } return ret; }  }
MongoGazetteer extends AbstractMultiMapGazetteer<ObjectId> { @Override public Map<String, Object> getAdditionalData(String key) { ObjectId id = getId(key); if (id == null) { return Collections.emptyMap(); } Document doc = coll.find(new Document("_id", id)) .projection(new Document(valueField, 0).append("_id", 0)) .first(); if (doc == null) { return Collections.emptyMap(); } Map<String, Object> ret = new HashMap<>(); for (Entry<String, Object> mongoEntry : doc.entrySet()) { ret.put(mongoEntry.getKey(), mongoEntry.getValue()); } return ret; }  @Override void init(Resource connection, Map<String, Object> config); @Override Map<String, Object> getAdditionalData(String key); @Override void destroy(); @SuppressWarnings("unchecked") @Override void reloadValues(); }
MongoGazetteer extends AbstractMultiMapGazetteer<ObjectId> { @Override public Map<String, Object> getAdditionalData(String key) { ObjectId id = getId(key); if (id == null) { return Collections.emptyMap(); } Document doc = coll.find(new Document("_id", id)) .projection(new Document(valueField, 0).append("_id", 0)) .first(); if (doc == null) { return Collections.emptyMap(); } Map<String, Object> ret = new HashMap<>(); for (Entry<String, Object> mongoEntry : doc.entrySet()) { ret.put(mongoEntry.getKey(), mongoEntry.getValue()); } return ret; }  @Override void init(Resource connection, Map<String, Object> config); @Override Map<String, Object> getAdditionalData(String key); @Override void destroy(); @SuppressWarnings("unchecked") @Override void reloadValues(); static final String CONFIG_COLLECTION; static final String CONFIG_VALUE_FIELD; static final String DEFAULT_COLLECTION; static final String DEFAULT_VALUE_FIELD; }