@Override public synchronized boolean updateIfChanged(String identifier) throws IOException, RegistryException { // identify installed vocabulary by identifier Vocabulary installed = get(identifier); if (installed != null) { // match vocabulary by identifier and issued date Vocabulary matched = null; for (Vocabulary v : registryManager.getVocabularies()) { if (v.getUriString() != null && v.getUriString().equalsIgnoreCase(identifier) && installed.getIssued() != null && v.getIssued() != null && installed.getIssued().compareTo(v.getIssued()) == 0) { matched = v; break; } } // verify the version was updated if (matched != null && matched.getUriResolvable() != null) { File vocabFile = getVocabFile(matched.getUriResolvable()); return downloader.downloadIfChanged(matched.getUriResolvable().toURL(), vocabFile); } } return false; }
/** * Iterate through all registered vocabularies and populate a map where each key is the name of * the file if it were persisted, and the value is the Vocabulary object. * * @return map containing all registered vocabularies */ private Map<String, Vocabulary> getFileNameToVocabularyMap() { Map<String, Vocabulary> map = Maps.newHashMap(); try { for (Vocabulary v : registryManager.getVocabularies()) { if (v.getUriString() != null && v.getUriResolvable() != null) { String filename = org.gbif.ipt.utils.FileUtils.getSuffixedFileName( v.getUriResolvable().toString(), VOCAB_FILE_SUFFIX); map.put(filename, v); } } } catch (RegistryException e) { // add startup error message about Registry error String msg = RegistryException.logRegistryException(e.getType(), baseAction); warnings.addStartupError(msg); log.error(msg); // add startup error message that explains the consequence of the Registry error msg = baseAction.getText( "admin.extensions.vocabularies.couldnt.load", new String[] {cfg.getRegistryUrl()}); warnings.addStartupError(msg); log.error(msg); } return map; }
@Override public synchronized void installOrUpdateDefaults() throws InvalidConfigException, RegistryException { // all registered vocabularies List<Vocabulary> vocabularies = registryManager.getVocabularies(); for (Vocabulary latest : getLatestDefaults(vocabularies)) { Vocabulary installed = null; for (Vocabulary vocabulary : list()) { if (latest.getUriString().equalsIgnoreCase(vocabulary.getUriString())) { installed = vocabulary; break; } } if (installed == null) { try { install(latest.getUriResolvable().toURL()); } catch (MalformedURLException e) { throw new InvalidConfigException( InvalidConfigException.TYPE.INVALID_VOCABULARY, "Vocabulary has an invalid URL: " + latest.getUriResolvable().toString()); } } else { try { updateToLatest(installed, latest); } catch (IOException e) { throw new InvalidConfigException( InvalidConfigException.TYPE.INVALID_DATA_DIR, "Can't update default vocabulary: " + installed.getUriString(), e); } } } // update each installed vocabulary indicating whether it is the latest version (for its // identifier) or not updateIsLatest(list(), vocabularies); }