Search in sources :

Example 1 with DisableUserProblemFactChange

use of org.kie.kogito.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange 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();
}
Also used : User(org.kie.kogito.taskassigning.core.model.User) DisableUserProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange) TaskAssigningSolution(org.kie.kogito.taskassigning.core.model.TaskAssigningSolution) UserDataEvent(org.kie.kogito.taskassigning.service.event.UserDataEvent) RemoveUserProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveUserProblemFactChange) ProblemFactChange(org.optaplanner.core.api.solver.ProblemFactChange) AssignTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange) DisableUserProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange) UserPropertyChangeProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange) AddUserProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AddUserProblemFactChange) RemoveTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange) AddTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange) ReleaseTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange) Test(org.junit.jupiter.api.Test)

Example 2 with DisableUserProblemFactChange

use of org.kie.kogito.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange in project kogito-apps by kiegroup.

the class SolutionChangesBuilder method addFullSyncUserChanges.

private void addFullSyncUserChanges(List<org.kie.kogito.taskassigning.user.service.User> externalUserList) {
    final Set<String> updatedUserIds = new HashSet<>();
    externalUserList.stream().filter(externalUser -> !IS_PLANNING_USER.test(externalUser.getId())).map(externalUser -> fromExternalUser(externalUser, processorRegistry)).forEach(synchedUser -> {
        final User previousUser = usersById.get(synchedUser.getId());
        updatedUserIds.add(synchedUser.getId());
        if (previousUser == null) {
            // add brand new users
            newUserChanges.add(new AddUserProblemFactChange(synchedUser));
        } else if (!equalsByProperties(previousUser, synchedUser)) {
            // update the users that has changes.
            updateUserChanges.add(new UserPropertyChangeProblemFactChange(previousUser, true, synchedUser.getAttributes(), synchedUser.getGroups()));
        }
    });
    // current users not present in the synchronization data set are marked for disabling.
    usersById.values().stream().filter(previousUser -> !IS_PLANNING_USER.test(previousUser.getId())).filter(previousUser -> !updatedUserIds.contains(previousUser.getId())).filter(User::isEnabled).forEach(previousUser -> updateUserChanges.add(new DisableUserProblemFactChange(previousUser)));
}
Also used : IndexedElement.addInOrder(org.kie.kogito.taskassigning.service.util.IndexedElement.addInOrder) RemoveUserProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveUserProblemFactChange) TaskUtil.fromTaskData(org.kie.kogito.taskassigning.service.util.TaskUtil.fromTaskData) READY(org.kie.kogito.taskassigning.service.TaskState.READY) TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ProblemFactChange(org.optaplanner.core.api.solver.ProblemFactChange) Function(java.util.function.Function) RESERVED(org.kie.kogito.taskassigning.service.TaskState.RESERVED) AssignTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange) ArrayList(java.util.ArrayList) DisableUserProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange) HashSet(java.util.HashSet) Task(org.kie.kogito.taskassigning.core.model.Task) UserDataEvent(org.kie.kogito.taskassigning.service.event.UserDataEvent) UserPropertyChangeProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange) TaskHelper.filterNonDummyAssignments(org.kie.kogito.taskassigning.core.model.solver.TaskHelper.filterNonDummyAssignments) IS_PLANNING_USER(org.kie.kogito.taskassigning.core.model.ModelConstants.IS_PLANNING_USER) Map(java.util.Map) AttributesProcessorRegistry(org.kie.kogito.taskassigning.service.processing.AttributesProcessorRegistry) AddUserProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AddUserProblemFactChange) TraceUtil(org.kie.kogito.taskassigning.service.util.TraceUtil) Logger(org.slf4j.Logger) Set(java.util.Set) UserUtil.fromExternalUser(org.kie.kogito.taskassigning.service.util.UserUtil.fromExternalUser) TaskAssigningSolution(org.kie.kogito.taskassigning.core.model.TaskAssigningSolution) IndexedElement(org.kie.kogito.taskassigning.service.util.IndexedElement) Collectors(java.util.stream.Collectors) User(org.kie.kogito.taskassigning.core.model.User) Objects(java.util.Objects) List(java.util.List) RemoveTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange) AddTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange) TaskInfoChangeProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.TaskInfoChangeProblemFactChange) ReleaseTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange) TaskHelper.hasPinnedTasks(org.kie.kogito.taskassigning.core.model.solver.TaskHelper.hasPinnedTasks) UserUtil.fromExternalUser(org.kie.kogito.taskassigning.service.util.UserUtil.fromExternalUser) User(org.kie.kogito.taskassigning.core.model.User) DisableUserProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange) AddUserProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AddUserProblemFactChange) HashSet(java.util.HashSet) UserPropertyChangeProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange)

Example 3 with DisableUserProblemFactChange

use of org.kie.kogito.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange in project kogito-apps by kiegroup.

the class SolutionChangesBuilderTest method assertChange.

private static void assertChange(List<ProblemFactChange<TaskAssigningSolution>> result, int index, DisableUserProblemFactChange expected) {
    assertThat(result.get(index)).isInstanceOf(DisableUserProblemFactChange.class);
    DisableUserProblemFactChange change = (DisableUserProblemFactChange) result.get(index);
    assertUserEquals(change.getUser(), expected.getUser());
}
Also used : DisableUserProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange)

Aggregations

DisableUserProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange)3 TaskAssigningSolution (org.kie.kogito.taskassigning.core.model.TaskAssigningSolution)2 User (org.kie.kogito.taskassigning.core.model.User)2 AddTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange)2 AddUserProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.AddUserProblemFactChange)2 AssignTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange)2 ReleaseTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange)2 RemoveTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange)2 RemoveUserProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveUserProblemFactChange)2 UserPropertyChangeProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange)2 UserDataEvent (org.kie.kogito.taskassigning.service.event.UserDataEvent)2 ProblemFactChange (org.optaplanner.core.api.solver.ProblemFactChange)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Function (java.util.function.Function)1