use of org.olat.core.commons.services.notifications.Subscriber in project openolat by klemens.
the class NotificationsManagerImpl method updateSubscriberLatestEmail.
protected void updateSubscriberLatestEmail(List<Subscriber> subscribersToUpdate) {
if (subscribersToUpdate == null || subscribersToUpdate.isEmpty()) {
// nothing to do
return;
}
StringBuilder q = new StringBuilder();
q.append("select sub from notisub sub ").append(" inner join fetch sub.publisher where sub.key in (:aKey)");
EntityManager em = dbInstance.getCurrentEntityManager();
List<Long> keys = PersistenceHelper.toKeys(subscribersToUpdate);
List<Subscriber> subscribers = em.createQuery(q.toString(), Subscriber.class).setParameter("aKey", keys).getResultList();
for (Subscriber subscriber : subscribers) {
subscriber.setLastModified(new Date());
subscriber.setLatestEmailed(new Date());
em.merge(subscriber);
}
}
use of org.olat.core.commons.services.notifications.Subscriber in project openolat by klemens.
the class NotificationsManagerImpl method processSubscribersByEmail.
private void processSubscribersByEmail(Identity ident) {
if (ident.getStatus().compareTo(Identity.STATUS_VISIBLE_LIMIT) >= 0) {
// send only to active user
return;
}
String userInterval = getUserIntervalOrDefault(ident);
if ("never".equals(userInterval)) {
return;
}
long start = System.currentTimeMillis();
Date compareDate = getCompareDateFromInterval(userInterval);
Property p = propertyManager.findProperty(ident, null, null, null, LATEST_EMAIL_USER_PROP);
if (p != null) {
Date latestEmail = new Date(p.getLongValue());
if (latestEmail.after(compareDate)) {
// nothing to do
return;
}
}
Date defaultCompareDate = getDefaultCompareDate();
List<Subscriber> subscribers = getSubscribers(ident);
if (subscribers.isEmpty()) {
return;
}
String langPrefs = null;
if (ident.getUser() != null && ident.getUser().getPreferences() != null) {
langPrefs = ident.getUser().getPreferences().getLanguage();
}
Locale locale = I18nManager.getInstance().getLocaleOrDefault(langPrefs);
boolean veto = false;
Subscriber latestSub = null;
List<SubscriptionItem> items = new ArrayList<>();
List<Subscriber> subsToUpdate = new ArrayList<>();
for (Subscriber sub : subscribers) {
Date latestEmail = sub.getLatestEmailed();
SubscriptionItem subsitem = null;
if (latestEmail == null || compareDate.after(latestEmail)) {
// no notif. ever sent until now
if (latestEmail == null) {
latestEmail = defaultCompareDate;
} else if (latestEmail.before(defaultCompareDate)) {
// no notification older than a month
latestEmail = defaultCompareDate;
}
subsitem = createSubscriptionItem(sub, locale, SubscriptionInfo.MIME_HTML, SubscriptionInfo.MIME_HTML, latestEmail);
} else if (latestEmail != null && latestEmail.after(compareDate)) {
// already send an email within the user's settings interval
// veto = true;
}
if (subsitem != null) {
items.add(subsitem);
subsToUpdate.add(sub);
}
latestSub = sub;
}
Translator translator = Util.createPackageTranslator(NotificationSubscriptionController.class, locale);
notifySubscribersByEmail(latestSub, items, subsToUpdate, translator, start, veto);
}
use of org.olat.core.commons.services.notifications.Subscriber in project openolat by klemens.
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 klemens.
the class NotificationsManagerImpl method unsubscribe.
@Override
public void unsubscribe(List<Identity> identities, SubscriptionContext subscriptionContext) {
if (identities == null || identities.isEmpty())
return;
Publisher p = getPublisherForUpdate(subscriptionContext);
if (p != null) {
for (Identity identity : identities) {
Subscriber s = getSubscriber(identity, p);
if (s != null) {
deleteSubscriber(s);
} else {
logWarn("could not unsubscribe " + identity.getName() + " from publisher:" + p.getResName() + "," + p.getResId() + "," + p.getSubidentifier(), null);
}
}
}
dbInstance.commit();
}
use of org.olat.core.commons.services.notifications.Subscriber 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();
}
Aggregations