Skip to content
Snippets Groups Projects
Commit 40bafd6d authored by srosse's avatar srosse
Browse files

OO-4188: fully load the task list before using it inn group task

parent d2169e6c
No related branches found
No related tags found
No related merge requests found
...@@ -37,16 +37,17 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -37,16 +37,17 @@ import java.util.concurrent.atomic.AtomicInteger;
import javax.persistence.LockModeType; import javax.persistence.LockModeType;
import javax.persistence.Query; import javax.persistence.Query;
import org.apache.logging.log4j.Logger;
import org.hibernate.LazyInitializationException; import org.hibernate.LazyInitializationException;
import org.olat.basesecurity.GroupRoles; import org.olat.basesecurity.GroupRoles;
import org.olat.basesecurity.IdentityRef; import org.olat.basesecurity.IdentityRef;
import org.olat.core.commons.modules.bc.FolderConfig; import org.olat.core.commons.modules.bc.FolderConfig;
import org.olat.core.commons.persistence.DB; import org.olat.core.commons.persistence.DB;
import org.olat.core.commons.persistence.QueryBuilder;
import org.olat.core.commons.services.notifications.NotificationsManager; import org.olat.core.commons.services.notifications.NotificationsManager;
import org.olat.core.commons.services.notifications.PublisherData; import org.olat.core.commons.services.notifications.PublisherData;
import org.olat.core.commons.services.notifications.SubscriptionContext; import org.olat.core.commons.services.notifications.SubscriptionContext;
import org.olat.core.id.Identity; import org.olat.core.id.Identity;
import org.apache.logging.log4j.Logger;
import org.olat.core.logging.Tracing; import org.olat.core.logging.Tracing;
import org.olat.core.util.FileUtils; import org.olat.core.util.FileUtils;
import org.olat.core.util.StringHelper; import org.olat.core.util.StringHelper;
...@@ -755,6 +756,31 @@ public class GTAManagerImpl implements GTAManager { ...@@ -755,6 +756,31 @@ public class GTAManagerImpl implements GTAManager {
return tasks.isEmpty() ? null : tasks.get(0); return tasks.isEmpty() ? null : tasks.get(0);
} }
/**
* Load the task list with the underlying repository
* entry (full).
*
* @param task
* @return
*/
public TaskList getTaskList(TaskRef task ) {
QueryBuilder sb = new QueryBuilder();
sb.append("select taskList from gtatask task")
.append(" inner join task.taskList as taskList")
.append(" inner join fetch taskList.entry as v")
.append(" inner join fetch v.olatResource as ores")
.append(" inner join fetch v.statistics as statistics")
.append(" left join fetch v.lifecycle as lifecycle")
.append(" where task.key=:taskKey");
List<TaskList> tasks = dbInstance.getCurrentEntityManager()
.createQuery(sb.toString(), TaskList.class)
.setParameter("taskKey", task.getKey())
.getResultList();
return tasks.isEmpty() ? null : tasks.get(0);
}
@Override @Override
public int deleteTaskList(RepositoryEntryRef entry, GTACourseNode cNode) { public int deleteTaskList(RepositoryEntryRef entry, GTACourseNode cNode) {
...@@ -1690,7 +1716,8 @@ public class GTAManagerImpl implements GTAManager { ...@@ -1690,7 +1716,8 @@ public class GTAManagerImpl implements GTAManager {
private void syncAssessmentEntry(TaskImpl taskImpl, GTACourseNode cNode, Role by) { private void syncAssessmentEntry(TaskImpl taskImpl, GTACourseNode cNode, Role by) {
if(taskImpl == null || taskImpl.getTaskStatus() == null || cNode == null) return; if(taskImpl == null || taskImpl.getTaskStatus() == null || cNode == null) return;
RepositoryEntry courseRepoEntry = taskImpl.getTaskList().getEntry(); TaskList taskList = getTaskList(taskImpl);
RepositoryEntry courseRepoEntry = taskList.getEntry();
AssessmentEntryStatus assessmentStatus = convertToAssessmentEntrystatus(taskImpl, cNode); AssessmentEntryStatus assessmentStatus = convertToAssessmentEntrystatus(taskImpl, cNode);
if(GTAType.group.name().equals(cNode.getModuleConfiguration().getStringValue(GTACourseNode.GTASK_TYPE))) { if(GTAType.group.name().equals(cNode.getModuleConfiguration().getStringValue(GTACourseNode.GTASK_TYPE))) {
//update whole group //update whole group
......
...@@ -194,6 +194,44 @@ public class GTAManagerTest extends OlatTestCase { ...@@ -194,6 +194,44 @@ public class GTAManagerTest extends OlatTestCase {
Assert.assertEquals(1, assignedTasks.size()); Assert.assertEquals(1, assignedTasks.size());
} }
@Test
public void getTaskList_byTask() {
Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-3");
Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("gta-user-4");
BusinessGroup businessGroup = businessGroupDao.createAndPersist(coach, "gdao", "gdao-desc", -1, -1, false, false, false, false, false);
businessGroupRelationDao.addRole(participant, businessGroup, GroupRole.participant.name());
dbInstance.commit();
RepositoryEntry re = deployGTACourse();
GTACourseNode node = getGTACourseNode(re);
node.getModuleConfiguration().setStringValue(GTACourseNode.GTASK_TYPE, GTAType.group.name());
TaskList tasks = gtaManager.createIfNotExists(re, node);
File taskFile = new File("bg.txt");
Assert.assertNotNull(tasks);
dbInstance.commit();
//select
AssignmentResponse response = gtaManager.selectTask(businessGroup, tasks, node, taskFile);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(response);
List<Task> assignedTasks = gtaManager.getTasks(participant, re, node);
Assert.assertNotNull(assignedTasks);
Assert.assertEquals(1, assignedTasks.size());
//reload and check
TaskList reloadedTasks = gtaManager.getTaskList(assignedTasks.get(0));
dbInstance.commitAndCloseSession();// entry nneed to be fetched
Assert.assertNotNull(reloadedTasks);
Assert.assertEquals(tasks, reloadedTasks);
Assert.assertTrue(reloadedTasks instanceof TaskListImpl);
TaskListImpl tasksImpl = (TaskListImpl)reloadedTasks;
Assert.assertNotNull(tasksImpl.getCreationDate());
Assert.assertNotNull(tasksImpl.getLastModified());
Assert.assertEquals(re, tasksImpl.getEntry());
Assert.assertEquals(node.getIdent(), tasksImpl.getCourseNodeIdent());
dbInstance.commit();
}
@Test @Test
public void isTaskAssigned() { public void isTaskAssigned() {
//create an individual task //create an individual task
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment