Search in sources :

Example 31 with NotificationsManager

use of org.olat.core.commons.services.notifications.NotificationsManager in project openolat by klemens.

the class OLATUpgrade_7_1_0 method migrateNotificationPublishers.

private void migrateNotificationPublishers(UpgradeManager upgradeManager, UpgradeHistoryData uhd) {
    if (!uhd.getBooleanDataValue(TASK_CHECK_NOTIFICATIONS)) {
        log.audit("+-----------------------------------------------------------------------------+");
        log.audit("+... Check the businesspath for the publishers (notifications)             ...+");
        log.audit("+-----------------------------------------------------------------------------+");
        if (!portletRepositoryTeacherEnabled && !portletRepositoryStudentEnabled) {
            log.audit("**** Repository portlets disabled: don't need to check publishers. ****");
            uhd.setBooleanDataValue(TASK_CHECK_NOTIFICATIONS, true);
            upgradeManager.setUpgradesHistory(uhd, VERSION);
            return;
        }
        int counter = 0;
        NotificationsManager notificationMgr = NotificationsManager.getInstance();
        List<Publisher> allPublishers = notificationMgr.getAllPublisher();
        if (log.isDebug())
            log.info("Found " + allPublishers.size() + " publishers to check.");
        for (Publisher publisher : allPublishers) {
            if (publisher != null && StringHelper.containsNonWhitespace(publisher.getBusinessPath()) && (publisher.getBusinessPath().startsWith("[Identity") || publisher.getBusinessPath().startsWith("ROOT[Identity"))) {
                try {
                    String businessPath = publisher.getBusinessPath();
                    int startIndex = businessPath.indexOf("[Identity");
                    int stopIndex = businessPath.indexOf("]", startIndex);
                    int wide = stopIndex - startIndex;
                    if (wide > 30) {
                        // Identity:326394598 cannot be too wide
                        continue;
                    } else if (stopIndex + 1 >= businessPath.length()) {
                        // only identity
                        continue;
                    }
                    String correctPath = businessPath.substring(stopIndex + 1);
                    publisher.setBusinessPath(correctPath);
                    DBFactory.getInstance().updateObject(publisher);
                } catch (ObjectDeletedException e) {
                    log.warn("Publisher was already deleted, no update possible! Publisher key: " + publisher.getKey());
                } catch (Exception e) {
                    log.warn("Publisher was already deleted, no update possible! Publisher key: " + publisher.getKey());
                }
                counter++;
            }
            if (counter > 0 && counter % 100 == 0) {
                log.audit("Another 100 publishers done");
                DBFactory.getInstance().intermediateCommit();
            }
        }
        DBFactory.getInstance().intermediateCommit();
        log.audit("**** Checked " + counter + " publishers. ****");
        uhd.setBooleanDataValue(TASK_CHECK_NOTIFICATIONS, true);
        upgradeManager.setUpgradesHistory(uhd, VERSION);
    }
}
Also used : NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) ObjectDeletedException(org.hibernate.ObjectDeletedException) Publisher(org.olat.core.commons.services.notifications.Publisher) ObjectDeletedException(org.hibernate.ObjectDeletedException)

Example 32 with NotificationsManager

use of org.olat.core.commons.services.notifications.NotificationsManager in project openolat by klemens.

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;
}
Also used : SubscriptionItem(org.olat.core.commons.services.notifications.SubscriptionItem) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo)

Example 33 with NotificationsManager

use of org.olat.core.commons.services.notifications.NotificationsManager in project openolat by klemens.

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);
    }
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager)

Example 34 with NotificationsManager

use of org.olat.core.commons.services.notifications.NotificationsManager in project openolat by klemens.

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();
}
Also used : NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Publisher(org.olat.core.commons.services.notifications.Publisher) PublisherVO(org.olat.core.commons.services.notifications.restapi.vo.PublisherVO) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 35 with NotificationsManager

use of org.olat.core.commons.services.notifications.NotificationsManager in project openolat by klemens.

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();
}
Also used : SubscriberVO(org.olat.core.commons.services.notifications.restapi.vo.SubscriberVO) Subscriber(org.olat.core.commons.services.notifications.Subscriber) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Publisher(org.olat.core.commons.services.notifications.Publisher) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

NotificationsManager (org.olat.core.commons.services.notifications.NotificationsManager)42 Subscriber (org.olat.core.commons.services.notifications.Subscriber)24 ArrayList (java.util.ArrayList)18 GET (javax.ws.rs.GET)18 Produces (javax.ws.rs.Produces)18 HashSet (java.util.HashSet)12 Publisher (org.olat.core.commons.services.notifications.Publisher)12 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)12 ICourse (org.olat.course.ICourse)12 CourseTreeVisitor (org.olat.course.run.userview.CourseTreeVisitor)12 VisibleTreeFilter (org.olat.course.run.userview.VisibleTreeFilter)12 Path (javax.ws.rs.Path)10 UserRequest (org.olat.core.gui.UserRequest)8 Identity (org.olat.core.id.Identity)8 INode (org.olat.core.util.nodes.INode)8 Visitor (org.olat.core.util.tree.Visitor)8 BCCourseNode (org.olat.course.nodes.BCCourseNode)8 RestSecurityHelper.getUserRequest (org.olat.restapi.security.RestSecurityHelper.getUserRequest)8 List (java.util.List)6 Map (java.util.Map)6