use of org.olat.core.commons.services.notifications.NotificationsManager in project OpenOLAT by OpenOLAT.
the class PreferencesFormController method initForm.
/**
* @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#initForm(org.olat.core.gui.components.form.flexible.FormItemContainer,
* org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
*/
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
setFormTitle("title.prefs");
setFormContextHelp("Configuration#_einstellungen");
// load preferences
Preferences prefs = tobeChangedIdentity.getUser().getPreferences();
// Username
StaticTextElement username = uifactory.addStaticTextElement("form.username", tobeChangedIdentity.getName(), formLayout);
username.setElementCssClass("o_sel_home_settings_username");
username.setEnabled(false);
// Roles
final String[] roleKeys = new String[] { Constants.GROUP_USERMANAGERS, Constants.GROUP_GROUPMANAGERS, Constants.GROUP_POOL_MANAGER, Constants.GROUP_AUTHORS, Constants.GROUP_INST_ORES_MANAGER, Constants.GROUP_ADMIN };
String iname = getIdentity().getUser().getProperty("institutionalName", null);
String ilabel = iname != null ? translate("rightsForm.isInstitutionalResourceManager.institution", iname) : translate("rightsForm.isInstitutionalResourceManager");
final String[] roleValues = new String[] { translate("rightsForm.isUsermanager"), translate("rightsForm.isGroupmanager"), translate("rightsForm.isPoolmanager"), translate("rightsForm.isAuthor"), ilabel, translate("rightsForm.isAdmin") };
final BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
String userRoles = "";
List<String> roles = securityManager.getRolesAsString(tobeChangedIdentity);
for (String role : roles) {
for (int i = 0; i < roleKeys.length; i++) {
if (roleKeys[i].equals(role)) {
userRoles = userRoles + roleValues[i] + ", ";
}
}
}
if (userRoles.equals("")) {
userRoles = translate("rightsForm.isAnonymous.false");
} else {
userRoles = userRoles.substring(0, userRoles.lastIndexOf(","));
}
uifactory.addStaticTextElement("rightsForm.roles", userRoles, formLayout);
username.setElementCssClass("o_sel_home_settings_username");
username.setEnabled(false);
// Language
Map<String, String> languages = I18nManager.getInstance().getEnabledLanguagesTranslated();
String[] langKeys = StringHelper.getMapKeysAsStringArray(languages);
String[] langValues = StringHelper.getMapValuesAsStringArray(languages);
ArrayHelper.sort(langKeys, langValues, false, true, false);
language = uifactory.addDropdownSingleselect("form.language", formLayout, langKeys, langValues, null);
language.setElementCssClass("o_sel_home_settings_language");
String langKey = prefs.getLanguage();
// this server
if (prefs.getLanguage() != null && i18nModule.getEnabledLanguageKeys().contains(langKey)) {
language.select(prefs.getLanguage(), true);
} else {
language.select(I18nModule.getDefaultLocale().toString(), true);
}
// Font size
String[] cssFontsizeValues = new String[] { translate("form.fontsize.xsmall"), translate("form.fontsize.small"), translate("form.fontsize.normal"), translate("form.fontsize.large"), translate("form.fontsize.xlarge"), translate("form.fontsize.presentation") };
fontsize = uifactory.addDropdownSingleselect("form.fontsize", formLayout, cssFontsizeKeys, cssFontsizeValues, null);
fontsize.setElementCssClass("o_sel_home_settings_fontsize");
fontsize.select(prefs.getFontsize(), true);
fontsize.addActionListener(FormEvent.ONCHANGE);
// Email notification interval
NotificationsManager nMgr = NotificationsManager.getInstance();
List<String> intervals = nMgr.getEnabledNotificationIntervals();
if (intervals.size() > 0) {
String[] intervalKeys = new String[intervals.size()];
intervals.toArray(intervalKeys);
String[] intervalValues = new String[intervalKeys.length];
String i18nPrefix = "interval.";
for (int i = 0; i < intervalKeys.length; i++) {
intervalValues[i] = translate(i18nPrefix + intervalKeys[i]);
}
notificationInterval = uifactory.addDropdownSingleselect("form.notification", formLayout, intervalKeys, intervalValues, null);
notificationInterval.setElementCssClass("o_sel_home_settings_notification_interval");
notificationInterval.select(prefs.getNotificationInterval(), true);
}
// fxdiff VCRP-16: intern mail system
MailModule mailModule = (MailModule) CoreSpringFactory.getBean("mailModule");
if (mailModule.isInternSystem()) {
String userEmail = UserManager.getInstance().getUserDisplayEmail(tobeChangedIdentity, ureq.getLocale());
String[] mailInternLabels = new String[] { translate("mail." + mailIntern[0], userEmail), translate("mail." + mailIntern[1], userEmail) };
mailSystem = uifactory.addRadiosVertical("mail-system", "mail.system", formLayout, mailIntern, mailInternLabels);
mailSystem.setElementCssClass("o_sel_home_settings_mail");
String mailPrefs = prefs.getReceiveRealMail();
if (StringHelper.containsNonWhitespace(mailPrefs)) {
if ("true".equals(mailPrefs)) {
mailSystem.select(mailIntern[1], true);
} else {
mailSystem.select(mailIntern[0], true);
}
} else if (mailModule.isReceiveRealMailUserDefaultSetting()) {
mailSystem.select(mailIntern[1], true);
} else {
mailSystem.select(mailIntern[0], true);
}
}
// Text encoding
Map<String, Charset> charsets = Charset.availableCharsets();
String currentCharset = UserManager.getInstance().getUserCharset(tobeChangedIdentity);
String[] csKeys = StringHelper.getMapKeysAsStringArray(charsets);
charset = uifactory.addDropdownSingleselect("form.charset", formLayout, csKeys, csKeys, null);
charset.setElementCssClass("o_sel_home_settings_charset");
if (currentCharset != null) {
for (String csKey : csKeys) {
if (csKey.equals(currentCharset)) {
charset.select(currentCharset, true);
}
}
}
if (!charset.isOneSelected() && charsets.containsKey("UTF-8")) {
charset.select("UTF-8", true);
}
// Submit and cancel buttons
final FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("button_layout", getTranslator());
formLayout.add(buttonLayout);
buttonLayout.setElementCssClass("o_sel_home_settings_prefs_buttons");
uifactory.addFormSubmitButton("submit", buttonLayout);
uifactory.addFormCancelButton("cancel", buttonLayout, ureq, getWindowControl());
}
use of org.olat.core.commons.services.notifications.NotificationsManager in project OpenOLAT by OpenOLAT.
the class OLATUpgrade_7_1_0 method migrateNotificationPublishers.
private void migrateNotificationPublishers(UpgradeManager upgradeManager, UpgradeHistoryData uhd) {
if (!uhd.getBooleanDataValue(TASK_CHECK_NOTIFICATIONS)) {
log.audit("+-----------------------------------------------------------------------------+");
log.audit("+... Check the businesspath for the publishers (notifications) ...+");
log.audit("+-----------------------------------------------------------------------------+");
if (!portletRepositoryTeacherEnabled && !portletRepositoryStudentEnabled) {
log.audit("**** Repository portlets disabled: don't need to check publishers. ****");
uhd.setBooleanDataValue(TASK_CHECK_NOTIFICATIONS, true);
upgradeManager.setUpgradesHistory(uhd, VERSION);
return;
}
int counter = 0;
NotificationsManager notificationMgr = NotificationsManager.getInstance();
List<Publisher> allPublishers = notificationMgr.getAllPublisher();
if (log.isDebug())
log.info("Found " + allPublishers.size() + " publishers to check.");
for (Publisher publisher : allPublishers) {
if (publisher != null && StringHelper.containsNonWhitespace(publisher.getBusinessPath()) && (publisher.getBusinessPath().startsWith("[Identity") || publisher.getBusinessPath().startsWith("ROOT[Identity"))) {
try {
String businessPath = publisher.getBusinessPath();
int startIndex = businessPath.indexOf("[Identity");
int stopIndex = businessPath.indexOf("]", startIndex);
int wide = stopIndex - startIndex;
if (wide > 30) {
// Identity:326394598 cannot be too wide
continue;
} else if (stopIndex + 1 >= businessPath.length()) {
// only identity
continue;
}
String correctPath = businessPath.substring(stopIndex + 1);
publisher.setBusinessPath(correctPath);
DBFactory.getInstance().updateObject(publisher);
} catch (ObjectDeletedException e) {
log.warn("Publisher was already deleted, no update possible! Publisher key: " + publisher.getKey());
} catch (Exception e) {
log.warn("Publisher was already deleted, no update possible! Publisher key: " + publisher.getKey());
}
counter++;
}
if (counter > 0 && counter % 100 == 0) {
log.audit("Another 100 publishers done");
DBFactory.getInstance().intermediateCommit();
}
}
DBFactory.getInstance().intermediateCommit();
log.audit("**** Checked " + counter + " publishers. ****");
uhd.setBooleanDataValue(TASK_CHECK_NOTIFICATIONS, true);
upgradeManager.setUpgradesHistory(uhd, VERSION);
}
}
use of org.olat.core.commons.services.notifications.NotificationsManager in project openolat by klemens.
the class NotificationNewsController method event.
/**
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
* org.olat.core.gui.components.Component,
* org.olat.core.gui.control.Event)
*/
@Override
protected void event(UserRequest ureq, Component source, Event event) {
if (source == emailLink) {
// send email to user with the currently visible date
NotificationsManager man = NotificationsManager.getInstance();
List<SubscriptionItem> infoList = new ArrayList<>();
List<Subscriber> subsList = new ArrayList<>();
for (Subscriber subscriber : subsInfoMap.keySet()) {
subsList.add(subscriber);
SubscriptionItem item = man.createSubscriptionItem(subscriber, getLocale(), SubscriptionInfo.MIME_HTML, SubscriptionInfo.MIME_HTML, compareDate);
if (item != null) {
infoList.add(item);
}
}
if (man.sendMailToUserAndUpdateSubscriber(subscriberIdentity, infoList, getTranslator(), subsList)) {
showInfo("email.ok");
} else {
showError("email.nok");
}
}
}
use of org.olat.core.commons.services.notifications.NotificationsManager in project openolat by klemens.
the class NotificationNewsController method updateNewsDataModel.
/**
* Update the new data model and refresh the GUI
*/
protected List<Subscriber> updateNewsDataModel() {
if (compareDate == null) {
// compare date is mandatory
return Collections.emptyList();
}
List<String> notiTypes = new ArrayList<>();
if (StringHelper.containsNonWhitespace(newsType) && !newsType.equals("all")) {
notiTypes.add(newsType);
}
NotificationsManager man = NotificationsManager.getInstance();
List<Subscriber> subs = man.getSubscribers(subscriberIdentity, notiTypes);
newsVC.contextPut("subs", subs);
subsInfoMap = NotificationHelper.getSubscriptionMap(getLocale(), true, compareDate, subs);
NotificationSubscriptionAndNewsFormatter subsFormatter = new NotificationSubscriptionAndNewsFormatter(getTranslator(), subsInfoMap);
newsVC.contextPut("subsFormatter", subsFormatter);
return subs;
}
use of org.olat.core.commons.services.notifications.NotificationsManager in project openolat by klemens.
the class NotificationsWebService method subscribe.
@PUT
@Path("subscribers")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response subscribe(PublisherVO publisherVO, @Context HttpServletRequest request) {
if (!isAdmin(request)) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
NotificationsManager notificationsMgr = NotificationsManager.getInstance();
BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
SubscriptionContext subscriptionContext = new SubscriptionContext(publisherVO.getResName(), publisherVO.getResId(), publisherVO.getSubidentifier());
PublisherData publisherData = new PublisherData(publisherVO.getType(), publisherVO.getData(), publisherVO.getBusinessPath());
List<UserVO> userVoes = publisherVO.getUsers();
List<Long> identityKeys = new ArrayList<>();
for (UserVO userVo : userVoes) {
identityKeys.add(userVo.getKey());
}
List<Identity> identities = securityManager.loadIdentityByKeys(identityKeys);
notificationsMgr.subscribe(identities, subscriptionContext, publisherData);
return Response.ok().build();
}
Aggregations