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;
}
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;
}
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();
}
}
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();
}
}
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();
}
}
Aggregations