Skip to content

Commit

Permalink
Fix #57
Browse files Browse the repository at this point in the history
  • Loading branch information
enridaga committed Feb 22, 2016
1 parent 023c555 commit c4050ea
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 14 deletions.
25 changes: 11 additions & 14 deletions basil/src/main/java/uk/ac/open/kmi/basil/core/ApiManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import uk.ac.open.kmi.basil.core.exceptions.ApiInvocationException;
import uk.ac.open.kmi.basil.core.exceptions.SpecificationParsingException;
import uk.ac.open.kmi.basil.doc.Doc;
import uk.ac.open.kmi.basil.invoke.DirectExecutor;
import uk.ac.open.kmi.basil.invoke.QueryExecutor;
import uk.ac.open.kmi.basil.sparql.QueryParameter;
import uk.ac.open.kmi.basil.sparql.Specification;
import uk.ac.open.kmi.basil.sparql.SpecificationFactory;
Expand All @@ -33,10 +35,18 @@
public class ApiManagerImpl implements ApiManager {
private Store data;
private UserManager userManager;
private QueryExecutor executor;

public ApiManagerImpl(Store store, UserManager um) {
data = store;
userManager = um;
executor = new DirectExecutor();
}

public ApiManagerImpl(Store store, UserManager um, QueryExecutor exe) {
data = store;
userManager = um;
executor = exe;
}

/**
Expand Down Expand Up @@ -106,20 +116,7 @@ public InvocationResult invokeApi(String id, MultivaluedMap<String, String> para
}
Specification specification = data.loadSpec(id);
Query q = rewrite(specification, parameters);
QueryExecution qe = QueryExecutionFactory.sparqlService(specification.getEndpoint(), q);

if (q.isSelectType()) {
return new InvocationResult(qe.execSelect(), q);
} else if (q.isConstructType()) {
return new InvocationResult(qe.execConstruct(), q);
} else if (q.isAskType()) {
return new InvocationResult(qe.execAsk(), q);
} else if (q.isDescribeType()) {
return new InvocationResult(qe.execDescribe(), q);
} else {
throw new ApiInvocationException("Unsupported query type: " + q.getQueryType());
}

return executor.execute(q, specification.getEndpoint());
}

public String createSpecification(String username, String endpoint, String body)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package uk.ac.open.kmi.basil.invoke;

import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;

import uk.ac.open.kmi.basil.core.InvocationResult;
import uk.ac.open.kmi.basil.core.exceptions.ApiInvocationException;

/**
*
* @author enridaga
*
*/
public class DirectExecutor implements QueryExecutor {

@Override
public InvocationResult execute(Query q, String endpoint) throws ApiInvocationException {
QueryExecution qe = QueryExecutionFactory.sparqlService(endpoint, q);
if (q.isSelectType()) {
return new InvocationResult(qe.execSelect(), q);
} else if (q.isConstructType()) {
return new InvocationResult(qe.execConstruct(), q);
} else if (q.isAskType()) {
return new InvocationResult(qe.execAsk(), q);
} else if (q.isDescribeType()) {
return new InvocationResult(qe.execDescribe(), q);
} else {
throw new ApiInvocationException("Unsupported query type: " + q.getQueryType());
}
}

}
11 changes: 11 additions & 0 deletions basil/src/main/java/uk/ac/open/kmi/basil/invoke/QueryExecutor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package uk.ac.open.kmi.basil.invoke;

import com.hp.hpl.jena.query.Query;

import uk.ac.open.kmi.basil.core.InvocationResult;
import uk.ac.open.kmi.basil.core.exceptions.ApiInvocationException;

public interface QueryExecutor {

public InvocationResult execute(Query query, String endpoint) throws ApiInvocationException;
}

0 comments on commit c4050ea

Please sign in to comment.