public class StoreApi
extends java.lang.Object
implements java.io.Serializable
Constructor and Description |
---|
StoreApi(SessionIssuer sessionIssuer)
Construct an interface to the triple store that can be invoked
using HTTP.
|
Modifier and Type | Method and Description |
---|---|
void |
authorizeAndProcessCommand(java.lang.String command,
java.util.Map<java.lang.String,Datum> inputs,
javax.servlet.http.HttpServletResponse response,
StoreSession storeSession)
Process a command, obtaining authorization from inputs,
and place the results in an HTTP response
|
StoreSession |
getAuthorizedStoreSession(Datum authDatum,
StoreSession requestingSession)
Get the authorized store session from an input datum containing
authorization in the form of a credential with its correct key.
|
org.json.simple.JSONArray |
getChanges(java.util.Map<java.lang.String,Datum> inputs,
StoreSession authorizedSession)
Get the changes of an update
|
static org.json.simple.JSONObject |
getJsonFromDatum(Datum datum,
java.util.Map<java.lang.String,Datum> binaries)
Get a JSON object representing a Datum
|
void |
handleHttpRequest(java.lang.String command,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
StoreSession storeSession)
Handle an HTTP request.
|
org.json.simple.JSONObject |
newItemsJo(java.util.Map<java.lang.String,Item> newItemsMap,
StoreSession authorizedSession)
Get a JSON object representing the new items.
|
java.util.Map<java.lang.String,Datum> |
processCommand(java.lang.String command,
java.util.Map<java.lang.String,Datum> inputs,
StoreSession authorizedSession)
Process a command using an authorized session
|
org.json.simple.JSONArray |
query(JoinConstraint[] constraints,
java.util.Map<java.lang.String,Datum> outputBinaries,
StoreSession authorizedSession)
Handle a query.
|
java.util.Map<java.lang.String,Item> |
update(org.json.simple.JSONArray changes,
java.util.Map<java.lang.String,Datum> inputs,
StoreSession authorizedSession)
Handle an update
|
public StoreApi(SessionIssuer sessionIssuer)
sessionIssuer
- the session issuer of a triple store.
It includes a reference to the store.public void handleHttpRequest(java.lang.String command, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, StoreSession storeSession) throws java.io.IOException
Handle an HTTP request. The request must be a POST request.
This method gets the inputs, establishes the authorized store session to process the request, invokes one of the specific request handling methods, and places the result in the response.
command
- the command to be processed. If it is null,
the command is obtained from the HTTP request. If it is not
null, it supersedes the command in the HTTP request.request
- an HTTP POST request conveying a command and
its inputs. The command is the value of the request "command"
parameter. It can be 'query" or 'update'. The inputs are
supplied in the multipart form data content.response
- the response to the request.storeSession
- the requesting store session, or null.
If the request includes authorization input then its credential
is used to generate the authorized session for processing the
command. If the request does not include authorization then
the command is processed with an authorized session whose access
level is the lowest (public) level.java.io.IOException
java.lang.Exception
public void authorizeAndProcessCommand(java.lang.String command, java.util.Map<java.lang.String,Datum> inputs, javax.servlet.http.HttpServletResponse response, StoreSession storeSession) throws java.lang.Exception
command
- the command to be processedinputs
- authorization and command parametersresponse
- the HTTP response in which the results
are to be placedstoreSession
- the requesting store sessionjava.lang.Exception
public java.util.Map<java.lang.String,Datum> processCommand(java.lang.String command, java.util.Map<java.lang.String,Datum> inputs, StoreSession authorizedSession) throws java.lang.Exception
command
- the command to be processedinputs
- the command parametersauthorizedSession
- the store session to process the commandjava.lang.Exception
public StoreSession getAuthorizedStoreSession(Datum authDatum, StoreSession requestingSession)
authDatum
- an input datum containing authorization
information.requestingSession
- the requesting store session.java.lang.Exception
public org.json.simple.JSONArray query(JoinConstraint[] constraints, java.util.Map<java.lang.String,Datum> outputBinaries, StoreSession authorizedSession) throws java.lang.Exception
constraints
- the request constraints.outputBinaries
- a map to which an entry is added for each
binary value in the solutionsauthorizedSession
- the authorized store sessionjava.lang.Exception
public org.json.simple.JSONArray getChanges(java.util.Map<java.lang.String,Datum> inputs, StoreSession authorizedSession) throws java.lang.Exception
inputs
- a map whose "json" entry is a string representation of a
JSON array whose members are JSON objects specifying the changes, and
whose other entries include the binary values referenced by
these JSON objects.authorizedSession
- the authorized store sessionjava.lang.Exception
public java.util.Map<java.lang.String,Item> update(org.json.simple.JSONArray changes, java.util.Map<java.lang.String,Datum> inputs, StoreSession authorizedSession) throws java.lang.Exception
changes
- a JSONArray specifying the changes.inputs
- the input parameters of the request. It includes
entries giving the binary values of the changes.authorizedSession
- the authorized store sessionjava.lang.Exception
public org.json.simple.JSONObject newItemsJo(java.util.Map<java.lang.String,Item> newItemsMap, StoreSession authorizedSession) throws java.lang.Exception
newItemsMap
- a map with an entry for each new item,
whose key is the item's handle, and whose value is the item's
identifier.authorizedSession
- the authorized store sessionjava.lang.Exception
public static org.json.simple.JSONObject getJsonFromDatum(Datum datum, java.util.Map<java.lang.String,Datum> binaries) throws java.lang.Exception
datum
- a datum.binaries
- a String-Datum map to which an
entry will be added if the datum is a Binary datum.java.lang.Exception