Search in sources :

Example 6 with PlanningItemList

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

the class TaskAssigningRuntimeResourceTest method executePlanning.

@Test
public void executePlanning() {
    Marshaller marshaller = MarshallerFactory.getMarshaller(XSTREAM, this.getClass().getClassLoader());
    PlanningItemList planningItemList = new PlanningItemList();
    String payload = marshaller.marshall(planningItemList);
    PlanningExecutionResult expectedResult = PlanningExecutionResult.builder().build();
    when(runtimeServiceBase.executePlanning(eq(planningItemList), eq(USER_ID))).thenReturn(expectedResult);
    String rawResult = resource.executePlanning(httpHeaders, USER_ID, payload).getEntity().toString();
    String expectedResultInRawFormat = marshaller.marshall(expectedResult);
    assertEquals(expectedResultInRawFormat, rawResult);
}
Also used : Marshaller(org.kie.server.api.marshalling.Marshaller) PlanningItemList(org.kie.server.api.model.taskassigning.PlanningItemList) PlanningExecutionResult(org.kie.server.api.model.taskassigning.PlanningExecutionResult) Test(org.junit.Test)

Example 7 with PlanningItemList

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

the class TaskAssigningRuntimeServiceBase method executePlanning.

public PlanningExecutionResult executePlanning(PlanningItemList planningItemList, String userId) {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    checkServerStatus();
    Map<String, List<PlanningCommand>> commandsByContainer;
    try {
        commandsByContainer = calculatePlanningCommands(planningItemList, userId);
    } catch (PlanningException e) {
        LOGGER.debug("An error was produced during plan calculation, containerId: {}, error code: {}, message: {}", e.getContainerId(), e.getCode(), e.getMessage());
        return PlanningExecutionResult.builder().error(e.getCode()).errorMessage(e.getMessage()).containerId(e.getContainerId()).build();
    } catch (Exception e) {
        final String msg = String.format(UNEXPECTED_ERROR_DURING_PLAN_CALCULATION, e.getMessage());
        LOGGER.error(msg, e);
        return PlanningExecutionResult.builder().error(PlanningExecutionResult.ErrorCode.UNEXPECTED_ERROR).errorMessage(msg).build();
    }
    stopWatch.stop();
    LOGGER.debug("Time to calculate the planning commands: {}", stopWatch);
    stopWatch.reset();
    stopWatch.start();
    for (Map.Entry<String, List<PlanningCommand>> entry : commandsByContainer.entrySet()) {
        try {
            executeContainerCommands(entry.getKey(), entry.getValue());
        } catch (PlanningException e) {
            LOGGER.debug("An error was produced during plan execution on containerId: {}, error code: {}, message: {}", entry.getKey(), e.getCode(), e.getMessage());
            return PlanningExecutionResult.builder().error(e.getCode()).errorMessage(e.getMessage()).containerId(e.getContainerId()).build();
        } catch (Exception e) {
            final String msg = String.format(UNEXPECTED_ERROR_DURING_PLAN_EXECUTION, entry.getKey(), e.getMessage());
            LOGGER.error(msg, e);
            return PlanningExecutionResult.builder().error(PlanningExecutionResult.ErrorCode.UNEXPECTED_ERROR).errorMessage(msg).containerId(entry.getKey()).build();
        }
    }
    stopWatch.stop();
    LOGGER.debug("Time for executing the planning with planning items: {}  ->  {}", planningItemList.getItems().size(), stopWatch);
    return PlanningExecutionResult.builder().build();
}
Also used : PlanningException(org.kie.server.services.taskassigning.runtime.command.PlanningException) ArrayList(java.util.ArrayList) PlanningItemList(org.kie.server.api.model.taskassigning.PlanningItemList) StatusConverter.convertToStringList(org.kie.server.api.model.taskassigning.util.StatusConverter.convertToStringList) List(java.util.List) StatusConverter.convertFromString(org.kie.server.api.model.taskassigning.util.StatusConverter.convertFromString) HashMap(java.util.HashMap) Map(java.util.Map) KieServicesException(org.kie.server.api.exception.KieServicesException) PlanningException(org.kie.server.services.taskassigning.runtime.command.PlanningException) StopWatch(org.apache.commons.lang3.time.StopWatch)

Example 8 with PlanningItemList

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

the class TaskAssigningRuntimeServiceBaseTest method executePlanningWithTaskInInProgressOrSuspendedStatusWithActualOwnerChanged.

private void executePlanningWithTaskInInProgressOrSuspendedStatusWithActualOwnerChanged(Status status) {
    TaskData taskData = mockTaskData(TASK_ID, status, PREVIOUS_ASSIGNED_USER_ID_CHANGED, null);
    List<TaskData> taskDataList = Collections.singletonList(taskData);
    PlanningItem planningItem = mockPlanningItem(TASK_ID, CONTAINER_ID, ASSIGNED_USER_ID);
    PlanningItemList planningItemList = new PlanningItemList(Collections.singletonList(planningItem));
    prepareExecution(taskDataList, CONTAINER_ID);
    PlanningExecutionResult result = serviceBase.executePlanning(planningItemList, USER_ID);
    verify(userTaskService, never()).execute(eq(CONTAINER_ID), any());
    String errorMessage = String.format(TASK_MODIFIED_ERROR_MSG_2, planningItem.getPlanningTask().getTaskId(), PREVIOUS_ASSIGNED_USER_ID_CHANGED, ASSIGNED_USER_ID);
    assertHasError(result, PlanningExecutionResult.ErrorCode.TASK_MODIFIED_SINCE_PLAN_CALCULATION_ERROR, errorMessage, CONTAINER_ID);
}
Also used : PlanningItemList(org.kie.server.api.model.taskassigning.PlanningItemList) PlanningExecutionResult(org.kie.server.api.model.taskassigning.PlanningExecutionResult) StatusConverter.convertToString(org.kie.server.api.model.taskassigning.util.StatusConverter.convertToString) PlanningItem(org.kie.server.api.model.taskassigning.PlanningItem) TaskData(org.kie.server.api.model.taskassigning.TaskData)

Example 9 with PlanningItemList

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

the class TaskAssigningRuntimeServiceBaseTest method executePlanningWithTaskInReservedStatusWithPlanningTaskButReassigned.

@Test
public void executePlanningWithTaskInReservedStatusWithPlanningTaskButReassigned() {
    PlanningTask planningTask = mockPlanningTask(TASK_ID, PREVIOUS_ASSIGNED_USER_ID);
    TaskData taskData = mockTaskData(TASK_ID, Reserved, PREVIOUS_ASSIGNED_USER_ID_CHANGED, planningTask);
    List<TaskData> taskDataList = Collections.singletonList(taskData);
    PlanningItem planningItem = mockPlanningItem(TASK_ID, CONTAINER_ID, ASSIGNED_USER_ID);
    PlanningItemList planningItemList = new PlanningItemList(Collections.singletonList(planningItem));
    prepareExecution(taskDataList, CONTAINER_ID);
    PlanningExecutionResult result = serviceBase.executePlanning(planningItemList, USER_ID);
    verify(userTaskService, never()).execute(eq(CONTAINER_ID), any());
    String errorMessage = String.format(TASK_MODIFIED_ERROR_MSG_1, taskData.getTaskId(), PREVIOUS_ASSIGNED_USER_ID_CHANGED, PREVIOUS_ASSIGNED_USER_ID);
    assertHasError(result, PlanningExecutionResult.ErrorCode.TASK_MODIFIED_SINCE_PLAN_CALCULATION_ERROR, errorMessage, CONTAINER_ID);
}
Also used : PlanningTask(org.kie.server.api.model.taskassigning.PlanningTask) PlanningItemList(org.kie.server.api.model.taskassigning.PlanningItemList) PlanningExecutionResult(org.kie.server.api.model.taskassigning.PlanningExecutionResult) StatusConverter.convertToString(org.kie.server.api.model.taskassigning.util.StatusConverter.convertToString) PlanningItem(org.kie.server.api.model.taskassigning.PlanningItem) TaskData(org.kie.server.api.model.taskassigning.TaskData) Test(org.junit.Test)

Example 10 with PlanningItemList

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

the class TaskAssigningRuntimeServiceBaseTest method executePlanningWithTaskInReservedStatusWithPlanningTaskDontReassigned.

@Test
public void executePlanningWithTaskInReservedStatusWithPlanningTaskDontReassigned() {
    PlanningTask planningTask = mockPlanningTask(TASK_ID, PREVIOUS_ASSIGNED_USER_ID);
    TaskData taskData = mockTaskData(TASK_ID, Reserved, PREVIOUS_ASSIGNED_USER_ID, planningTask);
    List<TaskData> taskDataList = Collections.singletonList(taskData);
    PlanningItem planningItem = mockPlanningItem(TASK_ID, CONTAINER_ID, ASSIGNED_USER_ID);
    PlanningItemList planningItemList = new PlanningItemList(Collections.singletonList(planningItem));
    prepareExecution(taskDataList, CONTAINER_ID);
    PlanningExecutionResult result = serviceBase.executePlanning(planningItemList, USER_ID);
    verify(userTaskService).execute(eq(CONTAINER_ID), planningCommandCaptor.capture());
    assertDelegateAndSaveCommand(planningCommandCaptor.getAllValues(), 0, USER_ID, planningItem);
    assertNoError(result);
}
Also used : PlanningTask(org.kie.server.api.model.taskassigning.PlanningTask) PlanningItemList(org.kie.server.api.model.taskassigning.PlanningItemList) PlanningExecutionResult(org.kie.server.api.model.taskassigning.PlanningExecutionResult) PlanningItem(org.kie.server.api.model.taskassigning.PlanningItem) TaskData(org.kie.server.api.model.taskassigning.TaskData) Test(org.junit.Test)

Aggregations

PlanningItemList (org.kie.server.api.model.taskassigning.PlanningItemList)14 PlanningExecutionResult (org.kie.server.api.model.taskassigning.PlanningExecutionResult)13 TaskData (org.kie.server.api.model.taskassigning.TaskData)10 PlanningItem (org.kie.server.api.model.taskassigning.PlanningItem)9 Test (org.junit.Test)8 CompositeCommand (org.jbpm.services.task.commands.CompositeCommand)3 PlanningTask (org.kie.server.api.model.taskassigning.PlanningTask)3 StatusConverter.convertToString (org.kie.server.api.model.taskassigning.util.StatusConverter.convertToString)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 StopWatch (org.apache.commons.lang3.time.StopWatch)2 Status (org.kie.api.task.model.Status)2 KieServicesException (org.kie.server.api.exception.KieServicesException)2 KieContainerStatus (org.kie.server.api.model.KieContainerStatus)2 StatusConverter.convertFromString (org.kie.server.api.model.taskassigning.util.StatusConverter.convertFromString)2 StatusConverter.convertToStringList (org.kie.server.api.model.taskassigning.util.StatusConverter.convertToStringList)2 PlanningException (org.kie.server.services.taskassigning.runtime.command.PlanningException)2 ApiOperation (io.swagger.annotations.ApiOperation)1