Search in sources :

Example 86 with IdentityEnvironment

use of org.olat.core.id.IdentityEnvironment in project openolat by klemens.

the class UserCalendarWebService method getCalendars.

private void getCalendars(CalendarVisitor calVisitor, UserRequest ureq) {
    Roles roles = ureq.getUserSession().getRoles();
    Identity retrievedUser = ureq.getIdentity();
    CalendarModule calendarModule = CoreSpringFactory.getImpl(CalendarModule.class);
    if (calendarModule.isEnabled()) {
        if (calendarModule.isEnablePersonalCalendar()) {
            KalendarRenderWrapper personalWrapper = getPersonalCalendar(ureq.getIdentity());
            calVisitor.visit(personalWrapper);
        }
        if (calendarModule.isEnableCourseToolCalendar() || calendarModule.isEnableCourseElementCalendar()) {
            RepositoryManager rm = RepositoryManager.getInstance();
            ACService acManager = CoreSpringFactory.getImpl(ACService.class);
            SearchRepositoryEntryParameters repoParams = new SearchRepositoryEntryParameters(retrievedUser, roles, "CourseModule");
            repoParams.setOnlyExplicitMember(true);
            repoParams.setIdentity(retrievedUser);
            IdentityEnvironment ienv = new IdentityEnvironment();
            ienv.setIdentity(retrievedUser);
            ienv.setRoles(roles);
            List<RepositoryEntry> entries = rm.genericANDQueryWithRolesRestriction(repoParams, 0, -1, true);
            for (RepositoryEntry entry : entries) {
                AccessResult result = acManager.isAccessible(entry, retrievedUser, false);
                if (result.isAccessible()) {
                    try {
                        final ICourse course = CourseFactory.loadCourse(entry);
                        CourseConfig config = course.getCourseEnvironment().getCourseConfig();
                        UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
                        if (config.isCalendarEnabled()) {
                            KalendarRenderWrapper wrapper = CourseCalendars.getCourseCalendarWrapper(ureq, userCourseEnv, null);
                            calVisitor.visit(wrapper);
                        } else {
                            CalCourseNodeVisitor visitor = new CalCourseNodeVisitor();
                            new CourseTreeVisitor(course, ienv).visit(visitor, new VisibleTreeFilter());
                            if (visitor.isFound()) {
                                KalendarRenderWrapper wrapper = CourseCalendars.getCourseCalendarWrapper(ureq, userCourseEnv, null);
                                calVisitor.visit(wrapper);
                            }
                        }
                    } catch (Exception e) {
                        log.error("", e);
                    }
                }
            }
        }
        if (calendarModule.isEnableGroupCalendar()) {
            CollaborationManager collaborationManager = CoreSpringFactory.getImpl(CollaborationManager.class);
            // start found forums in groups
            BusinessGroupService bgm = CoreSpringFactory.getImpl(BusinessGroupService.class);
            SearchBusinessGroupParams params = new SearchBusinessGroupParams(retrievedUser, true, true);
            params.addTools(CollaborationTools.TOOL_CALENDAR);
            List<BusinessGroup> groups = bgm.findBusinessGroups(params, null, 0, -1);
            for (BusinessGroup group : groups) {
                KalendarRenderWrapper wrapper = collaborationManager.getCalendar(group, ureq, false);
                calVisitor.visit(wrapper);
            }
        }
    }
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) BusinessGroup(org.olat.group.BusinessGroup) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) Roles(org.olat.core.id.Roles) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) WebApplicationException(javax.ws.rs.WebApplicationException) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) CourseConfig(org.olat.course.config.CourseConfig) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) BusinessGroupService(org.olat.group.BusinessGroupService) ACService(org.olat.resource.accesscontrol.ACService) AccessResult(org.olat.resource.accesscontrol.AccessResult) CalendarModule(org.olat.commons.calendar.CalendarModule) RepositoryManager(org.olat.repository.RepositoryManager) Identity(org.olat.core.id.Identity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) CollaborationManager(org.olat.collaboration.CollaborationManager)

Example 87 with IdentityEnvironment

use of org.olat.core.id.IdentityEnvironment in project openolat by klemens.

the class IdentityCertificatesController method doGenerateCertificate.

private void doGenerateCertificate(UserRequest ureq) {
    ICourse course = CourseFactory.loadCourse(courseEntry);
    CourseNode rootNode = course.getRunStructure().getRootNode();
    Roles roles = securityManager.getRoles(assessedIdentity);
    IdentityEnvironment identityEnv = new IdentityEnvironment(assessedIdentity, roles);
    UserCourseEnvironment assessedUserCourseEnv = new UserCourseEnvironmentImpl(identityEnv, course.getCourseEnvironment());
    ScoreAccounting scoreAccounting = assessedUserCourseEnv.getScoreAccounting();
    scoreAccounting.evaluateAll();
    ScoreEvaluation scoreEval = scoreAccounting.evalCourseNode((AssessableCourseNode) rootNode);
    CertificateTemplate template = null;
    Long templateKey = course.getCourseConfig().getCertificateTemplate();
    if (templateKey != null) {
        template = certificatesManager.getTemplateById(templateKey);
    }
    Float score = scoreEval == null ? null : scoreEval.getScore();
    Boolean passed = scoreEval == null ? null : scoreEval.getPassed();
    CertificateInfos certificateInfos = new CertificateInfos(assessedIdentity, score, passed);
    certificatesManager.generateCertificate(certificateInfos, courseEntry, template, true);
    loadList();
    showInfo("msg.certificate.pending");
    fireEvent(ureq, Event.CHANGED_EVENT);
}
Also used : ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) CertificateTemplate(org.olat.course.certificate.CertificateTemplate) CertificateInfos(org.olat.course.certificate.model.CertificateInfos) ICourse(org.olat.course.ICourse) Roles(org.olat.core.id.Roles) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) ScoreAccounting(org.olat.course.run.scoring.ScoreAccounting) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) CourseNode(org.olat.course.nodes.CourseNode) IdentityEnvironment(org.olat.core.id.IdentityEnvironment)

Example 88 with IdentityEnvironment

use of org.olat.core.id.IdentityEnvironment in project openolat by klemens.

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 89 with IdentityEnvironment

use of org.olat.core.id.IdentityEnvironment in project openolat by klemens.

the class UserSession method init.

public void init() {
    store = new HashMap<String, Object>(4);
    identityEnvironment = new IdentityEnvironment();
    singleUserSystemBus = CoordinatorManager.getInstance().getCoordinator().createSingleUserInstance();
    authenticated = false;
    sessionInfo = null;
}
Also used : IdentityEnvironment(org.olat.core.id.IdentityEnvironment)

Example 90 with IdentityEnvironment

use of org.olat.core.id.IdentityEnvironment in project openolat by klemens.

the class UserSessionManager method signOn.

/**
 * prior to calling this method, all instance vars must be set.
 */
public void signOn(UserSession usess) {
    boolean isDebug = log.isDebug();
    // fix a possible dead-lock see also OLAT-3390
    synchronized (usess) {
        if (isDebug)
            log.debug("signOn() START");
        if (usess.isAuthenticated()) {
            throw new AssertException("sign on: already signed on!");
        }
        IdentityEnvironment identityEnvironment = usess.getIdentityEnvironment();
        Identity identity = identityEnvironment.getIdentity();
        if (identity == null) {
            throw new AssertException("identity is null in identityEnvironment!");
        }
        SessionInfo sessionInfo = usess.getSessionInfo();
        if (sessionInfo == null) {
            throw new AssertException("sessionInfo was null for identity " + identity);
        }
        usess.setAuthenticated(true);
        if (sessionInfo.isWebDAV()) {
            // load user prefs
            usess.reloadPreferences();
            // we're only adding this webdav session to the authUserSessions - not to the userNameToIdentity.
            // userNameToIdentity is only needed for IM which can't do anything with a webdav session
            authUserSessions.add(usess);
            log.audit("Logged on [via webdav]: " + sessionInfo.toString());
        } else {
            UserSession invalidatedSession = null;
            if (isDebug) {
                log.debug("signOn() authUsersNamesOtherNodes.contains " + identity.getName() + ": " + authUsersNamesOtherNodes.contains(identity.getKey()));
            }
            // check if already a session exist for this user
            if ((userNameToIdentity.contains(identity.getKey()) || userSessionCache.containsKey(identity.getKey())) && !sessionInfo.isWebDAV() && !sessionInfo.isREST() && !usess.getRoles().isGuestOnly()) {
                log.info("Loggin-process II: User has already a session => signOffAndClear existing session");
                invalidatedSession = getUserSessionForGui(identity.getKey());
                // signOffAndClear does not remove the identity.getName().toLowerCase() from the userNameToIdentity
                if (invalidatedSession != null) {
                    authUserSessions.remove(invalidatedSession);
                }
            }
            authUserSessions.add(usess);
            // characters -> map stores values as such
            if (isDebug)
                log.debug("signOn() adding to userNameToIdentity: " + identity.getName().toLowerCase());
            userNameToIdentity.add(identity.getKey());
            userSessionCache.put(identity.getKey(), new Integer(Settings.getNodeId()));
            // reload user prefs
            usess.reloadPreferences();
            log.audit("Logged on: " + sessionInfo.toString());
            CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new SignOnOffEvent(identity, true), ORES_USERSESSION);
            // check if a session from any browser was invalidated (IE has a cookie set per Browserinstance!!)
            if (invalidatedSession != null || authUsersNamesOtherNodes.contains(identity.getKey())) {
                // put flag killed-existing-session into session-store to show info-message 'only one session for each user' on user-home screen
                usess.putEntry(STORE_KEY_KILLED_EXISTING_SESSION, Boolean.TRUE);
                if (isDebug)
                    log.debug("signOn() removing from authUsersNamesOtherNodes: " + identity.getName());
                authUsersNamesOtherNodes.remove(identity.getKey());
                // OLAT-3381 & OLAT-3382
                if (invalidatedSession != null) {
                    signOffAndClear(invalidatedSession);
                }
            }
            if (isDebug)
                log.debug("signOn() END");
        }
        // update logged in users counters
        if (sessionInfo.isREST()) {
            sessionCountRest.incrementAndGet();
        } else if (sessionInfo.isWebDAV()) {
            sessionCountDav.incrementAndGet();
        } else {
            sessionCountWeb.incrementAndGet();
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AssertException(org.olat.core.logging.AssertException) UserSession(org.olat.core.util.UserSession) SignOnOffEvent(org.olat.core.util.SignOnOffEvent) SessionInfo(org.olat.core.util.SessionInfo) Identity(org.olat.core.id.Identity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment)

Aggregations

IdentityEnvironment (org.olat.core.id.IdentityEnvironment)96 UserCourseEnvironmentImpl (org.olat.course.run.userview.UserCourseEnvironmentImpl)60 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)58 Identity (org.olat.core.id.Identity)56 ICourse (org.olat.course.ICourse)52 RepositoryEntry (org.olat.repository.RepositoryEntry)34 Roles (org.olat.core.id.Roles)30 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)22 ScoreEvaluation (org.olat.course.run.scoring.ScoreEvaluation)22 Test (org.junit.Test)20 VisibleTreeFilter (org.olat.course.run.userview.VisibleTreeFilter)20 CourseNode (org.olat.course.nodes.CourseNode)18 ArrayList (java.util.ArrayList)16 CourseTreeVisitor (org.olat.course.run.userview.CourseTreeVisitor)16 File (java.io.File)14 INode (org.olat.core.util.nodes.INode)12 Visitor (org.olat.core.util.tree.Visitor)12 VFSContainer (org.olat.core.util.vfs.VFSContainer)12 URL (java.net.URL)10 FOCourseNode (org.olat.course.nodes.FOCourseNode)10