use of org.olat.core.gui.translator.Translator in project OpenOLAT by OpenOLAT.
the class MailHelper method getTranslator.
/**
* Helper method to reuse translators. It makes no sense to build a new
* translator over and over again. We keep one for each language and reuse
* this one during the whole lifetime
*
* @param locale
* @return a translator for the given locale
*/
private static Translator getTranslator(Locale locale) {
String ident = locale.toString();
synchronized (translators) {
// o_clusterok brasato:::: nice idea, but move to translatorfactory and kick out translator.setLocale() (move it to LocaleChangableTranslator)
Translator trans = translators.get(ident);
if (trans == null) {
trans = Util.createPackageTranslator(MailHelper.class, locale);
translators.put(ident, trans);
}
return trans;
}
}
use of org.olat.core.gui.translator.Translator in project OpenOLAT by OpenOLAT.
the class ModifyCourseEvent method createEditorController.
/**
* Create an editor controller for the given course resourceable
*
* @param ureq
* @param wControl
* @param courseEntry
* @return editor controller for the given course resourceable; if the editor
* is already locked, it returns a controller with a lock message
*/
public static EditorMainController createEditorController(UserRequest ureq, WindowControl wControl, TooledStackedPanel toolbar, RepositoryEntry courseEntry, CourseNode selectedNode) {
ICourse course = loadCourse(courseEntry);
EditorMainController emc = new EditorMainController(ureq, wControl, toolbar, course, selectedNode);
if (emc.getLockEntry() == null) {
Translator translator = Util.createPackageTranslator(RunMainController.class, ureq.getLocale());
wControl.setWarning(translator.translate("error.editoralreadylocked", new String[] { "?" }));
return null;
} else if (!emc.getLockEntry().isSuccess()) {
// get i18n from the course runmaincontroller to say that this editor is
// already locked by another person
Translator translator = Util.createPackageTranslator(RunMainController.class, ureq.getLocale());
String lockerName = CoreSpringFactory.getImpl(UserManager.class).getUserDisplayName(emc.getLockEntry().getOwner());
wControl.setWarning(translator.translate("error.editoralreadylocked", new String[] { lockerName }));
return null;
}
// set the logger if editor is started
// since 5.2 groups / areas can be created from the editor -> should be logged.
emc.addLoggingResourceable(LoggingResourceable.wrap(course));
return emc;
}
use of org.olat.core.gui.translator.Translator 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);
}
use of org.olat.core.gui.translator.Translator in project OpenOLAT by OpenOLAT.
the class ScoreAccountingHelper method createCourseResultsOverviewXMLTable.
/**
* The results from assessable nodes are written to one row per user into an excel-sheet. An
* assessable node will only appear if it is producing at least one of the
* following variables: score, passed, attempts, comments.
*
* @param identities The list of identities which results need to be archived.
* @param myNodes The assessable nodes to archive.
* @param course The course.
* @param locale The locale.
* @param bos The output stream (which will be closed at the end, if you use a zip stream don't forget to shield it).
*/
public static void createCourseResultsOverviewXMLTable(List<Identity> identities, List<AssessableCourseNode> myNodes, ICourse course, Locale locale, OutputStream bos) {
OpenXMLWorkbook workbook = new OpenXMLWorkbook(bos, 1);
OpenXMLWorksheet sheet = workbook.nextWorksheet();
sheet.setHeaderRows(2);
int headerColCnt = 0;
Translator t = Util.createPackageTranslator(ScoreAccountingArchiveController.class, locale);
String sequentialNumber = t.translate("column.header.seqnum");
String login = t.translate("column.header.businesspath");
// user properties are dynamic
String sc = t.translate("column.header.score");
String pa = t.translate("column.header.passed");
String co = t.translate("column.header.comment");
String cco = t.translate("column.header.coachcomment");
String at = t.translate("column.header.attempts");
String il = t.translate("column.header.initialLaunchDate");
String slm = t.translate("column.header.scoreLastModified");
String na = t.translate("column.field.notavailable");
String mi = t.translate("column.field.missing");
String yes = t.translate("column.field.yes");
String no = t.translate("column.field.no");
String submitted = t.translate("column.field.submitted");
Row headerRow1 = sheet.newRow();
headerRow1.addCell(headerColCnt++, sequentialNumber);
headerRow1.addCell(headerColCnt++, login);
// Initial launch date
headerRow1.addCell(headerColCnt++, il);
// get user property handlers for this export, translate using the fallback
// translator configured in the property handler
List<UserPropertyHandler> userPropertyHandlers = UserManager.getInstance().getUserPropertyHandlersFor(ScoreAccountingHelper.class.getCanonicalName(), true);
t = UserManager.getInstance().getPropertyHandlerTranslator(t);
for (UserPropertyHandler propertyHandler : userPropertyHandlers) {
headerRow1.addCell(headerColCnt++, t.translate(propertyHandler.i18nColumnDescriptorLabelKey()));
}
int header1ColCnt = headerColCnt;
for (AssessableCourseNode acNode : myNodes) {
headerRow1.addCell(header1ColCnt++, acNode.getShortTitle());
header1ColCnt += acNode.getType().equals("ita") ? 1 : 0;
boolean scoreOk = acNode.hasScoreConfigured();
boolean passedOk = acNode.hasPassedConfigured();
boolean attemptsOk = acNode.hasAttemptsConfigured();
boolean commentOk = acNode.hasCommentConfigured();
if (scoreOk || passedOk || commentOk || attemptsOk) {
header1ColCnt += scoreOk ? 1 : 0;
header1ColCnt += passedOk ? 1 : 0;
header1ColCnt += attemptsOk ? 1 : 0;
// last modified
header1ColCnt++;
header1ColCnt += commentOk ? 1 : 0;
// coach comment
header1ColCnt++;
}
// column title
header1ColCnt--;
}
int header2ColCnt = headerColCnt;
Row headerRow2 = sheet.newRow();
for (AssessableCourseNode acNode : myNodes) {
if (acNode.getType().equals("ita")) {
headerRow2.addCell(header2ColCnt++, submitted);
}
boolean scoreOk = acNode.hasScoreConfigured();
boolean passedOk = acNode.hasPassedConfigured();
boolean attemptsOk = acNode.hasAttemptsConfigured();
boolean commentOk = acNode.hasCommentConfigured();
if (scoreOk || passedOk || commentOk || attemptsOk) {
if (scoreOk) {
headerRow2.addCell(header2ColCnt++, sc);
}
if (passedOk) {
headerRow2.addCell(header2ColCnt++, pa);
}
if (attemptsOk) {
headerRow2.addCell(header2ColCnt++, at);
}
// last modified
headerRow2.addCell(header2ColCnt++, slm);
if (commentOk) {
headerRow2.addCell(header2ColCnt++, co);
}
// coach comment
headerRow2.addCell(header2ColCnt++, cco);
}
}
// preload user properties cache
CourseEnvironment courseEnvironment = course.getCourseEnvironment();
int rowNumber = 0;
DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm");
UserCourseInformationsManager mgr = CoreSpringFactory.getImpl(UserCourseInformationsManager.class);
OLATResource courseResource = courseEnvironment.getCourseGroupManager().getCourseResource();
Map<Long, Date> firstTimes = mgr.getInitialLaunchDates(courseResource, identities);
for (Identity identity : identities) {
Row dataRow = sheet.newRow();
int dataColCnt = 0;
ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(identity);
String uname = BusinessControlFactory.getInstance().getAsURIString(Collections.singletonList(ce), false);
dataRow.addCell(dataColCnt++, ++rowNumber, null);
dataRow.addCell(dataColCnt++, uname, null);
if (firstTimes.containsKey(identity.getKey())) {
dataRow.addCell(dataColCnt++, firstTimes.get(identity.getKey()), workbook.getStyles().getDateStyle());
} else {
dataRow.addCell(dataColCnt++, mi);
}
// add dynamic user properties
for (UserPropertyHandler propertyHandler : userPropertyHandlers) {
String value = propertyHandler.getUserProperty(identity.getUser(), t.getLocale());
dataRow.addCell(dataColCnt++, (StringHelper.containsNonWhitespace(value) ? value : na));
}
// create a identenv with no roles, no attributes, no locale
IdentityEnvironment ienv = new IdentityEnvironment();
ienv.setIdentity(identity);
UserCourseEnvironment uce = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
ScoreAccounting scoreAccount = uce.getScoreAccounting();
scoreAccount.evaluateAll();
AssessmentManager am = course.getCourseEnvironment().getAssessmentManager();
for (AssessableCourseNode acnode : myNodes) {
boolean scoreOk = acnode.hasScoreConfigured();
boolean passedOk = acnode.hasPassedConfigured();
boolean attemptsOk = acnode.hasAttemptsConfigured();
boolean commentOk = acnode.hasCommentConfigured();
if (acnode.getType().equals("ita")) {
String log = acnode.getUserLog(uce);
String date = null;
Date lastUploaded = null;
try {
log = log.toLowerCase();
log = log.substring(0, log.lastIndexOf("submit"));
log = log.substring(log.lastIndexOf("date:"));
date = log.split("\n")[0].substring(6);
lastUploaded = df.parse(date);
} catch (Exception e) {
//
}
if (lastUploaded != null) {
dataRow.addCell(dataColCnt++, lastUploaded, workbook.getStyles().getDateStyle());
} else {
// date == null
dataRow.addCell(dataColCnt++, mi);
}
}
if (scoreOk || passedOk || commentOk || attemptsOk) {
ScoreEvaluation se = scoreAccount.evalCourseNode(acnode);
if (scoreOk) {
Float score = se.getScore();
if (score != null) {
dataRow.addCell(dataColCnt++, AssessmentHelper.getRoundedScore(score), null);
} else {
// score == null
dataRow.addCell(dataColCnt++, mi);
}
}
if (passedOk) {
Boolean passed = se.getPassed();
if (passed != null) {
String yesno;
if (passed.booleanValue()) {
yesno = yes;
} else {
yesno = no;
}
dataRow.addCell(dataColCnt++, yesno);
} else {
// passed == null
dataRow.addCell(dataColCnt++, mi);
}
}
if (attemptsOk) {
Integer attempts = am.getNodeAttempts(acnode, identity);
int a = attempts == null ? 0 : attempts.intValue();
dataRow.addCell(dataColCnt++, a, null);
}
Date lastModified = am.getScoreLastModifiedDate(acnode, identity);
if (lastModified != null) {
dataRow.addCell(dataColCnt++, lastModified, workbook.getStyles().getDateStyle());
} else {
dataRow.addCell(dataColCnt++, mi);
}
if (commentOk) {
// Comments for user
String comment = am.getNodeComment(acnode, identity);
if (comment != null) {
dataRow.addCell(dataColCnt++, comment);
} else {
dataRow.addCell(dataColCnt++, mi);
}
}
// Always export comments for tutors
String coachComment = am.getNodeCoachComment(acnode, identity);
if (coachComment != null) {
dataRow.addCell(dataColCnt++, coachComment);
} else {
dataRow.addCell(dataColCnt++, mi);
}
}
}
}
// min. max. informations
boolean first = true;
for (AssessableCourseNode acnode : myNodes) {
if (!acnode.hasScoreConfigured()) {
// only show min/max/cut legend when score configured
continue;
}
if (first) {
sheet.newRow().addCell(0, "");
sheet.newRow().addCell(0, "");
sheet.newRow().addCell(0, t.translate("legend"));
sheet.newRow().addCell(0, "");
first = false;
}
String minVal;
String maxVal;
String cutVal;
if (acnode instanceof STCourseNode || !acnode.hasScoreConfigured()) {
minVal = maxVal = cutVal = "-";
} else {
minVal = acnode.getMinScoreConfiguration() == null ? "-" : AssessmentHelper.getRoundedScore(acnode.getMinScoreConfiguration());
maxVal = acnode.getMaxScoreConfiguration() == null ? "-" : AssessmentHelper.getRoundedScore(acnode.getMaxScoreConfiguration());
if (acnode.hasPassedConfigured()) {
cutVal = acnode.getCutValueConfiguration() == null ? "-" : AssessmentHelper.getRoundedScore(acnode.getCutValueConfiguration());
} else {
cutVal = "-";
}
}
sheet.newRow().addCell(0, acnode.getShortTitle());
Row minRow = sheet.newRow();
minRow.addCell(2, "minValue");
minRow.addCell(3, minVal);
Row maxRow = sheet.newRow();
maxRow.addCell(2, "maxValue");
maxRow.addCell(3, maxVal);
Row cutRow = sheet.newRow();
cutRow.addCell(2, "cutValue");
cutRow.addCell(3, cutVal);
}
IOUtils.closeQuietly(workbook);
}
use of org.olat.core.gui.translator.Translator in project OpenOLAT by OpenOLAT.
the class CertificationNotificationHandler method createSubscriptionInfo.
@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
SubscriptionInfo si = null;
Publisher p = subscriber.getPublisher();
if (!NotificationsUpgradeHelper.checkCourse(p)) {
// course don't exist anymore
NotificationsManager.getInstance().deactivate(p);
return NotificationsManager.getInstance().getNoSubscriptionInfo();
}
try {
Date latestNews = p.getLatestNewsDate();
Identity identity = subscriber.getIdentity();
Translator trans = Util.createPackageTranslator(CertificateController.class, locale);
// can't be loaded when already deleted
if (NotificationsManager.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
Long courseId = new Long(p.getData());
final ICourse course = CourseFactory.loadCourse(courseId);
if (courseStatus(course)) {
// course admins or users with the course right to have full access to
// the assessment tool will have full access to user tests
RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
List<Certificate> certificates = certificatesManager.getCertificatesForNotifications(identity, entry, latestNews);
for (Certificate certificate : certificates) {
Date modDate = certificate.getCreationDate();
Identity assessedIdentity = certificate.getIdentity();
String fullname = userManager.getUserDisplayName(assessedIdentity);
String desc = trans.translate("notifications.desc", new String[] { fullname });
String urlToSend = null;
String businessPath = null;
if (p.getBusinessPath() != null) {
businessPath = p.getBusinessPath() + "[assessmentTool:0][Identity:" + assessedIdentity.getKey() + "]";
urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
}
SubscriptionListItem subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, "o_icon_certificate");
if (si == null) {
String title = trans.translate("notifications.header", new String[] { course.getCourseTitle() });
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(title, "o_icon_certificate"), null);
}
si.addSubscriptionListItem(subListItem);
}
}
}
if (si == null) {
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
return si;
} catch (Exception e) {
log.error("Error while creating assessment notifications", e);
return NotificationsManager.getInstance().getNoSubscriptionInfo();
}
}
Aggregations