use of org.olat.course.run.userview.UserCourseEnvironmentImpl in project OpenOLAT by OpenOLAT.
the class IdentityListCourseNodeController method doSetVisibility.
private void doSetVisibility(UserRequest ureq, Boolean visibility, List<AssessedIdentityElementRow> rows) {
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(), scoreEval.getAssessmentStatus(), visibility, scoreEval.getFullyAssessed(), scoreEval.getCurrentRunCompletion(), scoreEval.getCurrentRunStatus(), scoreEval.getAssessmentID());
assessableCourseNode.updateUserScoreEvaluation(doneEval, assessedUserCourseEnv, getIdentity(), false, Role.coach);
}
loadModel(ureq);
}
use of org.olat.course.run.userview.UserCourseEnvironmentImpl in project OpenOLAT by OpenOLAT.
the class RunMainController method loadUserCourseEnvironment.
private UserCourseEnvironmentImpl loadUserCourseEnvironment(UserRequest ureq, RepositoryEntrySecurity reSecurity) {
CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager();
List<BusinessGroup> coachedGroups;
if (reSecurity.isGroupCoach()) {
coachedGroups = cgm.getOwnedBusinessGroups(ureq.getIdentity());
} else {
coachedGroups = Collections.emptyList();
}
List<BusinessGroup> participatedGroups;
if (reSecurity.isGroupParticipant()) {
participatedGroups = cgm.getParticipatingBusinessGroups(ureq.getIdentity());
} else {
participatedGroups = Collections.emptyList();
}
List<BusinessGroup> waitingLists;
if (reSecurity.isGroupWaiting()) {
waitingLists = cgm.getWaitingListGroups(ureq.getIdentity());
} else {
waitingLists = Collections.emptyList();
}
return new UserCourseEnvironmentImpl(ureq.getUserSession().getIdentityEnvironment(), course.getCourseEnvironment(), getWindowControl(), coachedGroups, participatedGroups, waitingLists, reSecurity.isCourseCoach() || reSecurity.isGroupCoach(), reSecurity.isEntryAdmin(), reSecurity.isCourseParticipant() || reSecurity.isGroupParticipant(), reSecurity.isReadOnly());
}
use of org.olat.course.run.userview.UserCourseEnvironmentImpl in project OpenOLAT by OpenOLAT.
the class CourseSite method createController.
@Override
protected MainLayoutController createController(UserRequest ureq, WindowControl wControl, SiteConfiguration config) {
RepositoryManager rm = RepositoryManager.getInstance();
RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
RepositoryEntry entry = rm.lookupRepositoryEntryBySoftkey(repositorySoftKey, false);
if (entry == null) {
return getAlternativeController(ureq, wControl, config);
}
MainLayoutController c;
ICourse course = CourseFactory.loadCourse(entry);
UserSession usess = ureq.getUserSession();
// course-launch-state depending course-settings
RepositoryEntrySecurity reSecurity = rm.isAllowed(ureq, entry);
boolean isAllowedToLaunch = reSecurity.canLaunch();
boolean hasAccess = false;
if (isAllowedToLaunch) {
// either check with securityCallback or use access-settings from course-nodes
if (siteSecCallback != null) {
hasAccess = siteSecCallback.isAllowedToLaunchSite(ureq);
} else if (usess.isInAssessmentModeProcess() && !usess.matchLockResource(course)) {
hasAccess = false;
} else {
// check within course: accessibility of course root node
CourseNode rootNode = course.getRunStructure().getRootNode();
UserCourseEnvironmentImpl uce = new UserCourseEnvironmentImpl(ureq.getUserSession().getIdentityEnvironment(), course.getCourseEnvironment());
NodeEvaluation nodeEval = rootNode.eval(uce.getConditionInterpreter(), new TreeEvaluation(), new VisibleTreeFilter());
boolean mayAccessWholeTreeUp = NavigationHandler.mayAccessWholeTreeUp(nodeEval);
hasAccess = mayAccessWholeTreeUp && nodeEval.isVisible();
}
}
// load course (admins always see content) or alternative controller if course is not launchable
if (hasAccess || usess.getRoles().isOLATAdmin()) {
rs.incrementLaunchCounter(entry);
// build up the context path for linked course
WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ureq, entry, new StateSite(this), wControl, true);
CourseRuntimeController runCtr = new CourseRuntimeController(ureq, bwControl, entry, reSecurity, new RuntimeControllerCreator() {
@Override
public Controller create(UserRequest uureq, WindowControl wwControl, TooledStackedPanel toolbarPanel, RepositoryEntry re, RepositoryEntrySecurity security, AssessmentMode assessmentMode) {
return new RunMainController(uureq, wwControl, toolbarPanel, CourseFactory.loadCourse(re), re, security, assessmentMode);
}
}, false, true);
// Configure run controller
// a: don't show close link, is opened as site not tab
runCtr.setCourseCloseEnabled(false);
// b: don't show toolbar
if (!showToolController) {
runCtr.setToolControllerEnabled(false);
}
c = runCtr;
} else {
// access restricted (not in group / author) -> show controller
// defined in olat_extensions (type autoCreator)
c = getAlternativeController(ureq, wControl, config);
}
return c;
}
use of org.olat.course.run.userview.UserCourseEnvironmentImpl in project OpenOLAT by OpenOLAT.
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.course.run.userview.UserCourseEnvironmentImpl in project OpenOLAT by OpenOLAT.
the class AssessmentManagerTest method checkEfficiencyStatementManager.
/**
* This assumes that the student identity has scoreEvaluation information stored into the o_property
* for at least one test node into the "Demo course".
* It tests the EfficiencyStatementManager methods.
*/
private void checkEfficiencyStatementManager() {
log.info("Start testUpdateEfficiencyStatement");
List<Identity> identitiyList = new ArrayList<Identity>();
identitiyList.add(student);
Long courseResId = course.getCourseEnvironment().getCourseResourceableId();
RepositoryEntry courseRepositoryEntry = RepositoryManager.getInstance().lookupRepositoryEntry(OresHelper.createOLATResourceableInstance(CourseModule.class, courseResId), false);
assertNotNull(courseRepositoryEntry);
// check the stored EfficiencyStatement
EfficiencyStatement efficiencyStatement = checkEfficiencyStatement(courseRepositoryEntry);
// force the storing of the efficiencyStatement - this is usually done only at Learnresource/modify properties/Efficiency statement (ON)
efficiencyStatementManager.updateEfficiencyStatements(courseRepositoryEntry, identitiyList);
DBFactory.getInstance().closeSession();
// archive the efficiencyStatement into a temporary dir
try {
File archiveDir = File.createTempFile("junit", "output");
if (archiveDir.exists()) {
archiveDir.delete();
if (archiveDir.mkdir()) {
efficiencyStatementManager.archiveUserData(student, archiveDir);
log.info("Archived EfficiencyStatement path: " + archiveDir.getAbsolutePath());
}
}
} catch (IOException e) {
log.error("", e);
}
// delete the efficiencyStatements for the current course
efficiencyStatementManager.deleteEfficiencyStatementsFromCourse(courseRepositoryEntry.getKey());
DBFactory.getInstance().closeSession();
efficiencyStatement = efficiencyStatementManager.getUserEfficiencyStatementByCourseRepositoryEntry(courseRepositoryEntry, student);
DBFactory.getInstance().closeSession();
assertNull(efficiencyStatement);
// updateUserEfficiencyStatement of the student identity
IdentityEnvironment ienv = new IdentityEnvironment();
ienv.setIdentity(student);
UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
efficiencyStatementManager.updateUserEfficiencyStatement(userCourseEnv);
DBFactory.getInstance().closeSession();
// check again the stored EfficiencyStatement
efficiencyStatement = checkEfficiencyStatement(courseRepositoryEntry);
// delete the efficiencyStatement of the student
efficiencyStatementManager.deleteEfficientyStatement(student);
DBFactory.getInstance().closeSession();
efficiencyStatement = efficiencyStatementManager.getUserEfficiencyStatementByCourseRepositoryEntry(courseRepositoryEntry, student);
DBFactory.getInstance().closeSession();
assertNull(efficiencyStatement);
}
Aggregations