Search in sources :

Example 51 with PublisherData

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

the class NotificationsManagerTest method testValidSubscribers.

@Test
public void testValidSubscribers() {
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser("valid1-" + UUID.randomUUID().toString());
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("valid1-" + UUID.randomUUID().toString());
    // create a publisher
    String identifier = UUID.randomUUID().toString().replace("-", "");
    SubscriptionContext context = new SubscriptionContext("Valid", new Long(123), identifier);
    PublisherData publisherData = new PublisherData("testValidSubscribers", "e.g. forumdata=keyofforum", null);
    Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(publisher);
    // add subscribers
    notificationManager.subscribe(id1, context, publisherData);
    notificationManager.subscribe(id2, context, publisherData);
    dbInstance.commitAndCloseSession();
    // get valid subscribers
    List<Subscriber> subscribers = notificationManager.getValidSubscribers(id1);
    Assert.assertNotNull(subscribers);
    Assert.assertEquals(1, subscribers.size());
    Assert.assertEquals(publisher, subscribers.get(0).getPublisher());
    Assert.assertEquals(id1, subscribers.get(0).getIdentity());
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) 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 52 with PublisherData

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

the class GTAManagerImpl method getPublisherData.

@Override
public PublisherData getPublisherData(CourseEnvironment courseEnv, GTACourseNode cNode) {
    RepositoryEntry re = courseEnv.getCourseGroupManager().getCourseEntry();
    String businessPath = "[RepositoryEntry:" + re.getKey() + "][CourseNode:" + cNode.getIdent() + "]";
    return new PublisherData("GroupTask", "", businessPath);
}
Also used : RepositoryEntry(org.olat.repository.RepositoryEntry) PublisherData(org.olat.core.commons.services.notifications.PublisherData)

Example 53 with PublisherData

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

the class BusinessGroupMembershipProcessorTest method testUnlinkMemberOfBusinessGroup.

@Test
public void testUnlinkMemberOfBusinessGroup() {
    // create a group with members
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-1");
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-2");
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-3");
    BusinessGroup businessGroup = businessGroupDao.createAndPersist(coach, "mbr-proc-1", "mbr-proc-desc", -1, -1, false, false, false, false, false);
    businessGroupRelationDao.addRole(id1, businessGroup, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(id2, businessGroup, GroupRoles.participant.name());
    // create a publisher
    SubscriptionContext context = new SubscriptionContext(businessGroup, "");
    PublisherData publisherData = new PublisherData("testGroupPublishers", "e.g. something", null);
    Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
    Assert.assertNotNull(publisher);
    dbInstance.commitAndCloseSession();
    // subscribe
    notificationManager.subscribe(coach, context, publisherData);
    notificationManager.subscribe(id1, context, publisherData);
    notificationManager.subscribe(id2, context, publisherData);
    dbInstance.commitAndCloseSession();
    // remove id1 and check subscription
    MailPackage mailing = new MailPackage(false);
    List<Identity> identitiesToRemove = Collections.singletonList(id1);
    businessGroupService.removeParticipants(coach, identitiesToRemove, businessGroup, mailing);
    // wait for the remove of subscription
    waitForCondition(new CheckUnsubscription(id1, context, dbInstance, notificationManager), 5000);
    // check that subscription of id1 was deleted but not the ones of id2 and coach
    boolean subscribedId1 = notificationManager.isSubscribed(id1, context);
    Assert.assertFalse(subscribedId1);
    boolean subscribedId2 = notificationManager.isSubscribed(id2, context);
    Assert.assertTrue(subscribedId2);
    boolean subscribedCoach = notificationManager.isSubscribed(coach, context);
    Assert.assertTrue(subscribedCoach);
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) BusinessGroup(org.olat.group.BusinessGroup) 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 PublisherData

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

the class BusinessGroupMembershipProcessorTest method testUnlinkMemberOfBusinessGroup_with2Roles.

@Test
public void testUnlinkMemberOfBusinessGroup_with2Roles() {
    // create a group with members
    Identity member = JunitTestHelper.createAndPersistIdentityAsRndUser("mbr-proc-4");
    BusinessGroup businessGroup = businessGroupDao.createAndPersist(member, "mbr-proc-2", "mbr-proc-desc", -1, -1, false, false, false, false, false);
    businessGroupRelationDao.addRole(member, businessGroup, GroupRoles.participant.name());
    // create a publisher
    SubscriptionContext context = new SubscriptionContext(businessGroup, "");
    PublisherData publisherData = new PublisherData("testGroupPublishers", "e.g. something", null);
    notificationManager.getOrCreatePublisher(context, publisherData);
    notificationManager.subscribe(member, context, publisherData);
    dbInstance.commitAndCloseSession();
    // remove id1 as participant and check subscription
    businessGroupRelationDao.removeRole(member, businessGroup, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    // manually trigger the event
    businessGroupMembershipProcessor.event(new BusinessGroupModifiedEvent(BusinessGroupModifiedEvent.IDENTITY_REMOVED_EVENT, businessGroup, member));
    dbInstance.commitAndCloseSession();
    // check that subscription of member was not deleted because it's still coach
    boolean subscribed = notificationManager.isSubscribed(member, context);
    Assert.assertTrue(subscribed);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Identity(org.olat.core.id.Identity) PublisherData(org.olat.core.commons.services.notifications.PublisherData) BusinessGroupModifiedEvent(org.olat.group.ui.edit.BusinessGroupModifiedEvent) Test(org.junit.Test)

Example 55 with PublisherData

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

the class InfoSubscriptionManagerImpl method subscribe.

@Override
public void subscribe(OLATResourceable resource, String resSubPath, String businessPath, Identity identity) {
    PublisherData data = getInfoPublisherData(resource, businessPath);
    SubscriptionContext context = getInfoSubscriptionContext(resource, resSubPath);
    notificationsManager.subscribe(identity, context, data);
}
Also used : SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) PublisherData(org.olat.core.commons.services.notifications.PublisherData)

Aggregations

PublisherData (org.olat.core.commons.services.notifications.PublisherData)100 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)84 Test (org.junit.Test)64 Identity (org.olat.core.id.Identity)60 Publisher (org.olat.core.commons.services.notifications.Publisher)42 RepositoryEntry (org.olat.repository.RepositoryEntry)22 BusinessGroup (org.olat.group.BusinessGroup)20 HttpResponse (org.apache.http.HttpResponse)16 HttpGet (org.apache.http.client.methods.HttpGet)16 Subscriber (org.olat.core.commons.services.notifications.Subscriber)16 ArrayList (java.util.ArrayList)14 ContextualSubscriptionController (org.olat.core.commons.services.notifications.ui.ContextualSubscriptionController)12 Forum (org.olat.modules.fo.Forum)12 UriBuilder (javax.ws.rs.core.UriBuilder)10 SubscriptionInfoVO (org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO)8 SubscriptionListItemVO (org.olat.core.commons.services.notifications.restapi.vo.SubscriptionListItemVO)8 DBRuntimeException (org.olat.core.logging.DBRuntimeException)8 ICourse (org.olat.course.ICourse)8 File (java.io.File)6 URI (java.net.URI)6