Do not offer UMLS vocabulary in interface if umls.properties is absent. (#241)
* Replace hardcoded en locale with current locale in lang attributes * Do not offer UMLS vocabulary service in interface if umls.properties is absent
This commit is contained in:
parent
e3027841aa
commit
603e7f6bc8
2 changed files with 21 additions and 7 deletions
|
@ -4,12 +4,18 @@ package edu.cornell.mannlib.semservices.service.impl;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.apache.http.HttpVersion;
|
||||||
|
import org.apache.http.client.fluent.Form;
|
||||||
|
import org.apache.http.client.fluent.Request;
|
||||||
|
import org.apache.http.client.utils.URIBuilder;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
@ -18,11 +24,6 @@ import edu.cornell.mannlib.semservices.bo.Concept;
|
||||||
import edu.cornell.mannlib.semservices.exceptions.ConceptsNotFoundException;
|
import edu.cornell.mannlib.semservices.exceptions.ConceptsNotFoundException;
|
||||||
import edu.cornell.mannlib.semservices.service.ExternalConceptService;
|
import edu.cornell.mannlib.semservices.service.ExternalConceptService;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.json.JacksonUtils;
|
import edu.cornell.mannlib.vitro.webapp.utils.json.JacksonUtils;
|
||||||
import org.apache.http.HttpVersion;
|
|
||||||
import org.apache.http.client.fluent.Form;
|
|
||||||
import org.apache.http.client.fluent.Request;
|
|
||||||
import org.apache.http.client.utils.URIBuilder;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jaf30
|
* @author jaf30
|
||||||
|
@ -54,11 +55,13 @@ public class UMLSService implements ExternalConceptService {
|
||||||
private static String UMLS_AUTH_USER_URL = "https://utslogin.nlm.nih.gov/cas/v1/tickets";
|
private static String UMLS_AUTH_USER_URL = "https://utslogin.nlm.nih.gov/cas/v1/tickets";
|
||||||
private static String UMLS_AUTH_KEY_URL = "https://utslogin.nlm.nih.gov/cas/v1/api-key";
|
private static String UMLS_AUTH_KEY_URL = "https://utslogin.nlm.nih.gov/cas/v1/api-key";
|
||||||
private static String UTS_SERVICE_URL = "http://umlsks.nlm.nih.gov";
|
private static String UTS_SERVICE_URL = "http://umlsks.nlm.nih.gov";
|
||||||
|
private static final String UMLS_PROPERTIES = "/umls.properties";
|
||||||
|
private static final Log log = LogFactory.getLog(UMLSService.class);
|
||||||
|
|
||||||
{
|
{
|
||||||
if (username == null || apikey == null) {
|
if (username == null || apikey == null) {
|
||||||
final Properties properties = new Properties();
|
final Properties properties = new Properties();
|
||||||
try (InputStream stream = getClass().getResourceAsStream("/umls.properties")) {
|
try (InputStream stream = getClass().getResourceAsStream(UMLS_PROPERTIES)) {
|
||||||
properties.load(stream);
|
properties.load(stream);
|
||||||
username = properties.getProperty("username");
|
username = properties.getProperty("username");
|
||||||
password = properties.getProperty("password");
|
password = properties.getProperty("password");
|
||||||
|
@ -73,12 +76,19 @@ public class UMLSService implements ExternalConceptService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
log.error(e, e);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
log.error(e, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean configurationFileExists() {
|
||||||
|
URL config = UMLSService.class.getResource(UMLS_PROPERTIES);
|
||||||
|
return (config != null);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isConfigured() {
|
public boolean isConfigured() {
|
||||||
return !(StringUtils.isEmpty(username) && StringUtils.isEmpty(apikey));
|
return !(StringUtils.isEmpty(username) && StringUtils.isEmpty(apikey));
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import edu.cornell.mannlib.semservices.bo.Concept;
|
import edu.cornell.mannlib.semservices.bo.Concept;
|
||||||
import edu.cornell.mannlib.semservices.service.ExternalConceptService;
|
import edu.cornell.mannlib.semservices.service.ExternalConceptService;
|
||||||
|
import edu.cornell.mannlib.semservices.service.impl.UMLSService;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
/**
|
/**
|
||||||
* Utilities for search
|
* Utilities for search
|
||||||
|
@ -38,7 +39,9 @@ public class ConceptSearchServiceUtils {
|
||||||
//URL to label
|
//URL to label
|
||||||
public static HashMap<String, VocabSourceDescription> getVocabSources() {
|
public static HashMap<String, VocabSourceDescription> getVocabSources() {
|
||||||
HashMap<String, VocabSourceDescription> map = new HashMap<String, VocabSourceDescription>();
|
HashMap<String, VocabSourceDescription> map = new HashMap<String, VocabSourceDescription>();
|
||||||
|
if(UMLSService.configurationFileExists()) {
|
||||||
map.put(UMLSVocabSource, new VocabSourceDescription("UMLS", UMLSVocabSource, "http://www.nlm.nih.gov/research/umls/", "Unified Medical Language System"));
|
map.put(UMLSVocabSource, new VocabSourceDescription("UMLS", UMLSVocabSource, "http://www.nlm.nih.gov/research/umls/", "Unified Medical Language System"));
|
||||||
|
}
|
||||||
//Commenting out agrovoc for now until implementation is updated
|
//Commenting out agrovoc for now until implementation is updated
|
||||||
map.put(AgrovocVocabSource, new VocabSourceDescription("AGROVOC", AgrovocVocabSource, "http://www.fao.org/agrovoc/", "Agricultural Vocabulary"));
|
map.put(AgrovocVocabSource, new VocabSourceDescription("AGROVOC", AgrovocVocabSource, "http://www.fao.org/agrovoc/", "Agricultural Vocabulary"));
|
||||||
map.put(GemetVocabSource, new VocabSourceDescription("GEMET", GemetVocabSource, "http://www.eionet.europa.eu/gemet", "GEneral Multilingual Environmental Thesaurus"));
|
map.put(GemetVocabSource, new VocabSourceDescription("GEMET", GemetVocabSource, "http://www.eionet.europa.eu/gemet", "GEneral Multilingual Environmental Thesaurus"));
|
||||||
|
@ -53,6 +56,7 @@ public class ConceptSearchServiceUtils {
|
||||||
//Get the hashmap mapping service name to Service class
|
//Get the hashmap mapping service name to Service class
|
||||||
private static HashMap<String, String> getMapping() {
|
private static HashMap<String, String> getMapping() {
|
||||||
HashMap<String, String> map = new HashMap<String, String>();
|
HashMap<String, String> map = new HashMap<String, String>();
|
||||||
|
|
||||||
map.put(UMLSVocabSource, "edu.cornell.mannlib.semservices.service.impl.UMLSService");
|
map.put(UMLSVocabSource, "edu.cornell.mannlib.semservices.service.impl.UMLSService");
|
||||||
map.put(AgrovocVocabSource, "edu.cornell.mannlib.semservices.service.impl.AgrovocService");
|
map.put(AgrovocVocabSource, "edu.cornell.mannlib.semservices.service.impl.AgrovocService");
|
||||||
map.put(GemetVocabSource, "edu.cornell.mannlib.semservices.service.impl.GemetService");
|
map.put(GemetVocabSource, "edu.cornell.mannlib.semservices.service.impl.GemetService");
|
||||||
|
|
Loading…
Add table
Reference in a new issue