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

OO-1276: retrieve assessment data of the participants of the repository entry

parent 293960be
No related branches found
No related tags found
No related merge requests found
...@@ -83,6 +83,17 @@ public interface CheckboxManager { ...@@ -83,6 +83,17 @@ public interface CheckboxManager {
public float calculateScore(Identity identity, OLATResourceable ores, String resSubPath); public float calculateScore(Identity identity, OLATResourceable ores, String resSubPath);
/**
* Return the assessment data of the participants of the repository entry and or the business groups
* specified. If the repository entry and the business groups are omitted, all the assessment data
* are returned.
*
* @param ores
* @param resSubPath
* @param re
* @param groups
* @return
*/
public List<AssessmentData> getAssessmentDatas(OLATResourceable ores, String resSubPath, RepositoryEntry re, List<BusinessGroup> groups); public List<AssessmentData> getAssessmentDatas(OLATResourceable ores, String resSubPath, RepositoryEntry re, List<BusinessGroup> groups);
public VFSContainer getFileContainer(CourseEnvironment courseEnv, CheckListCourseNode cNode, Checkbox checkbox); public VFSContainer getFileContainer(CourseEnvironment courseEnv, CheckListCourseNode cNode, Checkbox checkbox);
......
...@@ -36,7 +36,6 @@ import javax.persistence.TypedQuery; ...@@ -36,7 +36,6 @@ import javax.persistence.TypedQuery;
import org.olat.basesecurity.Group; import org.olat.basesecurity.Group;
import org.olat.basesecurity.IdentityImpl; import org.olat.basesecurity.IdentityImpl;
import org.olat.basesecurity.model.GroupMembershipImpl;
import org.olat.core.commons.modules.bc.FolderConfig; import org.olat.core.commons.modules.bc.FolderConfig;
import org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl; import org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl;
import org.olat.core.commons.persistence.DB; import org.olat.core.commons.persistence.DB;
...@@ -450,12 +449,34 @@ public class CheckboxManagerImpl implements CheckboxManager { ...@@ -450,12 +449,34 @@ public class CheckboxManagerImpl implements CheckboxManager {
if(StringHelper.containsNonWhitespace(resSubPath)) { if(StringHelper.containsNonWhitespace(resSubPath)) {
sb.append(" and box.resSubPath=:resSubPath"); sb.append(" and box.resSubPath=:resSubPath");
} }
if(businessGroups != null && businessGroups.size() > 0) {
sb.append(" and check.identity.key in ( select membership.identity.key from ").append(GroupMembershipImpl.class.getName()).append(" membership ") boolean hasBusinessGroups = businessGroups != null && businessGroups.size() > 0;
if(hasBusinessGroups) {
sb.append(" and ");
if(re != null) {
sb.append(" ( ");
}
sb.append(" check.identity.key in ( select membership.identity.key from bgroupmember membership ")
.append(" where membership.group in (:baseGroups) and membership.role='").append(GroupRole.participant).append("'") .append(" where membership.group in (:baseGroups) and membership.role='").append(GroupRole.participant).append("'")
.append(" )"); .append(" )");
} }
if(re != null) {
if(hasBusinessGroups) {
sb.append(" or ");
} else {
sb.append(" and ");
}
sb.append(" check.identity.key in ( select membership.identity.key from repoentrytogroup as rel, bgroup as reBaseGroup, bgroupmember membership ")
.append(" where rel.entry.key=:repoKey and rel.group=reBaseGroup and membership.group=reBaseGroup and membership.role='").append(GroupRole.participant).append("'")
.append(" )");
if(hasBusinessGroups) {
sb.append(" ) ");
}
}
TypedQuery<DBCheck> query = dbInstance.getCurrentEntityManager() TypedQuery<DBCheck> query = dbInstance.getCurrentEntityManager()
.createQuery(sb.toString(), DBCheck.class) .createQuery(sb.toString(), DBCheck.class)
.setParameter("resName", ores.getResourceableTypeName()) .setParameter("resName", ores.getResourceableTypeName())
...@@ -463,14 +484,17 @@ public class CheckboxManagerImpl implements CheckboxManager { ...@@ -463,14 +484,17 @@ public class CheckboxManagerImpl implements CheckboxManager {
if(StringHelper.containsNonWhitespace(resSubPath)) { if(StringHelper.containsNonWhitespace(resSubPath)) {
query.setParameter("resSubPath", resSubPath); query.setParameter("resSubPath", resSubPath);
} }
if(businessGroups != null && businessGroups.size() > 0) {
if(hasBusinessGroups) {
List<Group> groups = new ArrayList<>(businessGroups.size()); List<Group> groups = new ArrayList<>(businessGroups.size());
for(BusinessGroup businessGroup:businessGroups) { for(BusinessGroup businessGroup:businessGroups) {
groups.add(businessGroup.getBaseGroup()); groups.add(businessGroup.getBaseGroup());
} }
query.setParameter("baseGroups", groups); query.setParameter("baseGroups", groups);
} }
//TODO group exists student where i'm coach? if(re != null) {
query.setParameter("repoKey", re.getKey());
}
List<DBCheck> checks = query.getResultList(); List<DBCheck> checks = query.getResultList();
Map<Long, AssessmentData> identToBox = new HashMap<Long,AssessmentData>(); Map<Long, AssessmentData> identToBox = new HashMap<Long,AssessmentData>();
......
...@@ -20,12 +20,14 @@ ...@@ -20,12 +20,14 @@
package org.olat.course.nodes.cl.manager; package org.olat.course.nodes.cl.manager;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import junit.framework.Assert; import junit.framework.Assert;
import org.junit.Test; import org.junit.Test;
import org.olat.basesecurity.GroupRoles;
import org.olat.core.commons.persistence.DB; import org.olat.core.commons.persistence.DB;
import org.olat.core.id.Identity; import org.olat.core.id.Identity;
import org.olat.core.id.OLATResourceable; import org.olat.core.id.OLATResourceable;
...@@ -35,6 +37,11 @@ import org.olat.course.nodes.cl.model.Checkbox; ...@@ -35,6 +37,11 @@ import org.olat.course.nodes.cl.model.Checkbox;
import org.olat.course.nodes.cl.model.CheckboxList; import org.olat.course.nodes.cl.model.CheckboxList;
import org.olat.course.nodes.cl.model.DBCheck; import org.olat.course.nodes.cl.model.DBCheck;
import org.olat.course.nodes.cl.model.DBCheckbox; import org.olat.course.nodes.cl.model.DBCheckbox;
import org.olat.group.BusinessGroup;
import org.olat.group.manager.BusinessGroupDAO;
import org.olat.group.manager.BusinessGroupRelationDAO;
import org.olat.repository.RepositoryEntry;
import org.olat.repository.manager.RepositoryEntryRelationDAO;
import org.olat.test.JunitTestHelper; import org.olat.test.JunitTestHelper;
import org.olat.test.OlatTestCase; import org.olat.test.OlatTestCase;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -50,7 +57,13 @@ public class CheckboxManagerTest extends OlatTestCase { ...@@ -50,7 +57,13 @@ public class CheckboxManagerTest extends OlatTestCase {
@Autowired @Autowired
private DB dbInstance; private DB dbInstance;
@Autowired @Autowired
private BusinessGroupDAO businessGroupDao;
@Autowired
private CheckboxManagerImpl checkboxManager; private CheckboxManagerImpl checkboxManager;
@Autowired
private BusinessGroupRelationDAO businessGroupRelationDao;
@Autowired
private RepositoryEntryRelationDAO repositoryEntryRelationDao;
@Test @Test
public void createCheckBox() { public void createCheckBox() {
...@@ -291,7 +304,104 @@ public class CheckboxManagerTest extends OlatTestCase { ...@@ -291,7 +304,104 @@ public class CheckboxManagerTest extends OlatTestCase {
Assert.assertTrue(collectedChecks.contains(check3_1)); Assert.assertTrue(collectedChecks.contains(check3_1));
Assert.assertTrue(collectedChecks.contains(check3_2)); Assert.assertTrue(collectedChecks.contains(check3_2));
} }
@Test
public void loadAssessmentDatas_inCourse() {
RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("check-18");
repositoryEntryRelationDao.addRole(id, entry, GroupRoles.participant.name());
dbInstance.commitAndCloseSession();
String checkboxId = UUID.randomUUID().toString();
String resSubPath = UUID.randomUUID().toString();
DBCheckbox checkbox = checkboxManager.createDBCheckbox(checkboxId, entry.getOlatResource(), resSubPath);
DBCheck check = checkboxManager.createCheck(checkbox, id, null, Boolean.TRUE);
dbInstance.commitAndCloseSession();
//load and check the check
List<AssessmentData> loadedChecks = checkboxManager.getAssessmentDatas(entry.getOlatResource(), resSubPath, entry, null);
Assert.assertNotNull(loadedChecks);
Assert.assertEquals(1, loadedChecks.size());
AssessmentData data = loadedChecks.get(0);
Assert.assertNotNull(data);
Assert.assertNotNull(data.getChecks());
Assert.assertEquals(1, data.getChecks().size());
Assert.assertEquals(check, data.getChecks().get(0));
Assert.assertEquals(id, data.getIdentity());
}
@Test
public void loadAssessmentDatas_inGroup() {
RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("check-19");
BusinessGroup group = businessGroupDao.createAndPersist(null, "gcheck", "gcheck-desc", 0, 10, true, true, false, false, false);
businessGroupRelationDao.addRole(id, group, GroupRoles.participant.name());
dbInstance.commitAndCloseSession();
String checkboxId = UUID.randomUUID().toString();
String resSubPath = UUID.randomUUID().toString();
DBCheckbox checkbox = checkboxManager.createDBCheckbox(checkboxId, entry.getOlatResource(), resSubPath);
DBCheck check = checkboxManager.createCheck(checkbox, id, null, Boolean.TRUE);
dbInstance.commitAndCloseSession();
List<BusinessGroup> groups = Collections.singletonList(group);
List<AssessmentData> loadedChecks = checkboxManager.getAssessmentDatas(entry.getOlatResource(), resSubPath, null, groups);
Assert.assertNotNull(loadedChecks);
Assert.assertEquals(1, loadedChecks.size());
AssessmentData data = loadedChecks.get(0);
Assert.assertNotNull(data);
Assert.assertNotNull(data.getChecks());
Assert.assertEquals(1, data.getChecks().size());
Assert.assertEquals(check, data.getChecks().get(0));
Assert.assertEquals(id, data.getIdentity());
}
@Test
public void loadAssessmentDatas_inGroupAndCourse() {
RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
Identity groupParticipant = JunitTestHelper.createAndPersistIdentityAsRndUser("check-20");
BusinessGroup group = businessGroupDao.createAndPersist(null, "gcheck", "gcheck-desc", 0, 10, true, true, false, false, false);
businessGroupRelationDao.addRole(groupParticipant, group, GroupRoles.participant.name());
Identity courseParticipant = JunitTestHelper.createAndPersistIdentityAsRndUser("check-21");
repositoryEntryRelationDao.addRole(courseParticipant, entry, GroupRoles.participant.name());
dbInstance.commitAndCloseSession();
//add some noise
Identity courseOwner = JunitTestHelper.createAndPersistIdentityAsRndUser("check-22");
repositoryEntryRelationDao.addRole(courseOwner, entry, GroupRoles.owner.name());
Identity groupWaiting = JunitTestHelper.createAndPersistIdentityAsRndUser("check-23");
businessGroupRelationDao.addRole(groupWaiting, group, GroupRoles.waiting.name());
dbInstance.commitAndCloseSession();
String checkboxId = UUID.randomUUID().toString();
String resSubPath = UUID.randomUUID().toString();
DBCheckbox checkbox = checkboxManager.createDBCheckbox(checkboxId, entry.getOlatResource(), resSubPath);
DBCheck checkGroup = checkboxManager.createCheck(checkbox, groupParticipant, null, Boolean.TRUE);
DBCheck checkCourse = checkboxManager.createCheck(checkbox, courseParticipant, null, Boolean.TRUE);
DBCheck checkNotVisible1 = checkboxManager.createCheck(checkbox, groupWaiting, null, Boolean.FALSE);
DBCheck checkNotVisible2 = checkboxManager.createCheck(checkbox, courseOwner, null, Boolean.FALSE);
dbInstance.commitAndCloseSession();
List<BusinessGroup> groups = Collections.singletonList(group);
List<AssessmentData> loadedChecks = checkboxManager.getAssessmentDatas(entry.getOlatResource(), resSubPath, entry, groups);
Assert.assertNotNull(loadedChecks);
Assert.assertEquals(2, loadedChecks.size());
List<DBCheck> collectedChecks = new ArrayList<>();
for(AssessmentData loadedCheck:loadedChecks) {
for(DBCheck loaded:loadedCheck.getChecks()) {
collectedChecks.add(loaded);
}
}
Assert.assertEquals(2, collectedChecks.size());
Assert.assertTrue(collectedChecks.contains(checkGroup));
Assert.assertTrue(collectedChecks.contains(checkCourse));
Assert.assertFalse(collectedChecks.contains(checkNotVisible1));
Assert.assertFalse(collectedChecks.contains(checkNotVisible2));
}
@Test @Test
public void countChecks_resource() { public void countChecks_resource() {
......
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