Search in sources :

Example 6 with TaskData

use of org.kie.server.api.model.taskassigning.TaskData in project droolsjbpm-integration by kiegroup.

the class TaskAssigningRuntimeServiceQueryHelperTest method readTaskDataSummary.

@Test
public void readTaskDataSummary() {
    List<TaskData> invocation0 = mockTasks();
    List<TaskData> invocation1 = Arrays.asList(mockTaskData(4L), mockTaskData(5L));
    List<TaskData> invocation2 = Collections.singletonList(mockTaskData(6L));
    doAnswer(new Answer() {

        private int invocations = 0;

        public Object answer(InvocationOnMock invocation) {
            switch(invocations++) {
                case 0:
                    return invocation0;
                case 1:
                    return invocation1;
                case 2:
                    return invocation2;
                default:
                    return Collections.emptyList();
            }
        }
    }).when(helper).executeQuery(eq(queryService), anyString(), any(TaskAssigningTaskDataWithPotentialOwnersQueryMapper.class), any(), any());
    List<TaskData> result = helper.readTasksDataSummary(0, Collections.emptyList(), 10);
    assertEquals(TASK1_ID, result.get(0).getTaskId(), 0);
    assertEquals(TASK2_ID, result.get(1).getTaskId(), 0);
    assertEquals(TASK3_ID, result.get(2).getTaskId(), 0);
    assertEquals(4L, result.get(3).getTaskId(), 0);
    assertEquals(5L, result.get(4).getTaskId(), 0);
    assertEquals(6L, result.get(5).getTaskId(), 0);
}
Also used : Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TaskAssigningTaskDataWithPotentialOwnersQueryMapper(org.kie.server.services.taskassigning.runtime.query.TaskAssigningTaskDataWithPotentialOwnersQueryMapper) TaskData(org.kie.server.api.model.taskassigning.TaskData) Test(org.junit.Test)

Example 7 with TaskData

use of org.kie.server.api.model.taskassigning.TaskData in project droolsjbpm-integration by kiegroup.

the class TaskAssigningRuntimeServiceQueryHelperTest method prepareQuery.

private Map<String, Object> prepareQuery(TaskInputVariablesReadMode readMode) {
    Map<String, Object> params = mockQueryParams(readMode);
    List<TaskData> taskDataList = mockTasks();
    doReturn(taskDataList).when(helper).executeQuery(eq(queryService), anyString(), any(TaskAssigningTaskDataWithPotentialOwnersQueryMapper.class), any(), any());
    KieContainerInstanceImpl container = mock(KieContainerInstanceImpl.class);
    when(container.getStatus()).thenReturn(KieContainerStatus.STARTED);
    when(registry.getContainer(CONTAINER_ID)).thenReturn(container);
    return params;
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) TaskAssigningTaskDataWithPotentialOwnersQueryMapper(org.kie.server.services.taskassigning.runtime.query.TaskAssigningTaskDataWithPotentialOwnersQueryMapper) TaskData(org.kie.server.api.model.taskassigning.TaskData)

Example 8 with TaskData

use of org.kie.server.api.model.taskassigning.TaskData in project droolsjbpm-integration by kiegroup.

the class TaskAssigningRuntimeServiceQueryHelperTest method mockTaskData.

private TaskData mockTaskData(Long taskId, Status status, boolean hasPlanningTask, String containerId) {
    TaskData taskData = TaskData.builder().taskId(taskId).status(status.name()).containerId(containerId).build();
    if (hasPlanningTask) {
        PlanningTask planningTask = PlanningTask.builder().taskId(taskId).build();
        taskData.setPlanningTask(planningTask);
    }
    return taskData;
}
Also used : PlanningTask(org.kie.server.api.model.taskassigning.PlanningTask) TaskData(org.kie.server.api.model.taskassigning.TaskData)

Example 9 with TaskData

use of org.kie.server.api.model.taskassigning.TaskData in project droolsjbpm-integration by kiegroup.

the class TaskUtilTest method fromTaskData.

private void fromTaskData(Map<String, Object> inputData, Set<Object> expectedSkills, Set<Object> expectedAffinities) {
    Set<OrganizationalEntity> potentialOwners = new HashSet<>();
    potentialOwners.add(OE_1);
    potentialOwners.add(OE_2);
    TaskData taskData = TaskData.builder().taskId(TASK_ID).processInstanceId(PROCESS_INSTANCE_ID).processId(PROCESS_ID).containerId(CONTAINER_ID).name(NAME).priority(PRIORITY).status(STATUS).inputData(inputData).potentialOwners(potentialOwners).build();
    Task task = TaskUtil.fromTaskData(taskData);
    assertEquals(TASK_ID, task.getId(), 0);
    assertEquals(PROCESS_INSTANCE_ID, task.getProcessInstanceId(), 0);
    assertEquals(PROCESS_ID, task.getProcessId());
    assertEquals(CONTAINER_ID, task.getContainerId());
    assertEquals(NAME, task.getName());
    assertEquals(PRIORITY, task.getPriority(), 0);
    assertEquals(STATUS, task.getStatus());
    assertEquals(inputData, task.getInputData());
    assertEquals(potentialOwners.size(), task.getPotentialOwners().size(), 2);
    User user = task.getPotentialOwners().stream().filter(u -> OE_1.getName().equals(u.getEntityId()) && u.isUser()).map(u -> (User) u).findFirst().orElse(null);
    assertNotNull(user);
    Group group = task.getPotentialOwners().stream().filter(g -> OE_2.getName().equals(g.getEntityId()) && !g.isUser()).map(g -> (Group) g).findFirst().orElse(null);
    assertNotNull(group);
    assertEquals(expectedSkills, task.getLabelValues(SKILLS.name()));
    assertEquals(expectedAffinities, task.getLabelValues(AFFINITIES.name()));
}
Also used : Arrays(java.util.Arrays) Group(org.kie.server.services.taskassigning.core.model.Group) Assert.assertNotNull(org.junit.Assert.assertNotNull) Set(java.util.Set) HashMap(java.util.HashMap) Test(org.junit.Test) TaskData(org.kie.server.api.model.taskassigning.TaskData) HashSet(java.util.HashSet) User(org.kie.server.services.taskassigning.core.model.User) Map(java.util.Map) AFFINITIES(org.kie.server.services.taskassigning.core.model.DefaultLabels.AFFINITIES) Collections(java.util.Collections) UserType(org.kie.server.api.model.taskassigning.UserType) OrganizationalEntity(org.kie.server.api.model.taskassigning.OrganizationalEntity) Assert.assertEquals(org.junit.Assert.assertEquals) SKILLS(org.kie.server.services.taskassigning.core.model.DefaultLabels.SKILLS) Task(org.kie.server.services.taskassigning.core.model.Task) Group(org.kie.server.services.taskassigning.core.model.Group) Task(org.kie.server.services.taskassigning.core.model.Task) User(org.kie.server.services.taskassigning.core.model.User) OrganizationalEntity(org.kie.server.api.model.taskassigning.OrganizationalEntity) HashSet(java.util.HashSet) TaskData(org.kie.server.api.model.taskassigning.TaskData)

Example 10 with TaskData

use of org.kie.server.api.model.taskassigning.TaskData in project droolsjbpm-integration by kiegroup.

the class TaskAssigningRuntimeResource method executeTasksQuery.

@ApiOperation(value = "Executes the task assigning integration query for returning the tasks information as a TaskDataList.", notes = "This operation is mainly intended for the tasks assigning integration implementation, third parties are recommended to use the queries described in the task assigning getting started guide.", response = TaskDataList.class)
@POST
@Path(TASK_ASSIGNING_QUERIES_TASK_DATA_URI)
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response executeTasksQuery(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "map with the query parameters", required = true, examples = @Example(value = { @ExampleProperty(mediaType = MediaType.APPLICATION_JSON, value = TASKS_QUERY_PARAMS_MAP_EXAMPLE_JSON), @ExampleProperty(mediaType = MediaType.APPLICATION_XML, value = TASKS_QUERY_PARAMS_MAP_EXAMPLE_XML) })) String payload) {
    final Variant v = getVariant(headers);
    // no container id available so only used to transfer conversation id if given by client
    final Header conversationIdHeader = buildConversationIdHeader("", context, headers);
    try {
        String contentType = getContentType(headers);
        @SuppressWarnings("unchecked") final Map<String, Object> queryParameters = marshallerHelper.unmarshal(payload, contentType, Map.class);
        final LocalDateTime queryTime = LocalDateTime.now();
        final List<TaskData> taskDataList = runtimeServiceBase.executeFindTasksQuery(queryParameters);
        final TaskDataList result = new TaskDataList(taskDataList);
        result.setQueryTime(queryTime);
        return createCorrectVariant(result, headers, Response.Status.OK, conversationIdHeader);
    } catch (Exception e) {
        LOGGER.error("Unexpected error finding tasks {}", 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) LocalDateTime(java.time.LocalDateTime) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) TaskDataList(org.kie.server.api.model.taskassigning.TaskDataList) TaskData(org.kie.server.api.model.taskassigning.TaskData) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

TaskData (org.kie.server.api.model.taskassigning.TaskData)55 Test (org.junit.Test)30 PlanningTask (org.kie.server.api.model.taskassigning.PlanningTask)26 TaskAssigningSolution (org.kie.server.services.taskassigning.core.model.TaskAssigningSolution)14 TaskUtil.fromTaskData (org.kie.server.services.taskassigning.planning.util.TaskUtil.fromTaskData)13 PlanningExecutionResult (org.kie.server.api.model.taskassigning.PlanningExecutionResult)10 PlanningItemList (org.kie.server.api.model.taskassigning.PlanningItemList)10 Task (org.kie.server.services.taskassigning.core.model.Task)10 AddTaskProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange)10 AddUserProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.AddUserProblemFactChange)10 AssignTaskProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange)10 DisableUserProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange)10 ReleaseTaskProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange)10 RemoveTaskProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange)10 RemoveUserProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.RemoveUserProblemFactChange)10 TaskPropertyChangeProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.TaskPropertyChangeProblemFactChange)10 UserPropertyChangeProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange)10 ProblemFactChange (org.optaplanner.core.impl.solver.ProblemFactChange)10 PlanningItem (org.kie.server.api.model.taskassigning.PlanningItem)9 ArrayList (java.util.ArrayList)8