use of org.olat.core.commons.services.notifications.NotificationsManager in project OpenOLAT by OpenOLAT.
the class NotificationsWebService method getPublisher.
/**
* Get the publisher by resource name and id + sub identifier.
*
* @response.representation.200.qname {http://www.example.com}publisherVo
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The publisher
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_PUBLISHERVO}
* @response.representation.204.doc The publisher doesn't exist
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @return It returns the <code>CourseVO</code> object representing the course.
*/
@GET
@Path("publisher/{ressourceName}/{ressourceId}/{subIdentifier}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getPublisher(@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();
}
PublisherVO publisherVo = new PublisherVO(publisher);
return Response.ok(publisherVo).build();
}
use of org.olat.core.commons.services.notifications.NotificationsManager in project OpenOLAT by OpenOLAT.
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.NotificationsManager in project OpenOLAT by OpenOLAT.
the class NotificationSubscriptionController method updateSubscriptionsDataModel.
/**
* Update the table model
*
* @param ureq
*/
void updateSubscriptionsDataModel() {
// Load subscriptions from DB. Don't use the ureq.getIdentity() but the
// subscriberIdentity instead to make this controller also be usable in the
// admin environment (admins might change notifications for a user)
NotificationsManager man = NotificationsManager.getInstance();
List<Subscriber> subs = man.getSubscribers(subscriberIdentity);
for (Iterator<Subscriber> subIt = subs.iterator(); subIt.hasNext(); ) {
Subscriber sub = subIt.next();
if (!man.isPublisherValid(sub.getPublisher())) {
subIt.remove();
}
}
subscriptionsTableModel.setObjects(subs);
// Tell table about model change or set table model if not already set
if (subscriptionsTableCtr.getTableDataModel() == null) {
subscriptionsTableCtr.setTableDataModel(subscriptionsTableModel);
} else {
subscriptionsTableCtr.modelChanged(true);
}
}
use of org.olat.core.commons.services.notifications.NotificationsManager in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class NotificationSubscriptionAndNewsFormatter method getSubscriptionItem.
public SubscriptionItem getSubscriptionItem(Subscriber sub) {
SubscriptionInfo subsInfo = subsInfoMap.get(sub);
NotificationsManager notiMgr = NotificationsManager.getInstance();
SubscriptionItem subscrItem = notiMgr.createSubscriptionItem(subsInfo, sub, translator.getLocale(), SubscriptionInfo.MIME_HTML, SubscriptionInfo.MIME_HTML);
return subscrItem;
}
Aggregations