Search in sources :

Example 1 with IGraphFactory

use of org.openntf.domino.rest.service.IGraphFactory in project org.openntf.domino by OpenNTF.

the class InfoResource method performRequest.

@GET
@Produces(MediaType.APPLICATION_JSON)
@SuppressWarnings("nls")
public Response performRequest(@Context final UriInfo uriInfo, @PathParam(Routes.NAMESPACE) final String namespace) throws JsonException, IOException {
    String jsonEntity = null;
    ResponseBuilder builder = Response.ok();
    ParamMap pm = Parameters.toParamMap(uriInfo);
    StringWriter sw = new StringWriter();
    DFramedTransactionalGraph<?> graph = this.getGraph(namespace);
    JsonGraphWriter writer = new JsonGraphWriter(sw, graph, pm, false, true, false);
    // writer.outObject(null);
    List<String> items = pm.get(Parameters.ITEM);
    if (items != null && items.size() > 0) {
        IGraphFactory factory = this.getService().getFactory(namespace);
        if (factory != null) {
            for (String item : items) {
                Object curResult = factory.processRequest(namespace, item, uriInfo.getQueryParameters());
                writer.outObject(curResult);
            }
        } else {
            System.err.println("No Factory found for namespace: " + namespace);
        }
    }
    jsonEntity = sw.toString();
    builder.type(MediaType.APPLICATION_JSON_TYPE).entity(jsonEntity);
    Response response = builder.build();
    return response;
}
Also used : Response(javax.ws.rs.core.Response) ParamMap(org.openntf.domino.rest.service.Parameters.ParamMap) StringWriter(java.io.StringWriter) JsonGraphWriter(org.openntf.domino.rest.json.JsonGraphWriter) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) IGraphFactory(org.openntf.domino.rest.service.IGraphFactory) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with IGraphFactory

use of org.openntf.domino.rest.service.IGraphFactory in project org.openntf.domino by OpenNTF.

the class CommandResource method performCommand.

@GET
@Produces(MediaType.APPLICATION_JSON)
public Response performCommand(@Context final UriInfo uriInfo, @PathParam(Routes.NAMESPACE) final String namespace) throws JsonException, IOException {
    String jsonEntity = null;
    ResponseBuilder builder = Response.ok();
    ParamMap pm = Parameters.toParamMap(uriInfo);
    StringWriter sw = new StringWriter();
    DFramedTransactionalGraph<?> graph = this.getGraph(namespace);
    JsonGraphWriter writer = new JsonGraphWriter(sw, graph, pm, false, true, false);
    // writer.outObject(null);
    List<String> commands = pm.get(Parameters.COMMAND);
    if (commands != null && commands.size() > 0) {
        IGraphFactory factory = this.getService().getFactory(namespace);
        if (factory != null) {
            for (String command : commands) {
                // System.out.println("TEMP DEBUG processing command " +
                // command + " in namespace " + namespace);
                Object curResult = factory.processCommand(namespace, command, uriInfo.getQueryParameters());
                writer.outObject(curResult);
            }
        } else {
            System.err.println("No Factory found for namespace: " + namespace);
        }
    }
    jsonEntity = sw.toString();
    builder.type(MediaType.APPLICATION_JSON_TYPE).entity(jsonEntity);
    Response response = builder.build();
    return response;
}
Also used : Response(javax.ws.rs.core.Response) ParamMap(org.openntf.domino.rest.service.Parameters.ParamMap) StringWriter(java.io.StringWriter) JsonGraphWriter(org.openntf.domino.rest.json.JsonGraphWriter) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) IGraphFactory(org.openntf.domino.rest.service.IGraphFactory) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

StringWriter (java.io.StringWriter)2 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 Response (javax.ws.rs.core.Response)2 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)2 JsonGraphWriter (org.openntf.domino.rest.json.JsonGraphWriter)2 IGraphFactory (org.openntf.domino.rest.service.IGraphFactory)2 ParamMap (org.openntf.domino.rest.service.Parameters.ParamMap)2