use of org.kie.server.api.model.instance.TaskInstance in project droolsjbpm-integration by kiegroup.
the class RuntimeDataResource method getTaskById.
@ApiOperation(value = "Returns information about a specified task instance.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Task not found for given id"), @ApiResponse(code = 200, response = TaskInstance.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = GET_TASK_RESPONSE_JSON) })) })
@GET
@Path(TASK_GET_URI)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getTaskById(@Context HttpHeaders headers, @ApiParam(value = "task id to load task instance", required = true) @PathParam(TASK_INSTANCE_ID) Long taskId, @ApiParam(value = "optional include SLA data - defaults to false", required = false) @QueryParam("withSLA") @DefaultValue("false") boolean withSLA) {
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 {
TaskInstance userTaskDesc = runtimeDataServiceBase.getTaskById(taskId, withSLA);
return createCorrectVariant(userTaskDesc, 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);
}
}
use of org.kie.server.api.model.instance.TaskInstance in project droolsjbpm-integration by kiegroup.
the class RuntimeDataResource method getTaskByWorkItemId.
@ApiOperation(value = "Returns task instances with a specified work item.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Task not found for given work item id"), @ApiResponse(code = 200, response = TaskInstance.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = GET_TASK_RESPONSE_JSON) })) })
@GET
@Path(TASK_BY_WORK_ITEM_ID_GET_URI)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getTaskByWorkItemId(@Context HttpHeaders headers, @ApiParam(value = "work item id to load task associated with", required = true) @PathParam("workItemId") Long workItemId) {
Variant v = getVariant(headers);
// no container id available so only used to transfer conversation id if given by client
Header conversationIdHeader = buildConversationIdHeader("", context, headers);
TaskInstance userTaskDesc = null;
try {
userTaskDesc = runtimeDataServiceBase.getTaskByWorkItemId(workItemId);
return createCorrectVariant(userTaskDesc, headers, Response.Status.OK, conversationIdHeader);
} catch (TaskNotFoundException e) {
return notFound(MessageFormat.format(TASK_INSTANCE_NOT_FOUND_FOR_WORKITEM, workItemId), v, conversationIdHeader);
} catch (Exception e) {
logger.error("Unexpected error during processing {}", e.getMessage(), e);
return internalServerError(errorMessage(e), v, conversationIdHeader);
}
}
use of org.kie.server.api.model.instance.TaskInstance in project droolsjbpm-integration by kiegroup.
the class FormServiceIntegrationTest method testFormName.
@Test
public void testFormName() throws Exception {
Long pid = processClient.startProcess(CONTAINER_ID, HIRING_2_PROCESS_ID);
assertNotNull(pid);
assertTrue(pid.longValue() > 0);
try {
changeUser(USER_ADMINISTRATOR);
List<TaskSummary> tasks = taskClient.findTasksAssignedAsBusinessAdministrator(USER_ADMINISTRATOR, 0, 10);
assertNotNull(tasks);
Long taskId = tasks.get(0).getId();
TaskInstance ti = taskClient.getTaskInstance(CONTAINER_ID, taskId);
assertEquals("HRInterview2", ti.getFormName());
taskClient.startTask(CONTAINER_ID, taskId, USER_ADMINISTRATOR);
taskClient.completeTask(CONTAINER_ID, taskId, USER_ADMINISTRATOR, Collections.emptyMap());
tasks = taskClient.findTasksAssignedAsBusinessAdministrator(USER_ADMINISTRATOR, 0, 10);
assertNotNull(tasks);
taskId = tasks.get(0).getId();
ti = taskClient.findTaskById(taskId);
assertEquals("Tech Interview", ti.getName());
assertEquals("TechInterview", ti.getFormName());
taskClient.startTask(CONTAINER_ID, taskId, USER_ADMINISTRATOR);
taskClient.completeTask(CONTAINER_ID, taskId, USER_ADMINISTRATOR, Collections.emptyMap());
List<WorkItemInstance> workItems = processClient.getWorkItemByProcessInstance(CONTAINER_ID, pid);
assertNotNull(workItems);
ti = taskClient.findTaskByWorkItemId(workItems.get(0).getId());
assertEquals("Create Proposal", ti.getName());
assertEquals("CreateProposal", ti.getFormName());
} finally {
changeUser(TestConfig.getUsername());
processClient.abortProcessInstance(CONTAINER_ID, pid);
}
}
use of org.kie.server.api.model.instance.TaskInstance in project businessautomation-cop by redhat-cop.
the class KieQueryTest method testLocalProcessVariablePersistence.
/**
* Test JPA Objects are persisted to the jBPM (local) Schema
*/
@Test
public void testLocalProcessVariablePersistence() throws InterruptedException {
Person person = new Person();
person.setAge(20);
person.setName("Joe");
person.setSurname("Bloggs");
Map<String, Object> params = this.getParams();
params.put("person", person);
// start process instance
Long processInstanceId = processServicesClient.startProcess(containerId, TestWorkflowConstant.PROCESS_ID.PVP_PROCESS_ID, params);
assertNotNull(processInstanceId);
TaskSummary task = this.assertTaskInstance(processInstanceId, 1, TestWorkflowConstant.SAMPLE_PROCESS_DATA.TASK_OWNER, "Task");
// Obtain Task Instances via the Internal Java API
List<UserTaskInstanceWithVarsDesc> tins = queryService.query(TestWorkflowConstant.QUERIES.ALL_TASKS_WITH_INPUT_VARS, UserTaskInstanceWithVarsQueryMapper.get(), new QueryContext(), QueryParam.in(COLUMN_TASK_STATUS, TestWorkflowConstant.getActiveTaskStatuses()));
assertNotNull(tins);
assertEquals(1, tins.size());
assertEquals(1, jdbcTemplate.queryForObject("SELECT COUNT(*) FROM PERSON", Integer.class).intValue());
MappedVariable mv = jdbcTemplate.queryForObject("SELECT * FROM MAPPEDVARIABLE WHERE PROCESSINSTANCEID = ? AND TASKID = ?", new Object[] { processInstanceId, task.getId() }, new RowMapper<MappedVariable>() {
public MappedVariable mapRow(ResultSet rs, int rowNum) throws SQLException {
MappedVariable mv = new MappedVariable();
mv.setMappedVarId(rs.getLong("mappedVarId"));
mv.setProcessInstanceId(rs.getLong("processInstanceId"));
mv.setVariableId(rs.getLong("variableId"));
mv.setTaskId(rs.getLong("taskId"));
mv.setVariableType(rs.getString("variableType"));
mv.setWorkItemId(rs.getLong("workItemId"));
return mv;
}
});
assertNotNull(mv);
assertEquals(mv.getProcessInstanceId(), processInstanceId);
assertEquals(mv.getTaskId(), task.getId());
assertTrue(mv.getVariableId() > 0);
Person p = jdbcTemplate.queryForObject("SELECT P.* FROM PERSON P WHERE P.ID = ? ", new Object[] { mv.getVariableId() }, new RowMapper<Person>() {
public Person mapRow(ResultSet rs, int rowNum) throws SQLException {
Person p = new Person();
p.setAge(rs.getInt("age"));
p.setName(rs.getString("name"));
p.setSurname(rs.getString("surname"));
return p;
}
});
assertEquals(person.getAge(), p.getAge());
assertEquals(person.getName(), p.getName());
assertEquals(person.getSurname(), p.getSurname());
Person person2 = new Person();
person2.setAge(17);
person2.setName("Joe");
person2.setSurname("Cloggs");
params = this.getParams();
params.put("person", person2);
// start process instance
Long processInstanceId2 = processServicesClient.startProcess(containerId, TestWorkflowConstant.PROCESS_ID.PVP_PROCESS_ID, params);
tins = queryService.query(TestWorkflowConstant.QUERIES.ALL_TASKS_WITH_INPUT_VARS, UserTaskInstanceWithVarsQueryMapper.get(), new QueryContext(), QueryParam.in(COLUMN_TASK_STATUS, TestWorkflowConstant.getActiveTaskStatuses()));
assertNotNull(tins);
assertEquals(2, tins.size());
QueryFilterSpec spec = new QueryFilterSpecBuilder().greaterThan("person_age", 18).equalsTo("person_name", "Joe").in("person_surname", Arrays.asList("Bloggs", "Cloggs")).addColumnMapping("PERSON_AGE", "integer").addColumnMapping("PERSON_NAME", "string").addColumnMapping("PERSON_SURNAME", "string").get();
System.out.println("===================");
List<TaskInstance> taskInstanceLogs = queryServicesClient.query(TestWorkflowConstant.QUERIES.ALL_TASKS_WITH_PERSON_VAR, QUERY_MAP_TASK_WITH_CUSTOM_VARS, spec, 0, 1000, TaskInstance.class);
System.out.println("===================");
assertNotNull(taskInstanceLogs);
assertEquals(1, taskInstanceLogs.size());
}
Aggregations