use of org.olat.core.id.IdentityEnvironment in project openolat by klemens.
the class PFManagerTest method provideCoachContainer.
@Test
public void provideCoachContainer() {
// prepare
Identity initialAuthor = JunitTestHelper.createAndPersistIdentityAsRndUser("check-16");
IdentityEnvironment ienv = new IdentityEnvironment();
ienv.setIdentity(initialAuthor);
PFCourseNode pfNode = new PFCourseNode();
pfNode.getModuleConfiguration().setBooleanEntry(PFCourseNode.CONFIG_KEY_COACHBOX, true);
pfNode.getModuleConfiguration().setBooleanEntry(PFCourseNode.CONFIG_KEY_PARTICIPANTBOX, true);
// import "Demo course" into the bcroot_junittest
RepositoryEntry entry = JunitTestHelper.deployDemoCourse(initialAuthor);
Long resourceableId = entry.getOlatResource().getResourceableId();
ICourse course = CourseFactory.loadCourse(resourceableId);
UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
Identity check4 = JunitTestHelper.createAndPersistIdentityAsRndUser("check-4");
repositoryEntryRelationDao.addRole(check4, entry, GroupRoles.coach.name());
VFSContainer vfsContainer = pfManager.provideCoachOrParticipantContainer(pfNode, userCourseEnv, check4, false);
Assert.assertNotNull(vfsContainer);
}
use of org.olat.core.id.IdentityEnvironment 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...");
}
use of org.olat.core.id.IdentityEnvironment in project openolat by klemens.
the class AssessmentHelper method createAndInitUserCourseEnvironment.
public static UserCourseEnvironment createAndInitUserCourseEnvironment(Identity identity, CourseEnvironment courseEnv) {
// create an identenv with no roles, no attributes, no locale
IdentityEnvironment ienv = new IdentityEnvironment();
ienv.setIdentity(identity);
UserCourseEnvironment uce = new UserCourseEnvironmentImpl(ienv, courseEnv);
// Fetch all score and passed and calculate score accounting for the entire
// course
uce.getScoreAccounting().evaluateAll();
return uce;
}
use of org.olat.core.id.IdentityEnvironment in project openolat by klemens.
the class CourseNodeOutcomeMapper method getUserCourseEnvironment.
private UserCourseEnvironment getUserCourseEnvironment(ICourse course) {
IdentityEnvironment identityEnvironment = new IdentityEnvironment();
identityEnvironment.setIdentity(getIdentity());
UserCourseEnvironmentImpl userCourseEnv = new UserCourseEnvironmentImpl(identityEnvironment, course.getCourseEnvironment());
return userCourseEnv;
}
use of org.olat.core.id.IdentityEnvironment in project openolat by klemens.
the class IdentityListCourseNodeController method doSetDone.
private void doSetDone(UserRequest ureq) {
Set<Integer> selections = tableEl.getMultiSelectedIndex();
List<AssessedIdentityElementRow> rows = new ArrayList<>(selections.size());
for (Integer i : selections) {
AssessedIdentityElementRow row = usersTableModel.getObject(i.intValue());
if (row != null && row.getAssessmentStatus() != AssessmentEntryStatus.done) {
rows.add(row);
}
}
if (rows == null || rows.isEmpty()) {
showWarning("warning.bulk.done");
} else if (courseNode instanceof AssessableCourseNode) {
ICourse course = CourseFactory.loadCourse(courseEntry);
AssessableCourseNode assessableCourseNode = (AssessableCourseNode) courseNode;
for (AssessedIdentityElementRow row : rows) {
Identity assessedIdentity = securityManager.loadIdentityByKey(row.getIdentityKey());
Roles roles = securityManager.getRoles(assessedIdentity);
IdentityEnvironment identityEnv = new IdentityEnvironment(assessedIdentity, roles);
UserCourseEnvironment assessedUserCourseEnv = new UserCourseEnvironmentImpl(identityEnv, course.getCourseEnvironment(), coachCourseEnv.isCourseReadOnly());
assessedUserCourseEnv.getScoreAccounting().evaluateAll();
ScoreEvaluation scoreEval = assessableCourseNode.getUserScoreEvaluation(assessedUserCourseEnv);
ScoreEvaluation doneEval = new ScoreEvaluation(scoreEval.getScore(), scoreEval.getPassed(), AssessmentEntryStatus.done, null, scoreEval.getFullyAssessed(), scoreEval.getCurrentRunCompletion(), scoreEval.getCurrentRunStatus(), scoreEval.getAssessmentID());
assessableCourseNode.updateUserScoreEvaluation(doneEval, assessedUserCourseEnv, getIdentity(), false, Role.coach);
}
loadModel(ureq);
}
}
Aggregations