Search in sources :

Example 21 with Identity

use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.

the class UserSessionManager method getUserSessionForGui.

/**
 * Lookup non-webdav, non-REST UserSession for identity key.
 * @param identityKey
 * @return user-session or null when no session was founded.
 */
private UserSession getUserSessionForGui(Long identityKey) {
    UserSession identitySession = null;
    if (identityKey != null) {
        // do not call from somewhere else then signOffAndClear!!
        Optional<UserSession> optionalSession = authUserSessions.stream().filter(userSession -> {
            Identity identity = userSession.getIdentity();
            if (identity != null && identityKey.equals(identity.getKey()) && userSession.getSessionInfo() != null && !userSession.getSessionInfo().isWebDAV() && !userSession.getSessionInfo().isREST()) {
                return true;
            }
            return false;
        }).findFirst();
        identitySession = optionalSession.isPresent() ? optionalSession.get() : null;
    }
    return identitySession;
}
Also used : IdentityEnvironment(org.olat.core.id.IdentityEnvironment) SignOnOffEvent(org.olat.core.util.SignOnOffEvent) AssertException(org.olat.core.logging.AssertException) Settings(org.olat.core.helpers.Settings) CoreLoggingResourceable(org.olat.core.logging.activity.CoreLoggingResourceable) Preferences(org.olat.core.util.prefs.Preferences) CacheWrapper(org.olat.core.util.cache.CacheWrapper) Autowired(org.springframework.beans.factory.annotation.Autowired) ThreadLocalUserActivityLogger(org.olat.core.logging.activity.ThreadLocalUserActivityLogger) ThreadLocalUserActivityLoggerInstaller(org.olat.core.logging.activity.ThreadLocalUserActivityLoggerInstaller) TreeSet(java.util.TreeSet) UserSession(org.olat.core.util.UserSession) HashSet(java.util.HashSet) Event(org.olat.core.gui.control.Event) OLATResourceable(org.olat.core.id.OLATResourceable) HttpServletRequest(javax.servlet.http.HttpServletRequest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GenericEventListener(org.olat.core.util.event.GenericEventListener) OresHelper(org.olat.core.util.resource.OresHelper) SessionInfo(org.olat.core.util.SessionInfo) Service(org.springframework.stereotype.Service) Disposable(org.olat.core.gui.control.Disposable) OLog(org.olat.core.logging.OLog) UserActivityLoggerImpl(org.olat.core.logging.activity.UserActivityLoggerImpl) HttpSession(javax.servlet.http.HttpSession) Iterator(java.util.Iterator) OlatLoggingAction(org.olat.core.logging.activity.OlatLoggingAction) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) List(java.util.List) DB(org.olat.core.commons.persistence.DB) Identity(org.olat.core.id.Identity) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) Comparator(java.util.Comparator) Tracing(org.olat.core.logging.Tracing) CoordinatorManager(org.olat.core.util.coordinate.CoordinatorManager) Roles(org.olat.core.id.Roles) HistoryManager(org.olat.core.id.context.HistoryManager) UserSession(org.olat.core.util.UserSession) Identity(org.olat.core.id.Identity)

Example 22 with Identity

use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.

the class UserSessionManager method internSignOffAndClear.

private void internSignOffAndClear(UserSession usess) {
    boolean isDebug = log.isDebug();
    if (isDebug)
        log.debug("signOffAndClear() START");
    signOffAndClearWithout(usess);
    // handle safely
    try {
        if (usess.isAuthenticated()) {
            SessionInfo sessionInfo = usess.getSessionInfo();
            IdentityEnvironment identityEnvironment = usess.getIdentityEnvironment();
            Identity identity = identityEnvironment.getIdentity();
            log.audit("Logged off: " + sessionInfo);
            CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new SignOnOffEvent(identity, false), ORES_USERSESSION);
            if (isDebug)
                log.debug("signOffAndClear() deregistering usersession from eventbus, id=" + sessionInfo);
            // fxdiff FXOLAT-231: event on GUI Preferences extern changes
            OLATResourceable ores = OresHelper.createOLATResourceableInstance(Preferences.class, identity.getKey());
            CoordinatorManager.getInstance().getCoordinator().getEventBus().deregisterFor(usess, ores);
        }
    } catch (Exception e) {
        log.error("exception in signOffAndClear: while sending signonoffevent!", e);
    }
    // clear all instance variables, set authenticated to false
    usess.init();
    if (isDebug)
        log.debug("signOffAndClear() END");
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) SignOnOffEvent(org.olat.core.util.SignOnOffEvent) SessionInfo(org.olat.core.util.SessionInfo) Identity(org.olat.core.id.Identity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) AssertException(org.olat.core.logging.AssertException)

Example 23 with Identity

use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.

the class BulkAssessmentTask method processReturnFile.

private void processReturnFile(AssessableCourseNode courseNode, BulkAssessmentRow row, UserCourseEnvironment uce, File assessedFolder) {
    String assessedId = row.getAssessedId();
    Identity identity = uce.getIdentityEnvironment().getIdentity();
    VFSContainer returnBox = getReturnBox(uce, courseNode, identity);
    if (returnBox != null) {
        for (String returnFilename : row.getReturnFiles()) {
            File returnFile = new File(assessedFolder, returnFilename);
            VFSItem currentReturnLeaf = returnBox.resolve(returnFilename);
            if (currentReturnLeaf != null) {
                // remove the current file (delete make a version if it is enabled)
                currentReturnLeaf.delete();
            }
            VFSLeaf returnLeaf = returnBox.createChildLeaf(returnFilename);
            if (returnFile.exists()) {
                try {
                    InputStream inStream = new FileInputStream(returnFile);
                    VFSManager.copyContent(inStream, returnLeaf);
                } catch (FileNotFoundException e) {
                    log.error("Cannot copy return file " + returnFilename + " from " + assessedId, e);
                }
            }
        }
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) FileNotFoundException(java.io.FileNotFoundException) VFSItem(org.olat.core.util.vfs.VFSItem) Identity(org.olat.core.id.Identity) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 24 with Identity

use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.

the class BulkAssessmentTask method updateTasksState.

private void updateTasksState(GTACourseNode courseNode, UserCourseEnvironment uce, TaskProcess status) {
    final GTAManager gtaManager = CoreSpringFactory.getImpl(GTAManager.class);
    Identity identity = uce.getIdentityEnvironment().getIdentity();
    RepositoryEntry entry = uce.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    org.olat.course.nodes.gta.Task gtaTask;
    TaskList taskList = gtaManager.getTaskList(entry, courseNode);
    if (taskList == null) {
        taskList = gtaManager.createIfNotExists(entry, courseNode);
        gtaTask = gtaManager.createTask(null, taskList, status, null, identity, courseNode);
    } else {
        gtaTask = gtaManager.getTask(identity, taskList);
        if (gtaTask == null) {
            gtaManager.createTask(null, taskList, status, null, identity, courseNode);
        }
    }
    gtaManager.nextStep(status, courseNode);
}
Also used : TaskList(org.olat.course.nodes.gta.TaskList) GTAManager(org.olat.course.nodes.gta.GTAManager) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity)

Example 25 with Identity

use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.

the class BulkAssessmentTask method sendFeedback.

private void sendFeedback(List<BulkAssessmentFeedback> feedbacks) {
    if (task == null) {
        log.error("Haven't a task to know creator and modifiers of the task", null);
        return;
    }
    Identity creator = task.getCreator();
    String language = creator.getUser().getPreferences().getLanguage();
    Locale locale = I18nManager.getInstance().getLocaleOrDefault(language);
    Translator translator = Util.createPackageTranslator(BulkAssessmentOverviewController.class, locale, Util.createPackageTranslator(AssessmentManager.class, locale));
    MailManager mailManager = CoreSpringFactory.getImpl(MailManager.class);
    TaskExecutorManager taskManager = CoreSpringFactory.getImpl(TaskExecutorManager.class);
    String feedbackStr = renderFeedback(feedbacks, translator);
    MailBundle mail = new MailBundle();
    mail.setToId(creator);
    mail.setFrom(WebappHelper.getMailConfig("mailReplyTo"));
    List<Identity> modifiers = taskManager.getModifiers(task);
    if (modifiers.size() > 0) {
        ContactList cc = new ContactList("CC");
        cc.addAllIdentites(modifiers);
        mail.setContactList(cc);
    }
    String businessPath = "";
    ICourse course = CourseFactory.loadCourse(courseRes);
    CourseNode node = course.getRunStructure().getNode(courseNodeIdent);
    String courseTitle = course.getCourseTitle();
    String nodeTitle = node.getShortTitle();
    String numOfAssessedIds = Integer.toString(datas == null ? 0 : datas.getRowsSize());
    String date = Formatter.getInstance(locale).formatDateAndTime(new Date());
    mail.setContext(new MailContextImpl(courseRes, courseNodeIdent, businessPath));
    String subject = translator.translate("confirmation.mail.subject", new String[] { courseTitle, nodeTitle });
    String body = translator.translate("confirmation.mail.body", new String[] { courseTitle, nodeTitle, feedbackStr, numOfAssessedIds, date });
    mail.setContent(subject, body);
    mailManager.sendMessage(mail);
}
Also used : Locale(java.util.Locale) TaskExecutorManager(org.olat.core.commons.services.taskexecutor.TaskExecutorManager) MailContextImpl(org.olat.core.util.mail.MailContextImpl) AssessmentManager(org.olat.course.assessment.AssessmentManager) ICourse(org.olat.course.ICourse) ContactList(org.olat.core.util.mail.ContactList) Date(java.util.Date) Translator(org.olat.core.gui.translator.Translator) MailManager(org.olat.core.util.mail.MailManager) CourseNode(org.olat.course.nodes.CourseNode) TACourseNode(org.olat.course.nodes.TACourseNode) GTACourseNode(org.olat.course.nodes.GTACourseNode) MSCourseNode(org.olat.course.nodes.MSCourseNode) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) ProjectBrokerCourseNode(org.olat.course.nodes.ProjectBrokerCourseNode) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle)

Aggregations

Identity (org.olat.core.id.Identity)3749 Test (org.junit.Test)1956 RepositoryEntry (org.olat.repository.RepositoryEntry)898 BusinessGroup (org.olat.group.BusinessGroup)560 ArrayList (java.util.ArrayList)550 Date (java.util.Date)312 URI (java.net.URI)272 ICourse (org.olat.course.ICourse)266 HttpResponse (org.apache.http.HttpResponse)260 File (java.io.File)211 AssessmentManager (org.olat.course.assessment.AssessmentManager)210 Path (javax.ws.rs.Path)182 OLATResource (org.olat.resource.OLATResource)172 OLATResourceable (org.olat.core.id.OLATResourceable)156 Roles (org.olat.core.id.Roles)154 HashMap (java.util.HashMap)151 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)142 HashSet (java.util.HashSet)136 List (java.util.List)132 Produces (javax.ws.rs.Produces)130