Search in sources :

Example 6 with UserCourseEnvironmentImpl

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);
}
Also used : CalculatedAssessableCourseNode(org.olat.course.nodes.CalculatedAssessableCourseNode) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) AssessedIdentityElementRow(org.olat.modules.assessment.ui.AssessedIdentityElementRow) ICourse(org.olat.course.ICourse) Roles(org.olat.core.id.Roles) Identity(org.olat.core.id.Identity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment)

Example 7 with UserCourseEnvironmentImpl

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());
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) BusinessGroup(org.olat.group.BusinessGroup)

Example 8 with UserCourseEnvironmentImpl

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;
}
Also used : TooledStackedPanel(org.olat.core.gui.components.stack.TooledStackedPanel) AssessmentMode(org.olat.course.assessment.AssessmentMode) StateSite(org.olat.core.id.context.StateSite) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) RunMainController(org.olat.course.run.RunMainController) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) WindowControl(org.olat.core.gui.control.WindowControl) MainLayoutController(org.olat.core.gui.control.generic.layout.MainLayoutController) RunMainController(org.olat.course.run.RunMainController) CourseRuntimeController(org.olat.course.run.CourseRuntimeController) Controller(org.olat.core.gui.control.Controller) RuntimeControllerCreator(org.olat.repository.ui.RepositoryEntryRuntimeController.RuntimeControllerCreator) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) RepositoryEntrySecurity(org.olat.repository.model.RepositoryEntrySecurity) CourseRuntimeController(org.olat.course.run.CourseRuntimeController) UserSession(org.olat.core.util.UserSession) TreeEvaluation(org.olat.course.run.userview.TreeEvaluation) MainLayoutController(org.olat.core.gui.control.generic.layout.MainLayoutController) RepositoryManager(org.olat.repository.RepositoryManager) CourseNode(org.olat.course.nodes.CourseNode) NodeEvaluation(org.olat.course.run.userview.NodeEvaluation) UserRequest(org.olat.core.gui.UserRequest) RepositoryService(org.olat.repository.RepositoryService)

Example 9 with UserCourseEnvironmentImpl

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...");
}
Also used : ENCourseNode(org.olat.course.nodes.ENCourseNode) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager) Test(org.junit.Test)

Example 10 with UserCourseEnvironmentImpl

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);
}
Also used : UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) ArrayList(java.util.ArrayList) CourseModule(org.olat.course.CourseModule) RepositoryEntry(org.olat.repository.RepositoryEntry) IOException(java.io.IOException) Identity(org.olat.core.id.Identity) File(java.io.File) IdentityEnvironment(org.olat.core.id.IdentityEnvironment)

Aggregations

UserCourseEnvironmentImpl (org.olat.course.run.userview.UserCourseEnvironmentImpl)84 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)60 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)58 ICourse (org.olat.course.ICourse)40 Identity (org.olat.core.id.Identity)32 RepositoryEntry (org.olat.repository.RepositoryEntry)28 CourseNode (org.olat.course.nodes.CourseNode)24 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)22 ScoreEvaluation (org.olat.course.run.scoring.ScoreEvaluation)22 Roles (org.olat.core.id.Roles)14 ArrayList (java.util.ArrayList)12 NodeEvaluation (org.olat.course.run.userview.NodeEvaluation)12 VisibleTreeFilter (org.olat.course.run.userview.VisibleTreeFilter)12 IQTESTCourseNode (org.olat.course.nodes.IQTESTCourseNode)10 BusinessGroup (org.olat.group.BusinessGroup)10 VFSContainer (org.olat.core.util.vfs.VFSContainer)8 TreeEvaluation (org.olat.course.run.userview.TreeEvaluation)8 Test (org.junit.Test)7 WebApplicationException (javax.ws.rs.WebApplicationException)6 TreeNode (org.olat.core.gui.components.tree.TreeNode)6