Search in sources :

Example 1 with UserPropertyChangeProblemFactChange

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

the class SolutionChangesBuilderTest method assertChange.

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

Example 2 with UserPropertyChangeProblemFactChange

use of org.kie.kogito.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange 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 UserPropertyChangeProblemFactChange

use of org.kie.kogito.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange 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);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) RemoveUserProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveUserProblemFactChange) Mock(org.mockito.Mock) TaskUtil.fromTaskData(org.kie.kogito.taskassigning.service.util.TaskUtil.fromTaskData) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ZonedDateTime(java.time.ZonedDateTime) READY(org.kie.kogito.taskassigning.service.TaskState.READY) TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment) HashMap(java.util.HashMap) Group(org.kie.kogito.taskassigning.core.model.Group) ProblemFactChange(org.optaplanner.core.api.solver.ProblemFactChange) Captor(org.mockito.Captor) RESERVED(org.kie.kogito.taskassigning.service.TaskState.RESERVED) AssignTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange) DisableUserProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange) Task(org.kie.kogito.taskassigning.core.model.Task) UserDataEvent(org.kie.kogito.taskassigning.service.event.UserDataEvent) TestUtil.mockTaskData(org.kie.kogito.taskassigning.service.TestUtil.mockTaskData) UserPropertyChangeProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) AssertionsForInterfaceTypes.assertThat(org.assertj.core.api.AssertionsForInterfaceTypes.assertThat) AttributesProcessorRegistry(org.kie.kogito.taskassigning.service.processing.AttributesProcessorRegistry) AddUserProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AddUserProblemFactChange) Mockito.doReturn(org.mockito.Mockito.doReturn) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Set(java.util.Set) ScoreDirector(org.optaplanner.core.api.score.director.ScoreDirector) TaskAssigningSolution(org.kie.kogito.taskassigning.core.model.TaskAssigningSolution) Collectors(java.util.stream.Collectors) User(org.kie.kogito.taskassigning.core.model.User) TestUtil.parseZonedDateTime(org.kie.kogito.taskassigning.service.TestUtil.parseZonedDateTime) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) List(java.util.List) Mockito.never(org.mockito.Mockito.never) 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) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) Group(org.kie.kogito.taskassigning.core.model.Group) 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) UserPropertyChangeProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange)

Aggregations

UserPropertyChangeProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Task (org.kie.kogito.taskassigning.core.model.Task)2 TaskAssigningSolution (org.kie.kogito.taskassigning.core.model.TaskAssigningSolution)2 TaskAssignment (org.kie.kogito.taskassigning.core.model.TaskAssignment)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 DisableUserProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange)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 READY (org.kie.kogito.taskassigning.service.TaskState.READY)2 RESERVED (org.kie.kogito.taskassigning.service.TaskState.RESERVED)2 UserDataEvent (org.kie.kogito.taskassigning.service.event.UserDataEvent)2