use of javax.ws.rs.core.Variant in project openolat by klemens.
the class MediaTypeVariants method isPaged.
public static boolean isPaged(HttpServletRequest httpRequest, Request request) {
String accept = httpRequest.getHeader("Accept");
if (StringHelper.containsNonWhitespace(accept)) {
try {
MediaType requestMediaType = MediaType.valueOf(accept);
if (APPLICATION_JSON_PAGED.equals(requestMediaType) || APPLICATION_XML_PAGED.equals(requestMediaType)) {
return true;
}
} catch (IllegalArgumentException e) {
// can fail
}
}
Variant variant = request.selectVariant(variants);
return (variant != null && (variant.getMediaType().equals(APPLICATION_JSON_PAGED) || variant.getMediaType().equals(APPLICATION_XML_PAGED)));
}
use of javax.ws.rs.core.Variant in project dataverse by IQSS.
the class Users method getTraces.
@GET
@Path("{identifier}/traces/{element}")
@Produces("text/csv, application/json")
public Response getTraces(@Context Request req, @PathParam("identifier") String identifier, @PathParam("element") String element) {
try {
AuthenticatedUser userToQuery = authSvc.getAuthenticatedUser(identifier);
if (!elements.contains(element)) {
throw new BadRequestException("Not a valid element");
}
JsonObjectBuilder jsonObj = execCommand(new GetUserTracesCommand(createDataverseRequest(findUserOrDie()), userToQuery, element));
List<Variant> vars = Variant.mediaTypes(MediaType.valueOf(FileUtil.MIME_TYPE_CSV), MediaType.APPLICATION_JSON_TYPE).add().build();
MediaType requestedType = req.selectVariant(vars).getMediaType();
if ((requestedType != null) && (requestedType.equals(MediaType.APPLICATION_JSON_TYPE))) {
return ok(jsonObj);
}
JsonArray items = null;
try {
items = jsonObj.build().getJsonObject("traces").getJsonObject(element).getJsonArray("items");
} catch (Exception e) {
return ok(jsonObj);
}
return ok(FileUtil.jsonArrayOfObjectsToCSV(items, items.getJsonObject(0).keySet().toArray(new String[0])), MediaType.valueOf(FileUtil.MIME_TYPE_CSV), element + ".csv");
} catch (WrappedResponse ex) {
return ex.getResponse();
}
}
use of javax.ws.rs.core.Variant in project OpenOLAT by OpenOLAT.
the class MediaTypeVariants method isPaged.
public static boolean isPaged(HttpServletRequest httpRequest, Request request) {
String accept = httpRequest.getHeader("Accept");
if (StringHelper.containsNonWhitespace(accept)) {
try {
MediaType requestMediaType = MediaType.valueOf(accept);
if (APPLICATION_JSON_PAGED.equals(requestMediaType) || APPLICATION_XML_PAGED.equals(requestMediaType)) {
return true;
}
} catch (IllegalArgumentException e) {
// can fail
}
}
Variant variant = request.selectVariant(variants);
return (variant != null && (variant.getMediaType().equals(APPLICATION_JSON_PAGED) || variant.getMediaType().equals(APPLICATION_XML_PAGED)));
}
use of javax.ws.rs.core.Variant in project droolsjbpm-integration by kiegroup.
the class CaseQueryResource method getCaseInstances.
@ApiOperation(value = "Returns cases instances with authentication checks.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 200, response = CaseInstanceList.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = CASE_INSTANCES_JSON) })) })
@GET
@Path(CASE_ALL_INSTANCES_GET_URI)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getCaseInstances(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "data item name that case instances will be filtered by", required = false) @QueryParam("dataItemName") String dataItemName, @ApiParam(value = "data item value that case instances will be filtered by", required = false) @QueryParam("dataItemValue") String dataItemValue, @ApiParam(value = "case instance owner that case instances will be filtered by", required = false) @QueryParam("owner") String owner, @ApiParam(value = "optional case instance status (open, closed, canceled) - defaults ot open (1) only", required = false, allowableValues = "open,closed,cancelled") @QueryParam("status") List<String> status, @ApiParam(value = "optional pagination - at which page to start, defaults to 0 (meaning first)", required = false) @QueryParam("page") @DefaultValue("0") Integer page, @ApiParam(value = "optional pagination - size of the result, defaults to 10", required = false) @QueryParam("pageSize") @DefaultValue("10") Integer pageSize, @ApiParam(value = "optional sort column, no default", required = false) @QueryParam("sort") String sort, @ApiParam(value = "optional sort direction (asc, desc) - defaults to asc", required = false) @QueryParam("sortOrder") @DefaultValue("true") boolean sortOrder, @ApiParam(value = "optional flag to load data when loading case instance", required = false) @QueryParam("withData") @DefaultValue("false") boolean withData) {
return invokeCaseOperation(headers, "", null, (Variant v, String type, Header... customHeaders) -> {
CaseInstanceList responseObject = null;
if (dataItemName != null && !dataItemName.isEmpty() && dataItemValue != null && !dataItemValue.isEmpty()) {
logger.debug("About to look for case instances by data item name {} and value {} with status {}", dataItemName, dataItemValue, status);
responseObject = this.caseManagementRuntimeDataServiceBase.getCaseInstancesByCaseFileData(dataItemName, dataItemValue, status, page, pageSize, sort, sortOrder, withData);
} else if (dataItemName != null && !dataItemName.isEmpty()) {
logger.debug("About to look for case instances by data item name {} with status {}", dataItemName, status);
responseObject = this.caseManagementRuntimeDataServiceBase.getCaseInstancesByCaseFileData(dataItemName, null, status, page, pageSize, sort, sortOrder, withData);
} else if (owner != null && !owner.isEmpty()) {
logger.debug("About to look for case instances owned by {} with status {}", owner, status);
responseObject = this.caseManagementRuntimeDataServiceBase.getCaseInstancesOwnedBy(owner, status, page, pageSize, sort, sortOrder, withData);
} else {
logger.debug("About to look for case instances with status {}", status);
responseObject = this.caseManagementRuntimeDataServiceBase.getCaseInstancesAnyRole(status, page, pageSize, sort, sortOrder, withData);
}
logger.debug("Returning OK response with content '{}'", responseObject);
return createCorrectVariant(responseObject, headers, Response.Status.OK, customHeaders);
});
}
use of javax.ws.rs.core.Variant in project droolsjbpm-integration by kiegroup.
the class CaseQueryResource method queryCaseUserTasksByVariables.
@ApiOperation(value = "Queries cases tasks by variables", response = CaseUserTaskWithVariablesList.class)
@POST
@Path(RestURI.VARIABLES_TASKS_CASES_URI)
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@KieServerEndpoint(categories = { EndpointType.DEFAULT, EndpointType.HISTORY })
public Response queryCaseUserTasksByVariables(@Context HttpHeaders headers, String payload, @ApiParam(value = "optional pagination - at which page to start, defaults to 0 (meaning first)", required = false) @QueryParam("page") @DefaultValue("0") Integer page, @ApiParam(value = "optional pagination - size of the result, defaults to 10", required = false) @QueryParam("pageSize") @DefaultValue("10") Integer pageSize) {
Header conversationIdHeader = buildConversationIdHeader("", context, headers);
Variant v = getVariant(headers);
try {
String type = getContentType(headers);
CaseUserTaskWithVariablesList taskVariableSummaryList = caseManagementRuntimeDataServiceBase.queryUserTasksByVariables(payload, type, new QueryContext((page * pageSize), pageSize));
logger.debug("Returning result of case instance user task search: {}", taskVariableSummaryList);
return createCorrectVariant(taskVariableSummaryList, headers, Response.Status.OK, conversationIdHeader);
} catch (Exception e) {
logger.error("Unexpected error during processing {}", e.getMessage(), e);
return internalServerError(errorMessage(e), v, conversationIdHeader);
}
}
Aggregations