@Override public Cache<VocabularyTerm> getTermCache(Vocabulary vocabulary) { if (!this.caches.containsKey(vocabulary.getIdentifier())) { try { initialize(vocabulary); } catch (InitializationException ex) { return null; } } return this.caches.get(vocabulary.getIdentifier()); }
@Override public SolrClient getSolrConnection(Vocabulary vocabulary) { if (!this.cores.containsKey(vocabulary.getIdentifier())) { try { initialize(vocabulary); } catch (InitializationException ex) { return null; } } return this.cores.get(vocabulary.getIdentifier()); }
@Override public boolean isVocabularySupported(Vocabulary vocabulary) { return getTargetVocabularyId().equals(vocabulary.getIdentifier()); }
@Override public boolean isVocabularySupported(Vocabulary vocabulary) { return getTargetVocabularyId().equals(vocabulary.getIdentifier()); }
@Override public SolrClient getReplacementSolrConnection(Vocabulary vocabulary) { return this.getSolrConnection(vocabulary.getIdentifier() + TEMP); }
@Override public boolean isVocabularySupported(@Nonnull final Vocabulary vocabulary) { return getTargetVocabularyIds().contains(vocabulary.getIdentifier()); }
@Override public void replaceCore(Vocabulary vocabulary) throws InitializationException { final String absPath = this.environment.getPermanentDirectory().getAbsolutePath(); final File indexOrigin = new File(absPath, SOLR + vocabulary.getIdentifier() + "/data"); final File indexTemp = new File(absPath, SOLR + vocabulary.getIdentifier() + TEMP + "/data"); try { CoreContainer container = this.coreContainer.getContainer(); SolrCore solrCore = container.getCore(vocabulary.getIdentifier()); if (solrCore != null) { solrCore.close(); } container.unload(vocabulary.getIdentifier(), true, false, false); FileUtils.copyDirectory(indexTemp, indexOrigin); initialize(vocabulary); } catch (IOException ex) { ex.printStackTrace(); } }
@Override public Response resolveTerm(String termId) { VocabularyTerm term = this.vm.resolveTerm(termId); if (term == null) { return Response.status(Response.Status.NOT_FOUND).build(); } JSONObject rep = term.toJSON(); rep.put("links", this.autolinker.get().forResource(getClass(), this.uriInfo) .withExtraParameters("vocabulary-id", term.getVocabulary().getIdentifier()).build()); return Response.ok(rep, MediaType.APPLICATION_JSON_TYPE).build(); } }
@Override public void createReplacementCore(Vocabulary vocabulary) throws InitializationException { try { final String replacementCoreId = vocabulary.getIdentifier() + TEMP; final String absPath = this.environment.getPermanentDirectory().getAbsolutePath(); File tempDirectory = new File(absPath, SOLR + replacementCoreId); if (!tempDirectory.exists()) { Files.createDirectories(tempDirectory.toPath()); } CoreContainer container = this.coreContainer.getContainer(); File configOrigin = new File(absPath, SOLR + vocabulary.getIdentifier() + "/conf"); File configTemp = new File(absPath, SOLR + replacementCoreId + "/conf"); FileUtils.copyDirectory(configOrigin, configTemp); container.create(replacementCoreId, Collections.<String, String>emptyMap()); SolrClient core = new EmbeddedSolrServer(container, replacementCoreId); this.cores.put(replacementCoreId, core); } catch (IOException ex) { throw new InitializationException("Invalid Solr resource: " + ex.getMessage(), ex); } }
@Override public Response resolveTerm(String termId) { VocabularyTerm term = this.vm.resolveTerm(termId); if (term == null) { return Response.status(Response.Status.NOT_FOUND).build(); } JSONObject rep = term.toJSON(); rep.put("links", this.autolinker.get().forResource(getClass(), this.uriInfo) .withExtraParameters("vocabulary-id", term.getVocabulary().getIdentifier()).build()); return Response.ok(rep, MediaType.APPLICATION_JSON_TYPE).build(); } }
@Override public void discardReplacementCore(Vocabulary vocabulary) { final String replacementCoreId = vocabulary.getIdentifier() + TEMP; if (this.cores.containsKey(replacementCoreId)) { CoreContainer container = this.coreContainer.getContainer(); SolrCore solrCore = container.getCore(replacementCoreId); if (solrCore != null) { solrCore.close(); } container.unload(replacementCoreId, true, true, true); this.cores.remove(replacementCoreId); this.caches.remove(replacementCoreId); } } }
@Override public void extendTerm(VocabularyInputTerm term, Vocabulary vocabulary) { Locale targetLocale = getTargetLocale(); String label = this.translator.getTranslation(vocabulary.getIdentifier(), term.getId().replace(':', '_') + KEY_MAP.get(NAME_KEY), targetLocale); String definition = this.translator.getTranslation(vocabulary.getIdentifier(), term.getId().replace(':', '_') + KEY_MAP.get(DESCRIPTION_KEY), targetLocale); String synonyms = this.translator.getTranslation(vocabulary.getIdentifier(), term.getId().replace(':', '_') + KEY_MAP.get(SYNONYM_KEY), targetLocale); if (StringUtils.isNotBlank(label)) { term.set(String.format(TRANSLATED_FIELD_FORMAT, NAME_KEY, targetLocale), label); } if (StringUtils.isNotBlank(definition)) { term.set(String.format(TRANSLATED_FIELD_FORMAT, DESCRIPTION_KEY, targetLocale), definition); } if (StringUtils.isNotBlank(synonyms)) { term.set(String.format(TRANSLATED_FIELD_FORMAT, SYNONYM_KEY, targetLocale), splitMultiValuedText(synonyms)); } }
@Override public void extendTerm(VocabularyInputTerm term, Vocabulary vocabulary) { if (!isTargetLocaleEnabled()) { return; } Locale targetLocale = getTargetLocale(); String label = this.translator.getTranslation(vocabulary.getIdentifier(), term.getId().replace(':', '_') + KEY_MAP.get(NAME_KEY), targetLocale); String definition = this.translator.getTranslation(vocabulary.getIdentifier(), term.getId().replace(':', '_') + KEY_MAP.get(DESCRIPTION_KEY), targetLocale); String synonyms = this.translator.getTranslation(vocabulary.getIdentifier(), term.getId().replace(':', '_') + KEY_MAP.get(SYNONYM_KEY), targetLocale); if (StringUtils.isNotBlank(label)) { term.set(String.format(TRANSLATED_FIELD_FORMAT, NAME_KEY, targetLocale), label); } if (StringUtils.isNotBlank(definition)) { term.set(String.format(TRANSLATED_FIELD_FORMAT, DESCRIPTION_KEY, targetLocale), definition); } if (StringUtils.isNotBlank(synonyms)) { term.set(String.format(TRANSLATED_FIELD_FORMAT, SYNONYM_KEY, targetLocale), splitMultiValuedText(synonyms)); } }
vocabulary.getIdentifier(), targetLocale, ex.getMessage()); vocabulary.getIdentifier(), targetLocale, ex.getMessage());
vocabulary.getIdentifier(), targetLocale, ex.getMessage()); vocabulary.getIdentifier(), targetLocale, ex.getMessage());
@Override public org.phenotips.vocabularies.rest.model.Vocabulary createLinkedVocabularyRepresentation( final Vocabulary vocabulary, final Autolinker linker, final Function<Vocabulary, List<org.phenotips.vocabularies.rest.model.Category>> categorySupplier) { final org.phenotips.vocabularies.rest.model.Vocabulary vocabularyRep = categorySupplier != null ? createVocabularyRepresentation(vocabulary).withCategories(categorySupplier.apply(vocabulary)) : createVocabularyRepresentation(vocabulary); vocabularyRep.withLinks(linker.withExtraParameters(VOCABULARY_ID_LABEL, vocabulary.getIdentifier()).build()); return vocabularyRep; }
private void initialize(Vocabulary vocabulary) throws InitializationException final String coreIdentifier = vocabulary.getIdentifier(); SolrCore solrCore = container.getCore(coreIdentifier);
@Override public org.phenotips.vocabularies.rest.model.Vocabulary createVocabularyRepresentation(Vocabulary vocabulary) { org.phenotips.vocabularies.rest.model.Vocabulary result = new org.phenotips.vocabularies.rest.model.Vocabulary(); result .withIdentifier(vocabulary.getIdentifier()) .withName(vocabulary.getName()) .withAliases(vocabulary.getAliases()) .withSize(vocabulary.size()) .withVersion(vocabulary.getVersion()); try { result.withDefaultSourceLocation(vocabulary.getDefaultSourceLocation()); } catch (UnsupportedOperationException e) { // Don't do anything and leave source empty } return result; }
@Override public org.phenotips.vocabularies.rest.model.Vocabulary createVocabularyRepresentation(Vocabulary vocabulary) { org.phenotips.vocabularies.rest.model.Vocabulary result = new org.phenotips.vocabularies.rest.model.Vocabulary(); result .withIdentifier(vocabulary.getIdentifier()) .withName(vocabulary.getName()) .withAliases(vocabulary.getAliases()) .withSize(vocabulary.size()) .withVersion(vocabulary.getVersion()); try { result.withDefaultSourceLocation(vocabulary.getDefaultSourceLocation()); } catch (UnsupportedOperationException e) { // Don't do anything and leave source empty } return result; }