Search in sources :

Example 1 with UserPropertyChangeProblemFactChange

use of org.kie.server.services.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange in project droolsjbpm-integration by kiegroup.

the class SolutionChangesBuilderTest method assertOneChange.

private void assertOneChange(List<ProblemFactChange<TaskAssigningSolution>> result, int index, UserPropertyChangeProblemFactChange expected) {
    UserPropertyChangeProblemFactChange change = (UserPropertyChangeProblemFactChange) result.get(index);
    assertUserEquals(expected.getUser(), change.getUser());
    assertEquals(1, result.stream().filter(calculated -> calculated instanceof UserPropertyChangeProblemFactChange).count());
}
Also used : UserPropertyChangeProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange)

Example 2 with UserPropertyChangeProblemFactChange

use of org.kie.server.services.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange in project droolsjbpm-integration by kiegroup.

the class SolutionChangesBuilder method addUserChanges.

private void addUserChanges(final Map<String, User> usersById, final List<AddUserProblemFactChange> newUserChanges, final List<ProblemFactChange<TaskAssigningSolution>> updateUserChanges) {
    final Set<String> updatedUserIds = new HashSet<>();
    filterDuplicates(externalUserList).filter(externalUser -> !IS_PLANNING_USER.test(externalUser.getId())).map(UserUtil::fromExternalUser).forEach(user -> {
        final User previousUser = usersById.get(user.getEntityId());
        updatedUserIds.add(user.getEntityId());
        if (previousUser == null) {
            newUserChanges.add(new AddUserProblemFactChange(user));
        } else if (!equalsByProperties(previousUser, user)) {
            updateUserChanges.add(new UserPropertyChangeProblemFactChange(previousUser, true, user.getAttributes(), user.getAllLabelValues(), user.getGroups()));
        }
    });
    usersById.values().stream().filter(user -> !IS_PLANNING_USER.test(user.getEntityId())).filter(user -> !updatedUserIds.contains(user.getEntityId())).filter(User::isEnabled).forEach(user -> updateUserChanges.add(new DisableUserProblemFactChange(user)));
}
Also used : IndexedElement.addInOrder(org.kie.server.services.taskassigning.planning.util.IndexedElement.addInOrder) StatusConverter.convertToString(org.kie.server.api.model.taskassigning.util.StatusConverter.convertToString) AddUserProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.AddUserProblemFactChange) DUMMY_TASK_PLANNER_241(org.kie.server.services.taskassigning.core.model.ModelConstants.DUMMY_TASK_PLANNER_241) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) PLANNING_USER(org.kie.server.services.taskassigning.core.model.ModelConstants.PLANNING_USER) Function(java.util.function.Function) ArrayList(java.util.ArrayList) TaskData(org.kie.server.api.model.taskassigning.TaskData) HashSet(java.util.HashSet) User(org.kie.server.services.taskassigning.core.model.User) Map(java.util.Map) UserUtil.filterDuplicates(org.kie.server.services.taskassigning.planning.util.UserUtil.filterDuplicates) TaskPropertyChangeProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.TaskPropertyChangeProblemFactChange) RemoveTaskProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange) DisableUserProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange) Task(org.kie.server.services.taskassigning.core.model.Task) TaskHelper.hasPinnedTasks(org.kie.server.services.taskassigning.core.model.solver.TaskHelper.hasPinnedTasks) TaskUtil.fromTaskData(org.kie.server.services.taskassigning.planning.util.TaskUtil.fromTaskData) Logger(org.slf4j.Logger) IS_PLANNING_USER(org.kie.server.services.taskassigning.core.model.ModelConstants.IS_PLANNING_USER) UserSystemService(org.kie.server.services.taskassigning.user.system.api.UserSystemService) Set(java.util.Set) ReleaseTaskProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange) ProblemFactChange(org.optaplanner.core.impl.solver.ProblemFactChange) StatusConverter.convertFromString(org.kie.server.api.model.taskassigning.util.StatusConverter.convertFromString) Collectors(java.util.stream.Collectors) UserPropertyChangeProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange) Objects(java.util.Objects) RemoveUserProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.RemoveUserProblemFactChange) TraceHelper.traceProgrammedChanges(org.kie.server.services.taskassigning.planning.TraceHelper.traceProgrammedChanges) List(java.util.List) AssignTaskProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange) AddTaskProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange) TaskAssigningSolution(org.kie.server.services.taskassigning.core.model.TaskAssigningSolution) IS_NOT_DUMMY(org.kie.server.services.taskassigning.core.model.ModelConstants.IS_NOT_DUMMY) UserUtil.fromExternalUser(org.kie.server.services.taskassigning.planning.util.UserUtil.fromExternalUser) IndexedElement(org.kie.server.services.taskassigning.planning.util.IndexedElement) UserUtil(org.kie.server.services.taskassigning.planning.util.UserUtil) Status(org.kie.api.task.model.Status) User(org.kie.server.services.taskassigning.core.model.User) UserUtil.fromExternalUser(org.kie.server.services.taskassigning.planning.util.UserUtil.fromExternalUser) DisableUserProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange) AddUserProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.AddUserProblemFactChange) StatusConverter.convertToString(org.kie.server.api.model.taskassigning.util.StatusConverter.convertToString) StatusConverter.convertFromString(org.kie.server.api.model.taskassigning.util.StatusConverter.convertFromString) HashSet(java.util.HashSet) UserPropertyChangeProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange)

Example 3 with UserPropertyChangeProblemFactChange

use of org.kie.server.services.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange in project droolsjbpm-integration by kiegroup.

the class SolutionChangesBuilderTest method addUserPropertyChange.

private void addUserPropertyChange(User currentUser, org.kie.server.services.taskassigning.user.system.api.User externalUser, boolean shouldHaveChanged) {
    List<User> userList = mockUserList(currentUser, mockUser("anotherUser"), mockUser("anotherUser1"));
    org.kie.server.services.taskassigning.user.system.api.User externalUserRepeated1 = mockExternalUser(externalUser.getId());
    org.kie.server.services.taskassigning.user.system.api.User newExternalUserRepeated2 = mockExternalUser(externalUser.getId());
    List<org.kie.server.services.taskassigning.user.system.api.User> externalUserList = mockExternalUserList(externalUser, externalUserRepeated1, newExternalUserRepeated2);
    TaskAssigningSolution solution = mockSolution(Collections.emptyList(), userList);
    List<ProblemFactChange<TaskAssigningSolution>> result = SolutionChangesBuilder.create().withSolution(solution).withTasks(Collections.emptyList()).withUserSystem(userSystemService).withUsersUpdate(externalUserList).withContext(context).build();
    User fromExternalUser = fromExternalUser(externalUser);
    UserPropertyChangeProblemFactChange expected = new UserPropertyChangeProblemFactChange(currentUser, fromExternalUser.isEnabled(), fromExternalUser.getAttributes(), fromExternalUser.getAllLabelValues(), fromExternalUser.getGroups());
    if (shouldHaveChanged) {
        assertChangeIsTheChangeSetId(result, 0);
        assertOneChange(result, 1, expected);
        UserPropertyChangeProblemFactChange createdChange = (UserPropertyChangeProblemFactChange) result.get(1);
        assertEquals(expected.getUser().getEntityId(), createdChange.getUser().getEntityId());
        assertEquals(expected.isEnabled(), createdChange.isEnabled());
        assertEquals(expected.getAttributes(), createdChange.getAttributes());
        assertEquals(expected.getGroups(), createdChange.getGroups());
        assertEquals(expected.getLabelValues(), createdChange.getLabelValues());
    } else {
        assertNoChange(result, UserPropertyChangeProblemFactChange.class);
    }
}
Also used : UserUtil.fromExternalUser(org.kie.server.services.taskassigning.planning.util.UserUtil.fromExternalUser) User(org.kie.server.services.taskassigning.core.model.User) TaskAssigningSolution(org.kie.server.services.taskassigning.core.model.TaskAssigningSolution) TaskPropertyChangeProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.TaskPropertyChangeProblemFactChange) DisableUserProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange) ReleaseTaskProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange) UserPropertyChangeProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange) AssignTaskProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange) AddTaskProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange) AddUserProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.AddUserProblemFactChange) RemoveTaskProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange) ProblemFactChange(org.optaplanner.core.impl.solver.ProblemFactChange) RemoveUserProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.RemoveUserProblemFactChange) UserPropertyChangeProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange)

Aggregations

UserPropertyChangeProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange)3 TaskAssigningSolution (org.kie.server.services.taskassigning.core.model.TaskAssigningSolution)2 User (org.kie.server.services.taskassigning.core.model.User)2 AddTaskProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange)2 AddUserProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.AddUserProblemFactChange)2 AssignTaskProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange)2 DisableUserProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange)2 ReleaseTaskProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange)2 RemoveTaskProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange)2 RemoveUserProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.RemoveUserProblemFactChange)2 TaskPropertyChangeProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.TaskPropertyChangeProblemFactChange)2 UserUtil.fromExternalUser (org.kie.server.services.taskassigning.planning.util.UserUtil.fromExternalUser)2 ProblemFactChange (org.optaplanner.core.impl.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