use of org.kie.kogito.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange in project kogito-apps by kiegroup.
the class SolutionChangesBuilder method addTaskChanges.
private void addTaskChanges(TaskAssignment taskAssignment, TaskData taskData) {
String taskState = taskData.getState();
if (READY.value().equals(taskState)) {
context.setTaskPublished(taskData.getId(), false);
releasedTasksChanges.add(new ReleaseTaskProblemFactChange(taskAssignment));
} else if (RESERVED.value().equals(taskState)) {
context.setTaskPublished(taskData.getId(), true);
if (!taskData.getActualOwner().equals(taskAssignment.getUser().getId()) || !taskAssignment.isPinned()) {
final User user = getUser(usersById.get(taskData.getActualOwner()), taskData.getActualOwner());
AssignTaskProblemFactChange change = new AssignTaskProblemFactChange(taskAssignment, user, true);
addChangeToUser(assignToUserChangesByUserId, change, user, -1, true);
}
} else if (TaskState.isTerminal(taskState)) {
removedTasksSet.add(taskAssignment);
}
if (!removedTasksSet.contains(taskAssignment)) {
Task updatedTask = fromTaskData(taskData);
if (!equalsByTaskInfoProperties(taskAssignment.getTask(), updatedTask)) {
processorRegistry.applyAttributesProcessor(updatedTask, updatedTask.getAttributes());
} else {
updatedTask.setAttributes(taskAssignment.getTask().getAttributes());
}
taskPropertyChanges.add(new TaskInfoChangeProblemFactChange(taskAssignment, updatedTask));
}
}
use of org.kie.kogito.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange in project kogito-apps by kiegroup.
the class SolutionChangesBuilder method build.
public List<ProblemFactChange<TaskAssigningSolution>> build() {
usersById = solution.getUserList().stream().collect(Collectors.toMap(User::getId, Function.identity()));
Map<String, TaskAssignment> taskAssignmentById = filterNonDummyAssignments(solution.getTaskAssignmentList()).stream().collect(Collectors.toMap(TaskAssignment::getId, Function.identity()));
TaskAssignment taskAssignment;
for (TaskData taskData : taskDataList) {
taskAssignment = taskAssignmentById.remove(taskData.getId());
if (taskAssignment == null) {
addNewTaskChanges(taskData);
} else {
addTaskChanges(taskAssignment, taskData);
}
}
for (TaskAssignment removedTask : removedTasksSet) {
removedTaskChanges.add(new RemoveTaskProblemFactChange(removedTask));
}
if (userDataEvent != null) {
addFullSyncUserChanges(userDataEvent.getData());
} else {
addRemovableUserChanges();
}
totalChanges.addAll(newUserChanges);
totalChanges.addAll(removedTaskChanges);
totalChanges.addAll(releasedTasksChanges);
for (List<IndexedElement<AssignTaskProblemFactChange>> assignTaskToUserChanges : assignToUserChangesByUserId.values()) {
List<AssignTaskProblemFactChange> assignTaskChanges = assignTaskToUserChanges.stream().map(IndexedElement::getElement).collect(Collectors.toList());
totalChanges.addAll(assignTaskChanges);
}
totalChanges.addAll(taskPropertyChanges);
totalChanges.addAll(updateUserChanges);
totalChanges.addAll(newTasksChanges);
totalChanges.addAll(removableUserChanges);
traceChanges();
if (!totalChanges.isEmpty()) {
totalChanges.add(0, scoreDirector -> context.setCurrentChangeSetId(context.nextChangeSetId()));
}
return totalChanges;
}
use of org.kie.kogito.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange in project kogito-apps by kiegroup.
the class SolutionChangesBuilder method addNewTaskChanges.
private void addNewTaskChanges(TaskData taskData) {
Task newTask;
if (READY.value().equals(taskData.getState())) {
newTask = fromTaskData(taskData);
processorRegistry.applyAttributesProcessor(newTask, newTask.getAttributes());
newTasksChanges.add(new AddTaskProblemFactChange(new TaskAssignment(newTask)));
context.setTaskPublished(taskData.getId(), false);
} else if (RESERVED.value().equals(taskData.getState())) {
newTask = fromTaskData(taskData);
processorRegistry.applyAttributesProcessor(newTask, newTask.getAttributes());
User user = getUser(usersById.get(taskData.getActualOwner()), taskData.getActualOwner());
AssignTaskProblemFactChange change = new AssignTaskProblemFactChange(new TaskAssignment(newTask), user, true);
context.setTaskPublished(taskData.getId(), true);
addChangeToUser(assignToUserChangesByUserId, change, user, -1, true);
}
}
Aggregations