Search in sources :

Example 51 with Publisher

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

the class NewUsersNotificationHandler method createSubscriptionInfo.

@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
    Publisher p = subscriber.getPublisher();
    Date latestNews = p.getLatestNewsDate();
    SubscriptionInfo si;
    Translator translator = Util.createPackageTranslator(this.getClass(), locale);
    // there could be news for me, investigate deeper
    try {
        if (NotificationsManager.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
            List<Identity> identities = UsersSubscriptionManager.getInstance().getNewIdentityCreated(compareDate);
            if (identities.isEmpty()) {
                si = NotificationsManager.getInstance().getNoSubscriptionInfo();
            } else {
                translator = Util.createPackageTranslator(this.getClass(), locale);
                si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(getItemTitle(identities, translator), CSSHelper.CSS_CLASS_GROUP), null);
                SubscriptionListItem subListItem;
                for (Identity newUser : identities) {
                    String desc = translator.translate("notifications.entry", new String[] { NotificationHelper.getFormatedName(newUser) });
                    String businessPath = "[Identity:" + newUser.getKey() + "]";
                    String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
                    Date modDate = newUser.getCreationDate();
                    subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, CSSHelper.CSS_CLASS_USER);
                    si.addSubscriptionListItem(subListItem);
                }
            }
        } else {
            si = NotificationsManager.getInstance().getNoSubscriptionInfo();
        }
    } catch (Exception e) {
        log.error("Error creating new identity's notifications for subscriber: " + subscriber.getKey(), e);
        si = NotificationsManager.getInstance().getNoSubscriptionInfo();
    }
    return si;
}
Also used : SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) Translator(org.olat.core.gui.translator.Translator) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) Publisher(org.olat.core.commons.services.notifications.Publisher) TitleItem(org.olat.core.commons.services.notifications.model.TitleItem) Identity(org.olat.core.id.Identity) Date(java.util.Date)

Example 52 with Publisher

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

the class UsersSubscriptionManagerImpl method getNewUsersSubscriber.

public Subscriber getNewUsersSubscriber(Identity identity) {
    SubscriptionContext context = getNewUsersSubscriptionContext();
    Publisher publisher = NotificationsManager.getInstance().getPublisher(context);
    if (publisher == null) {
        return null;
    }
    return NotificationsManager.getInstance().getSubscriber(identity, publisher);
}
Also used : SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Publisher(org.olat.core.commons.services.notifications.Publisher)

Example 53 with Publisher

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

the class InfoMessageFrontendManagerTest method removeInfoMessagesAndSubscriptionContext.

@Test
public void removeInfoMessagesAndSubscriptionContext() {
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("info-1");
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("info-2");
    RepositoryEntry resource = JunitTestHelper.createAndPersistRepositoryEntry();
    BusinessGroup businessGroup = groupService.createBusinessGroup(null, "gdao1", "gdao1-desc", -1, -1, false, false, resource);
    final OLATResourceable ores = new OLATResourceable() {

        @Override
        public String getResourceableTypeName() {
            return businessGroup.getResourceableTypeName();
        }

        @Override
        public Long getResourceableId() {
            return businessGroup.getResourceableId();
        }
    };
    // create, save
    InfoMessage msg1 = infoManager.createInfoMessage(ores, InfoMessageFrontendManager.businessGroupResSubPath, null, id2);
    msg1.setTitle("title-1");
    msg1.setMessage("message-1");
    assertNotNull(msg1);
    infoManager.saveInfoMessage(msg1);
    // create, save
    InfoMessage msg2 = infoManager.createInfoMessage(ores, InfoMessageFrontendManager.businessGroupResSubPath, null, id1);
    msg2.setTitle("title-2");
    msg2.setMessage("message-2");
    assertNotNull(msg2);
    infoManager.saveInfoMessage(msg2);
    // create, save
    InfoMessage msg3 = infoManager.createInfoMessage(ores, InfoMessageFrontendManager.businessGroupResSubPath, null, id1);
    msg3.setTitle("title-3");
    msg3.setMessage("message-3");
    assertNotNull(msg3);
    infoManager.saveInfoMessage(msg3);
    dbInstance.commitAndCloseSession();
    SubscriptionContext sc = new SubscriptionContext(businessGroup.getResourceableTypeName(), businessGroup.getResourceableId(), InfoMessageFrontendManager.businessGroupResSubPath);
    PublisherData pd = new PublisherData("InfoMessage", "e.g. infoMessage=anyMessage", null);
    // subscribe
    notificationManager.subscribe(id1, sc, pd);
    notificationManager.subscribe(id2, sc, pd);
    dbInstance.closeSession();
    // check if publisher was created
    Publisher p = notificationManager.getPublisher(sc);
    assertNotNull(p);
    // check before message deletion
    List<InfoMessage> loadedMessages1 = infoManager.loadInfoMessageByResource(ores, InfoMessageFrontendManager.businessGroupResSubPath, null, null, null, 0, 0);
    Assert.assertEquals(3, loadedMessages1.size());
    Assert.assertTrue(loadedMessages1.contains(msg1));
    Assert.assertTrue(loadedMessages1.contains(msg2));
    Assert.assertTrue(loadedMessages1.contains(msg3));
    // delete
    infoManager.removeInfoMessagesAndSubscriptionContext(businessGroup);
    dbInstance.commitAndCloseSession();
    // check if messages are deleted
    List<InfoMessage> loadedMessages2 = infoManager.loadInfoMessageByResource(ores, InfoMessageFrontendManager.businessGroupResSubPath, null, null, null, 0, 0);
    Assert.assertEquals(0, loadedMessages2.size());
    Assert.assertFalse(loadedMessages2.contains(msg1));
    Assert.assertFalse(loadedMessages2.contains(msg2));
    Assert.assertFalse(loadedMessages2.contains(msg3));
    // check if pubisher is deleted
    Publisher p2 = notificationManager.getPublisher(sc);
    assertNull("publisher marked deleted should not be found", p2);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) OLATResourceable(org.olat.core.id.OLATResourceable) RepositoryEntry(org.olat.repository.RepositoryEntry) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Publisher(org.olat.core.commons.services.notifications.Publisher) Identity(org.olat.core.id.Identity) PublisherData(org.olat.core.commons.services.notifications.PublisherData) Test(org.junit.Test)

Example 54 with Publisher

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

the class OLATUpgrade_9_4_0 method fixBusinessPathPublisher.

private boolean fixBusinessPathPublisher(UpgradeManager upgradeManager, UpgradeHistoryData uhd) {
    if (!uhd.getBooleanDataValue(FIX_PUBLISHER_BUSINESSPATH)) {
        List<Publisher> publishers = getPublishers();
        int count = 0;
        int updates = 0;
        for (Publisher publisher : publishers) {
            boolean updated = processPublisher(publisher);
            if (count % 10 == 0) {
                dbInstance.commit();
            }
            if (updated)
                updates++;
        }
        dbInstance.commit();
        log.audit("Update " + updates + " publisher with partial business path.");
        uhd.setBooleanDataValue(FIX_PUBLISHER_BUSINESSPATH, true);
        upgradeManager.setUpgradesHistory(uhd, VERSION);
    }
    return true;
}
Also used : Publisher(org.olat.core.commons.services.notifications.Publisher)

Example 55 with Publisher

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

the class NotificationsManagerTest method testAllPublishers.

@Test
public void testAllPublishers() {
    String identifier = UUID.randomUUID().toString().replace("-", "");
    SubscriptionContext context = new SubscriptionContext("All", new Long(123), identifier);
    PublisherData publisherData = new PublisherData("testAllPublishers", "e.g. forumdata=keyofforum", null);
    Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(publisher);
    List<Publisher> publishers = notificationManager.getAllPublisher();
    Assert.assertNotNull(publishers);
    Assert.assertTrue(publishers.contains(publisher));
}
Also used : SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Publisher(org.olat.core.commons.services.notifications.Publisher) PublisherData(org.olat.core.commons.services.notifications.PublisherData) Test(org.junit.Test)

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