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());
}
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()));
}
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;
}
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);
}
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);
}
Aggregations