use of org.olat.core.commons.services.notifications.Subscriber in project openolat by klemens.
the class NotificationSubscriptionController method event.
/**
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
* org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
*/
protected void event(UserRequest ureq, Controller source, Event event) {
if (source == subscriptionsTableCtr) {
if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
TableEvent te = (TableEvent) event;
String actionid = te.getActionId();
Subscriber sub = subscriptionsTableModel.getObject(te.getRowId());
if (actionid.equals("launch")) {
// User want to go to the subscription source, e.g. the forum or the
// folder
NotificationUIFactory.launchSubscriptionResource(ureq, getWindowControl(), sub);
} else if (actionid.equals("del")) {
delYesNoC = activateYesNoDialog(ureq, null, translate("confirm.delete"), delYesNoC);
delYesNoC.setUserObject(sub);
return;
}
}
} else if (source == delYesNoC) {
if (DialogBoxUIFactory.isYesEvent(event)) {
// ok
// Remove subscription and update data model
Subscriber sub = (Subscriber) delYesNoC.getUserObject();
NotificationsManager.getInstance().unsubscribe(sub);
updateSubscriptionsDataModel();
showInfo("info.notification.deleted");
// Notify parent controller
fireEvent(ureq, Event.CHANGED_EVENT);
}
// cleanup dialog
delYesNoC.dispose();
delYesNoC = null;
}
}
use of org.olat.core.commons.services.notifications.Subscriber in project openolat by klemens.
the class NotificationsPortletRunController method reloadModel.
/**
* @see org.olat.core.gui.control.generic.portal.AbstractPortletRunController#reloadModel(org.olat.core.gui.UserRequest, org.olat.core.gui.control.generic.portal.SortingCriteria)
*/
protected void reloadModel(SortingCriteria sortingCriteria) {
if (sortingCriteria.getSortingType() == SortingCriteria.AUTO_SORTING) {
Map<Subscriber, SubscriptionInfo> subscriptionMap = NotificationHelper.getSubscriptionMap(getIdentity(), getLocale(), true, compareDate);
notificationsList = new ArrayList<Subscriber>();
for (Iterator<Map.Entry<Subscriber, SubscriptionInfo>> it_subs = subscriptionMap.entrySet().iterator(); it_subs.hasNext(); ) {
Map.Entry<Subscriber, SubscriptionInfo> sInfo = it_subs.next();
Subscriber subscrer = sInfo.getKey();
SubscriptionInfo infos = sInfo.getValue();
if (infos.hasNews()) {
notificationsList.add(subscrer);
}
}
notificationsList = getSortedList(notificationsList, sortingCriteria);
List<PortletEntry<Subscriber>> entries = convertNotificationToPortletEntryList(notificationsList);
notificationListModel = new NotificationsPortletTableDataModel(entries, getLocale(), subscriptionMap);
tableCtr.setTableDataModel(notificationListModel);
} else {
reloadModel(getPersistentManuallySortedItems());
}
}
use of org.olat.core.commons.services.notifications.Subscriber in project openolat by klemens.
the class NotificationsPortletRunController method getAllPortletEntries.
private List<PortletEntry<Subscriber>> getAllPortletEntries() {
notificationsList = man.getValidSubscribers(getIdentity());
// calc subscriptioninfo for all subscriptions and, if only those with news are to be shown, remove the other ones
for (Iterator<Subscriber> it_subs = notificationsList.iterator(); it_subs.hasNext(); ) {
Subscriber subscriber = it_subs.next();
Publisher pub = subscriber.getPublisher();
NotificationsHandler notifHandler = man.getNotificationsHandler(pub);
if (notifHandler == null) {
it_subs.remove();
} else {
SubscriptionInfo subsInfo = notifHandler.createSubscriptionInfo(subscriber, getLocale(), compareDate);
if (!subsInfo.hasNews()) {
it_subs.remove();
}
}
}
return convertNotificationToPortletEntryList(notificationsList);
}
use of org.olat.core.commons.services.notifications.Subscriber in project openolat by klemens.
the class NotificationsWebService method getSubscriber.
@GET
@Path("subscribers/{ressourceName}/{ressourceId}/{subIdentifier}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getSubscriber(@PathParam("ressourceName") String ressourceName, @PathParam("ressourceId") Long ressourceId, @PathParam("subIdentifier") String subIdentifier, @Context HttpServletRequest request) {
if (!isAdmin(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
NotificationsManager notificationsMgr = NotificationsManager.getInstance();
SubscriptionContext subsContext = new SubscriptionContext(ressourceName, ressourceId, subIdentifier);
Publisher publisher = notificationsMgr.getPublisher(subsContext);
if (publisher == null) {
return Response.ok().status(Status.NO_CONTENT).build();
}
List<Subscriber> subscribers = notificationsMgr.getSubscribers(publisher);
SubscriberVO[] subscriberVoes = new SubscriberVO[subscribers.size()];
int count = 0;
for (Subscriber subscriber : subscribers) {
SubscriberVO subscriberVO = new SubscriberVO();
subscriberVO.setPublisherKey(publisher.getKey());
subscriberVO.setSubscriberKey(subscriber.getKey());
subscriberVO.setIdentityKey(subscriber.getIdentity().getKey());
subscriberVoes[count++] = subscriberVO;
}
return Response.ok(subscriberVoes).build();
}
use of org.olat.core.commons.services.notifications.Subscriber in project openolat by klemens.
the class NotificationsWebService method getNotifications.
/**
* Retrieves the notification of the logged in user.
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The notifications
* @response.representation.200.example {@link org.olat.core.commons.services.notifications.restapi.vo.Examples#SAMPLE_INFOVOes}
* @response.representation.404.doc The identity not found
* @param date The date (optional)
* @param type The type of notifications (User, Forum...) (optional)
* @param httpRequest The HTTP request
* @return an xml or json representation of a the user being search. The xml
* correspond to a <code>SubscriptionInfoVO</code>. <code>SubscriptionInfoVO</code>
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getNotifications(@QueryParam("date") String date, @QueryParam("type") String type, @Context HttpServletRequest httpRequest) {
Identity identity = RestSecurityHelper.getIdentity(httpRequest);
Locale locale = RestSecurityHelper.getLocale(httpRequest);
Date compareDate;
if (StringHelper.containsNonWhitespace(date)) {
compareDate = parseDate(date, locale);
} else {
NotificationsManager man = NotificationsManager.getInstance();
compareDate = man.getCompareDateFromInterval(man.getUserIntervalOrDefault(identity));
}
List<String> types = new ArrayList<String>(1);
if (StringHelper.containsNonWhitespace(type)) {
types.add(type);
}
Map<Subscriber, SubscriptionInfo> subsInfoMap = NotificationHelper.getSubscriptionMap(identity, locale, true, compareDate, types);
List<SubscriptionInfoVO> voes = new ArrayList<SubscriptionInfoVO>();
for (Map.Entry<Subscriber, SubscriptionInfo> entry : subsInfoMap.entrySet()) {
SubscriptionInfo info = entry.getValue();
if (info.hasNews()) {
Subscriber subscriber = entry.getKey();
voes.add(createSubscriptionInfoVO(subscriber.getPublisher(), info));
}
}
SubscriptionInfoVO[] voesArr = new SubscriptionInfoVO[voes.size()];
voes.toArray(voesArr);
return Response.ok(voesArr).build();
}
Aggregations