Search in sources :

Example 21 with ResponseBuilder

use of javax.ws.rs.core.Response.ResponseBuilder in project midpoint by Evolveum.

the class ModelRestService method addObject.

@POST
@Path("/{type}")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, "application/yaml" })
public <T extends ObjectType> Response addObject(@PathParam("type") String type, PrismObject<T> object, @QueryParam("options") List<String> options, @Context UriInfo uriInfo, @Context MessageContext mc) {
    LOGGER.debug("model rest service for add operation start");
    Task task = RestServiceUtil.initRequest(mc);
    OperationResult parentResult = task.getResult().createSubresult(OPERATION_ADD_OBJECT);
    Class clazz = ObjectTypes.getClassFromRestType(type);
    if (!object.getCompileTimeClass().equals(clazz)) {
        finishRequest(task);
        parentResult.recordFatalError("Request to add object of type " + object.getCompileTimeClass().getSimpleName() + " to the collection of " + type);
        return RestServiceUtil.createErrorResponseBuilder(Status.BAD_REQUEST, parentResult).build();
    }
    ModelExecuteOptions modelExecuteOptions = ModelExecuteOptions.fromRestOptions(options);
    String oid;
    Response response;
    try {
        oid = model.addObject(object, modelExecuteOptions, task, parentResult);
        LOGGER.debug("returned oid :  {}", oid);
        ResponseBuilder builder;
        if (oid != null) {
            URI resourceURI = uriInfo.getAbsolutePathBuilder().path(oid).build(oid);
            response = // TODO not the other way around?
            clazz.isAssignableFrom(TaskType.class) ? RestServiceUtil.createResponse(Response.Status.ACCEPTED, resourceURI, parentResult) : RestServiceUtil.createResponse(Response.Status.CREATED, resourceURI, parentResult);
        //				builder = clazz.isAssignableFrom(TaskType.class) ?		// TODO not the other way around?
        //						Response.accepted().location(resourceURI) : Response.created(resourceURI);
        } else {
            // OID might be null e.g. if the object creation is a subject of workflow approval
            //				builder = Response.accepted();			// TODO is this ok ?
            response = RestServiceUtil.createResponse(Response.Status.ACCEPTED, parentResult);
        }
    // (not used currently)
    //validateIfRequested(object, options, builder, task, parentResult);
    //			response = builder.build();
    } catch (Exception ex) {
        response = RestServiceUtil.handleException(parentResult, ex);
    }
    parentResult.computeStatus();
    finishRequest(task);
    return response;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) URI(java.net.URI) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 22 with ResponseBuilder

use of javax.ws.rs.core.Response.ResponseBuilder in project midpoint by Evolveum.

the class ModelRestService method compare.

@POST
@Path("/rpc/compare")
//	@Produces({"text/html", "application/xml"})
@Consumes({ "application/xml" })
public <T extends ObjectType> Response compare(PrismObject<T> clientObject, @QueryParam("readOptions") List<String> restReadOptions, @QueryParam("compareOptions") List<String> restCompareOptions, @QueryParam("ignoreItems") List<String> restIgnoreItems, @Context MessageContext mc) {
    Task task = RestServiceUtil.initRequest(mc);
    OperationResult result = task.getResult().createSubresult(OPERATION_COMPARE);
    Response response;
    try {
        ResponseBuilder builder;
        List<ItemPath> ignoreItemPaths = ItemPath.fromStringList(restIgnoreItems);
        final GetOperationOptions getOpOptions = GetOperationOptions.fromRestOptions(restReadOptions);
        Collection<SelectorOptions<GetOperationOptions>> readOptions = getOpOptions != null ? SelectorOptions.createCollection(getOpOptions) : null;
        ModelCompareOptions compareOptions = ModelCompareOptions.fromRestOptions(restCompareOptions);
        CompareResultType compareResult = modelService.compareObject(clientObject, readOptions, compareOptions, ignoreItemPaths, task, result);
        response = RestServiceUtil.createResponse(Response.Status.OK, compareResult, result);
    //			builder = Response.ok();
    //			builder.entity(compareResult);
    //
    //			response = builder.build();
    } catch (Exception ex) {
        response = RestServiceUtil.handleException(result, ex);
    }
    result.computeStatus();
    finishRequest(task);
    return response;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 23 with ResponseBuilder

use of javax.ws.rs.core.Response.ResponseBuilder in project OpenClinica by OpenClinica.

the class OpenRosaServices method doFieldSubmission.

@POST
@Path("/{studyOID}/fieldsubmission")
@Produces(MediaType.APPLICATION_XML)
public Response doFieldSubmission(@Context HttpServletRequest request, @Context HttpServletResponse response, @Context ServletContext servletContext, @PathParam("studyOID") String studyOID, @QueryParam(FORM_CONTEXT) String context) {
    ResponseBuilder builder = Response.noContent();
    ResponseEntity<String> responseEntity = openRosaSubmissionController.doFieldSubmission(request, response, studyOID, context);
    if (responseEntity == null) {
        LOGGER.debug("Null response from OpenRosaSubmissionController.");
        return builder.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    } else if (responseEntity.getStatusCode().equals(org.springframework.http.HttpStatus.CREATED)) {
        LOGGER.debug("Successful OpenRosa submission");
        builder.entity("<OpenRosaResponse xmlns=\"http://openrosa.org/http/response\">" + "<message>success</message>" + "</OpenRosaResponse>");
        return builder.status(Response.Status.CREATED).build();
    } else if (responseEntity.getStatusCode().equals(org.springframework.http.HttpStatus.NOT_ACCEPTABLE)) {
        LOGGER.debug("Failed OpenRosa submission");
        return builder.status(Response.Status.NOT_ACCEPTABLE).build();
    } else {
        LOGGER.debug("Failed OpenRosa submission with unhandled error");
        return builder.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 24 with ResponseBuilder

use of javax.ws.rs.core.Response.ResponseBuilder in project OpenClinica by OpenClinica.

the class OpenRosaServices method doSubmission.

/**
     * @api {post} /rest2/openrosa/:studyOid/submission Submit form data
     * @apiName doSubmission
     * @apiPermission admin
     * @apiVersion 3.8.0
     * @apiParam {String} studyOid Study Oid.
     * @apiParam {String} ecid Key that will be used to look up subject context information while processing submission.
     * @apiGroup Form
     * @apiDescription Submits the data from a completed form.
     */
@POST
@Path("/{studyOID}/submission")
@Produces(MediaType.APPLICATION_XML)
public Response doSubmission(@Context HttpServletRequest request, @Context HttpServletResponse response, @Context ServletContext servletContext, @PathParam("studyOID") String studyOID, @QueryParam(FORM_CONTEXT) String context) {
    ResponseBuilder builder = Response.noContent();
    ResponseEntity<String> responseEntity = openRosaSubmissionController.doSubmission(request, response, studyOID, context);
    if (responseEntity == null) {
        LOGGER.debug("Null response from OpenRosaSubmissionController.");
        return builder.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    } else if (responseEntity.getStatusCode().equals(org.springframework.http.HttpStatus.CREATED)) {
        LOGGER.debug("Successful OpenRosa submission");
        builder.entity("<OpenRosaResponse xmlns=\"http://openrosa.org/http/response\">" + "<message>success</message>" + "</OpenRosaResponse>");
        return builder.status(Response.Status.CREATED).build();
    } else if (responseEntity.getStatusCode().equals(org.springframework.http.HttpStatus.NOT_ACCEPTABLE)) {
        LOGGER.debug("Failed OpenRosa submission");
        return builder.status(Response.Status.NOT_ACCEPTABLE).build();
    } else {
        LOGGER.debug("Failed OpenRosa submission with unhandled error");
        return builder.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 25 with ResponseBuilder

use of javax.ws.rs.core.Response.ResponseBuilder in project OpenClinica by OpenClinica.

the class OpenRosaServices method doFieldDeletion.

@DELETE
@Path("/{studyOID}/fieldsubmission")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_XML)
public Response doFieldDeletion(@Context HttpServletRequest request, @Context HttpServletResponse response, @Context ServletContext servletContext, @PathParam("studyOID") String studyOID, @QueryParam(FORM_CONTEXT) String context) {
    ResponseBuilder builder = Response.noContent();
    ResponseEntity<String> responseEntity = openRosaSubmissionController.doFieldDeletion(request, response, studyOID, context);
    if (responseEntity == null) {
        LOGGER.debug("Null response from OpenRosaSubmissionController.");
        return builder.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    } else if (responseEntity.getStatusCode().equals(org.springframework.http.HttpStatus.CREATED)) {
        LOGGER.debug("Successful OpenRosa submission");
        builder.entity("<OpenRosaResponse xmlns=\"http://openrosa.org/http/response\">" + "<message>success</message>" + "</OpenRosaResponse>");
        return builder.status(Response.Status.CREATED).build();
    } else if (responseEntity.getStatusCode().equals(org.springframework.http.HttpStatus.NOT_ACCEPTABLE)) {
        LOGGER.debug("Failed OpenRosa submission");
        return builder.status(Response.Status.NOT_ACCEPTABLE).build();
    } else {
        LOGGER.debug("Failed OpenRosa submission with unhandled error");
        return builder.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)175 GET (javax.ws.rs.GET)84 Produces (javax.ws.rs.Produces)81 Path (javax.ws.rs.Path)69 WebApplicationException (javax.ws.rs.WebApplicationException)47 Viewable (org.apache.stanbol.commons.web.viewable.Viewable)40 IOException (java.io.IOException)30 MediaType (javax.ws.rs.core.MediaType)29 POST (javax.ws.rs.POST)23 IRI (org.semanticweb.owlapi.model.IRI)22 EntityhubLDPath (org.apache.stanbol.entityhub.ldpath.EntityhubLDPath)21 Response (javax.ws.rs.core.Response)20 MediaTypeUtil.getAcceptableMediaType (org.apache.stanbol.commons.web.base.utils.MediaTypeUtil.getAcceptableMediaType)19 URI (java.net.URI)18 Consumes (javax.ws.rs.Consumes)18 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)18 ByteArrayInputStream (java.io.ByteArrayInputStream)16 OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)16 HashSet (java.util.HashSet)14 ImmutableGraph (org.apache.clerezza.commons.rdf.ImmutableGraph)12