Search in sources :

Example 26 with Publisher

use of org.olat.core.commons.services.notifications.Publisher in project OpenOLAT by OpenOLAT.

the class NotificationsManagerImpl method deletePublishersOf.

/**
 * deletes all publishers of the given olatresourceable. e.g. ores =
 * businessgroup 123 -> deletes possible publishers: of Folder(toolfolder), of
 * Forum(toolforum)
 *
 * @param ores
 */
@Override
public void deletePublishersOf(OLATResourceable ores) {
    String type = ores.getResourceableTypeName();
    Long id = ores.getResourceableId();
    if (type == null || id == null)
        throw new AssertException("type/id cannot be null! type:" + type + " / id:" + id);
    List<Publisher> pubs = getPublishers(type, id);
    if (pubs.isEmpty())
        return;
    String q1 = "delete from notisub sub where sub.publisher in (:publishers)";
    DBQuery query1 = dbInstance.createQuery(q1);
    query1.setParameterList("publishers", pubs);
    query1.executeUpdate(FlushMode.AUTO);
    String q2 = "delete from notipublisher pub where pub in (:publishers)";
    DBQuery query2 = dbInstance.createQuery(q2);
    query2.setParameterList("publishers", pubs);
    query2.executeUpdate(FlushMode.AUTO);
}
Also used : AssertException(org.olat.core.logging.AssertException) DBQuery(org.olat.core.commons.persistence.DBQuery) Publisher(org.olat.core.commons.services.notifications.Publisher)

Example 27 with Publisher

use of org.olat.core.commons.services.notifications.Publisher in project OpenOLAT by OpenOLAT.

the class NotificationsManagerImpl method updatePublisherData.

@Override
public void updatePublisherData(SubscriptionContext subsContext, PublisherData data) {
    Publisher publisher = getPublisherForUpdate(subsContext);
    if (publisher != null) {
        publisher.setData(data.getData());
        dbInstance.getCurrentEntityManager().merge(publisher);
        dbInstance.commit();
    }
}
Also used : Publisher(org.olat.core.commons.services.notifications.Publisher)

Example 28 with Publisher

use of org.olat.core.commons.services.notifications.Publisher 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();
}
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 29 with Publisher

use of org.olat.core.commons.services.notifications.Publisher 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();
}
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)

Example 30 with Publisher

use of org.olat.core.commons.services.notifications.Publisher in project OpenOLAT by OpenOLAT.

the class NotificationsPortletRunController method getAllPortletEntries.

private List<PortletEntry<Subscriber>> getAllPortletEntries() {
    notificationsList = man.getValidSubscribers(getIdentity());
    // calc subscriptioninfo for all subscriptions and, if only those with news are to be shown, remove the other ones
    for (Iterator<Subscriber> it_subs = notificationsList.iterator(); it_subs.hasNext(); ) {
        Subscriber subscriber = it_subs.next();
        Publisher pub = subscriber.getPublisher();
        NotificationsHandler notifHandler = man.getNotificationsHandler(pub);
        if (notifHandler == null) {
            it_subs.remove();
        } else {
            SubscriptionInfo subsInfo = notifHandler.createSubscriptionInfo(subscriber, getLocale(), compareDate);
            if (!subsInfo.hasNews()) {
                it_subs.remove();
            }
        }
    }
    return convertNotificationToPortletEntryList(notificationsList);
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) NotificationsHandler(org.olat.core.commons.services.notifications.NotificationsHandler) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) Publisher(org.olat.core.commons.services.notifications.Publisher)

Aggregations

Publisher (org.olat.core.commons.services.notifications.Publisher)150 Identity (org.olat.core.id.Identity)62 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)60 PublisherData (org.olat.core.commons.services.notifications.PublisherData)44 SubscriptionInfo (org.olat.core.commons.services.notifications.SubscriptionInfo)44 Date (java.util.Date)42 Test (org.junit.Test)42 Subscriber (org.olat.core.commons.services.notifications.Subscriber)42 SubscriptionListItem (org.olat.core.commons.services.notifications.model.SubscriptionListItem)38 RepositoryEntry (org.olat.repository.RepositoryEntry)34 Translator (org.olat.core.gui.translator.Translator)30 TitleItem (org.olat.core.commons.services.notifications.model.TitleItem)28 OLATResourceable (org.olat.core.id.OLATResourceable)18 ICourse (org.olat.course.ICourse)18 BusinessGroup (org.olat.group.BusinessGroup)16 ArrayList (java.util.ArrayList)14 NotificationsManager (org.olat.core.commons.services.notifications.NotificationsManager)14 NotificationsHandler (org.olat.core.commons.services.notifications.NotificationsHandler)12 AssertException (org.olat.core.logging.AssertException)12 CourseNode (org.olat.course.nodes.CourseNode)8