use of org.kie.kogito.taskassigning.core.model.ChainElement in project kogito-apps by kiegroup.
the class AssignTaskProblemFactChange method findInsertPosition.
/**
* Find the first available "position" where a taskAssignment can be added in the tasks chain for a given user.
* <p>
* For a chain like:
* <p>
* U -> T1 -> T2 -> T3 -> T4 -> null
* <p>
* if e.g. T3 is returned, a new taskAssignment Tn will be later added in the following position.
* <p>
* U -> T1 -> T2 -> T3 -> Tn -> T4 -> null
* Given that we are using a chained structure, to pin a task assignment Tn to a given user, we must be sure that
* all the previous tasks in the chain are pinned to the same user. For keeping the structure consistency a task
* assignment Tn is inserted after the last pinned element in the chain. In the example above we have that existing
* tasks assignments T1, T2 and T3 are pinned.
*
* @param user the for adding a taskAssignment to.
* @return the proper ChainElement object were a taskAssignment can be added. This method will never return null.
*/
private static ChainElement findInsertPosition(User user) {
ChainElement result = user;
TaskAssignment nextTaskAssignment = user.getNextElement();
while (nextTaskAssignment != null && nextTaskAssignment.isPinned()) {
result = nextTaskAssignment;
nextTaskAssignment = nextTaskAssignment.getNextElement();
}
return result;
}
use of org.kie.kogito.taskassigning.core.model.ChainElement in project kogito-apps by kiegroup.
the class TestUtil method mockUser.
public static User mockUser(String userId, List<TaskAssignment> taskAssignments) {
User result = new User(userId, true);
ChainElement previousElement = result;
for (TaskAssignment taskAssignment : taskAssignments) {
taskAssignment.setUser(result);
taskAssignment.setPreviousElement(previousElement);
previousElement.setNextElement(taskAssignment);
previousElement = taskAssignment;
}
return result;
}
use of org.kie.kogito.taskassigning.core.model.ChainElement in project kogito-apps by kiegroup.
the class TaskHelperTest method extractTasksFiltered.
@Test
void extractTasksFiltered() {
ChainElement chainElement = buildChainElement();
List<TaskAssignment> result = TaskHelper.extractTaskAssignments(chainElement, testedTask -> testedTask.getId().equals(TASK_ID_1) || testedTask.getId().equals(TASK_ID_4));
assertThat(result.size()).isEqualTo(2);
assertThat(result.get(0).getId()).isEqualTo(TASK_ID_1);
assertThat(result.get(1).getId()).isEqualTo(TASK_ID_4);
}
use of org.kie.kogito.taskassigning.core.model.ChainElement in project kogito-apps by kiegroup.
the class TaskHelperTest method buildChainElement.
private ChainElement buildChainElement() {
ChainElement chainElement = new TaskAssignment(Task.newBuilder().build());
TaskAssignment taskAssignment1 = new TaskAssignment(Task.newBuilder().id(TASK_ID_1).build());
TaskAssignment taskAssignment2 = new TaskAssignment(Task.newBuilder().id(TASK_ID_2).build());
TaskAssignment taskAssignment3 = new TaskAssignment(Task.newBuilder().id(TASK_ID_3).build());
taskAssignment3.setPinned(true);
TaskAssignment taskAssignment4 = new TaskAssignment(Task.newBuilder().id(TASK_ID_4).build());
taskAssignment2.setPinned(true);
chainElement.setNextElement(taskAssignment1);
taskAssignment1.setNextElement(taskAssignment2);
taskAssignment2.setNextElement(taskAssignment3);
taskAssignment3.setNextElement(taskAssignment4);
return chainElement;
}
use of org.kie.kogito.taskassigning.core.model.ChainElement in project kogito-apps by kiegroup.
the class TaskHelperTest method extractTasks.
@Test
void extractTasks() {
ChainElement chainElement = buildChainElement();
List<TaskAssignment> result = TaskHelper.extractTaskAssignments(chainElement);
assertThat(result.size()).isEqualTo(4);
assertThat(result.get(0).getId()).isEqualTo(TASK_ID_1);
assertThat(result.get(1).getId()).isEqualTo(TASK_ID_2);
assertThat(result.get(2).getId()).isEqualTo(TASK_ID_3);
assertThat(result.get(3).getId()).isEqualTo(TASK_ID_4);
}
Aggregations