ThesaurusManager implements ThesaurusFinder { public Element buildResultfromThTable(ServiceContext context) throws SQLException, JDOMException, IOException { Element elRoot = new Element("thesauri"); Collection<Thesaurus> e = getThesauriMap().values(); for (Thesaurus currentTh : e) { Element elLoop = new Element("thesaurus"); Element elKey = new Element("key"); String key = currentTh.getKey(); elKey.addContent(key); Element elDname = new Element("dname"); String dname = currentTh.getDname(); elDname.addContent(dname); Element elFname = new Element("filename"); String fname = currentTh.getFname(); elFname.addContent(fname); Element elTitle = new Element("title"); String title = currentTh.getTitles(context.getApplicationContext()).get(context.getLanguage()); if (title == null) { title = currentTh.getTitle(); } elTitle.addContent(title); Element elMultilingualTitles = new Element("multilingualTitles"); for (Map.Entry<String, String> entry : currentTh.getMultilingualTitles().entrySet()) { Element elMultilingualTitle = new Element("multilingualTitle"); Element elMultilingualTitl_lang = new Element("lang"); elMultilingualTitl_lang.setText(entry.getKey()); Element elMultilingualTitle_title = new Element("title"); elMultilingualTitle_title.setText(entry.getValue()); elMultilingualTitle.addContent(elMultilingualTitl_lang); elMultilingualTitle.addContent(elMultilingualTitle_title); elMultilingualTitles.addContent(elMultilingualTitle); } Element elDublinCoreMultilingual = new Element("dublinCoreMultilinguals"); for (Map.Entry<String, Map<String,String>> entryLang : currentTh.getDublinCoreMultilingual().entrySet()) { String lang = entryLang.getKey(); for (Map.Entry<String, String> entryItem : entryLang.getValue().entrySet()) { Element elItem = new Element("dublinCoreMultilingual"); Element elLang = new Element("lang"); elLang.setText(lang); Element elTag = new Element("tag"); elTag.setText(entryItem.getKey()); Element elValue = new Element("value"); elValue.setText(entryItem.getValue()); elItem.addContent(elLang); elItem.addContent(elTag); elItem.addContent(elValue); elDublinCoreMultilingual.addContent(elItem); } } Element elType = new Element("type"); String type = currentTh.getType(); elType.addContent(type); Element elDate = new Element("date"); String date = currentTh.getDate(); elDate.addContent(date); Element elUrl = new Element("url"); String url = currentTh.getDownloadUrl(); elUrl.addContent(url); Element elDefaultURI = new Element("defaultNamespace"); String defaultURI = currentTh.getDefaultNamespace(); elDefaultURI.addContent(defaultURI); Element elActivated = new Element("activated"); char activated = Constants.YN_TRUE; final ThesaurusActivationRepository activationRepository = context.getBean(ThesaurusActivationRepository.class); final ThesaurusActivation activation = activationRepository.findOne(currentTh.getKey()); if (activation != null && !activation.isActivated()) { activated = Constants.YN_FALSE; } elActivated.setText("" + activated); elLoop.addContent(elKey); elLoop.addContent(elDname); elLoop.addContent(elFname); elLoop.addContent(elTitle); elLoop.addContent(elMultilingualTitles); elLoop.addContent(elDublinCoreMultilingual); elLoop.addContent(elDate); elLoop.addContent(elUrl); elLoop.addContent(elDefaultURI); elLoop.addContent(elType); elLoop.addContent(elActivated); elRoot.addContent(elLoop); } return elRoot; }  synchronized void init(boolean isTest, ServiceContext context, String thesauriRepository); Path buildThesaurusFilePath(String fname, String type, String dname); void addThesaurus(Thesaurus gst, boolean writeTitle); void remove(String name); Path getThesauriDirectory(); @Override Map<String, Thesaurus> getThesauriMap(); @Override @Nullable Thesaurus getThesaurusByName(@Nonnull String thesaurusName); @Override Thesaurus getThesaurusByConceptScheme(String uri); @Override boolean existsThesaurus(String name); String createUpdateThesaurusFromRegister(String uuid, String type, ServiceContext context); Element buildResultfromThTable(ServiceContext context);  }
@Test public void testBuildResultfromThTable() throws Exception { this.settingManager.setValue(Settings.SYSTEM_ENABLE_ALL_THESAURUS, false); final int numThesaurus = this.thesaurusManager.getThesauriMap().size(); Element element = this.thesaurusManager.buildResultfromThTable(createServiceContext()); assertEquals(numThesaurus, Xml.selectNodes(element, "thesaurus").size()); this.settingManager.setValue(Settings.SYSTEM_ENABLE_ALL_THESAURUS, true); element = this.thesaurusManager.buildResultfromThTable(createServiceContext()); assertEquals(numThesaurus + 1, Xml.selectNodes(element, "thesaurus").size()); this.settingManager.setValue(Settings.SYSTEM_ENABLE_ALL_THESAURUS, false); element = this.thesaurusManager.buildResultfromThTable(createServiceContext()); assertEquals(numThesaurus, Xml.selectNodes(element, "thesaurus").size()); }