Search in sources :

Example 6 with TaskDataEvent

use of org.kie.kogito.taskassigning.service.event.TaskDataEvent in project kogito-apps by kiegroup.

the class TaskAssigningServiceTest method mockTaskDataEvent.

private static TaskDataEvent mockTaskDataEvent(String taskId, String state, ZonedDateTime lastUpdate) {
    TaskData taskData = mock(TaskData.class);
    doReturn(taskId).when(taskData).getId();
    doReturn(state).when(taskData).getState();
    doReturn(lastUpdate).when(taskData).getLastUpdate();
    return new TaskDataEvent(taskData);
}
Also used : TaskDataEvent(org.kie.kogito.taskassigning.service.event.TaskDataEvent) TestUtil.mockTaskData(org.kie.kogito.taskassigning.service.TestUtil.mockTaskData)

Example 7 with TaskDataEvent

use of org.kie.kogito.taskassigning.service.event.TaskDataEvent in project kogito-apps by kiegroup.

the class EventUtilTest method mockTaskDataEvent.

private static TaskDataEvent mockTaskDataEvent(String taskId, ZonedDateTime lastUpdate) {
    TaskData taskData = mock(TaskData.class);
    doReturn(taskId).when(taskData).getId();
    doReturn(lastUpdate).when(taskData).getLastUpdate();
    return new TaskDataEvent(taskData);
}
Also used : TaskDataEvent(org.kie.kogito.taskassigning.service.event.TaskDataEvent) TaskData(org.kie.kogito.taskassigning.service.TaskData)

Example 8 with TaskDataEvent

use of org.kie.kogito.taskassigning.service.event.TaskDataEvent in project kogito-apps by kiegroup.

the class TaskAssigningService method executeSolutionChange.

synchronized void executeSolutionChange(TaskAssigningSolution solution) {
    if (isNotOperative()) {
        LOGGER.warn(SERVICE_INOPERATIVE_MESSAGE, context.getStatus());
        return;
    }
    try {
        LOGGER.debug("process the next generated solution, applyingPlanningExecutionResult: {}", applyingPlanningExecutionResult.get());
        if (LOGGER.isTraceEnabled()) {
            traceSolution(LOGGER, solution);
        }
        clearWaitForImprovedSolutionTimer();
        currentSolution.set(solution);
        List<ProblemFactChange<TaskAssigningSolution>> pendingEventsChanges = null;
        if (applyingPlanningExecutionResult.get()) {
            // solution is the result of applying the pinning changes corresponding to the last executed plan,
            // prioritize events that could have arrived in the middle if any.
            applyingPlanningExecutionResult.set(false);
            List<DataEvent<?>> pendingEvents = pollEvents();
            List<TaskDataEvent> pendingTaskDataEvents = filterNewestTaskEventsInContext(context, pendingEvents);
            UserDataEvent pendingUserDataEvent = filterNewestUserEvent(pendingEvents);
            if (!pendingTaskDataEvents.isEmpty() || pendingUserDataEvent != null) {
                pendingEventsChanges = SolutionChangesBuilder.create().forSolution(solution).withContext(context).withUserServiceConnector(userServiceConnectorDelegate).withProcessors(processorRegistry).fromTasksData(fromTaskDataEvents(pendingTaskDataEvents)).fromUserDataEvent(pendingUserDataEvent).build();
            }
        }
        if (pendingEventsChanges != null && !pendingEventsChanges.isEmpty()) {
            LOGGER.debug("executeSolutionChange - we have pendingEventsChanges: {} to apply", pendingEventsChanges.size());
            cancelScheduledImproveSolutionOnBackgroundTimer();
            solverExecutor.addProblemFactChanges(pendingEventsChanges);
        } else {
            executePlanOrResumeEvents(solution);
        }
    } catch (Exception e) {
        failFast(e);
    }
}
Also used : TaskDataEvent(org.kie.kogito.taskassigning.service.event.TaskDataEvent) TaskDataEvent(org.kie.kogito.taskassigning.service.event.TaskDataEvent) UserDataEvent(org.kie.kogito.taskassigning.service.event.UserDataEvent) SolutionUpdatedOnBackgroundDataEvent(org.kie.kogito.taskassigning.service.event.SolutionUpdatedOnBackgroundDataEvent) DataEvent(org.kie.kogito.taskassigning.service.event.DataEvent) AssignTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange) ProblemFactChange(org.optaplanner.core.api.solver.ProblemFactChange) UserDataEvent(org.kie.kogito.taskassigning.service.event.UserDataEvent)

Aggregations

TaskDataEvent (org.kie.kogito.taskassigning.service.event.TaskDataEvent)8 SolutionUpdatedOnBackgroundDataEvent (org.kie.kogito.taskassigning.service.event.SolutionUpdatedOnBackgroundDataEvent)3 UserDataEvent (org.kie.kogito.taskassigning.service.event.UserDataEvent)3 Test (org.junit.jupiter.api.Test)2 TaskAssigningSolution (org.kie.kogito.taskassigning.core.model.TaskAssigningSolution)2 AssignTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange)2 TaskData (org.kie.kogito.taskassigning.service.TaskData)2 DataEvent (org.kie.kogito.taskassigning.service.event.DataEvent)2 ProblemFactChange (org.optaplanner.core.api.solver.ProblemFactChange)2 ArrayList (java.util.ArrayList)1 TaskAssignment (org.kie.kogito.taskassigning.core.model.TaskAssignment)1 TaskAssigningServiceContext (org.kie.kogito.taskassigning.service.TaskAssigningServiceContext)1 TestUtil.mockTaskData (org.kie.kogito.taskassigning.service.TestUtil.mockTaskData)1