Search in sources :

Example 1 with User

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

the class SolutionChangesBuilderTest method buildUsersForEqualityCase.

private Pair<User, org.kie.server.services.taskassigning.user.system.api.User> buildUsersForEqualityCase() {
    Map<String, Set<Object>> labelValues = new HashMap<>();
    labelValues.put(DefaultLabels.SKILLS.name(), Collections.singleton(SKILL1));
    labelValues.put(DefaultLabels.AFFINITIES.name(), Collections.emptySet());
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(SKILLS_ATTRIBUTE_NAME, SKILL1);
    attributes.put(ATTRIBUTE1_ID, ATTRIBUTE1_VALUE);
    User user1 = mockUser(USER1_ID, true, Collections.singleton(new Group(GROUP1_ID.hashCode(), GROUP1_ID)), attributes, labelValues);
    Map<String, Object> externalUserAttributes = new HashMap<>();
    externalUserAttributes.put(ATTRIBUTE1_ID, ATTRIBUTE1_VALUE);
    externalUserAttributes.put(SKILLS_ATTRIBUTE_NAME, SKILL1);
    Set<org.kie.server.services.taskassigning.user.system.api.Group> externalUserGroups = new HashSet<>();
    externalUserGroups.add(mockExternalGroup(GROUP1_ID));
    org.kie.server.services.taskassigning.user.system.api.User externalUser = mockExternalUser(USER1_ID, externalUserGroups, externalUserAttributes);
    return Pair.of(user1, externalUser);
}
Also used : Group(org.kie.server.services.taskassigning.core.model.Group) Set(java.util.Set) HashSet(java.util.HashSet) UserUtil.fromExternalUser(org.kie.server.services.taskassigning.planning.util.UserUtil.fromExternalUser) User(org.kie.server.services.taskassigning.core.model.User) HashMap(java.util.HashMap) StatusConverter.convertToString(org.kie.server.api.model.taskassigning.util.StatusConverter.convertToString) HashSet(java.util.HashSet)

Example 2 with User

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

the class TaskUtilTest method fromTaskData.

private void fromTaskData(Map<String, Object> inputData, Set<Object> expectedSkills, Set<Object> expectedAffinities) {
    Set<OrganizationalEntity> potentialOwners = new HashSet<>();
    potentialOwners.add(OE_1);
    potentialOwners.add(OE_2);
    TaskData taskData = TaskData.builder().taskId(TASK_ID).processInstanceId(PROCESS_INSTANCE_ID).processId(PROCESS_ID).containerId(CONTAINER_ID).name(NAME).priority(PRIORITY).status(STATUS).inputData(inputData).potentialOwners(potentialOwners).build();
    Task task = TaskUtil.fromTaskData(taskData);
    assertEquals(TASK_ID, task.getId(), 0);
    assertEquals(PROCESS_INSTANCE_ID, task.getProcessInstanceId(), 0);
    assertEquals(PROCESS_ID, task.getProcessId());
    assertEquals(CONTAINER_ID, task.getContainerId());
    assertEquals(NAME, task.getName());
    assertEquals(PRIORITY, task.getPriority(), 0);
    assertEquals(STATUS, task.getStatus());
    assertEquals(inputData, task.getInputData());
    assertEquals(potentialOwners.size(), task.getPotentialOwners().size(), 2);
    User user = task.getPotentialOwners().stream().filter(u -> OE_1.getName().equals(u.getEntityId()) && u.isUser()).map(u -> (User) u).findFirst().orElse(null);
    assertNotNull(user);
    Group group = task.getPotentialOwners().stream().filter(g -> OE_2.getName().equals(g.getEntityId()) && !g.isUser()).map(g -> (Group) g).findFirst().orElse(null);
    assertNotNull(group);
    assertEquals(expectedSkills, task.getLabelValues(SKILLS.name()));
    assertEquals(expectedAffinities, task.getLabelValues(AFFINITIES.name()));
}
Also used : Arrays(java.util.Arrays) Group(org.kie.server.services.taskassigning.core.model.Group) Assert.assertNotNull(org.junit.Assert.assertNotNull) Set(java.util.Set) HashMap(java.util.HashMap) Test(org.junit.Test) 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) AFFINITIES(org.kie.server.services.taskassigning.core.model.DefaultLabels.AFFINITIES) Collections(java.util.Collections) UserType(org.kie.server.api.model.taskassigning.UserType) OrganizationalEntity(org.kie.server.api.model.taskassigning.OrganizationalEntity) Assert.assertEquals(org.junit.Assert.assertEquals) SKILLS(org.kie.server.services.taskassigning.core.model.DefaultLabels.SKILLS) Task(org.kie.server.services.taskassigning.core.model.Task) Group(org.kie.server.services.taskassigning.core.model.Group) Task(org.kie.server.services.taskassigning.core.model.Task) User(org.kie.server.services.taskassigning.core.model.User) OrganizationalEntity(org.kie.server.api.model.taskassigning.OrganizationalEntity) HashSet(java.util.HashSet) TaskData(org.kie.server.api.model.taskassigning.TaskData)

Example 3 with User

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

the class RemoveUserProblemFactChangeTest method doChange.

@Test
public void doChange() {
    List<Task> workingUserTasks = Arrays.asList(mockTask(TASK_ID1, true), mockTask(TASK_ID2, true), mockTask(TASK_ID3, false), mockTask(TASK_ID4, false));
    User workingUser = mockUser(USER_ID_1, workingUserTasks);
    workingUser.setEnabled(true);
    workingSolution.getUserList().add(workingUser);
    int originalUsersSize = workingSolution.getUserList().size();
    when(scoreDirector.lookUpWorkingObjectOrReturnNull(user)).thenReturn(workingUser);
    change.doChange(scoreDirector);
    verify(scoreDirector).beforeProblemPropertyChanged(workingUser);
    verify(scoreDirector).afterProblemPropertyChanged(workingUser);
    verify(scoreDirector).triggerVariableListeners();
    assertThat(workingUser.isEnabled()).isFalse();
    workingUserTasks.forEach(task -> assertTaskWasReleased(task, scoreDirector));
    verify(scoreDirector).beforeProblemFactRemoved(workingUser);
    verify(scoreDirector).afterProblemFactRemoved(workingUser);
    assertThat(workingSolution.getUserList().size()).isEqualTo(originalUsersSize - 1);
    assertThat(workingSolution.getUserList()).contains(user2, user3);
    assertThat(workingSolution.getUserList()).doesNotContain(workingUser);
}
Also used : TestUtil.mockTask(org.kie.server.services.taskassigning.core.model.TestUtil.mockTask) Task(org.kie.server.services.taskassigning.core.model.Task) User(org.kie.server.services.taskassigning.core.model.User) TestUtil.mockUser(org.kie.server.services.taskassigning.core.model.TestUtil.mockUser) Test(org.junit.Test)

Example 4 with User

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

the class TaskAssigningGenerator method createUserList.

private void createUserList(TaskAssigningSolution solution, int userListSize, List<Group> groupList) {
    List<User> userList = new ArrayList<>(userListSize);
    userNameGenerator.predictMaximumSizeAndReset(userListSize);
    for (int i = 0; i < userListSize; i++) {
        User user = new User();
        user.setId((long) i);
        String userName = userNameGenerator.generateNextValue();
        user.setEntityId(userName);
        int groupListSize = USER_GROUP_SET_SIZE_MINIMUM + random.nextInt(USER_GROUP_SET_MAXIMUM - USER_GROUP_SET_SIZE_MINIMUM);
        if (groupListSize > groupList.size()) {
            groupListSize = groupList.size();
        }
        Set<Group> groupSet = new LinkedHashSet<>(groupListSize);
        int groupListIndex = random.nextInt(groupList.size());
        for (int j = 0; j < groupListSize; j++) {
            groupSet.add(groupList.get(groupListIndex));
            groupListIndex = (groupListIndex + 1) % groupList.size();
        }
        user.setGroups(groupSet);
        logger.trace("Created user with entityId ({}).", userName);
        userList.add(user);
    }
    solution.setUserList(userList);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Group(org.kie.server.services.taskassigning.core.model.Group) User(org.kie.server.services.taskassigning.core.model.User) ArrayList(java.util.ArrayList)

Example 5 with User

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

the class TaskAssigningGenerator method createTaskList.

private void createTaskList(TaskAssigningSolution solution, int taskListSize, List<Group> groupList) {
    List<User> userList = solution.getUserList();
    List<Task> taskList = new ArrayList<>(taskListSize);
    for (int i = 0; i < taskListSize; i++) {
        Task task = new Task();
        task.setId((long) i);
        task.setName("Task_" + task.getId());
        task.setPriority(random.nextInt(TASK_MAX_PRIORITY + 1));
        Set<OrganizationalEntity> potentialOwners = new LinkedHashSet<>();
        int groupListIndex = random.nextInt(groupList.size());
        int groupPotentialOwnersSize = TASK_POTENTIAL_OWNERS_GROUP_SIZE_MINIMUM + random.nextInt(TASK_POTENTIAL_OWNERS_GROUP_SIZE_MAXIMUM - TASK_POTENTIAL_OWNERS_GROUP_SIZE_MINIMUM);
        if (groupPotentialOwnersSize > groupList.size()) {
            groupPotentialOwnersSize = groupList.size();
        }
        for (int j = 0; j < groupPotentialOwnersSize; j++) {
            potentialOwners.add(groupList.get(groupListIndex));
            groupListIndex = (groupListIndex + 1) % groupList.size();
        }
        int userListIndex = random.nextInt(userList.size());
        int userPotentialOwnersSize = TASK_POTENTIAL_OWNERS_USER_SIZE_MINIMUM + random.nextInt(TASK_POTENTIAL_OWNERS_USER_SIZE_MAXIMUM - TASK_POTENTIAL_OWNERS_USER_SIZE_MINIMUM);
        if (userPotentialOwnersSize > userList.size()) {
            userPotentialOwnersSize = userList.size();
        }
        for (int j = 0; j < userPotentialOwnersSize; j++) {
            potentialOwners.add(userList.get(userListIndex));
            userListIndex = (userListIndex + 1) % userList.size();
        }
        task.setPotentialOwners(potentialOwners);
        taskList.add(task);
    }
    solution.setTaskList(taskList);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Task(org.kie.server.services.taskassigning.core.model.Task) User(org.kie.server.services.taskassigning.core.model.User) OrganizationalEntity(org.kie.server.services.taskassigning.core.model.OrganizationalEntity) ArrayList(java.util.ArrayList)

Aggregations

User (org.kie.server.services.taskassigning.core.model.User)56 Task (org.kie.server.services.taskassigning.core.model.Task)33 TaskAssigningSolution (org.kie.server.services.taskassigning.core.model.TaskAssigningSolution)25 Test (org.junit.Test)22 UserUtil.fromExternalUser (org.kie.server.services.taskassigning.planning.util.UserUtil.fromExternalUser)17 TaskOrUser (org.kie.server.services.taskassigning.core.model.TaskOrUser)16 ArrayList (java.util.ArrayList)14 AssignTaskProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange)14 AddTaskProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange)13 ReleaseTaskProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange)13 TaskPropertyChangeProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.TaskPropertyChangeProblemFactChange)13 AddUserProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.AddUserProblemFactChange)12 DisableUserProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange)12 RemoveTaskProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange)12 RemoveUserProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.RemoveUserProblemFactChange)12 UserPropertyChangeProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange)12 ProblemFactChange (org.optaplanner.core.impl.solver.ProblemFactChange)12 PlanningTask (org.kie.server.api.model.taskassigning.PlanningTask)9 TaskData (org.kie.server.api.model.taskassigning.TaskData)8 Group (org.kie.server.services.taskassigning.core.model.Group)8