Search in sources :

Example 1 with TaskEventInstanceList

use of org.kie.server.api.model.instance.TaskEventInstanceList in project droolsjbpm-integration by kiegroup.

the class UserTaskResource method getTaskEvents.

@ApiOperation(value = "Returns all events for a specified task instance.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Task with given id not found"), @ApiResponse(code = 200, response = TaskEventInstanceList.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = GET_TASK_EVENTS_RESPONSE_JSON) })) })
@GET
@Path(TASK_INSTANCE_EVENTS_GET_URI)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getTaskEvents(@Context HttpHeaders headers, @ApiParam(value = "container id that task instance belongs to", required = true, example = "evaluation_1.0.0-SNAPSHOT") @PathParam(CONTAINER_ID) String containerId, @ApiParam(value = "identifier of the task instance that events should be loaded for", required = true, example = "123") @PathParam(TASK_INSTANCE_ID) Long taskId, @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) {
    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 {
        TaskEventInstanceList result = runtimeDataServiceBase.getTaskEvents(taskId, page, pageSize, sort, sortOrder);
        return createCorrectVariant(result, headers, Response.Status.OK, conversationIdHeader);
    } catch (TaskNotFoundException e) {
        return notFound(errorMessage(e, MessageFormat.format(TASK_INSTANCE_NOT_FOUND, taskId)), v, conversationIdHeader);
    } catch (Exception e) {
        logger.error("Unexpected error during processing {}", e.getMessage(), e);
        return internalServerError(errorMessage(e), v, conversationIdHeader);
    }
}
Also used : RestUtils.createCorrectVariant(org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant) RestUtils.getVariant(org.kie.server.remote.rest.common.util.RestUtils.getVariant) Variant(javax.ws.rs.core.Variant) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) TaskEventInstanceList(org.kie.server.api.model.instance.TaskEventInstanceList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with TaskEventInstanceList

use of org.kie.server.api.model.instance.TaskEventInstanceList in project droolsjbpm-integration by kiegroup.

the class RuntimeDataResource method getTaskEvents.

@ApiOperation(value = "Returns events for a specified task instance.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 200, response = TaskEventInstanceList.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = GET_TASK_EVENTS_RESPONSE_JSON) })) })
@GET
@Path(TASKS_EVENTS_GET_URI)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getTaskEvents(@Context HttpHeaders headers, @ApiParam(value = "task id to load task events for", required = true) @PathParam(TASK_INSTANCE_ID) Long taskId, @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) {
    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 {
        TaskEventInstanceList result = runtimeDataServiceBase.getTaskEvents(taskId, page, pageSize, sort, sortOrder);
        return createCorrectVariant(result, headers, Response.Status.OK, conversationIdHeader);
    } catch (TaskNotFoundException e) {
        return notFound(MessageFormat.format(TASK_INSTANCE_NOT_FOUND, taskId), v, conversationIdHeader);
    } catch (Exception e) {
        logger.error("Unexpected error during processing {}", e.getMessage(), e);
        return internalServerError(errorMessage(e), v, conversationIdHeader);
    }
}
Also used : RestUtils.createCorrectVariant(org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant) RestUtils.getVariant(org.kie.server.remote.rest.common.util.RestUtils.getVariant) Variant(javax.ws.rs.core.Variant) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) TaskEventInstanceList(org.kie.server.api.model.instance.TaskEventInstanceList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with TaskEventInstanceList

use of org.kie.server.api.model.instance.TaskEventInstanceList in project droolsjbpm-integration by kiegroup.

the class RuntimeDataServiceBase method getTaskEvents.

public TaskEventInstanceList getTaskEvents(long taskId, Integer page, Integer pageSize, String sort, boolean sortOrder) {
    if (sort == null || sort.isEmpty()) {
        sort = "Id";
    }
    logger.debug("About to search for task {} events", taskId);
    List<TaskEvent> tasks = runtimeDataService.getTaskEvents(taskId, buildQueryFilter(page, pageSize, sort, sortOrder));
    logger.debug("Found {} task events available for task '{}'", tasks.size(), taskId);
    TaskEventInstanceList result = null;
    if (tasks == null) {
        result = new TaskEventInstanceList(new TaskEventInstance[0]);
    } else {
        TaskEventInstance[] instances = new TaskEventInstance[tasks.size()];
        int counter = 0;
        for (TaskEvent taskSummary : tasks) {
            TaskEventInstance task = TaskEventInstance.builder().id(taskSummary.getTaskId()).taskId(taskSummary.getTaskId()).date(taskSummary.getLogTime()).processInstanceId(taskSummary.getProcessInstanceId()).type(taskSummary.getType().toString()).user(taskSummary.getUserId()).workItemId(taskSummary.getWorkItemId()).message(taskSummary.getMessage()).correlationKey(taskSummary.getCorrelationKey()).processType(taskSummary.getProcessType()).assignedOwner(taskSummary.getCurrentOwner()).build();
            instances[counter] = task;
            counter++;
        }
        result = new TaskEventInstanceList(instances);
    }
    return result;
}
Also used : TaskEvent(org.kie.internal.task.api.model.TaskEvent) TaskEventInstanceList(org.kie.server.api.model.instance.TaskEventInstanceList) TaskEventInstance(org.kie.server.api.model.instance.TaskEventInstance)

Example 4 with TaskEventInstanceList

use of org.kie.server.api.model.instance.TaskEventInstanceList in project droolsjbpm-integration by kiegroup.

the class UserTaskServicesClientImpl method findTaskEvents.

@Override
public List<TaskEventInstance> findTaskEvents(String containerId, Long taskId, Integer page, Integer pageSize, String sort, boolean sortOrder) {
    TaskEventInstanceList taskSummaryList = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CONTAINER_ID, containerId);
        valuesMap.put(TASK_INSTANCE_ID, taskId);
        String queryString = getPagingQueryString("?sort=" + sort + "&sortOrder=" + sortOrder, page, pageSize);
        taskSummaryList = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), TASK_URI + "/" + TASK_INSTANCE_EVENTS_GET_URI, valuesMap) + queryString, TaskEventInstanceList.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("QueryService", "getTaskEvents", new Object[] { taskId, page, pageSize, sort, sortOrder })));
        ServiceResponse<TaskEventInstanceList> response = (ServiceResponse<TaskEventInstanceList>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        taskSummaryList = response.getResult();
    }
    if (taskSummaryList != null && taskSummaryList.getTaskEvents() != null) {
        return Arrays.asList(taskSummaryList.getTaskEvents());
    }
    return Collections.emptyList();
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) HashMap(java.util.HashMap) CommandScript(org.kie.server.api.commands.CommandScript) TaskEventInstanceList(org.kie.server.api.model.instance.TaskEventInstanceList)

Aggregations

TaskEventInstanceList (org.kie.server.api.model.instance.TaskEventInstanceList)4 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Variant (javax.ws.rs.core.Variant)2 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)2 Header (org.kie.server.remote.rest.common.Header)2 RestUtils.buildConversationIdHeader (org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader)2 RestUtils.createCorrectVariant (org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant)2 RestUtils.getVariant (org.kie.server.remote.rest.common.util.RestUtils.getVariant)2 HashMap (java.util.HashMap)1 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)1 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)1 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)1 TaskEvent (org.kie.internal.task.api.model.TaskEvent)1 CommandScript (org.kie.server.api.commands.CommandScript)1 DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)1 KieServerCommand (org.kie.server.api.model.KieServerCommand)1