Search in sources :

Example 1 with User

use of org.kie.server.services.taskassigning.user.system.api.User in project droolsjbpm-integration by kiegroup.

the class SolutionSynchronizerTest method initSolverExecutor.

@Test(timeout = TEST_TIMEOUT)
@SuppressWarnings("unchecked")
public void initSolverExecutor() throws Exception {
    CompletableFuture future = startRunnableBase();
    LocalDateTime firstQueryTime = LocalDateTime.now();
    List<User> userList = mockUserList();
    List<TaskAssigningRuntimeDelegate.FindTasksResult> results = mockTasksQueryExecutions(firstQueryTime);
    LocalDateTime firstSuccessfulQueryTime = results.get(results.size() - 1).getQueryTime();
    queryExecutionsCountDown = new CountDownLatch(results.size());
    prepareQueryExecutionsWithOutEmptyStatus(results);
    when(emptySolution.getTaskList()).thenReturn(Collections.emptyList());
    when(generatedSolution.getTaskList()).thenReturn(Collections.singletonList(new Task()));
    when(solverExecutor.isStopped()).thenReturn(true);
    when(userSystemService.findAllUsers()).thenReturn(userList);
    runnableBase.initSolverExecutor();
    // wait for the query executions to happen
    queryExecutionsCountDown.await();
    verify(delegate, times(results.size())).findTasks(anyList(), eq(null), anyObject());
    verify(solverExecutor).start(solutionCaptor.capture());
    assertEquals(generatedSolution, solutionCaptor.getValue());
    LocalDateTime nextQueryTime = context.shiftQueryTime(firstSuccessfulQueryTime.withNano(0));
    LocalDateTime previousQueryTime = context.shiftQueryTime(nextQueryTime);
    assertEquals(previousQueryTime, context.getPreviousQueryTime());
    assertEquals(nextQueryTime, context.getNextQueryTime());
    runnableBase.destroy();
    future.get();
    assertTrue(runnableBase.isDestroyed());
}
Also used : LocalDateTime(java.time.LocalDateTime) CompletableFuture(java.util.concurrent.CompletableFuture) Task(org.kie.server.services.taskassigning.core.model.Task) User(org.kie.server.services.taskassigning.user.system.api.User) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 2 with User

use of org.kie.server.services.taskassigning.user.system.api.User in project droolsjbpm-integration by kiegroup.

the class SimpleUserSystemServiceHelper method buildInfo.

/**
 * Reads the users definitions for a file in the Wildfly roles.properties definition file format. See class comments.
 * Additionally loads the users skills and affinities if present.
 * @param usersIn InputStream with the user + roles file in the WF format.
 * @param skillsIn InputStream with the users skills.
 * @param affinitiesIn InputStream with the users affinities.
 * @return a UserGroupInfo instance with the Users and Groups loaded.
 * @throws IOException if an I/O error occurs
 */
public static UserGroupInfo buildInfo(InputStream usersIn, InputStream skillsIn, InputStream affinitiesIn) throws IOException {
    final Map<String, User> usersMap = new HashMap<>();
    final Map<String, Group> groupMap = new HashMap<>();
    final List<ElementLine> lines = readLines(usersIn);
    final List<ElementLine> skillLines = skillsIn != null ? readLines(skillsIn) : Collections.emptyList();
    final List<ElementLine> affinityLines = affinitiesIn != null ? readLines(affinitiesIn) : Collections.emptyList();
    for (ElementLine line : lines) {
        Set<Group> userGroups = new HashSet<>();
        User user = new UserImpl(line.getElementId(), userGroups, new HashMap<>());
        line.values.forEach(groupName -> {
            Group group = groupMap.computeIfAbsent(groupName, GroupImpl::new);
            userGroups.add(group);
        });
        usersMap.put(user.getId(), user);
    }
    populateAttribute(usersMap, SKILLS_ATTRIBUTE_NAME, skillLines);
    populateAttribute(usersMap, AFFINITIES_ATTRIBUTE_NAME, affinityLines);
    return new UserGroupInfo(new ArrayList<>(usersMap.values()), new ArrayList<>(groupMap.values()));
}
Also used : Group(org.kie.server.services.taskassigning.user.system.api.Group) User(org.kie.server.services.taskassigning.user.system.api.User) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 3 with User

use of org.kie.server.services.taskassigning.user.system.api.User in project droolsjbpm-integration by kiegroup.

the class AbstractStringListValueAttributeMapValueExtractorTest method mockUser.

protected static User mockUser(String attributeName, String value) {
    User user = mock(User.class);
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(attributeName, value);
    when(user.getAttributes()).thenReturn(attributes);
    return user;
}
Also used : User(org.kie.server.services.taskassigning.user.system.api.User) HashMap(java.util.HashMap)

Example 4 with User

use of org.kie.server.services.taskassigning.user.system.api.User in project droolsjbpm-integration by kiegroup.

the class SolutionSynchronizer method recoverSolution.

private TaskAssigningSolution recoverSolution() {
    final TaskAssigningRuntimeDelegate.FindTasksResult result = delegate.findTasks(Arrays.asList(Ready, Reserved, InProgress, Suspended), null, TaskInputVariablesReadMode.READ_FOR_ALL);
    final LocalDateTime nextQueryTime = context.shiftQueryTime(trimMillis(result.getQueryTime()));
    final LocalDateTime adjustedFirstQueryTime = context.shiftQueryTime(nextQueryTime);
    context.setPreviousQueryTime(adjustedFirstQueryTime);
    context.setNextQueryTime(nextQueryTime);
    context.clearTaskChangeTimes();
    final List<TaskData> taskDataList = result.getTasks();
    LOGGER.debug("{} tasks where loaded for solution recovery, with result.queryTime: {}", taskDataList.size(), result.getQueryTime());
    final List<User> externalUsers = userSystemService.findAllUsers();
    return buildSolution(taskDataList, externalUsers);
}
Also used : LocalDateTime(java.time.LocalDateTime) User(org.kie.server.services.taskassigning.user.system.api.User) TaskData(org.kie.server.api.model.taskassigning.TaskData)

Example 5 with User

use of org.kie.server.services.taskassigning.user.system.api.User in project droolsjbpm-integration by kiegroup.

the class SolutionSynchronizerTest method mockUsersQueryExecutions.

/**
 * Mock the results of the findAllUsers method execution and emulate errors in the middle by producing null.
 * Last execution produces values.
 * execution 0, null
 * execution 1, no results
 * execution 2, results are produced.
 */
private List<List<User>> mockUsersQueryExecutions() {
    User user = mock(User.class);
    List<User> result0Failure = null;
    List<User> result1 = Collections.emptyList();
    List<User> result2 = Collections.singletonList(user);
    return Arrays.asList(result0Failure, result1, result2);
}
Also used : User(org.kie.server.services.taskassigning.user.system.api.User)

Aggregations

User (org.kie.server.services.taskassigning.user.system.api.User)7 HashMap (java.util.HashMap)3 LocalDateTime (java.time.LocalDateTime)2 HashSet (java.util.HashSet)2 Test (org.junit.Test)2 Group (org.kie.server.services.taskassigning.user.system.api.Group)2 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 TaskData (org.kie.server.api.model.taskassigning.TaskData)1 Task (org.kie.server.services.taskassigning.core.model.Task)1