updates to include error handling in external concept services

This commit is contained in:
hjkhjk54 2011-12-02 22:03:52 +00:00
parent 2fb20f1efe
commit f9d402bff6
11 changed files with 184 additions and 32 deletions

View 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;
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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;
}

View file

@ -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();
}

View file

@ -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;
}

View file

@ -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;
}