Search in sources :

Example 6 with PlanningExecutionResult

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);
    }
}
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) PlanningItemList(org.kie.server.api.model.taskassigning.PlanningItemList) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) PlanningExecutionResult(org.kie.server.api.model.taskassigning.PlanningExecutionResult) 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)

Example 7 with PlanningExecutionResult

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);
}
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 8 with PlanningExecutionResult

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);
}
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 PlanningExecutionResult

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);
}
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 PlanningExecutionResult

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

PlanningExecutionResult (org.kie.server.api.model.taskassigning.PlanningExecutionResult)14 PlanningItemList (org.kie.server.api.model.taskassigning.PlanningItemList)12 Test (org.junit.Test)9 PlanningItem (org.kie.server.api.model.taskassigning.PlanningItem)9 TaskData (org.kie.server.api.model.taskassigning.TaskData)9 StatusConverter.convertToString (org.kie.server.api.model.taskassigning.util.StatusConverter.convertToString)3 CompositeCommand (org.jbpm.services.task.commands.CompositeCommand)2 PlanningTask (org.kie.server.api.model.taskassigning.PlanningTask)2 ApiOperation (io.swagger.annotations.ApiOperation)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Variant (javax.ws.rs.core.Variant)1 Status (org.kie.api.task.model.Status)1 Marshaller (org.kie.server.api.marshalling.Marshaller)1 KieContainerStatus (org.kie.server.api.model.KieContainerStatus)1 Header (org.kie.server.remote.rest.common.Header)1 RestUtils.buildConversationIdHeader (org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader)1 RestUtils.createCorrectVariant (org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant)1