use of org.olat.core.commons.services.notifications.Publisher in project OpenOLAT by OpenOLAT.
the class ForumNotificationsHandler method createSubscriptionInfo.
/**
* @see org.olat.core.commons.services.notifications.NotificationsHandler#createSubscriptionInfo(org.olat.core.commons.services.notifications.Subscriber,
* java.util.Locale, java.util.Date)
*/
@Override
public SubscriptionInfo createSubscriptionInfo(final Subscriber subscriber, Locale locale, Date compareDate) {
try {
Publisher p = subscriber.getPublisher();
Date latestNews = p.getLatestNewsDate();
SubscriptionInfo si;
// there could be news for me, investigate deeper
if (NotificationsManager.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
String businessControlString = "";
Long forumKey = Long.valueOf(0);
try {
forumKey = Long.parseLong(p.getData());
} catch (NumberFormatException e) {
logError("Could not parse forum key!", e);
NotificationsManager.getInstance().deactivate(p);
return NotificationsManager.getInstance().getNoSubscriptionInfo();
}
if ("CourseModule".equals(p.getResName())) {
RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(OresHelper.createOLATResourceableInstance(p.getResName(), p.getResId()), false);
if (re.getRepositoryEntryStatus().isClosed() || re.getRepositoryEntryStatus().isUnpublished()) {
return NotificationsManager.getInstance().getNoSubscriptionInfo();
}
}
final List<Message> mInfos = ForumManager.getInstance().getNewMessageInfo(forumKey, compareDate);
final Translator translator = Util.createPackageTranslator(ForumNotificationsHandler.class, locale);
businessControlString = p.getBusinessPath() + "[Message:";
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), getTitleItem(p, translator), null);
for (Message mInfo : mInfos) {
String title = mInfo.getTitle();
Identity creator = mInfo.getCreator();
Identity modifier = mInfo.getModifier();
Date modDate = mInfo.getLastModified();
String name;
if (modifier != null) {
if (modifier.equals(creator) && StringHelper.containsNonWhitespace(mInfo.getPseudonym())) {
name = mInfo.getPseudonym();
} else {
name = NotificationHelper.getFormatedName(modifier);
}
} else if (StringHelper.containsNonWhitespace(mInfo.getPseudonym())) {
name = mInfo.getPseudonym();
} else if (mInfo.isGuest()) {
name = translator.translate("anonymous.poster");
} else {
name = NotificationHelper.getFormatedName(creator);
}
final String descKey = "notifications.entry" + (mInfo.getCreationDate().equals(mInfo.getLastModified()) ? "" : ".modified");
final String desc = translator.translate(descKey, new String[] { title, name });
String urlToSend = null;
String businessPath = null;
if (p.getBusinessPath() != null) {
businessPath = businessControlString + mInfo.getKey().toString() + "]";
urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
}
SubscriptionListItem subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, ForumHelper.CSS_ICON_CLASS_MESSAGE);
si.addSubscriptionListItem(subListItem);
}
} else {
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
return si;
} catch (Exception e) {
log.error("Error while creating forum's notifications from publisher with key:" + subscriber.getKey(), e);
checkPublisher(subscriber.getPublisher());
return NotificationsManager.getInstance().getNoSubscriptionInfo();
}
}
use of org.olat.core.commons.services.notifications.Publisher in project OpenOLAT by OpenOLAT.
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);
}
use of org.olat.core.commons.services.notifications.Publisher in project OpenOLAT by OpenOLAT.
the class BusinessGroupMembershipProcessorTest method testUnlinkRepositoryEntry.
@Test
public void testUnlinkRepositoryEntry() {
RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
// 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.addRelationToResource(businessGroup, re);
businessGroupRelationDao.addRole(id1, businessGroup, GroupRoles.participant.name());
businessGroupRelationDao.addRole(id2, businessGroup, GroupRoles.participant.name());
repositoryEntryRelationDao.addRole(coach, re, GroupRoles.owner.name());
// create a publisher
SubscriptionContext context = new SubscriptionContext(re.getOlatResource(), "");
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 link between group and repository entry
businessGroupService.removeResourceFrom(Collections.singletonList(businessGroup), re);
dbInstance.commitAndCloseSession();
// wait for the remove of subscription
waitForCondition(new CheckUnsubscription(id1, context, dbInstance, notificationManager), 5000);
waitForCondition(new CheckUnsubscription(id2, 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.assertFalse(subscribedId2);
boolean subscribedCoach = notificationManager.isSubscribed(coach, context);
Assert.assertTrue(subscribedCoach);
}
use of org.olat.core.commons.services.notifications.Publisher in project OpenOLAT by OpenOLAT.
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);
}
use of org.olat.core.commons.services.notifications.Publisher in project OpenOLAT by OpenOLAT.
the class AbstractTaskNotificationHandler method createSubscriptionInfo.
/**
* @see org.olat.core.commons.services.notifications.NotificationsHandler#createSubscriptionInfo(org.olat.core.commons.services.notifications.Subscriber,
* java.util.Locale, java.util.Date)
*/
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
Publisher p = subscriber.getPublisher();
Date latestNews = p.getLatestNewsDate();
SubscriptionInfo si;
// there could be news for me, investigate deeper
try {
if (NotificationsManager.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
String folderRoot = p.getData();
if (isLogDebugEnabled()) {
logDebug("folderRoot=", folderRoot);
}
final List<FileInfo> fInfos = FolderManager.getFileInfos(folderRoot, compareDate);
final Translator translator = Util.createPackageTranslator(AbstractTaskNotificationHandler.class, locale);
RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(OresHelper.createOLATResourceableInstance("CourseModule", p.getResId()), false);
if (re == null) {
if (!checkPublisher(p)) {
return NotificationsManager.getInstance().getNoSubscriptionInfo();
}
} else if (re.getRepositoryEntryStatus().isClosed()) {
return NotificationsManager.getInstance().getNoSubscriptionInfo();
}
String displayName = re.getDisplayname();
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(translator.translate(getNotificationHeaderKey(), new String[] { displayName }), getCssClassIcon()), null);
SubscriptionListItem subListItem;
for (Iterator<FileInfo> it_infos = fInfos.iterator(); it_infos.hasNext(); ) {
FileInfo fi = it_infos.next();
MetaInfo metaInfo = fi.getMetaInfo();
String filePath = fi.getRelPath();
if (isLogDebugEnabled())
logDebug("filePath=", filePath);
String fullUserName = getUserNameFromFilePath(metaInfo, filePath);
Date modDate = fi.getLastModified();
String desc = translator.translate(getNotificationEntryKey(), new String[] { filePath, fullUserName });
String businessPath = p.getBusinessPath();
String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
String iconCssClass = null;
if (metaInfo != null) {
iconCssClass = metaInfo.getIconCssClass();
}
subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, iconCssClass);
si.addSubscriptionListItem(subListItem);
}
} else {
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
} catch (Exception e) {
getLogger().error("Cannot create task notifications for subscriber: " + subscriber.getKey(), e);
checkPublisher(p);
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
return si;
}
Aggregations