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);
}
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();
}
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);
}
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);
}
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);
}
Aggregations