use of org.olat.course.run.environment.CourseEnvironment in project openolat by klemens.
the class AssessedBusinessGroupCourseNodeListController method loadModel.
protected void loadModel() {
if (assessmentCallback.canAssessBusinessGoupMembers()) {
RepositoryEntry testEntry = null;
if (courseNode.needsReferenceToARepositoryEntry()) {
testEntry = courseNode.getReferencedRepositoryEntry();
}
SearchAssessedIdentityParams params = new SearchAssessedIdentityParams(courseEntry, courseNode.getIdent(), testEntry, assessmentCallback);
if (assessmentCallback.getCoachedGroups() != null) {
List<Long> groupKeys = assessmentCallback.getCoachedGroups().stream().map(c -> c.getKey()).collect(Collectors.toList());
params.setBusinessGroupKeys(groupKeys);
}
List<AssessedBusinessGroup> rows = assessmentToolManager.getBusinessGroupStatistics(getIdentity(), params);
Set<Long> keys = rows.stream().map(c -> c.getKey()).collect(Collectors.toSet());
List<BusinessGroup> groups;
if (assessmentCallback.isAdmin()) {
CourseEnvironment courseEnv = CourseFactory.loadCourse(courseEntry).getCourseEnvironment();
groups = courseEnv.getCourseGroupManager().getAllBusinessGroups();
} else if (assessmentCallback.getCoachedGroups() != null) {
groups = assessmentCallback.getCoachedGroups();
} else {
groups = Collections.emptyList();
}
for (BusinessGroup group : groups) {
if (!keys.contains(group.getKey())) {
rows.add(new AssessedBusinessGroup(group.getKey(), group.getName(), 0.0d, 0, 0, 0, 0));
}
}
tableModel.setObjects(rows);
tableEl.reset();
tableEl.reloadData();
}
}
use of org.olat.course.run.environment.CourseEnvironment in project openolat by klemens.
the class PFManagerTest method getParticipants.
@Test
public void getParticipants() {
// prepare
Identity initialAuthor = JunitTestHelper.createAndPersistIdentityAsRndUser("check-1");
RepositoryEntry entry = JunitTestHelper.deployDemoCourse(initialAuthor);
// import "Demo course" into the bcroot_junittest
Long resourceableId = entry.getOlatResource().getResourceableId();
ICourse course = CourseFactory.loadCourse(resourceableId);
CourseEnvironment courseEnv = course.getCourseEnvironment();
repositoryEntryRelationDao.addRole(initialAuthor, entry, GroupRoles.coach.name());
for (int i = 0; i < 5; i++) {
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("pf-user-" + (i + 12));
repositoryEntryRelationDao.addRole(id, entry, GroupRoles.participant.name());
}
dbInstance.commitAndCloseSession();
List<Identity> ids = pfManager.getParticipants(initialAuthor, courseEnv, true);
// check
Assert.assertEquals(ids.size(), 5);
Assert.assertFalse(ids.contains(initialAuthor));
}
use of org.olat.course.run.environment.CourseEnvironment in project openolat by klemens.
the class EnrollmentManagerConcurrentTest method testConcurrentEnrollmentWithWaitingList_big.
@Test
@Ignore
public void testConcurrentEnrollmentWithWaitingList_big() {
List<Identity> ids = new ArrayList<Identity>(100);
for (int i = 0; i < 100; i++) {
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("enroll-a-" + i + "-" + UUID.randomUUID().toString());
ids.add(id);
}
Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("enroller");
RepositoryEntry addedEntry = JunitTestHelper.deployBasicCourse(author);
ENCourseNode enNode1 = new ENCourseNode();
ENCourseNode enNode2 = new ENCourseNode();
ENCourseNode enNode3 = new ENCourseNode();
ENCourseNode enNode4 = new ENCourseNode();
ENCourseNode enNode5 = new ENCourseNode();
CourseEnvironment cenv = CourseFactory.loadCourse(addedEntry).getCourseEnvironment();
BusinessGroup group1 = businessGroupService.createBusinessGroup(author, "Enrollment 1", "Enroll 1", new Integer(1), new Integer(8), true, true, addedEntry);
BusinessGroup group2 = businessGroupService.createBusinessGroup(author, "Enrollment 2", "Enroll 2", new Integer(1), new Integer(10), true, true, addedEntry);
BusinessGroup group3 = businessGroupService.createBusinessGroup(author, "Enrollment 3", "Enroll 3", new Integer(1), new Integer(4), true, true, addedEntry);
BusinessGroup group4 = businessGroupService.createBusinessGroup(author, "Enrollment 4", "Enroll 4", new Integer(1), new Integer(10), true, true, addedEntry);
BusinessGroup group5 = businessGroupService.createBusinessGroup(author, "Enrollment 5", "Enroll 5", new Integer(1), new Integer(9), true, true, addedEntry);
dbInstance.commitAndCloseSession();
EnrollThread[] threads = new EnrollThread[100];
final CountDownLatch doneSignal = new CountDownLatch(ids.size());
int t = 0;
for (int i = 0; i < 30; i++) {
threads[t++] = new EnrollThread(ids.get(i), addedEntry, group1, enNode1, cenv, doneSignal);
}
for (int i = 30; i < 50; i++) {
threads[t++] = new EnrollThread(ids.get(i), addedEntry, group2, enNode2, cenv, doneSignal);
}
for (int i = 50; i < 70; i++) {
threads[t++] = new EnrollThread(ids.get(i), addedEntry, group3, enNode3, cenv, doneSignal);
}
for (int i = 70; i < 90; i++) {
threads[t++] = new EnrollThread(ids.get(i), addedEntry, group4, enNode4, cenv, doneSignal);
}
for (int i = 90; i < 100; i++) {
threads[t++] = new EnrollThread(ids.get(i), addedEntry, group5, enNode5, cenv, doneSignal);
}
for (EnrollThread thread : threads) {
thread.start();
}
try {
boolean interrupt = doneSignal.await(360, TimeUnit.SECONDS);
assertTrue("Test takes too long (more than 10s)", interrupt);
} catch (InterruptedException e) {
fail("" + e.getMessage());
}
dbInstance.commitAndCloseSession();
List<Identity> enrolled_1_Ids = businessGroupService.getMembers(group1, GroupRoles.participant.name());
Assert.assertEquals(8, enrolled_1_Ids.size());
List<Identity> enrolled_2_Ids = businessGroupService.getMembers(group2, GroupRoles.participant.name());
Assert.assertEquals(10, enrolled_2_Ids.size());
List<Identity> enrolled_3_Ids = businessGroupService.getMembers(group3, GroupRoles.participant.name());
Assert.assertEquals(4, enrolled_3_Ids.size());
List<Identity> enrolled_4_Ids = businessGroupService.getMembers(group4, GroupRoles.participant.name());
Assert.assertEquals(10, enrolled_4_Ids.size());
List<Identity> enrolled_5_Ids = businessGroupService.getMembers(group5, GroupRoles.participant.name());
Assert.assertEquals(9, enrolled_5_Ids.size());
}
use of org.olat.course.run.environment.CourseEnvironment in project openolat by klemens.
the class EnrollmentManagerConcurrentTest method testConcurrentEnrollmentWithWaitingList.
@Test
public void testConcurrentEnrollmentWithWaitingList() {
int NUM_OF_USERS = 30;
List<Identity> ids = new ArrayList<Identity>(NUM_OF_USERS);
for (int i = 0; i < NUM_OF_USERS; i++) {
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("enroll-a-" + i + "-" + UUID.randomUUID().toString());
ids.add(id);
}
ENCourseNode enNode = new ENCourseNode();
Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("enroller");
RepositoryEntry addedEntry = JunitTestHelper.deployBasicCourse(author);
CourseEnvironment cenv = CourseFactory.createCourse(addedEntry, "Test-Enroll", "Test", "Test enrollment with concurrent users").getCourseEnvironment();
BusinessGroup group = businessGroupService.createBusinessGroup(id1, "Enrollment", "Enroll", new Integer(1), new Integer(10), true, false, null);
Assert.assertNotNull(group);
dbInstance.commitAndCloseSession();
final CountDownLatch doneSignal = new CountDownLatch(ids.size());
EnrollThread[] threads = new EnrollThread[NUM_OF_USERS];
int t = 0;
for (Identity id : ids) {
threads[t++] = new EnrollThread(id, addedEntry, group, enNode, cenv, doneSignal);
}
for (EnrollThread thread : threads) {
thread.start();
}
try {
boolean interrupt = doneSignal.await(360, TimeUnit.SECONDS);
assertTrue("Test takes too long (more than 10s)", interrupt);
} catch (InterruptedException e) {
fail("" + e.getMessage());
}
dbInstance.commitAndCloseSession();
List<Identity> enrolledIds = businessGroupService.getMembers(group, GroupRoles.participant.name());
Assert.assertNotNull(enrolledIds);
Assert.assertEquals(10, enrolledIds.size());
List<Identity> waitingIds = businessGroupService.getMembers(group, GroupRoles.waiting.name());
Assert.assertNotNull(waitingIds);
Assert.assertEquals(ids.size() - 10, waitingIds.size());
}
use of org.olat.course.run.environment.CourseEnvironment in project openolat by klemens.
the class EnrollmentManagerConcurrentTest method testEnroll.
// Test for WaitingList
// /////////////////////
/**
* Enroll 3 identities (group with max-size=2 and waiting-list).
* Cancel enrollment. Check size after each step.
*/
@Test
public void testEnroll() throws Exception {
log.info("testEnroll: start...");
ENCourseNode enNode = new ENCourseNode();
OLATResource resource = resourceManager.createOLATResourceInstance(CourseModule.class);
RepositoryEntry addedEntry = repositoryService.create("Ayanami", "-", "Enrollment test course 1", "A JUnit course", resource);
CourseEnvironment cenv = CourseFactory.createCourse(addedEntry, "Test", "Test", "learningObjectives").getCourseEnvironment();
// 1. enroll wg1 user
IdentityEnvironment ienv = new IdentityEnvironment();
ienv.setIdentity(wg1);
UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(ienv, cenv);
CoursePropertyManager coursePropertyManager = userCourseEnv.getCourseEnvironment().getCoursePropertyManager();
log.info("enrollmentManager=" + enrollmentManager);
log.info("bgWithWaitingList=" + bgWithWaitingList);
assertTrue("bgWithWaitingList is null", bgWithWaitingList != null);
log.info("userCourseEnv=" + userCourseEnv);
log.info("userCourseEnv.getCourseEnvironment()=" + userCourseEnv.getCourseEnvironment());
enrollmentManager.doEnroll(wg1, wg1Roles, bgWithWaitingList, enNode, coursePropertyManager, this, /*WindowControl mock*/
testTranslator, new ArrayList<Long>(), /*enrollableGroupNames*/
new ArrayList<Long>(), /*enrollableAreaNames*/
userCourseEnv.getCourseEnvironment().getCourseGroupManager());
assertTrue("Enrollment failed, user='wg1'", businessGroupService.isIdentityInBusinessGroup(wg1, bgWithWaitingList));
int participantsCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.participant.name());
assertTrue("Wrong number of participants," + participantsCounter, participantsCounter == 1);
// 2. enroll wg2 user
ienv = new IdentityEnvironment();
ienv.setIdentity(wg2);
userCourseEnv = new UserCourseEnvironmentImpl(ienv, cenv);
coursePropertyManager = userCourseEnv.getCourseEnvironment().getCoursePropertyManager();
enrollmentManager.doEnroll(wg2, wg2Roles, bgWithWaitingList, enNode, coursePropertyManager, this, /*WindowControl mock*/
testTranslator, new ArrayList<Long>(), /*enrollableGroupNames*/
new ArrayList<Long>(), /*enrollableAreaNames*/
userCourseEnv.getCourseEnvironment().getCourseGroupManager());
assertTrue("Enrollment failed, user='wg2'", businessGroupService.isIdentityInBusinessGroup(wg2, bgWithWaitingList));
assertTrue("Enrollment failed, user='wg1'", businessGroupService.isIdentityInBusinessGroup(wg1, bgWithWaitingList));
participantsCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.participant.name());
assertTrue("Wrong number of participants," + participantsCounter, participantsCounter == 2);
// 3. enroll wg3 user => list is full => waiting-list
ienv = new IdentityEnvironment();
ienv.setIdentity(wg3);
userCourseEnv = new UserCourseEnvironmentImpl(ienv, cenv);
coursePropertyManager = userCourseEnv.getCourseEnvironment().getCoursePropertyManager();
enrollmentManager.doEnroll(wg3, wg3Roles, bgWithWaitingList, enNode, coursePropertyManager, this, /*WindowControl mock*/
testTranslator, new ArrayList<Long>(), /*enrollableGroupNames*/
new ArrayList<Long>(), /*enrollableAreaNames*/
userCourseEnv.getCourseEnvironment().getCourseGroupManager());
assertFalse("Wrong enrollment, user='wg3' is in PartipiciantGroup, must be on waiting-list", businessGroupService.isIdentityInBusinessGroup(wg3, bgWithWaitingList));
assertFalse("Wrong enrollment, user='wg3' is in PartipiciantGroup, must be on waiting-list", businessGroupService.hasRoles(wg3, bgWithWaitingList, GroupRoles.participant.name()));
assertTrue("Wrong enrollment, user='wg3' must be on waiting-list", businessGroupService.hasRoles(wg3, bgWithWaitingList, GroupRoles.waiting.name()));
assertTrue("Enrollment failed, user='wg2'", businessGroupService.isIdentityInBusinessGroup(wg2, bgWithWaitingList));
assertTrue("Enrollment failed, user='wg1'", businessGroupService.isIdentityInBusinessGroup(wg1, bgWithWaitingList));
participantsCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.participant.name());
assertTrue("Wrong number of participants," + participantsCounter, participantsCounter == 2);
int waitingListCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.waiting.name());
assertTrue("Wrong number of waiting-list, must be 1, is " + waitingListCounter, waitingListCounter == 1);
// cancel enrollment for wg2 => transfer wg3 from waiting-list to participants
ienv = new IdentityEnvironment();
ienv.setIdentity(wg2);
userCourseEnv = new UserCourseEnvironmentImpl(ienv, cenv);
coursePropertyManager = userCourseEnv.getCourseEnvironment().getCoursePropertyManager();
enrollmentManager.doCancelEnrollment(wg2, bgWithWaitingList, enNode, coursePropertyManager, this, /*WindowControl mock*/
testTranslator);
assertFalse("Cancel enrollment failed, user='wg2' is still participants.", businessGroupService.isIdentityInBusinessGroup(wg2, bgWithWaitingList));
assertTrue("Enrollment failed, user='wg3'", businessGroupService.isIdentityInBusinessGroup(wg3, bgWithWaitingList));
assertTrue("Enrollment failed, user='wg1'", businessGroupService.isIdentityInBusinessGroup(wg1, bgWithWaitingList));
participantsCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.participant.name());
assertTrue("Wrong number of participants, must be 2, is " + participantsCounter, participantsCounter == 2);
waitingListCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.waiting.name());
assertTrue("Wrong number of waiting-list, must be 0, is " + waitingListCounter, waitingListCounter == 0);
// cancel enrollment for wg1
ienv = new IdentityEnvironment();
ienv.setIdentity(wg1);
userCourseEnv = new UserCourseEnvironmentImpl(ienv, cenv);
coursePropertyManager = userCourseEnv.getCourseEnvironment().getCoursePropertyManager();
enrollmentManager.doCancelEnrollment(wg1, bgWithWaitingList, enNode, coursePropertyManager, this, /*WindowControl mock*/
testTranslator);
assertFalse("Cancel enrollment failed, user='wg2' is still participants.", businessGroupService.isIdentityInBusinessGroup(wg2, bgWithWaitingList));
assertFalse("Cancel enrollment failed, user='wg1' is still participants.", businessGroupService.isIdentityInBusinessGroup(wg1, bgWithWaitingList));
assertTrue("Enrollment failed, user='wg3'", businessGroupService.isIdentityInBusinessGroup(wg3, bgWithWaitingList));
participantsCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.participant.name());
assertTrue("Wrong number of participants, must be 1, is " + participantsCounter, participantsCounter == 1);
waitingListCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.waiting.name());
assertTrue("Wrong number of waiting-list, must be 0, is " + waitingListCounter, waitingListCounter == 0);
// cancel enrollment for wg3
ienv = new IdentityEnvironment();
ienv.setIdentity(wg3);
userCourseEnv = new UserCourseEnvironmentImpl(ienv, cenv);
coursePropertyManager = userCourseEnv.getCourseEnvironment().getCoursePropertyManager();
enrollmentManager.doCancelEnrollment(wg3, bgWithWaitingList, enNode, coursePropertyManager, this, /*WindowControl mock*/
testTranslator);
assertFalse("Cancel enrollment failed, user='wg3' is still participants.", businessGroupService.isIdentityInBusinessGroup(wg3, bgWithWaitingList));
assertFalse("Cancel enrollment failed, user='wg2' is still participants.", businessGroupService.isIdentityInBusinessGroup(wg2, bgWithWaitingList));
assertFalse("Cancel enrollment failed, user='wg1' is still participants.", businessGroupService.isIdentityInBusinessGroup(wg1, bgWithWaitingList));
participantsCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.participant.name());
assertTrue("Wrong number of participants, must be 0, is " + participantsCounter, participantsCounter == 0);
waitingListCounter = businessGroupService.countMembers(bgWithWaitingList, GroupRoles.waiting.name());
assertTrue("Wrong number of waiting-list, must be 0, is " + waitingListCounter, waitingListCounter == 0);
log.info("testEnroll: done...");
}
Aggregations