TermUriTranslator implements Translator { @Override public String translate(String key) { KeywordBean keyword; if (thesaurus == null) { setThesaurus(); } if (thesaurus == null) { if (Log.isTraceEnabled(Geonet.THESAURUS)) { Log.trace(Geonet.THESAURUS, "Thesaurus not available [uri:" + conceptSchemeUri + ", lang:" + langCode + ", " + key + "]"); } return key; } try { keyword = thesaurus.getKeyword(key, langCode); } catch (TermNotFoundException e) { Log.error(Geonet.THESAURUS, "Term not found: " + key); return key; } catch (NullPointerException e) { Log.error(Geonet.THESAURUS, "NPE searching term: " + key); return key; } String label; try { label = keyword.getPreferredLabel(langCode); } catch (LabelNotFoundException e) { return keyword.getUriCode(); } return label; } TermUriTranslator(ThesaurusFinder finder, String langCode, String conceptSchemeUri); @Override String translate(String key);  }
@Test public void testTermWithPreferredLabelForLanguage() throws IOException, ConfigurationException { ThesaurusFinder finder = createThesaurusFinderFor(isoLangMapper, "TermUriTranslatorTest.rdf"); Translator translator = new TermUriTranslator(finder, "eng", "http: String label = translator.translate("http: assertEquals("ocean temperature", label); }
@Test public void testTermWithNoPreferredLabelForLanguage() throws IOException, ConfigurationException { ThesaurusFinder finder = createThesaurusFinderFor(isoLangMapper, "TermUriTranslatorTest.rdf"); Translator translator = new TermUriTranslator(finder, "ger", "http: String label = translator.translate("http: assertEquals("http: }
@Test public void testMissingTerm() throws IOException, ConfigurationException { ThesaurusFinder finder = createThesaurusFinderFor(isoLangMapper, "TermUriTranslatorTest.rdf"); Translator translator = new TermUriTranslator(finder, "ger", "http: String label = translator.translate("http: assertEquals("http: }