use of javax.ws.rs.core.Variant in project droolsjbpm-integration by kiegroup.
the class DocumentResource method getDocumentContent.
@ApiOperation(value = "Retrieves document's content identified by given documentId", response = byte[].class, code = 200, responseHeaders = { @ResponseHeader(name = "Content-Disposition", description = "provides file name of the document") })
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Document with given id not found") })
@GET
@Path(DOCUMENT_INSTANCE_CONTENT_GET_URI)
@Produces({ MediaType.APPLICATION_OCTET_STREAM })
public Response getDocumentContent(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "document id of a document that content should be retruned from", required = true, example = "xxx-yyy-zzz") @PathParam("documentId") String documentId) {
Variant v = getVariant(headers);
// no container id available so only used to transfer conversation id if given by client
Header conversationIdHeader = buildConversationIdHeader("", context, headers);
try {
final DocumentInstance document = documentServiceBase.getDocument(documentId);
if (document == null) {
return notFound("Document with id " + documentId + " not found", v, conversationIdHeader);
}
String fileName = MimeUtility.encodeWord(document.getName(), "utf-8", "Q");
StreamingOutput entity = new StreamingOutput() {
@Override
public void write(OutputStream output) throws IOException, WebApplicationException {
output.write(document.getContent());
}
};
if (conversationIdHeader != null) {
return Response.ok().entity(entity).header(conversationIdHeader.getName(), conversationIdHeader.getValue()).header("Content-Disposition", "attachment; filename=\"" + fileName + "\"").build();
}
return Response.ok().entity(entity).header("Content-Disposition", "attachment; filename=\"" + fileName + "\"").build();
} catch (Exception e) {
logger.error("Unexpected error during processing {}", e.getMessage(), e);
return internalServerError(errorMessage(e), v, conversationIdHeader);
}
}
use of javax.ws.rs.core.Variant in project droolsjbpm-integration by kiegroup.
the class DocumentResource method listDocuments.
@ApiOperation(value = "Returns all documents from KIE Server.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 200, response = DocumentInstanceList.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = GET_DOCUMENTS_RESPONSE_JSON) })) })
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response listDocuments(@javax.ws.rs.core.Context HttpHeaders headers, @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) {
Variant v = getVariant(headers);
// no container id available so only used to transfer conversation id if given by client
Header conversationIdHeader = buildConversationIdHeader("", context, headers);
try {
DocumentInstanceList documents = documentServiceBase.listDocuments(page, pageSize);
return createCorrectVariant(documents, headers, Response.Status.OK, conversationIdHeader);
} catch (Exception e) {
logger.error("Unexpected error during processing {}", e.getMessage(), e);
return internalServerError(errorMessage(e), v, conversationIdHeader);
}
}
use of javax.ws.rs.core.Variant in project droolsjbpm-integration by kiegroup.
the class RuntimeDataResource method queryUserTasksByVariables.
@ApiOperation(value = "Queries process tasks by variables", response = ProcessInstanceUserTaskWithVariablesList.class)
@POST
@Path(RestURI.VARIABLES_TASKS_PROCESSES_URI)
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@KieServerEndpoint(categories = { EndpointType.DEFAULT, EndpointType.HISTORY })
public Response queryUserTasksByVariables(@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, @ApiParam(value = "optional sort column", required = false) @QueryParam("orderBy") String orderBy, @ApiParam(value = "optional sort direction - true ascending, false descending", required = false) @QueryParam("asc") @DefaultValue("true") boolean asc) {
Header conversationIdHeader = buildConversationIdHeader("", context, headers);
Variant v = getVariant(headers);
try {
String type = getContentType(headers);
ProcessInstanceUserTaskWithVariablesList taskVariableSummaryList = runtimeDataServiceBase.queryUserTasksByVariables(payload, type, new QueryContext(page * pageSize, pageSize, orderBy, asc));
logger.debug("Returning result of process tasks 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);
}
}
use of javax.ws.rs.core.Variant in project droolsjbpm-integration by kiegroup.
the class RuntimeDataResource method queryProcessesByVariables.
@ApiOperation(value = "Queries processes by variables and tasks", response = ProcessInstanceCustomVarsList.class)
@POST
@Path(RestURI.VARIABLES_PROCESSES_URI)
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@KieServerEndpoint(categories = { EndpointType.DEFAULT, EndpointType.HISTORY })
public Response queryProcessesByVariables(@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, @ApiParam(value = "optional sort column", required = false) @QueryParam("orderBy") String orderBy, @ApiParam(value = "optional sort direction - true ascending, false descending", required = false) @QueryParam("asc") @DefaultValue("true") boolean asc) {
Header conversationIdHeader = buildConversationIdHeader("", context, headers);
Variant v = getVariant(headers);
try {
String type = getContentType(headers);
ProcessInstanceCustomVarsList processVariableSummaryList = runtimeDataServiceBase.queryProcessesByVariables(payload, type, new QueryContext(page * pageSize, pageSize, orderBy, asc));
logger.debug("Returning result of process instance search: {}", processVariableSummaryList);
return createCorrectVariant(processVariableSummaryList, headers, Response.Status.OK, conversationIdHeader);
} catch (Exception e) {
logger.error("Unexpected error during processing {}", e.getMessage(), e);
return internalServerError(errorMessage(e), v, conversationIdHeader);
}
}
use of javax.ws.rs.core.Variant in project droolsjbpm-integration by kiegroup.
the class RuntimeDataResource method getProcessesByDeploymentIdProcessId.
@ApiOperation(value = "Returns information about a specified process definition in a specified KIE container.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 200, response = ProcessDefinition.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = GET_PROCESS_DEF_RESPONSE_JSON) })) })
@GET
@Path(PROCESS_DEFINITIONS_BY_CONTAINER_ID_DEF_ID_GET_URI)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getProcessesByDeploymentIdProcessId(@Context HttpHeaders headers, @ApiParam(value = "container id that process definition belongs to", required = true) @PathParam(CONTAINER_ID) String containerId, @ApiParam(value = "process id to load process definition", required = true) @PathParam(PROCESS_ID) String processId) {
Variant v = getVariant(headers);
// no container id available so only used to transfer conversation id if given by client
Header conversationIdHeader = buildConversationIdHeader(containerId, context, headers);
ProcessDefinition processDesc = null;
try {
processDesc = runtimeDataServiceBase.getProcessesByDeploymentIdProcessId(containerId, processId);
return createCorrectVariant(processDesc, headers, Response.Status.OK, conversationIdHeader);
} catch (IllegalArgumentException e) {
return notFound(MessageFormat.format(PROCESS_DEFINITION_NOT_FOUND, processId, containerId), v, conversationIdHeader);
}
}
Aggregations