use of org.olat.core.commons.services.notifications.Subscriber in project OpenOLAT by OpenOLAT.
the class NotificationsManagerImpl method markSubscriberRead.
private Subscriber markSubscriberRead(Identity identity, Publisher p) {
Subscriber sub = getSubscriber(identity, p);
if (sub != null) {
sub.setLastModified(new Date());
sub = dbInstance.getCurrentEntityManager().merge(sub);
}
return sub;
}
use of org.olat.core.commons.services.notifications.Subscriber in project OpenOLAT by OpenOLAT.
the class NotificationsManagerImpl method subscribe.
@Override
public void subscribe(List<Identity> identities, SubscriptionContext subscriptionContext, PublisherData publisherData) {
if (identities == null || identities.isEmpty())
return;
Publisher toUpdate = getPublisherForUpdate(subscriptionContext);
if (toUpdate == null) {
// create the publisher
findOrCreatePublisher(subscriptionContext, publisherData);
// lock the publisher
toUpdate = getPublisherForUpdate(subscriptionContext);
}
for (Identity identity : identities) {
Subscriber s = getSubscriber(identity, toUpdate);
if (s == null) {
// no subscriber -> create.
// s.latestReadDate >= p.latestNewsDate == no news for subscriber when no
// news after subscription time
doCreateAndPersistSubscriber(toUpdate, identity);
}
}
dbInstance.commit();
}
use of org.olat.core.commons.services.notifications.Subscriber in project OpenOLAT by OpenOLAT.
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();
}
use of org.olat.core.commons.services.notifications.Subscriber in project OpenOLAT by OpenOLAT.
the class DateChooserController method setSubscribers.
public void setSubscribers(List<Subscriber> subscribers) {
String selectedKey = typeSelection.isOneSelected() ? typeSelection.getSelectedKey() : null;
Set<String> types = new HashSet<String>();
for (Subscriber subscriber : subscribers) {
String type = subscriber.getPublisher().getType();
types.add(type);
}
typeKeys = new String[types.size() + 1];
typeValues = new String[types.size() + 1];
typeKeys[0] = "all";
typeValues[0] = translate("news.type.all");
int count = 1;
for (String type : types) {
String typeName = NewControllerFactory.translateResourceableTypeName(type, getLocale());
typeKeys[count] = type;
typeValues[count++] = typeName;
}
typeSelection.setKeysAndValues(typeKeys, typeValues, null);
if (selectedKey != null) {
// select the current key but check if it still exists
for (String typeKey : typeKeys) {
if (typeKey.equals(selectedKey)) {
typeSelection.select(selectedKey, true);
break;
}
}
}
if (!typeSelection.isOneSelected()) {
typeSelection.select("all", true);
}
}
use of org.olat.core.commons.services.notifications.Subscriber in project OpenOLAT by OpenOLAT.
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;
}
}
Aggregations