use of org.olat.core.commons.services.notifications.NotificationsManager 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();
}
use of org.olat.core.commons.services.notifications.NotificationsManager in project openolat by klemens.
the class ModifyCourseEvent method clearCalenderSubscriptions.
/**
* Checks all learning group calendars and the course calendar for publishers (of subscriptions)
* and sets their state to "1" which indicates that the ressource is deleted.
*/
private static void clearCalenderSubscriptions(OLATResourceable res, ICourse course) {
// set Publisher state to 1 (= ressource is deleted) for all calendars of the course
CalendarManager calMan = CoreSpringFactory.getImpl(CalendarManager.class);
CalendarNotificationManager notificationManager = CoreSpringFactory.getImpl(CalendarNotificationManager.class);
NotificationsManager nfm = NotificationsManager.getInstance();
if (course != null) {
CourseGroupManager courseGroupManager = course.getCourseEnvironment().getCourseGroupManager();
List<BusinessGroup> learningGroups = courseGroupManager.getAllBusinessGroups();
// all learning and right group calendars
for (BusinessGroup bg : learningGroups) {
KalendarRenderWrapper calRenderWrapper = calMan.getGroupCalendar(bg);
SubscriptionContext subsContext = notificationManager.getSubscriptionContext(calRenderWrapper);
Publisher pub = nfm.getPublisher(subsContext);
if (pub != null) {
// int 0 is OK -> all other is not OK
pub.setState(1);
}
}
}
// the course calendar
try {
/**
* TODO:gs 2010-01-26
* OLAT-4947: if we do not have an repo entry we get an exception here.
* This is normal in the case of courseimport and click canceling.
*/
KalendarRenderWrapper courseCalendar = calMan.getCalendarForDeletion(res);
if (courseCalendar != null) {
SubscriptionContext subContext = notificationManager.getSubscriptionContext(courseCalendar, res);
OLATResourceable oresToDelete = OresHelper.createOLATResourceableInstance(subContext.getResName(), subContext.getResId());
nfm.deletePublishersOf(oresToDelete);
}
} catch (AssertException e) {
// if we have a broken course (e.g. canceled import or no repo entry somehow) skip calendar deletion...
}
}
use of org.olat.core.commons.services.notifications.NotificationsManager in project openolat by klemens.
the class InfoCourseNode method cleanupOnDelete.
@Override
public /**
* is called when deleting this node, clean up info-messages and subscriptions!
*/
void cleanupOnDelete(ICourse course) {
super.cleanupOnDelete(course);
// delete infoMessages and subscriptions (OLAT-6171)
String resSubpath = getIdent();
InfoMessageFrontendManager infoService = CoreSpringFactory.getImpl(InfoMessageFrontendManager.class);
List<InfoMessage> messages = infoService.loadInfoMessageByResource(course, resSubpath, null, null, null, 0, 0);
for (InfoMessage im : messages) {
infoService.deleteInfoMessage(im);
}
final SubscriptionContext subscriptionContext = CourseModule.createTechnicalSubscriptionContext(course.getCourseEnvironment(), this);
NotificationsManager notifManagar = NotificationsManager.getInstance();
notifManagar.delete(subscriptionContext);
super.cleanupOnDelete(course);
}
use of org.olat.core.commons.services.notifications.NotificationsManager in project openolat by klemens.
the class BCWebService method getFolders.
/**
* Retrieves metadata of the course node
* @response.representation.200.qname {http://www.example.com}folderVOes
* @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_FOLDERVOes}
* @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
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getFolders(@PathParam("courseId") Long courseId, @Context HttpServletRequest httpRequest) {
final 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();
}
final UserRequest ureq = getUserRequest(httpRequest);
RepositoryEntry entry = RepositoryManager.getInstance().lookupRepositoryEntry(course, true);
ACService acManager = CoreSpringFactory.getImpl(ACService.class);
AccessResult result = acManager.isAccessible(entry, ureq.getIdentity(), false);
if (!result.isAccessible()) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
final 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());
break;
}
}
final List<FolderVO> folderVOs = new ArrayList<FolderVO>();
new CourseTreeVisitor(course, ureq.getUserSession().getIdentityEnvironment()).visit(new Visitor() {
@Override
public void visit(INode node) {
if (node instanceof BCCourseNode) {
BCCourseNode bcNode = (BCCourseNode) node;
FolderVO folder = createFolderVO(ureq.getUserSession().getIdentityEnvironment(), course, bcNode, subscribed);
folderVOs.add(folder);
}
}
}, new VisibleTreeFilter());
FolderVOes voes = new FolderVOes();
voes.setFolders(folderVOs.toArray(new FolderVO[folderVOs.size()]));
voes.setTotalCount(folderVOs.size());
return Response.ok(voes).build();
}
use of org.olat.core.commons.services.notifications.NotificationsManager in project openolat by klemens.
the class BCCourseNodeEditForm method updatePublisher.
private void updatePublisher(VFSContainer container) {
File realFile = VFSManager.getRealFile(container);
String relPath = new File(FolderConfig.getCanonicalRoot()).toPath().relativize(realFile.toPath()).toString();
NotificationsManager notifManager = NotificationsManager.getInstance();
SubscriptionContext nodefolderSubContext = CourseModule.createSubscriptionContext(course.getCourseEnvironment(), node);
Publisher publisher = notifManager.getPublisher(nodefolderSubContext);
if (publisher != null) {
String businessPath = getWindowControl().getBusinessControl().getAsString();
String data = "/" + relPath;
PublisherData pdata = new PublisherData(OresHelper.calculateTypeName(BCCourseNode.class), data, businessPath);
notifManager.updatePublisherData(nodefolderSubContext, pdata);
}
}
Aggregations