Search in sources :

Example 1 with Group

use of org.kie.server.services.taskassigning.core.model.Group 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 Group

use of org.kie.server.services.taskassigning.core.model.Group 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 Group

use of org.kie.server.services.taskassigning.core.model.Group 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 4 with Group

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

the class TaskAssigningGenerator method createTaskAssigningSolution.

private TaskAssigningSolution createTaskAssigningSolution(String fileName, int taskListSize, int groupListSize, int userListSize) {
    TaskAssigningSolution solution = new TaskAssigningSolution();
    solution.setId(0L);
    List<Group> groupList = createGroupList(groupListSize);
    createUserList(solution, userListSize, groupList);
    createTaskList(solution, taskListSize, groupList);
    BigInteger totalFacts = AbstractSolutionImporter.factorial(taskListSize + userListSize - 1);
    BigInteger fixedFacts = AbstractSolutionImporter.factorial(userListSize - 1);
    BigInteger possibleSolutionSize = (totalFacts == null || fixedFacts == null) ? null : totalFacts.divide(fixedFacts);
    logger.info("TaskAssigningSolution {} has {} tasks, {} groups, and {} users with a search space of {}.", fileName, taskListSize, groupListSize, userListSize, AbstractSolutionImporter.getFlooredPossibleSolutionSize(possibleSolutionSize));
    return solution;
}
Also used : Group(org.kie.server.services.taskassigning.core.model.Group) TaskAssigningSolution(org.kie.server.services.taskassigning.core.model.TaskAssigningSolution) BigInteger(java.math.BigInteger)

Example 5 with Group

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

the class TaskUtil method fromTaskData.

public static Task fromTaskData(TaskData taskData) {
    final Task task = new Task(taskData.getTaskId(), taskData.getProcessInstanceId(), taskData.getProcessId(), taskData.getContainerId(), taskData.getName(), taskData.getPriority(), taskData.getStatus(), taskData.getInputData());
    if (taskData.getPotentialOwners() != null) {
        taskData.getPotentialOwners().forEach(potentialOwner -> {
            if (isUser(potentialOwner.getType())) {
                task.getPotentialOwners().add(new User(potentialOwner.getName().hashCode(), potentialOwner.getName()));
            } else {
                task.getPotentialOwners().add(new Group(potentialOwner.getName().hashCode(), potentialOwner.getName()));
            }
        });
    }
    LabelValueExtractorRegistry.getInstance().applyLabelValueExtractors(TaskData.class, taskData, task::setLabelValues);
    return task;
}
Also used : 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) UserUtil.isUser(org.kie.server.services.taskassigning.planning.util.UserUtil.isUser)

Aggregations

Group (org.kie.server.services.taskassigning.core.model.Group)10 User (org.kie.server.services.taskassigning.core.model.User)8 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 Set (java.util.Set)2 Task (org.kie.server.services.taskassigning.core.model.Task)2 TaskAssigningSolution (org.kie.server.services.taskassigning.core.model.TaskAssigningSolution)2 TaskOrUser (org.kie.server.services.taskassigning.core.model.TaskOrUser)2 BigInteger (java.math.BigInteger)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1 Before (org.junit.Before)1 OrganizationalEntity (org.kie.server.api.model.taskassigning.OrganizationalEntity)1 TaskData (org.kie.server.api.model.taskassigning.TaskData)1