use of org.olat.core.commons.services.notifications.Subscriber in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class NotificationsManagerImpl method subscribe.
/**
* @param identity
* @param subscriptionContext
* @param publisherData
*/
@Override
public void subscribe(Identity identity, SubscriptionContext subscriptionContext, PublisherData publisherData) {
// need to sync as opt-in is sometimes implemented
Publisher toUpdate = getPublisherForUpdate(subscriptionContext);
if (toUpdate == null) {
// create the publisher
findOrCreatePublisher(subscriptionContext, publisherData);
// lock the publisher
toUpdate = getPublisherForUpdate(subscriptionContext);
}
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 DocumentPoolNotificationsHandler method createSubscriptionInfo.
@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
Publisher p = subscriber.getPublisher();
Date latestNews = p.getLatestNewsDate();
try {
SubscriptionInfo si;
String taxonomyKey = documentPoolModule.getTaxonomyTreeKey();
if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews) && StringHelper.isLong(taxonomyKey)) {
Taxonomy taxonomy = taxonomyService.getTaxonomy(new TaxonomyRefImpl(new Long(taxonomyKey)));
if (taxonomy == null) {
return notificationsManager.getNoSubscriptionInfo();
}
Identity identity = subscriber.getIdentity();
Roles roles = securityManager.getRoles(identity);
boolean isTaxonomyAdmin = roles.isOLATAdmin();
Translator translator = Util.createPackageTranslator(DocumentPoolMainController.class, locale);
String templates = translator.translate("document.pool.templates");
TaxonomyTreeBuilder builder = new TaxonomyTreeBuilder(taxonomy, identity, null, isTaxonomyAdmin, documentPoolModule.isTemplatesDirectoryEnabled(), templates, locale);
TreeModel model = builder.buildTreeModel();
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), getTitleItemForPublisher(), null);
new TreeVisitor(node -> {
TaxonomyTreeNode tNode = (TaxonomyTreeNode) node;
if (tNode.getTaxonomyLevel() != null && tNode.isDocumentsLibraryEnabled() && tNode.isCanRead()) {
VFSContainer container = taxonomyService.getDocumentsLibrary(tNode.getTaxonomyLevel());
String prefixBusinessPath = "[DocumentPool:" + taxonomy.getKey() + "][TaxonomyLevel:" + tNode.getTaxonomyLevel().getKey() + "][path=";
createSubscriptionInfo(container, prefixBusinessPath, compareDate, si, p, translator);
} else if (tNode.getType() == TaxonomyTreeNodeType.templates) {
VFSContainer container = taxonomyService.getDocumentsLibrary(taxonomy);
String prefixBusinessPath = "[DocumentPool:" + taxonomy.getKey() + "][Templates:0s][path=";
createSubscriptionInfo(container, prefixBusinessPath, compareDate, si, p, translator);
}
}, model.getRootNode(), false).visitAll();
} else {
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
return si;
} catch (Exception e) {
log.error("Cannot create document pool notifications for subscriber: " + subscriber.getKey(), e);
return notificationsManager.getNoSubscriptionInfo();
}
}
use of org.olat.core.commons.services.notifications.Subscriber in project OpenOLAT by OpenOLAT.
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.Subscriber in project openolat by klemens.
the class CoursesInfosWebService method collectSubscriptions.
private void collectSubscriptions(Identity identity, Set<Long> forumNotified, Map<Long, Set<String>> courseNotified) {
NotificationsManager man = NotificationsManager.getInstance();
{
// collect subscriptions
List<String> notiTypes = new ArrayList<String>();
notiTypes.add("FolderModule");
notiTypes.add("Forum");
List<Subscriber> subs = man.getSubscribers(identity, notiTypes);
for (Subscriber sub : subs) {
String publisherType = sub.getPublisher().getType();
String resName = sub.getPublisher().getResName();
if ("CourseModule".equals(resName)) {
if ("FolderModule".equals(publisherType)) {
Long courseKey = sub.getPublisher().getResId();
if (!courseNotified.containsKey(courseKey)) {
courseNotified.put(courseKey, new HashSet<String>());
}
courseNotified.get(courseKey).add(sub.getPublisher().getSubidentifier());
} else if ("Forum".equals(publisherType)) {
Long forumKey = Long.parseLong(sub.getPublisher().getData());
forumNotified.add(forumKey);
}
}
}
}
}
Aggregations