Search in sources :

Example 41 with TaskInstance

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);
    }
}
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) TaskInstance(org.kie.server.api.model.instance.TaskInstance) 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) 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 42 with TaskInstance

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);
    }
}
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) TaskInstance(org.kie.server.api.model.instance.TaskInstance) 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) 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 43 with TaskInstance

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);
    }
}
Also used : TaskInstance(org.kie.server.api.model.instance.TaskInstance) TaskSummary(org.kie.server.api.model.instance.TaskSummary) WorkItemInstance(org.kie.server.api.model.instance.WorkItemInstance) Test(org.junit.Test)

Example 44 with TaskInstance

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());
}
Also used : QueryFilterSpecBuilder(org.kie.server.api.util.QueryFilterSpecBuilder) TaskInstance(org.kie.server.api.model.instance.TaskInstance) SQLException(java.sql.SQLException) UserTaskInstanceWithVarsDesc(org.jbpm.services.api.model.UserTaskInstanceWithVarsDesc) QueryContext(org.kie.internal.query.QueryContext) QueryFilterSpec(org.kie.server.api.model.definition.QueryFilterSpec) TaskSummary(org.kie.server.api.model.instance.TaskSummary) ResultSet(java.sql.ResultSet) MappedVariable(org.drools.persistence.jpa.marshaller.MappedVariable) Person(org.redhat.services.model.Person) Test(org.junit.Test)

Aggregations

TaskInstance (org.kie.server.api.model.instance.TaskInstance)44 Test (org.junit.Test)29 TaskSummary (org.kie.server.api.model.instance.TaskSummary)27 HashMap (java.util.HashMap)24 OrgEntities (org.kie.server.api.model.admin.OrgEntities)8 JbpmKieServerBaseIntegrationTest (org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)7 ProcessInstance (org.kie.server.api.model.instance.ProcessInstance)6 QueryDefinition (org.kie.server.api.model.definition.QueryDefinition)5 WorkItemInstance (org.kie.server.api.model.instance.WorkItemInstance)5 ArrayList (java.util.ArrayList)4 CommandScript (org.kie.server.api.commands.CommandScript)4 DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)4 KieServerCommand (org.kie.server.api.model.KieServerCommand)4 ServiceResponse (org.kie.server.api.model.ServiceResponse)4 Calendar (java.util.Calendar)3 Date (java.util.Date)3 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)3 UserTaskInstanceWithVarsDesc (org.jbpm.services.api.model.UserTaskInstanceWithVarsDesc)3 QueryFilterSpecBuilder (org.kie.server.api.util.QueryFilterSpecBuilder)3 ApiOperation (io.swagger.annotations.ApiOperation)2