Skip to content

Commit

Permalink
Support error reporting, using the Error Report corner of the OpenTox…
Browse files Browse the repository at this point in the history
… API (thanx to Pantelis for the tip)
  • Loading branch information
egonw committed Nov 6, 2011
1 parent 158a065 commit 58a7da2
Showing 1 changed file with 39 additions and 2 deletions.
Expand Up @@ -24,8 +24,10 @@
import java.security.GeneralSecurityException;
import java.util.HashMap;

import net.bioclipse.core.business.BioclipseException;
import net.bioclipse.core.domain.StringMatrix;
import net.bioclipse.opentox.Activator;
import net.bioclipse.opentox.api.TaskState.STATUS;
import net.bioclipse.rdf.business.IRDFStore;
import net.bioclipse.rdf.business.RDFManager;

Expand All @@ -49,6 +51,14 @@ public class Task {
" OPTIONAL { ?task ot:resultURI ?result }" +
"}";

private final static String QUERY_ERROR_REPORT =
"PREFIX ot: <http://www.opentox.org/api/1.1#>" +
"" +
"SELECT ?task ?message WHERE {" +
" ?task ot:errorReport ?report ." +
" ?report ot:message ?message ." +
"}";

public static void delete(String task) throws IOException, GeneralSecurityException {
HttpClient client = new HttpClient();
DeleteMethod method = new DeleteMethod(task);
Expand Down Expand Up @@ -109,6 +119,17 @@ public static TaskState getState(String task)
state.setFinished(false);
state.setPercentageCompleted(getPercentageCompleted(createStore(result)));
break;
case 500:
state.setFinished(true);
state.setStatus(STATUS.ERROR);
IRDFStore store = createStore(result);
try {
logger.debug("RDF: " + rdf.asRDFN3(store));
} catch (BioclipseException e) {}
String error = getErrorMessage(store);
throw new IllegalStateException(
"Service error: " + error
);
default:
logger.error("Task error (" + status + "): " + task);
logger.debug("Response: " + result);
Expand All @@ -122,12 +143,29 @@ public static TaskState getState(String task)
return state;
}

private static String getErrorMessage(IRDFStore store) {
try {
StringMatrix matrix = rdf.sparql(store, QUERY_ERROR_REPORT);
logger.debug("SPARQL results (error): " + matrix);
if (matrix != null && matrix.getRowCount() != 0 &&
matrix.hasColumn("message")) {
String message = matrix.get(1, "message");
if (message.contains("^^"))
message = message.substring(0, message.lastIndexOf("^^"));
return message;
}
} catch (Exception e) {
logger.debug("Error while getting the error message: " + e.getMessage());
}
return "unknown error";
}

private static float getPercentageCompleted(IRDFStore store) {
try {
StringMatrix matrix = rdf.sparql(store, QUERY_TASK_DETAILS);
if (matrix != null && matrix.getRowCount() != 0 &&
matrix.hasColumn("completed")) {
String floatStr = matrix.get(0, "completed");
String floatStr = matrix.get(1, "completed");
if (floatStr.contains("^^"))
floatStr = floatStr.substring(0, floatStr.indexOf("^^"));
logger.debug("Found completed: " + floatStr);
Expand Down Expand Up @@ -157,7 +195,6 @@ private static IRDFStore createStore(InputStream rdfResults) {
private static String getResultSetURI(IRDFStore store) {
try {
StringMatrix matrix = rdf.sparql(store, QUERY_TASK_DETAILS);
logger.debug("SPARQL results (URI): " + matrix);
if (matrix != null && matrix.getRowCount() != 0 &&
matrix.hasColumn("result")) {
String uri = matrix.get(1, "result");
Expand Down

0 comments on commit 58a7da2

Please sign in to comment.