diff --git a/api/src/main/java/edu/cornell/mannlib/semservices/service/impl/UMLSService.java b/api/src/main/java/edu/cornell/mannlib/semservices/service/impl/UMLSService.java index 59653f3f..040f7904 100644 --- a/api/src/main/java/edu/cornell/mannlib/semservices/service/impl/UMLSService.java +++ b/api/src/main/java/edu/cornell/mannlib/semservices/service/impl/UMLSService.java @@ -4,12 +4,18 @@ package edu.cornell.mannlib.semservices.service.impl; import java.io.IOException; import java.io.InputStream; +import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.Properties; import org.apache.commons.logging.Log; 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.ObjectNode; @@ -18,11 +24,6 @@ import edu.cornell.mannlib.semservices.bo.Concept; import edu.cornell.mannlib.semservices.exceptions.ConceptsNotFoundException; import edu.cornell.mannlib.semservices.service.ExternalConceptService; 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 @@ -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_KEY_URL = "https://utslogin.nlm.nih.gov/cas/v1/api-key"; 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) { final Properties properties = new Properties(); - try (InputStream stream = getClass().getResourceAsStream("/umls.properties")) { + try (InputStream stream = getClass().getResourceAsStream(UMLS_PROPERTIES)) { properties.load(stream); username = properties.getProperty("username"); password = properties.getProperty("password"); @@ -73,11 +76,18 @@ public class UMLSService implements ExternalConceptService { } } } catch (Exception e) { + log.error(e, 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() { return !(StringUtils.isEmpty(username) && StringUtils.isEmpty(apikey)); diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/utils/ConceptSearchService/ConceptSearchServiceUtils.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/utils/ConceptSearchService/ConceptSearchServiceUtils.java index 70268cd9..d6b0e733 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/utils/ConceptSearchService/ConceptSearchServiceUtils.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/utils/ConceptSearchService/ConceptSearchServiceUtils.java @@ -12,6 +12,7 @@ import org.apache.commons.logging.LogFactory; import edu.cornell.mannlib.semservices.bo.Concept; import edu.cornell.mannlib.semservices.service.ExternalConceptService; +import edu.cornell.mannlib.semservices.service.impl.UMLSService; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; /** * Utilities for search @@ -38,7 +39,9 @@ public class ConceptSearchServiceUtils { //URL to label public static HashMap getVocabSources() { HashMap map = new HashMap(); - map.put(UMLSVocabSource, new VocabSourceDescription("UMLS", UMLSVocabSource, "http://www.nlm.nih.gov/research/umls/", "Unified Medical Language System")); + if(UMLSService.configurationFileExists()) { + 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 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")); @@ -53,6 +56,7 @@ public class ConceptSearchServiceUtils { //Get the hashmap mapping service name to Service class private static HashMap getMapping() { HashMap map = new HashMap(); + map.put(UMLSVocabSource, "edu.cornell.mannlib.semservices.service.impl.UMLSService"); map.put(AgrovocVocabSource, "edu.cornell.mannlib.semservices.service.impl.AgrovocService"); map.put(GemetVocabSource, "edu.cornell.mannlib.semservices.service.impl.GemetService");