Search in sources :

Example 36 with SubscriptionContext

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

the class EPStructureManager method removeStructureRecursively.

public void removeStructureRecursively(PortfolioStructure struct) {
    List<PortfolioStructure> children = loadStructureChildren(struct);
    for (PortfolioStructure childstruct : children) {
        removeStructureRecursively(childstruct);
    }
    // remove artefact-links
    List<AbstractArtefact> thisStructsArtefacts = getArtefacts(struct);
    for (AbstractArtefact artefact : thisStructsArtefacts) {
        removeArtefactFromStructure(artefact, struct, false);
    }
    // remove from parent
    PortfolioStructure parent = loadStructureParent(struct);
    if (parent == null && struct.getRoot() != null)
        parent = struct.getRoot();
    removeStructure(parent, struct);
    // remove collect restriction
    struct.getCollectRestrictions().clear();
    // remove sharings
    if (struct instanceof EPAbstractMap) {
        ((EPAbstractMap) struct).getGroups().clear();
    }
    // remove comments and ratings
    CommentAndRatingService commentAndRatingService = CoreSpringFactory.getImpl(CommentAndRatingService.class);
    commentAndRatingService.deleteAllIgnoringSubPath(struct.getOlatResource());
    // FXOLAT-431 remove subscriptions if the current struct is a map
    if (struct instanceof EPAbstractMap) {
        SubscriptionContext subsContext = new SubscriptionContext(EPNotificationsHandler.TYPENNAME, struct.getResourceableId(), EPNotificationsHandler.TYPENNAME);
        NotificationsManager.getInstance().delete(subsContext);
    }
    // remove structure itself
    struct = (EPStructureElement) dbInstance.loadObject((EPStructureElement) struct);
    dbInstance.deleteObject(struct);
    if (struct instanceof EPAbstractMap) {
        removeBaseGroup((EPAbstractMap) struct);
    }
    // which need the resource
    if (!(struct instanceof EPStructuredMapTemplate)) {
        resourceManager.deleteOLATResourceable(struct);
    }
}
Also used : EPAbstractMap(org.olat.portfolio.model.structel.EPAbstractMap) EPStructuredMapTemplate(org.olat.portfolio.model.structel.EPStructuredMapTemplate) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) CommentAndRatingService(org.olat.core.commons.services.commentAndRating.CommentAndRatingService) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext)

Example 37 with SubscriptionContext

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

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

the class UsersSubscriptionManagerImpl method unsubscribe.

/**
 * Unsubscribe to notifications of new identity created
 */
public void unsubscribe(Identity identity) {
    SubscriptionContext context = getNewUsersSubscriptionContext();
    NotificationsManager.getInstance().unsubscribe(identity, context);
}
Also used : SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext)

Example 39 with SubscriptionContext

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

the class UsersSubscriptionManagerImpl method subscribe.

/**
 * Subscribe to notifications of new identity created
 */
public void subscribe(Identity identity) {
    PublisherData data = getNewUsersPublisherData();
    SubscriptionContext context = getNewUsersSubscriptionContext();
    NotificationsManager.getInstance().subscribe(identity, context, data);
}
Also used : SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) PublisherData(org.olat.core.commons.services.notifications.PublisherData)

Example 40 with SubscriptionContext

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

the class BCCourseNode method cleanupOnDelete.

/**
 * Delete the folder if node is deleted.
 *
 * @see org.olat.course.nodes.CourseNode#cleanupOnDelete(org.olat.course.ICourse)
 */
@Override
public void cleanupOnDelete(ICourse course) {
    super.cleanupOnDelete(course);
    // mark the subscription to this node as deleted
    SubscriptionContext folderSubContext = CourseModule.createTechnicalSubscriptionContext(course.getCourseEnvironment(), this);
    NotificationsManager.getInstance().delete(folderSubContext);
    // delete filesystem
    File fFolderRoot = new File(FolderConfig.getCanonicalRoot() + getFoldernodePathRelToFolderBase(course.getCourseEnvironment(), this));
    if (fFolderRoot.exists())
        FileUtils.deleteDirsAndFiles(fFolderRoot, true, true);
}
Also used : SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) File(java.io.File)

Aggregations

SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)204 PublisherData (org.olat.core.commons.services.notifications.PublisherData)84 Identity (org.olat.core.id.Identity)72 Test (org.junit.Test)66 Publisher (org.olat.core.commons.services.notifications.Publisher)58 RepositoryEntry (org.olat.repository.RepositoryEntry)38 VFSContainer (org.olat.core.util.vfs.VFSContainer)32 VFSSecurityCallback (org.olat.core.util.vfs.callbacks.VFSSecurityCallback)28 BusinessGroup (org.olat.group.BusinessGroup)28 ArrayList (java.util.ArrayList)20 Subscriber (org.olat.core.commons.services.notifications.Subscriber)20 HttpResponse (org.apache.http.HttpResponse)18 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)18 Forum (org.olat.modules.fo.Forum)18 File (java.io.File)16 HttpGet (org.apache.http.client.methods.HttpGet)16 CollaborationTools (org.olat.collaboration.CollaborationTools)14 OLATResourceable (org.olat.core.id.OLATResourceable)14 NamedContainerImpl (org.olat.core.util.vfs.NamedContainerImpl)14 Roles (org.olat.core.id.Roles)12