use of org.kie.server.services.taskassigning.core.model.Task 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);
}
use of org.kie.server.services.taskassigning.core.model.Task in project droolsjbpm-integration by kiegroup.
the class PlanningBuilder method buildPlanningItems.
private List<PlanningItem> buildPlanningItems(User user) {
int index = 0;
int publishedCount = 0;
PlanningItem planningItem;
// dummy tasks has nothing to with the jBPM runtime, don't process them
final List<Task> userTasks = extractTasks(user, IS_NOT_DUMMY);
final List<PlanningItem> userPlanningItems = new ArrayList<>();
for (Task task : userTasks) {
planningItem = PlanningItem.builder().containerId(task.getContainerId()).taskId(task.getId()).processInstanceId(task.getProcessInstanceId()).planningTask(PlanningTask.builder().taskId(task.getId()).published(task.isPinned()).assignedUser(user.getUser().getEntityId()).index(index++).build()).build();
userPlanningItems.add(planningItem);
publishedCount += planningItem.getPlanningTask().isPublished() ? 1 : 0;
}
Iterator<PlanningItem> userPlanningItemsIt = userPlanningItems.iterator();
while (userPlanningItemsIt.hasNext() && (publishedCount < publishWindowSize || IS_PLANNING_USER.test(user.getEntityId()))) {
planningItem = userPlanningItemsIt.next();
if (!planningItem.getPlanningTask().isPublished()) {
planningItem.getPlanningTask().setPublished(true);
publishedCount++;
}
}
return userPlanningItems;
}
use of org.kie.server.services.taskassigning.core.model.Task in project droolsjbpm-integration by kiegroup.
the class SolutionBuilder method build.
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())) {
// If actualOwner is empty the only chance is that the task was in Ready status and changed to
// Suspended, since Reserved and InProgress tasks has always an owner in jBPM.
// Finally tasks with no actualOwner (Suspended) are skipped, since they'll be properly added to
// the solution when they change to Ready status and the proper jBPM event is raised.
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:
// no other cases exists, sonar required.
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) {
// create the user by convention.
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);
});
// Add the DUMMY_TASK to avoid running into scenarios where the solution remains with no tasks.
tasks.add(DUMMY_TASK);
final List<User> users = new ArrayList<>(usersById.values());
return new TaskAssigningSolution(-1, users, tasks);
}
use of org.kie.server.services.taskassigning.core.model.Task in project droolsjbpm-integration by kiegroup.
the class SolutionChangesBuilderTest method addReassignReservedOrInProgressOrSuspendedTaskWhenItWasManuallyReassigned.
private void addReassignReservedOrInProgressOrSuspendedTaskWhenItWasManuallyReassigned(Status status, boolean addActualOwnerToSolution) {
TaskData taskData = mockTaskData(TASK_ID, NAME, status, ACTUAL_OWNER_ENTITY_ID);
Task task = fromTaskData(taskData);
User user = mockUser(USER_ENTITY_ID);
task.setUser(user);
List<User> userList = new ArrayList<>();
userList.add(user);
if (addActualOwnerToSolution) {
User actualOwner = mockUser(ACTUAL_OWNER_ENTITY_ID);
userList.add(actualOwner);
}
TaskAssigningSolution solution = mockSolution(Collections.singletonList(task), userList);
List<ProblemFactChange<TaskAssigningSolution>> result = SolutionChangesBuilder.create().withSolution(solution).withTasks(mockTaskDataList(taskData)).withUserSystem(userSystemService).withContext(context).build();
assertChangeIsTheChangeSetId(result, 0);
assertChange(result, 1, new AssignTaskProblemFactChange(task, mockUser(ACTUAL_OWNER_ENTITY_ID), true));
assertTaskChangeRegistered(taskData.getTaskId(), taskData.getLastModificationDate());
}
use of org.kie.server.services.taskassigning.core.model.Task in project droolsjbpm-integration by kiegroup.
the class SolutionChangesBuilderTest method addRemoveReservedOrInProgressOrSuspendedTaskChangeWhenActualOwnerNotPresent.
private void addRemoveReservedOrInProgressOrSuspendedTaskChangeWhenActualOwnerNotPresent(Status status) {
TaskData taskData = mockTaskData(TASK_ID, NAME, status, null);
Task task = fromTaskData(taskData);
TaskAssigningSolution solution = mockSolution(Collections.singletonList(task), Collections.emptyList());
List<ProblemFactChange<TaskAssigningSolution>> result = SolutionChangesBuilder.create().withSolution(solution).withTasks(mockTaskDataList(taskData)).withUserSystem(userSystemService).withContext(context).build();
assertChangeIsTheChangeSetId(result, 0);
assertChange(result, 1, new RemoveTaskProblemFactChange(task));
assertTaskChangeRegistered(taskData.getTaskId(), taskData.getLastModificationDate());
}
Aggregations