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;
}
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");
}
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);
}
}
}
}
}
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);
}
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);
}
Aggregations