use of org.olat.core.commons.services.notifications.NotificationsManager in project openolat by klemens.
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 klemens.
the class BCWebService method getFolder.
/**
* Retrieves metadata of the course node
* @response.representation.200.qname {http://www.example.com}folderVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The course node metadatas
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_FOLDERVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The course or parentNode not found
* @param courseId The course resourceable's id
* @param nodeId The node's id
* @param httpRequest The HTTP request
* @return The persisted structure element (fully populated)
*/
@GET
@Path("{nodeId}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getFolder(@PathParam("courseId") Long courseId, @PathParam("nodeId") String nodeId, @Context HttpServletRequest httpRequest) {
ICourse course = CoursesWebService.loadCourse(courseId);
if (course == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
} else if (!CourseWebService.isCourseAccessible(course, false, httpRequest)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
CourseNode courseNode = course.getRunStructure().getNode(nodeId);
if (courseNode == null || !(courseNode instanceof BCCourseNode)) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
UserRequest ureq = getUserRequest(httpRequest);
boolean accessible = (new CourseTreeVisitor(course, ureq.getUserSession().getIdentityEnvironment())).isAccessible(courseNode, new VisibleTreeFilter());
if (accessible) {
Set<String> subscribed = new HashSet<String>();
NotificationsManager man = NotificationsManager.getInstance();
List<String> notiTypes = Collections.singletonList("FolderModule");
List<Subscriber> subs = man.getSubscribers(ureq.getIdentity(), notiTypes);
for (Subscriber sub : subs) {
Long courseKey = sub.getPublisher().getResId();
if (courseId.equals(courseKey)) {
subscribed.add(sub.getPublisher().getSubidentifier());
}
}
FolderVO folderVo = createFolderVO(ureq.getUserSession().getIdentityEnvironment(), course, (BCCourseNode) courseNode, subscribed);
return Response.ok(folderVo).build();
} else {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
}
use of org.olat.core.commons.services.notifications.NotificationsManager in project openolat by klemens.
the class MyForumsWebService method getForums.
/**
* Retrieves a list of forums on a user base. All forums of groups
* where the user is participant/tutor + all forums in course where
* the user is a participant (owner, tutor or participant)
* @response.representation.200.qname {http://www.example.com}forumVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The forums
* @response.representation.200.example {@link org.olat.modules.fo.restapi.Examples#SAMPLE_FORUMVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @param identityKey The key of the user (IdentityImpl)
* @param httpRequest The HTTP request
* @return The forums
*/
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getForums(@PathParam("identityKey") Long identityKey, @Context HttpServletRequest httpRequest) {
Roles roles;
Identity retrievedUser = getIdentity(httpRequest);
if (retrievedUser == null) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
} else if (!identityKey.equals(retrievedUser.getKey())) {
if (isAdmin(httpRequest)) {
retrievedUser = BaseSecurityManager.getInstance().loadIdentityByKey(identityKey);
roles = BaseSecurityManager.getInstance().getRoles(retrievedUser);
} else {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
} else {
roles = getRoles(httpRequest);
}
Map<Long, Long> groupNotified = new HashMap<Long, Long>();
Map<Long, Collection<Long>> courseNotified = new HashMap<Long, Collection<Long>>();
final Set<Long> subscriptions = new HashSet<Long>();
NotificationsManager man = NotificationsManager.getInstance();
{
// collect subscriptions
List<String> notiTypes = Collections.singletonList("Forum");
List<Subscriber> subs = man.getSubscribers(retrievedUser, notiTypes);
for (Subscriber sub : subs) {
String resName = sub.getPublisher().getResName();
Long forumKey = Long.parseLong(sub.getPublisher().getData());
subscriptions.add(forumKey);
if ("BusinessGroup".equals(resName)) {
Long groupKey = sub.getPublisher().getResId();
groupNotified.put(groupKey, forumKey);
} else if ("CourseModule".equals(resName)) {
Long courseKey = sub.getPublisher().getResId();
if (!courseNotified.containsKey(courseKey)) {
courseNotified.put(courseKey, new ArrayList<Long>());
}
courseNotified.get(courseKey).add(forumKey);
}
}
}
final List<ForumVO> forumVOs = new ArrayList<ForumVO>();
final IdentityEnvironment ienv = new IdentityEnvironment(retrievedUser, roles);
for (Map.Entry<Long, Collection<Long>> e : courseNotified.entrySet()) {
final Long courseKey = e.getKey();
final Collection<Long> forumKeys = e.getValue();
final ICourse course = CourseFactory.loadCourse(courseKey);
new CourseTreeVisitor(course, ienv).visit(new Visitor() {
@Override
public void visit(INode node) {
if (node instanceof FOCourseNode) {
FOCourseNode forumNode = (FOCourseNode) node;
ForumVO forumVo = ForumCourseNodeWebService.createForumVO(course, forumNode, subscriptions);
if (forumKeys.contains(forumVo.getForumKey())) {
forumVOs.add(forumVo);
}
}
}
}, new VisibleTreeFilter());
}
/*
RepositoryManager rm = RepositoryManager.getInstance();
ACService acManager = CoreSpringFactory.getImpl(ACService.class);
SearchRepositoryEntryParameters repoParams = new SearchRepositoryEntryParameters(retrievedUser, roles, "CourseModule");
repoParams.setOnlyExplicitMember(true);
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.getOlatResource());
final IdentityEnvironment ienv = new IdentityEnvironment(retrievedUser, roles);
new CourseTreeVisitor(course, ienv).visit(new Visitor() {
@Override
public void visit(INode node) {
if(node instanceof FOCourseNode) {
FOCourseNode forumNode = (FOCourseNode)node;
ForumVO forumVo = ForumCourseNodeWebService.createForumVO(course, forumNode, subscriptions);
forumVOs.add(forumVo);
}
}
});
} catch (Exception e) {
log.error("", e);
}
}
}*/
// start found forums in groups
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
SearchBusinessGroupParams params = new SearchBusinessGroupParams(retrievedUser, true, true);
params.addTools(CollaborationTools.TOOL_FORUM);
List<BusinessGroup> groups = bgs.findBusinessGroups(params, null, 0, -1);
// list forum keys
List<Long> groupIds = new ArrayList<Long>();
Map<Long, BusinessGroup> groupsMap = new HashMap<Long, BusinessGroup>();
for (BusinessGroup group : groups) {
if (groupNotified.containsKey(group.getKey())) {
ForumVO forumVo = new ForumVO();
forumVo.setName(group.getName());
forumVo.setGroupKey(group.getKey());
forumVo.setForumKey(groupNotified.get(group.getKey()));
forumVo.setSubscribed(true);
forumVOs.add(forumVo);
groupIds.remove(group.getKey());
} else {
groupIds.add(group.getKey());
groupsMap.put(group.getKey(), group);
}
}
PropertyManager pm = PropertyManager.getInstance();
List<Property> forumProperties = pm.findProperties(OresHelper.calculateTypeName(BusinessGroup.class), groupIds, PROP_CAT_BG_COLLABTOOLS, KEY_FORUM);
for (Property prop : forumProperties) {
Long forumKey = prop.getLongValue();
if (forumKey != null && groupsMap.containsKey(prop.getResourceTypeId())) {
BusinessGroup group = groupsMap.get(prop.getResourceTypeId());
ForumVO forumVo = new ForumVO();
forumVo.setName(group.getName());
forumVo.setGroupKey(group.getKey());
forumVo.setForumKey(prop.getLongValue());
forumVo.setSubscribed(false);
forumVOs.add(forumVo);
}
}
ForumVOes voes = new ForumVOes();
voes.setForums(forumVOs.toArray(new ForumVO[forumVOs.size()]));
voes.setTotalCount(forumVOs.size());
return Response.ok(voes).build();
}
use of org.olat.core.commons.services.notifications.NotificationsManager in project OpenOLAT by OpenOLAT.
the class CoursesInfosWebService method collectSubscriptions.
private void collectSubscriptions(Identity identity, Set<Long> forumNotified, Map<Long, Set<String>> courseNotified) {
NotificationsManager man = NotificationsManager.getInstance();
{
// collect subscriptions
List<String> notiTypes = new ArrayList<String>();
notiTypes.add("FolderModule");
notiTypes.add("Forum");
List<Subscriber> subs = man.getSubscribers(identity, notiTypes);
for (Subscriber sub : subs) {
String publisherType = sub.getPublisher().getType();
String resName = sub.getPublisher().getResName();
if ("CourseModule".equals(resName)) {
if ("FolderModule".equals(publisherType)) {
Long courseKey = sub.getPublisher().getResId();
if (!courseNotified.containsKey(courseKey)) {
courseNotified.put(courseKey, new HashSet<String>());
}
courseNotified.get(courseKey).add(sub.getPublisher().getSubidentifier());
} else if ("Forum".equals(publisherType)) {
Long forumKey = Long.parseLong(sub.getPublisher().getData());
forumNotified.add(forumKey);
}
}
}
}
}
use of org.olat.core.commons.services.notifications.NotificationsManager in project OpenOLAT by OpenOLAT.
the class OLATUpgrade_7_0_1 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("+-----------------------------------------------------------------------------+");
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);
}
}
Aggregations