use of org.kie.kogito.taskassigning.service.event.UserDataEvent in project kogito-apps by kiegroup.
the class SolutionChangesBuilderTest method addNewUserChange.
@Test
void addNewUserChange() {
org.kie.kogito.taskassigning.user.service.User newExternalUser = mockExternalUser(USER_1);
User newUser = mockUser(USER_1);
TaskAssigningSolution solution = mockSolution(Collections.emptyList(), Collections.emptyList());
UserDataEvent event = new UserDataEvent(Collections.singletonList(newExternalUser), ZonedDateTime.now());
List<ProblemFactChange<TaskAssigningSolution>> result = SolutionChangesBuilder.create().withContext(context).withUserServiceConnector(userServiceConnector).withProcessors(processorRegistry).fromTasksData(Collections.emptyList()).fromUserDataEvent(event).forSolution(solution).build();
AddUserProblemFactChange expected = new AddUserProblemFactChange(newUser);
assertChangeIsTheChangeSetId(result, 0);
assertChange(result, 1, expected);
assertThatUserProcessorsWereApplied(newExternalUser);
}
use of org.kie.kogito.taskassigning.service.event.UserDataEvent in project kogito-apps by kiegroup.
the class SolutionChangesBuilderTest method addDisableUserChange.
@Test
void addDisableUserChange() {
User user = mockUser(USER_1);
user.setEnabled(true);
TaskAssigningSolution solution = mockSolution(Collections.singletonList(user), Collections.emptyList());
UserDataEvent event = new UserDataEvent(Collections.emptyList(), ZonedDateTime.now());
List<ProblemFactChange<TaskAssigningSolution>> result = SolutionChangesBuilder.create().withContext(context).withUserServiceConnector(userServiceConnector).withProcessors(processorRegistry).fromTasksData(Collections.emptyList()).fromUserDataEvent(event).forSolution(solution).build();
DisableUserProblemFactChange expected = new DisableUserProblemFactChange(user);
assertChangeIsTheChangeSetId(result, 0);
assertChange(result, 1, expected);
assertThatUserProcessorsWereNotApplied();
}
use of org.kie.kogito.taskassigning.service.event.UserDataEvent in project kogito-apps by kiegroup.
the class TaskAssigningService method processDataEvents.
/**
* Invoked when a set of events are received for processing.
* Three main scenarios might happen:
* a) A solution already exists and thus the proper problem fact changes are calculated and passed to the solver for
* execution. If there are no changes to apply, wait for more events.
*
* b) No solution exists. Instruct the solution data loader to read the users information and the solver will be
* started when this information is returned plus the information collected from the events.
*
* c) A solution improved on background event arrives and must be processed accordingly.
*
* @param events a list of events to process.
*/
synchronized void processDataEvents(List<DataEvent<?>> events) {
if (isNotOperative()) {
LOGGER.warn(SERVICE_INOPERATIVE_MESSAGE, context.getStatus());
return;
}
try {
List<TaskDataEvent> newTaskDataEvents = filterNewestTaskEventsInContext(context, events);
if (currentSolution.get() == null) {
List<TaskDataEvent> activeTaskEvents = newTaskDataEvents.stream().filter(IS_ACTIVE_TASK_EVENT).collect(Collectors.toList());
if (!activeTaskEvents.isEmpty()) {
// b) no solution exists, store the events and get the users from the external user service.
startingEvents = activeTaskEvents;
startingFromEvents.set(true);
loadSolutionData(false, true, config.getDataLoaderPageSize());
} else {
resumeEvents();
}
} else {
// a) a solution exists, calculate and apply the potential changes if any.
UserDataEvent userDataEvent = filterNewestUserEvent(events);
List<ProblemFactChange<TaskAssigningSolution>> changes = SolutionChangesBuilder.create().forSolution(currentSolution.get()).withContext(context).withUserServiceConnector(userServiceConnectorDelegate).withProcessors(processorRegistry).fromTasksData(fromTaskDataEvents(newTaskDataEvents)).fromUserDataEvent(userDataEvent).build();
if (!changes.isEmpty()) {
LOGGER.debug("processDataEvents - there are changes: {} to apply", changes.size());
cancelScheduledImproveSolutionOnBackgroundTimer();
solverExecutor.addProblemFactChanges(changes);
} else {
// c) check if an event for the improve solution on background period has arrived and a better
// solution was produced
SolutionUpdatedOnBackgroundDataEvent solutionImprovedOnBackgroundEvent = filterNewestSolutionUpdatedOnBackgroundEvent(events);
TaskAssigningSolution currentLastBestSolution = lastBestSolution.get();
if (solutionImprovedOnBackgroundEvent != null && hasToApplyImprovedOnBackgroundSolution(solutionImprovedOnBackgroundEvent, currentLastBestSolution)) {
// a better solution was produced during the improveSolutionOnBackgroundDuration period
LOGGER.debug("processDataEvents - apply the improved on background solution: {}", currentLastBestSolution);
executeSolutionChange(currentLastBestSolution);
} else {
executePlanOrResumeEvents(currentSolution.get());
}
}
}
} catch (Exception e) {
failFast(e);
}
}
use of org.kie.kogito.taskassigning.service.event.UserDataEvent in project kogito-apps by kiegroup.
the class UserServiceAdapter method onQuerySuccessful.
private void onQuerySuccessful(List<User> users) {
if (!destroyed.get()) {
taskAssigningServiceEventConsumer.accept(new UserDataEvent(users, ZonedDateTime.now()));
programNextExecution(config.getUserServiceSyncInterval());
}
}
use of org.kie.kogito.taskassigning.service.event.UserDataEvent in project kogito-apps by kiegroup.
the class SolutionChangesBuilderTest method addUpdateUserChange.
private void addUpdateUserChange(User user, org.kie.kogito.taskassigning.user.service.User updatedExternalUser) {
TaskAssigningSolution solution = mockSolution(Collections.singletonList(user), Collections.emptyList());
UserDataEvent event = new UserDataEvent(Collections.singletonList(updatedExternalUser), ZonedDateTime.now());
List<ProblemFactChange<TaskAssigningSolution>> result = SolutionChangesBuilder.create().withContext(context).withUserServiceConnector(userServiceConnector).withProcessors(processorRegistry).fromTasksData(Collections.emptyList()).fromUserDataEvent(event).forSolution(solution).build();
Set<Group> expectedGroups = updatedExternalUser.getGroups().stream().map(externalGroup -> new Group(externalGroup.getId())).collect(Collectors.toSet());
UserPropertyChangeProblemFactChange expected = new UserPropertyChangeProblemFactChange(user, true, updatedExternalUser.getAttributes(), expectedGroups);
assertChangeIsTheChangeSetId(result, 0);
assertChange(result, 1, expected);
assertThatUserProcessorsWereApplied(updatedExternalUser);
}
Aggregations