@Test public void buildAndCheckSuspendedTaskWithUnChangedPlanningTaskPublishedWasProcessedCorrect() { PlanningTask planningTask = PlanningTask.builder() .taskId(1L) .assignedUser(USER1) .published(true) .index(1) .build(); TaskData taskData = mockTaskData(1L, Suspended, planningTask.getAssignedUser()); buildAndCheckTaskWithPlanningTaskWasProcessedCorrect(taskData, planningTask, planningTask.getAssignedUser(), true); }
public TaskAssigningSolution build() { final List<Task> tasks = new ArrayList<>(); final Map<String, List<IndexedElement<Task>>> assignedTasksByUserId = new HashMap<>(); final Map<String, User> usersById = filterDuplicates(externalUsers) .filter(externalUser -> !IS_PLANNING_USER.test(externalUser.getId())) .map(UserUtil::fromExternalUser) .collect(Collectors.toMap(User::getEntityId, Function.identity())); usersById.put(PLANNING_USER.getEntityId(), PLANNING_USER); taskDataList.forEach(taskData -> { context.setTaskChangeTime(taskData.getTaskId(), taskData.getLastModificationDate()); final Task task = fromTaskData(taskData); final Status status = convertFromString(task.getStatus()); switch (status) { case Ready: tasks.add(task); break; case Reserved: case InProgress: case Suspended: if (isNoneEmpty(taskData.getActualOwner())) { tasks.add(task); final PlanningTask planningTask = taskData.getPlanningTask(); if (planningTask != null && taskData.getActualOwner().equals(planningTask.getAssignedUser())) { boolean pinned = InProgress == status || Suspended == status || planningTask.getPublished() || !usersById.containsKey(taskData.getActualOwner()); addTaskToUser(assignedTasksByUserId, task, planningTask.getAssignedUser(), planningTask.getIndex(), pinned); } else { boolean pinned = (Reserved == status && !IS_PLANNING_USER.test(taskData.getActualOwner())) || InProgress == status || Suspended == status; addTaskToUser(assignedTasksByUserId, task, taskData.getActualOwner(), -1, pinned); } } break; default: throw new IndexOutOfBoundsException("Value: " + taskData.getStatus() + " is out of range in current switch"); } }); assignedTasksByUserId.forEach((key, assignedTasks) -> { User user = usersById.get(key); if (user == null) { user = new User(key.hashCode(), key); usersById.put(key, user); } final List<Task> userTasks = assignedTasks.stream().map(IndexedElement::getElement).collect(Collectors.toList()); addTasksToUser(user, userTasks); }); tasks.add(DUMMY_TASK); final List<User> users = new ArrayList<>(usersById.values()); return new TaskAssigningSolution(-1, users, tasks); }
SolutionBuilder { public TaskAssigningSolution build() { final List<Task> tasks = new ArrayList<>(); final Map<String, List<IndexedElement<Task>>> assignedTasksByUserId = new HashMap<>(); final Map<String, User> usersById = filterDuplicates(externalUsers) .filter(externalUser -> !IS_PLANNING_USER.test(externalUser.getId())) .map(UserUtil::fromExternalUser) .collect(Collectors.toMap(User::getEntityId, Function.identity())); usersById.put(PLANNING_USER.getEntityId(), PLANNING_USER); taskDataList.forEach(taskData -> { context.setTaskChangeTime(taskData.getTaskId(), taskData.getLastModificationDate()); final Task task = fromTaskData(taskData); final Status status = convertFromString(task.getStatus()); switch (status) { case Ready: tasks.add(task); break; case Reserved: case InProgress: case Suspended: if (isNoneEmpty(taskData.getActualOwner())) { tasks.add(task); final PlanningTask planningTask = taskData.getPlanningTask(); if (planningTask != null && taskData.getActualOwner().equals(planningTask.getAssignedUser())) { boolean pinned = InProgress == status || Suspended == status || planningTask.getPublished() || !usersById.containsKey(taskData.getActualOwner()); addTaskToUser(assignedTasksByUserId, task, planningTask.getAssignedUser(), planningTask.getIndex(), pinned); } else { boolean pinned = (Reserved == status && !IS_PLANNING_USER.test(taskData.getActualOwner())) || InProgress == status || Suspended == status; addTaskToUser(assignedTasksByUserId, task, taskData.getActualOwner(), -1, pinned); } } break; default: throw new IndexOutOfBoundsException("Value: " + taskData.getStatus() + " is out of range in current switch"); } }); assignedTasksByUserId.forEach((key, assignedTasks) -> { User user = usersById.get(key); if (user == null) { user = new User(key.hashCode(), key); usersById.put(key, user); } final List<Task> userTasks = assignedTasks.stream().map(IndexedElement::getElement).collect(Collectors.toList()); addTasksToUser(user, userTasks); }); tasks.add(DUMMY_TASK); final List<User> users = new ArrayList<>(usersById.values()); return new TaskAssigningSolution(-1, users, tasks); } }
SolutionBuilder { public TaskAssigningSolution build() { final List<Task> tasks = new ArrayList<>(); final Map<String, List<IndexedElement<Task>>> assignedTasksByUserId = new HashMap<>(); final Map<String, User> usersById = filterDuplicates(externalUsers) .filter(externalUser -> !IS_PLANNING_USER.test(externalUser.getId())) .map(UserUtil::fromExternalUser) .collect(Collectors.toMap(User::getEntityId, Function.identity())); usersById.put(PLANNING_USER.getEntityId(), PLANNING_USER); taskDataList.forEach(taskData -> { context.setTaskChangeTime(taskData.getTaskId(), taskData.getLastModificationDate()); final Task task = fromTaskData(taskData); final Status status = convertFromString(task.getStatus()); switch (status) { case Ready: tasks.add(task); break; case Reserved: case InProgress: case Suspended: if (isNoneEmpty(taskData.getActualOwner())) { tasks.add(task); final PlanningTask planningTask = taskData.getPlanningTask(); if (planningTask != null && taskData.getActualOwner().equals(planningTask.getAssignedUser())) { boolean pinned = InProgress == status || Suspended == status || planningTask.getPublished() || !usersById.containsKey(taskData.getActualOwner()); addTaskToUser(assignedTasksByUserId, task, planningTask.getAssignedUser(), planningTask.getIndex(), pinned); } else { boolean pinned = (Reserved == status && !IS_PLANNING_USER.test(taskData.getActualOwner())) || InProgress == status || Suspended == status; addTaskToUser(assignedTasksByUserId, task, taskData.getActualOwner(), -1, pinned); } } break; default: throw new IndexOutOfBoundsException("Value: " + taskData.getStatus() + " is out of range in current switch"); } }); assignedTasksByUserId.forEach((key, assignedTasks) -> { User user = usersById.get(key); if (user == null) { user = new User(key.hashCode(), key); usersById.put(key, user); } final List<Task> userTasks = assignedTasks.stream().map(IndexedElement::getElement).collect(Collectors.toList()); addTasksToUser(user, userTasks); }); tasks.add(DUMMY_TASK); final List<User> users = new ArrayList<>(usersById.values()); return new TaskAssigningSolution(-1, users, tasks); } private  SolutionBuilder(); }
SolutionBuilder { public TaskAssigningSolution build() { final List<Task> tasks = new ArrayList<>(); final Map<String, List<IndexedElement<Task>>> assignedTasksByUserId = new HashMap<>(); final Map<String, User> usersById = filterDuplicates(externalUsers) .filter(externalUser -> !IS_PLANNING_USER.test(externalUser.getId())) .map(UserUtil::fromExternalUser) .collect(Collectors.toMap(User::getEntityId, Function.identity())); usersById.put(PLANNING_USER.getEntityId(), PLANNING_USER); taskDataList.forEach(taskData -> { context.setTaskChangeTime(taskData.getTaskId(), taskData.getLastModificationDate()); final Task task = fromTaskData(taskData); final Status status = convertFromString(task.getStatus()); switch (status) { case Ready: tasks.add(task); break; case Reserved: case InProgress: case Suspended: if (isNoneEmpty(taskData.getActualOwner())) { tasks.add(task); final PlanningTask planningTask = taskData.getPlanningTask(); if (planningTask != null && taskData.getActualOwner().equals(planningTask.getAssignedUser())) { boolean pinned = InProgress == status || Suspended == status || planningTask.getPublished() || !usersById.containsKey(taskData.getActualOwner()); addTaskToUser(assignedTasksByUserId, task, planningTask.getAssignedUser(), planningTask.getIndex(), pinned); } else { boolean pinned = (Reserved == status && !IS_PLANNING_USER.test(taskData.getActualOwner())) || InProgress == status || Suspended == status; addTaskToUser(assignedTasksByUserId, task, taskData.getActualOwner(), -1, pinned); } } break; default: throw new IndexOutOfBoundsException("Value: " + taskData.getStatus() + " is out of range in current switch"); } }); assignedTasksByUserId.forEach((key, assignedTasks) -> { User user = usersById.get(key); if (user == null) { user = new User(key.hashCode(), key); usersById.put(key, user); } final List<Task> userTasks = assignedTasks.stream().map(IndexedElement::getElement).collect(Collectors.toList()); addTasksToUser(user, userTasks); }); tasks.add(DUMMY_TASK); final List<User> users = new ArrayList<>(usersById.values()); return new TaskAssigningSolution(-1, users, tasks); } private  SolutionBuilder(); static SolutionBuilder create(); SolutionBuilder withTasks(List<TaskData> taskDataList); SolutionBuilder withUsers(List<org.kie.server.services.taskassigning.user.system.api.User> externalUsers); SolutionBuilder withContext(SolverHandlerContext context); TaskAssigningSolution build(); }
SolutionBuilder { public TaskAssigningSolution build() { final List<Task> tasks = new ArrayList<>(); final Map<String, List<IndexedElement<Task>>> assignedTasksByUserId = new HashMap<>(); final Map<String, User> usersById = filterDuplicates(externalUsers) .filter(externalUser -> !IS_PLANNING_USER.test(externalUser.getId())) .map(UserUtil::fromExternalUser) .collect(Collectors.toMap(User::getEntityId, Function.identity())); usersById.put(PLANNING_USER.getEntityId(), PLANNING_USER); taskDataList.forEach(taskData -> { context.setTaskChangeTime(taskData.getTaskId(), taskData.getLastModificationDate()); final Task task = fromTaskData(taskData); final Status status = convertFromString(task.getStatus()); switch (status) { case Ready: tasks.add(task); break; case Reserved: case InProgress: case Suspended: if (isNoneEmpty(taskData.getActualOwner())) { tasks.add(task); final PlanningTask planningTask = taskData.getPlanningTask(); if (planningTask != null && taskData.getActualOwner().equals(planningTask.getAssignedUser())) { boolean pinned = InProgress == status || Suspended == status || planningTask.getPublished() || !usersById.containsKey(taskData.getActualOwner()); addTaskToUser(assignedTasksByUserId, task, planningTask.getAssignedUser(), planningTask.getIndex(), pinned); } else { boolean pinned = (Reserved == status && !IS_PLANNING_USER.test(taskData.getActualOwner())) || InProgress == status || Suspended == status; addTaskToUser(assignedTasksByUserId, task, taskData.getActualOwner(), -1, pinned); } } break; default: throw new IndexOutOfBoundsException("Value: " + taskData.getStatus() + " is out of range in current switch"); } }); assignedTasksByUserId.forEach((key, assignedTasks) -> { User user = usersById.get(key); if (user == null) { user = new User(key.hashCode(), key); usersById.put(key, user); } final List<Task> userTasks = assignedTasks.stream().map(IndexedElement::getElement).collect(Collectors.toList()); addTasksToUser(user, userTasks); }); tasks.add(DUMMY_TASK); final List<User> users = new ArrayList<>(usersById.values()); return new TaskAssigningSolution(-1, users, tasks); } private  SolutionBuilder(); static SolutionBuilder create(); SolutionBuilder withTasks(List<TaskData> taskDataList); SolutionBuilder withUsers(List<org.kie.server.services.taskassigning.user.system.api.User> externalUsers); SolutionBuilder withContext(SolverHandlerContext context); TaskAssigningSolution build();  }