use of org.olat.core.commons.services.notifications.SubscriptionContext in project OpenOLAT by OpenOLAT.
the class NotificationsTest method setUp.
@Before
public void setUp() throws Exception {
super.setUp();
if (!setup) {
userSubscriberId = JunitTestHelper.createAndPersistIdentityAsUser("rest-notifications-test-1");
userAndForumSubscriberId = JunitTestHelper.createAndPersistIdentityAsUser("rest-notifications-test-2");
JunitTestHelper.createAndPersistIdentityAsUser("rest-notifications-test-3");
SubscriptionContext subContext = UsersSubscriptionManager.getInstance().getNewUsersSubscriptionContext();
PublisherData publisherData = UsersSubscriptionManager.getInstance().getNewUsersPublisherData();
if (!notificationManager.isSubscribed(userSubscriberId, subContext)) {
notificationManager.subscribe(userSubscriberId, subContext, publisherData);
}
if (!notificationManager.isSubscribed(userAndForumSubscriberId, subContext)) {
notificationManager.subscribe(userAndForumSubscriberId, subContext, publisherData);
}
// create a forum
forum = ForumManager.getInstance().addAForum();
Message m1 = createMessage(userSubscriberId, forum);
Assert.assertNotNull(m1);
// subscribe
SubscriptionContext forumSubContext = new SubscriptionContext("NotificationRestCourse", forum.getKey(), "2387");
PublisherData forumPdata = new PublisherData(OresHelper.calculateTypeName(Forum.class), forum.getKey().toString(), "");
if (!notificationManager.isSubscribed(userAndForumSubscriberId, forumSubContext)) {
notificationManager.subscribe(userAndForumSubscriberId, forumSubContext, forumPdata);
}
notificationManager.markPublisherNews(forumSubContext, userSubscriberId, true);
// generate one notification
String randomLogin = UUID.randomUUID().toString().replace("-", "");
JunitTestHelper.createAndPersistIdentityAsUser(randomLogin);
setup = true;
}
dbInstance.commitAndCloseSession();
}
use of org.olat.core.commons.services.notifications.SubscriptionContext in project OpenOLAT by OpenOLAT.
the class DialogCourseNode method cleanupOnDelete.
/**
* life cycle of node data e.g properties stuff should be deleted if node gets
* deleted life cycle: create - delete - migrate
*/
@Override
public void cleanupOnDelete(ICourse course) {
super.cleanupOnDelete(course);
DialogElementsManager depm = CoreSpringFactory.getImpl(DialogElementsManager.class);
RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
List<DialogElement> dialogElements = depm.getDialogElements(entry, getIdent());
for (DialogElement dialogElement : dialogElements) {
Long forumKey = dialogElement.getForum().getKey();
SubscriptionContext subsContext = CourseModule.createSubscriptionContext(course.getCourseEnvironment(), this, forumKey.toString());
NotificationsManager.getInstance().delete(subsContext);
depm.deleteDialogElement(dialogElement);
}
}
use of org.olat.core.commons.services.notifications.SubscriptionContext in project OpenOLAT by OpenOLAT.
the class PFManager method provideParticipantFolder.
/**
* Provide participant folder in GUI.
*
* @param pfNode
* @param pfView
* @param courseEnv
* @param identity
* @param isCoach
* @return the VFS container
*/
public VFSContainer provideParticipantFolder(PFCourseNode pfNode, PFView pfView, Translator translator, CourseEnvironment courseEnv, Identity identity, boolean isCoach, boolean readOnly) {
SubscriptionContext nodefolderSubContext = CourseModule.createSubscriptionContext(courseEnv, pfNode);
String path = courseEnv.getCourseBaseContainer().getRelPath() + "/" + FILENAME_PARTICIPANTFOLDER;
VFSContainer courseElementBaseContainer = new OlatRootFolderImpl(path, null);
Path relPath = Paths.get(pfNode.getIdent(), getIdFolderName(identity));
VFSContainer userBaseContainer = VFSManager.resolveOrCreateContainerFromPath(courseElementBaseContainer, relPath.toString());
String baseContainerName = userManager.getUserDisplayName(identity);
VirtualContainer namedCourseFolder = new VirtualContainer(baseContainerName);
namedCourseFolder.setLocalSecurityCallback(new ReadOnlyCallback(nodefolderSubContext));
VFSContainer dropContainer = new NamedContainerImpl(PFView.onlyDrop.equals(pfView) || PFView.onlyReturn.equals(pfView) ? baseContainerName : translator.translate("drop.box"), VFSManager.resolveOrCreateContainerFromPath(userBaseContainer, FILENAME_DROPBOX));
if (pfNode.hasParticipantBoxConfigured()) {
namedCourseFolder.addItem(dropContainer);
}
VFSContainer returnContainer = new NamedContainerImpl(PFView.onlyDrop.equals(pfView) || PFView.onlyReturn.equals(pfView) ? baseContainerName : translator.translate("return.box"), VFSManager.resolveOrCreateContainerFromPath(userBaseContainer, FILENAME_RETURNBOX));
if (pfNode.hasCoachBoxConfigured()) {
namedCourseFolder.addItem(returnContainer);
}
if (readOnly) {
dropContainer.setLocalSecurityCallback(new ReadOnlyCallback(nodefolderSubContext));
returnContainer.setLocalSecurityCallback(new ReadOnlyCallback(nodefolderSubContext));
} else {
if (isCoach) {
dropContainer.setLocalSecurityCallback(new ReadOnlyCallback(nodefolderSubContext));
returnContainer.setLocalSecurityCallback(new ReadWriteDeleteCallback(nodefolderSubContext));
} else {
VFSContainer dropbox = resolveOrCreateDropFolder(courseEnv, pfNode, identity);
VFSSecurityCallback callback = calculateCallback(courseEnv, pfNode, dropbox, false);
dropContainer.setLocalSecurityCallback(callback);
returnContainer.setLocalSecurityCallback(new ReadOnlyCallback(nodefolderSubContext));
}
}
VFSContainer folderRunContainer;
switch(pfView) {
case dropAndReturn:
folderRunContainer = namedCourseFolder;
break;
case onlyDrop:
folderRunContainer = dropContainer;
break;
case onlyReturn:
folderRunContainer = returnContainer;
break;
default:
folderRunContainer = namedCourseFolder;
break;
}
return folderRunContainer;
}
use of org.olat.core.commons.services.notifications.SubscriptionContext in project OpenOLAT by OpenOLAT.
the class PFManager method provideParticipantContainer.
/**
* Provide participant view in webdav.
*
* @param pfNode
* @param courseEnv
* @param identity
* @return the VFS container
*/
private VFSContainer provideParticipantContainer(PFCourseNode pfNode, CourseEnvironment courseEnv, Identity identity, boolean courseReadOnly) {
Locale locale = I18nManager.getInstance().getLocaleOrDefault(identity.getUser().getPreferences().getLanguage());
Translator translator = Util.createPackageTranslator(PFRunController.class, locale);
SubscriptionContext subsContext = CourseModule.createSubscriptionContext(courseEnv, pfNode);
String path = courseEnv.getCourseBaseContainer().getRelPath() + "/" + FILENAME_PARTICIPANTFOLDER;
VFSContainer courseElementBaseContainer = new OlatRootFolderImpl(path, null);
VirtualContainer namedCourseFolder = new VirtualContainer(identity.getName());
Path relPath = Paths.get(pfNode.getIdent(), getIdFolderName(identity));
VFSContainer userBaseContainer = VFSManager.resolveOrCreateContainerFromPath(courseElementBaseContainer, relPath.toString());
if (pfNode.hasParticipantBoxConfigured()) {
VFSContainer dropContainer = new NamedContainerImpl(translator.translate("drop.box"), VFSManager.resolveOrCreateContainerFromPath(userBaseContainer, FILENAME_DROPBOX));
if (courseReadOnly) {
dropContainer.setLocalSecurityCallback(new ReadOnlyCallback(subsContext));
} else {
VFSContainer dropbox = resolveOrCreateDropFolder(courseEnv, pfNode, identity);
VFSSecurityCallback callback = calculateCallback(courseEnv, pfNode, dropbox, true);
dropContainer.setLocalSecurityCallback(callback);
}
namedCourseFolder.addItem(dropContainer);
}
if (pfNode.hasCoachBoxConfigured()) {
VFSContainer returnContainer = new NamedContainerImpl(translator.translate("return.box"), VFSManager.resolveOrCreateContainerFromPath(userBaseContainer, FILENAME_RETURNBOX));
returnContainer.setLocalSecurityCallback(new ReadOnlyCallback(subsContext));
namedCourseFolder.addItem(returnContainer);
}
return namedCourseFolder;
}
use of org.olat.core.commons.services.notifications.SubscriptionContext in project OpenOLAT by OpenOLAT.
the class PFManager method provideAdminContainer.
/**
* Provide admin view for webdav, contains all participants of the course.
*
* @param pfNode the pf node
* @param courseEnv the course env
* @return the VFS container
*/
public VFSContainer provideAdminContainer(PFCourseNode pfNode, CourseEnvironment courseEnv) {
Translator translator = Util.createPackageTranslator(PFRunController.class, I18nModule.getDefaultLocale());
SubscriptionContext nodefolderSubContext = CourseModule.createSubscriptionContext(courseEnv, pfNode);
RepositoryEntry re = courseEnv.getCourseGroupManager().getCourseEntry();
List<Identity> participants = repositoryEntryRelationDao.getMembers(re, RepositoryEntryRelationType.both, GroupRoles.participant.name());
participants = new ArrayList<>(new HashSet<>(participants));
String path = courseEnv.getCourseBaseContainer().getRelPath() + "/" + FILENAME_PARTICIPANTFOLDER;
VFSContainer courseElementBaseContainer = new OlatRootFolderImpl(path, null);
VirtualContainer namedCourseFolder = new VirtualContainer(translator.translate("participant.folder"));
for (Identity participant : participants) {
Path relPath = Paths.get(pfNode.getIdent(), getIdFolderName(participant));
VFSContainer userBaseContainer = VFSManager.resolveOrCreateContainerFromPath(courseElementBaseContainer, relPath.toString());
String participantfoldername = userManager.getUserDisplayName(participant);
VirtualContainer participantFolder = new VirtualContainer(participantfoldername);
participantFolder.setParentContainer(namedCourseFolder);
namedCourseFolder.addItem(participantFolder);
if (pfNode.hasParticipantBoxConfigured()) {
VFSContainer dropContainer = new NamedContainerImpl(translator.translate("drop.box"), VFSManager.resolveOrCreateContainerFromPath(userBaseContainer, FILENAME_DROPBOX));
dropContainer.setLocalSecurityCallback(new ReadOnlyCallback(nodefolderSubContext));
participantFolder.addItem(dropContainer);
}
if (pfNode.hasCoachBoxConfigured()) {
VFSContainer returnContainer = new NamedContainerImpl(translator.translate("return.box"), VFSManager.resolveOrCreateContainerFromPath(userBaseContainer, FILENAME_RETURNBOX));
returnContainer.setLocalSecurityCallback(new ReadWriteDeleteCallback(nodefolderSubContext));
participantFolder.addItem(returnContainer);
}
}
return namedCourseFolder;
}
Aggregations