updates to include error handling in external concept services
This commit is contained in:
parent
2fb20f1efe
commit
f9d402bff6
11 changed files with 184 additions and 32 deletions
|
@ -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 = "<p>No search results found.</p>";
|
||||
} else {
|
||||
var vocabUnavailable = "<p>The vocabulary service is unavailable. Please try again later.</p>";
|
||||
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+= "</ul>";
|
||||
} else {
|
||||
htmlAdd+= "<p>No search results found.</p>";
|
||||
htmlAdd+= "<p>No search results were found.</p>";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
34
src/edu/cornell/mannlib/semservices/bo/ConceptInfo.java
Normal file
34
src/edu/cornell/mannlib/semservices/bo/ConceptInfo.java
Normal file
|
@ -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<Concept> conceptList;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public ConceptInfo() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the vivoDepartmentList
|
||||
*/
|
||||
public List<Concept> getConceptList() {
|
||||
return conceptList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param vivoDepartmentList the vivoDepartmentList to set
|
||||
*/
|
||||
public void setConceptList(List<Concept> inputConceptList) {
|
||||
this.conceptList = inputConceptList;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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<Concept> processResults(String term);
|
||||
List<Concept> processResults(String term) throws Exception;
|
||||
|
||||
}
|
||||
|
|
|
@ -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<Concept> processResults(String term) {
|
||||
public List<Concept> processResults(String term) throws Exception {
|
||||
List<Concept> conceptList = new ArrayList<Concept>();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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<Concept> processResults(String term) {
|
||||
public List<Concept> processResults(String term) throws Exception {
|
||||
List<Concept> conceptList = new ArrayList<Concept>();
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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<Concept> processResults(String term) {
|
||||
public List<Concept> 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<Concept> conceptList = processOutput(results);
|
||||
return conceptList;
|
||||
}
|
||||
|
|
|
@ -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<Concept> results = ConceptSearchServiceUtils.getSearchResults(ctx, vreq);
|
||||
String json = renderJson(results);
|
||||
List<Concept> 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<Concept> conceptList) {
|
||||
protected String renderJson(ConceptInfo conceptInfo) {
|
||||
|
||||
JSONObject jsonObject = null;
|
||||
jsonObject = BeanToJsonSerializer.serializeToJsonObject(conceptList);
|
||||
jsonObject = BeanToJsonSerializer.serializeToJsonObject(conceptInfo);
|
||||
log.debug(jsonObject.toString());
|
||||
return jsonObject.toString();
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ public class ConceptSearchServiceUtils {
|
|||
HashMap<String, VocabSourceDescription> map = new HashMap<String, VocabSourceDescription>();
|
||||
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<Concept> getSearchResults(ServletContext context, VitroRequest vreq) {
|
||||
public static List<Concept> getSearchResults(ServletContext context, VitroRequest vreq) throws Exception {
|
||||
String searchServiceName = getSearchServiceUri(vreq);
|
||||
String searchServiceClassName = getConceptSearchServiceClassName(searchServiceName);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue