use of org.kie.server.api.model.taskassigning.PlanningExecutionResult in project droolsjbpm-integration by kiegroup.
the class TaskAssigningRuntimeResource method executePlanning.
@ApiOperation(value = "Executes a planning into the processes runtime.", notes = "This operation is intended for the task assigning integration implementation, third parties should avoid using it.", response = PlanningExecutionResult.class)
@POST
@Path(TASK_ASSIGNING_EXECUTE_PLANNING_URI)
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response executePlanning(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "identifier of the user to execute the planning on behalf of", required = true) @QueryParam("user") String userId, @ApiParam(value = "planning definition represented as PlanningItemList", required = true) 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 {
final String contentType = getContentType(headers);
final PlanningItemList planningItemList = marshallerHelper.unmarshal(payload, contentType, PlanningItemList.class);
final PlanningExecutionResult result = runtimeServiceBase.executePlanning(planningItemList, userId);
return createCorrectVariant(result, headers, Response.Status.OK, conversationIdHeader);
} catch (Exception e) {
LOGGER.error("Unexpected error executing planning {}", e.getMessage(), e);
return internalServerError(errorMessage(e), v);
}
}
use of org.kie.server.api.model.taskassigning.PlanningExecutionResult 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.PlanningExecutionResult 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.PlanningExecutionResult 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.PlanningExecutionResult 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