diff --git a/productMods/edit/forms/js/addConcept.js b/productMods/edit/forms/js/addConcept.js
index 2d0931d9..12361cb4 100644
--- a/productMods/edit/forms/js/addConcept.js
+++ b/productMods/edit/forms/js/addConcept.js
@@ -142,16 +142,17 @@ var addConceptForm = {
}
var vocabSourceValue = checkedVocabSource.val();
var dataServiceUrl = addConceptForm.dataServiceUrl + "?searchTerm=" + encodeURIComponent(searchValue) + "&source=" + encodeURIComponent(vocabSourceValue);
- $.getJSON(dataServiceUrl, function(results) {
+ //This should return an object including the concept list or any errors if there are any
+ $.getJSON(dataServiceUrl, function(results) {
var htmlAdd = "";
-
- if ( results== null || results.array == null || results.array.length == 0 ) {
- htmlAdd = "
No search results found.
";
- } else {
+ var vocabUnavailable = "The vocabulary service is unavailable. Please try again later.
";
+ if ( results== null || results.semanticServicesError != null || results.conceptList == null) {
+ htmlAdd = vocabUnavailable;
+ }
+ else {
//array is an array of objects representing concept information
//loop through and find all the best matches
-
- var bestMatchResults = addConceptForm.parseResults(results.array);
+ var bestMatchResults = addConceptForm.parseResults(results.conceptList);
var numberMatches = bestMatchResults.length;
var i;
//For each result, display
@@ -170,7 +171,7 @@ var addConceptForm = {
}
htmlAdd+= "";
} else {
- htmlAdd+= "No search results found.
";
+ htmlAdd+= "No search results were found.
";
}
}
diff --git a/productMods/edit/forms/js/customFormWithAutocomplete.js b/productMods/edit/forms/js/customFormWithAutocomplete.js
index 9c05765d..e7f46230 100644
--- a/productMods/edit/forms/js/customFormWithAutocomplete.js
+++ b/productMods/edit/forms/js/customFormWithAutocomplete.js
@@ -231,7 +231,8 @@ var customForm = {
dataType: 'json',
data: {
term: request.term,
- type: customForm.acType
+ type: customForm.acType,
+ multipleTypes:(customForm.acMultipleTypes == undefined || customForm.acMultipleTypes == null)? null: customForm.acMultipleTypes
},
complete: function(xhr, status) {
// Not sure why, but we need an explicit json parse here.
diff --git a/src/edu/cornell/mannlib/semservices/bo/ConceptInfo.java b/src/edu/cornell/mannlib/semservices/bo/ConceptInfo.java
new file mode 100644
index 00000000..14aa22e0
--- /dev/null
+++ b/src/edu/cornell/mannlib/semservices/bo/ConceptInfo.java
@@ -0,0 +1,34 @@
+/* $This file is distributed under the terms of the license in /doc/license.txt$ */
+
+package edu.cornell.mannlib.semservices.bo;
+
+
+import java.util.List;
+
+
+public class ConceptInfo extends SemanticServicesInfoBase {
+
+ private List conceptList;
+
+ /**
+ *
+ */
+ public ConceptInfo() {
+ super();
+ }
+
+ /**
+ * @return the vivoDepartmentList
+ */
+ public List getConceptList() {
+ return conceptList;
+ }
+
+ /**
+ * @param vivoDepartmentList the vivoDepartmentList to set
+ */
+ public void setConceptList(List inputConceptList) {
+ this.conceptList = inputConceptList;
+ }
+
+}
diff --git a/src/edu/cornell/mannlib/semservices/bo/SemanticServicesError.java b/src/edu/cornell/mannlib/semservices/bo/SemanticServicesError.java
new file mode 100644
index 00000000..e6107e94
--- /dev/null
+++ b/src/edu/cornell/mannlib/semservices/bo/SemanticServicesError.java
@@ -0,0 +1,75 @@
+/* $This file is distributed under the terms of the license in /doc/license.txt$ */
+
+package edu.cornell.mannlib.semservices.bo;
+
+public class SemanticServicesError {
+ private String message;
+ private String exception;
+ private String severity;
+
+ /**
+ *
+ */
+ public SemanticServicesError() {
+ super();
+ }
+
+
+
+ /**
+ * @param exception
+ * @param message
+ * @param severity
+ */
+ public SemanticServicesError(String exception, String message, String severity) {
+ super();
+ this.exception = exception;
+ this.message = message;
+ this.severity = severity;
+ }
+
+
+
+ /**
+ * @return the message
+ */
+ public String getMessage() {
+ return message;
+ }
+
+ /**
+ * @param message the message to set
+ */
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ /**
+ * @return the exception
+ */
+ public String getException() {
+ return exception;
+ }
+
+ /**
+ * @param exception the exception to set
+ */
+ public void setException(String exception) {
+ this.exception = exception;
+ }
+
+ /**
+ * @return the severity
+ */
+ public String getSeverity() {
+ return severity;
+ }
+
+ /**
+ * @param severity the severity to set
+ */
+ public void setSeverity(String severity) {
+ this.severity = severity;
+ }
+
+}
diff --git a/src/edu/cornell/mannlib/semservices/bo/SemanticServicesInfoBase.java b/src/edu/cornell/mannlib/semservices/bo/SemanticServicesInfoBase.java
new file mode 100644
index 00000000..d477f753
--- /dev/null
+++ b/src/edu/cornell/mannlib/semservices/bo/SemanticServicesInfoBase.java
@@ -0,0 +1,29 @@
+/* $This file is distributed under the terms of the license in /doc/license.txt$ */
+
+package edu.cornell.mannlib.semservices.bo;
+
+public class SemanticServicesInfoBase {
+
+ private SemanticServicesError semanticServicesError;
+ /**
+ *
+ */
+ public SemanticServicesInfoBase() {
+ super();
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @return the semanticServicesError
+ */
+ public SemanticServicesError getSemanticServicesError() {
+ return semanticServicesError;
+ }
+ /**
+ * @param semanticServicesError the semanticServicesError to set
+ */
+ public void setSemanticServicesError(SemanticServicesError semanticServicesError) {
+ this.semanticServicesError = semanticServicesError;
+ }
+
+}
diff --git a/src/edu/cornell/mannlib/semservices/service/ExternalConceptService.java b/src/edu/cornell/mannlib/semservices/service/ExternalConceptService.java
index 31e58e1c..891ee322 100644
--- a/src/edu/cornell/mannlib/semservices/service/ExternalConceptService.java
+++ b/src/edu/cornell/mannlib/semservices/service/ExternalConceptService.java
@@ -8,6 +8,6 @@ import edu.cornell.mannlib.semservices.bo.Concept;
public interface ExternalConceptService {
// this is the only method that needs to be exposed
- List processResults(String term);
+ List processResults(String term) throws Exception;
}
diff --git a/src/edu/cornell/mannlib/semservices/service/impl/AgrovocService.java b/src/edu/cornell/mannlib/semservices/service/impl/AgrovocService.java
index 0999f2df..50ac9092 100644
--- a/src/edu/cornell/mannlib/semservices/service/impl/AgrovocService.java
+++ b/src/edu/cornell/mannlib/semservices/service/impl/AgrovocService.java
@@ -35,7 +35,7 @@ public class AgrovocService implements ExternalConceptService {
protected final Log logger = LogFactory.getLog(getClass());
private java.lang.String AgrovocWS_address = "http://www.fao.org/webservices/AgrovocWS";
- public List processResults(String term) {
+ public List processResults(String term) throws Exception {
List conceptList = new ArrayList();
String termcode;
@@ -43,7 +43,7 @@ public class AgrovocService implements ExternalConceptService {
termcode = getTermcodeByTerm(term);
} catch (Exception e1) {
logger.error("Could not get termcode from service", e1);
- return null;
+ throw e1;
}
String format = "SKOS";
@@ -89,9 +89,6 @@ public class AgrovocService implements ExternalConceptService {
e.printStackTrace();
}
return conceptList;
- //JSONObject jsonObject = null;
- //jsonObject = BeanToJsonSerializer.serializeToJsonObject(conceptList);
- //return jsonObject.toString();
}
diff --git a/src/edu/cornell/mannlib/semservices/service/impl/GemetService.java b/src/edu/cornell/mannlib/semservices/service/impl/GemetService.java
index 7ac3229c..146a93da 100644
--- a/src/edu/cornell/mannlib/semservices/service/impl/GemetService.java
+++ b/src/edu/cornell/mannlib/semservices/service/impl/GemetService.java
@@ -49,7 +49,7 @@ public class GemetService implements ExternalConceptService {
private final String exampleUri = "http://www.w3.org/2004/02/skos/core%23example";
private final String acronymLabelUri = "http://www.w3.org/2004/02/skos/core%23acronymLabel";
- public List processResults(String term) {
+ public List processResults(String term) throws Exception {
List conceptList = new ArrayList();
String results = getConceptsMatchingKeyword(term);
conceptList = processOutput(results);
@@ -121,7 +121,7 @@ public class GemetService implements ExternalConceptService {
}
- protected String getAvailableLangs(String concept_uri) {
+ protected String getAvailableLangs(String concept_uri) throws Exception {
String result = new String();
String serviceUrl = GemetWS_address + "getAvailableLanguages" +
"?concept_uri=" + concept_uri;
@@ -129,7 +129,7 @@ public class GemetService implements ExternalConceptService {
return result;
}
- protected String getConcept(String concept_uri) {
+ protected String getConcept(String concept_uri) throws Exception {
String result = new String();
String serviceUrl = GemetWS_address + "getConcept" +
"?concept_uri=" + concept_uri +
@@ -137,7 +137,7 @@ public class GemetService implements ExternalConceptService {
result = getGemetResults(serviceUrl);
return result;
}
- protected String getAllTranslationsForConcept(String concept_uri, String property) {
+ protected String getAllTranslationsForConcept(String concept_uri, String property) throws Exception {
String result = new String();
String property_uri = new String();
if (property.equals("definition")) {
@@ -163,7 +163,7 @@ public class GemetService implements ExternalConceptService {
}
- protected String getRelatedConcepts(String concept_uri, String relation) {
+ protected String getRelatedConcepts(String concept_uri, String relation) throws Exception {
String result = new String();
String relation_uri = new String();
if (relation.equals("broader")) {
@@ -183,7 +183,7 @@ public class GemetService implements ExternalConceptService {
- protected String getConceptsMatchingKeyword(String keyword) {
+ protected String getConceptsMatchingKeyword(String keyword) throws Exception {
String result = new String();
String serviceUrl = GemetWS_address + "getConceptsMatchingKeyword" +
"?keyword=" + keyword +
@@ -196,7 +196,7 @@ public class GemetService implements ExternalConceptService {
}
- protected String getGemetResults(String url) {
+ protected String getGemetResults(String url) throws Exception {
String results = new String();
//System.out.println("url: "+url);
try {
@@ -215,7 +215,7 @@ public class GemetService implements ExternalConceptService {
} catch (Exception ex) {
logger.error("error occurred in servlet", ex);
- return null;
+ throw ex;
}
return results;
}
diff --git a/src/edu/cornell/mannlib/semservices/service/impl/UMLSService.java b/src/edu/cornell/mannlib/semservices/service/impl/UMLSService.java
index 69b64c6b..8ea36216 100644
--- a/src/edu/cornell/mannlib/semservices/service/impl/UMLSService.java
+++ b/src/edu/cornell/mannlib/semservices/service/impl/UMLSService.java
@@ -29,7 +29,7 @@ public class UMLSService implements ExternalConceptService {
private static final String submissionUrl = "http://link.informatics.stonybrook.edu/MeaningLookup/MlServiceServlet?";
private static final String baseUri = "http://link.informatics.stonybrook.edu/umls/CUI/";
- public List processResults(String term) {
+ public List processResults(String term) throws Exception{
String results = null;
String dataUrl = submissionUrl + "textToProcess="
+ URLEncoder.encode(term) + "&format=json";
@@ -50,9 +50,8 @@ public class UMLSService implements ExternalConceptService {
} catch (Exception ex) {
logger.error("error occurred in servlet", ex);
- return null;
+ throw ex;
}
- //System.out.println("results before processing: "+results);
List conceptList = processOutput(results);
return conceptList;
}
diff --git a/src/edu/cornell/mannlib/vitro/webapp/servlet/ConceptSearchServlet.java b/src/edu/cornell/mannlib/vitro/webapp/servlet/ConceptSearchServlet.java
index 224e74b0..deca950d 100644
--- a/src/edu/cornell/mannlib/vitro/webapp/servlet/ConceptSearchServlet.java
+++ b/src/edu/cornell/mannlib/vitro/webapp/servlet/ConceptSearchServlet.java
@@ -18,6 +18,8 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.semservices.bo.Concept;
+import edu.cornell.mannlib.semservices.bo.ConceptInfo;
+import edu.cornell.mannlib.semservices.bo.SemanticServicesError;
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.utils.ConceptSearchService.BeanToJsonSerializer;
@@ -40,9 +42,23 @@ public class ConceptSearchServlet extends VitroHttpServlet {
try{
ServletContext ctx = vreq.getSession().getServletContext();
+ //Captures both concept list and any errors if they exist
+ ConceptInfo conceptInfo = new ConceptInfo();
+ conceptInfo.setSemanticServicesError(null);
+
//Json output should be written out
- List results = ConceptSearchServiceUtils.getSearchResults(ctx, vreq);
- String json = renderJson(results);
+ List results = null;
+ try {
+ results = ConceptSearchServiceUtils.getSearchResults(ctx, vreq);
+ }
+ catch (Exception ex) {
+ SemanticServicesError semanticServicesError = new SemanticServicesError(
+ "Exception encountered ", ex.getMessage(), "fatal");
+ log.error("An error occurred retrieving search results");
+ conceptInfo.setSemanticServicesError(semanticServicesError);
+ }
+ conceptInfo.setConceptList(results);
+ String json = renderJson(conceptInfo);
json = StringUtils.replaceChars(json, "\r\t\n", "");
PrintWriter writer = resp.getWriter();
resp.setContentType("application/json");
@@ -54,10 +70,10 @@ public class ConceptSearchServlet extends VitroHttpServlet {
}
}
- protected String renderJson(List conceptList) {
+ protected String renderJson(ConceptInfo conceptInfo) {
JSONObject jsonObject = null;
- jsonObject = BeanToJsonSerializer.serializeToJsonObject(conceptList);
+ jsonObject = BeanToJsonSerializer.serializeToJsonObject(conceptInfo);
log.debug(jsonObject.toString());
return jsonObject.toString();
}
diff --git a/src/edu/cornell/mannlib/vitro/webapp/utils/ConceptSearchService/ConceptSearchServiceUtils.java b/src/edu/cornell/mannlib/vitro/webapp/utils/ConceptSearchService/ConceptSearchServiceUtils.java
index 8fdc42d7..a81d50de 100644
--- a/src/edu/cornell/mannlib/vitro/webapp/utils/ConceptSearchService/ConceptSearchServiceUtils.java
+++ b/src/edu/cornell/mannlib/vitro/webapp/utils/ConceptSearchService/ConceptSearchServiceUtils.java
@@ -39,7 +39,7 @@ public class ConceptSearchServiceUtils {
HashMap map = new HashMap();
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, "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"));
return map;
}
@@ -56,7 +56,7 @@ public class ConceptSearchServiceUtils {
return map;
}
- public static List getSearchResults(ServletContext context, VitroRequest vreq) {
+ public static List getSearchResults(ServletContext context, VitroRequest vreq) throws Exception {
String searchServiceName = getSearchServiceUri(vreq);
String searchServiceClassName = getConceptSearchServiceClassName(searchServiceName);