Skip to content
This repository was archived by the owner on Jan 15, 2022. It is now read-only.

Commit a76e22e

Browse files
authored
PLF-8447 : "Send me a digest email" on notification settings is not working (#412)
* PLF-8447 : Resume Daily and weekly digest mails jobs (#406) * PLF-8447 : Resume Daily and weekly digest mails jobs This commit add an upgrade plugin to resume jobs in environments in which the migration is already done. * PLF-8447 : Resume Daily and weekly digest mails jobs Before this fix, the Upgrade Plugin was not launched if the platform is already in version 6.0 In fact, for tribe, this plugin will be not launched. The fix change the target version for the UP so that it will be started also on 6.0.x * PLF-8447 : Send Digest mail are not working Before this fix, when the Upgrade Plugin is applied after a lot af weeks without running, all pending notification will be treated and sent. This Fix remove all daily and weekly notifications which are pending. * Use MailNotificationStorage instead of DAO * PLF-8447 : manage error. If an error occurs, throw it to relaunch the UP at next startup * PLF-8447 : limit the digest to version after 5.2.0 * PLF-8447 : the delete digest must be run if oldVersion is 5.2.0 * Update exception management * Add unit test * Update file headers
1 parent 7115e19 commit a76e22e

3 files changed

Lines changed: 167 additions & 0 deletions

File tree

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package org.exoplatform.platform.upgrade.plugins;
2+
3+
import org.exoplatform.commons.api.notification.NotificationContext;
4+
import org.exoplatform.commons.api.notification.service.storage.MailNotificationStorage;
5+
import org.exoplatform.commons.notification.impl.NotificationContextImpl;
6+
import org.exoplatform.commons.notification.impl.jpa.email.JPAMailNotificationStorage;
7+
import org.exoplatform.commons.notification.impl.jpa.email.dao.MailDigestDAO;
8+
import org.exoplatform.commons.notification.job.NotificationJob;
9+
import org.exoplatform.commons.upgrade.UpgradeProductPlugin;
10+
import org.exoplatform.commons.version.util.VersionComparator;
11+
import org.exoplatform.container.xml.InitParams;
12+
import org.exoplatform.services.log.ExoLogger;
13+
import org.exoplatform.services.log.Log;
14+
import org.exoplatform.services.scheduler.JobSchedulerService;
15+
16+
17+
/**
18+
* Upgrade plugin to resume daily and weekly digest jobs.
19+
* This jobs have been paused during migration of notification from JCR to RDBMS
20+
* This UP resume both jobs
21+
* In addition, if the migration comes from version 5.2.0+, we completly delete stored digest.
22+
* In fact, during the time the jobs were paused, the digest were stored in DB.
23+
* If we don't delete it, the first start will create old for old digests.
24+
*
25+
* Finally, if we upgrade from a version before 5.2.0, we don't delete digest :
26+
* The jobs were not paused, and there is no "old" digests stored.
27+
*/
28+
29+
public class ResumeDigestJobUpgradePlugin extends UpgradeProductPlugin {
30+
31+
private JobSchedulerService schedulerService;
32+
private MailNotificationStorage mailNotificationStorage;
33+
34+
private static final Log LOG = ExoLogger.getLogger(ResumeDigestJobUpgradePlugin.class);
35+
36+
37+
public ResumeDigestJobUpgradePlugin(JobSchedulerService schedulerService, MailNotificationStorage mailNotificationStorage, InitParams initParams) {
38+
super(initParams);
39+
this.mailNotificationStorage=mailNotificationStorage;
40+
this.schedulerService = schedulerService;
41+
}
42+
43+
44+
@Override
45+
public void processUpgrade(String oldVersion, String newVersion) {
46+
47+
48+
try {
49+
//Force remove digest items only source migration version is after 5.2.0
50+
//Before this version, there is no problem of blocking digest, so no need of delete it
51+
if (VersionComparator.isAfter(oldVersion, "5.2.0") ||
52+
VersionComparator.isSame(oldVersion, "5.2.0")) {
53+
NotificationContext context = NotificationContextImpl.cloneInstance();
54+
55+
//force remove weekly notification digest
56+
context.append(NotificationJob.JOB_DAILY, false);
57+
context.append(NotificationJob.JOB_WEEKLY, true);
58+
mailNotificationStorage.removeMessageAfterSent(context);
59+
60+
//force remove daily notification digest
61+
context.append(NotificationJob.JOB_WEEKLY, false);
62+
context.append(NotificationJob.JOB_DAILY, true);
63+
mailNotificationStorage.removeMessageAfterSent(context);
64+
}
65+
66+
schedulerService.resumeJob("NotificationDailyJob", "Notification");
67+
schedulerService.resumeJob("NotificationWeeklyJob", "Notification");
68+
} catch (Exception e) {
69+
LOG.error("Error when resuming daily and weekly job",e);
70+
throw new RuntimeException("An error occurred when resuming daily and weekly job");
71+
}
72+
}
73+
74+
@Override
75+
public boolean shouldProceedToUpgrade(String newVersion, String previousVersion) {
76+
return VersionComparator.isAfter(newVersion, previousVersion);
77+
}
78+
79+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.exoplatform.platform.upgrade.plugins;
2+
3+
import org.exoplatform.commons.api.notification.NotificationContext;
4+
import org.exoplatform.commons.api.notification.service.storage.MailNotificationStorage;
5+
import org.exoplatform.container.xml.InitParams;
6+
import org.exoplatform.services.scheduler.JobSchedulerService;
7+
import org.junit.Test;
8+
9+
import static org.mockito.Mockito.*;
10+
11+
public class ResumeDigestJobUpgradePluginTest {
12+
13+
@Test
14+
public void testResumeDigestJobUpgradePluginFrom510To520() throws Exception {
15+
//Given
16+
JobSchedulerService schedulerService = mock(JobSchedulerService.class);
17+
MailNotificationStorage mailNotificationStorage = mock(MailNotificationStorage.class);
18+
19+
// When
20+
ResumeDigestJobUpgradePlugin plugin = new ResumeDigestJobUpgradePlugin(schedulerService,
21+
mailNotificationStorage, new InitParams());
22+
plugin.processUpgrade("5.1.0", "5.2.0");
23+
24+
// Then
25+
verify(mailNotificationStorage, times(0)).removeMessageAfterSent(any(NotificationContext.class));
26+
verify(schedulerService,times(2)).resumeJob(anyString(),anyString());
27+
}
28+
29+
@Test
30+
public void testResumeDigestJobUpgradePluginFrom520To600() throws Exception {
31+
//Given
32+
JobSchedulerService schedulerService = mock(JobSchedulerService.class);
33+
MailNotificationStorage mailNotificationStorage = mock(MailNotificationStorage.class);
34+
35+
// When
36+
ResumeDigestJobUpgradePlugin plugin = new ResumeDigestJobUpgradePlugin(schedulerService,
37+
mailNotificationStorage, new InitParams());
38+
plugin.processUpgrade("5.2.0", "6.0.0");
39+
40+
// Then
41+
verify(mailNotificationStorage, times(2)).removeMessageAfterSent(any(NotificationContext.class));
42+
verify(schedulerService,times(2)).resumeJob(anyString(),anyString());
43+
}
44+
45+
@Test
46+
public void testResumeDigestJobUpgradePluginFrom510To600() throws Exception {
47+
//Given
48+
JobSchedulerService schedulerService = mock(JobSchedulerService.class);
49+
MailNotificationStorage mailNotificationStorage = mock(MailNotificationStorage.class);
50+
51+
// When
52+
ResumeDigestJobUpgradePlugin plugin = new ResumeDigestJobUpgradePlugin(schedulerService,
53+
mailNotificationStorage, new InitParams());
54+
plugin.processUpgrade("5.1.0", "6.0.0");
55+
56+
// Then
57+
verify(mailNotificationStorage, times(0)).removeMessageAfterSent(any(NotificationContext.class));
58+
verify(schedulerService,times(2)).resumeJob(anyString(),anyString());
59+
}
60+
}

extension/webapp/src/main/webapp/WEB-INF/conf/platform/upgrade/upgrade-configuration.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,5 +609,33 @@
609609
</value-param>
610610
</init-params>
611611
</component-plugin>
612+
<component-plugin>
613+
<name>ResumeDigestJobUpgradePlugin</name>
614+
<set-method>addUpgradePlugin</set-method>
615+
<type>org.exoplatform.platform.upgrade.plugins.ResumeDigestJobUpgradePlugin</type>
616+
<description>Resume the digest notification jobs daily and weekly (deactivated by mail notification migration)</description>
617+
<init-params>
618+
<value-param>
619+
<name>product.group.id</name>
620+
<description>The groupId of the product</description>
621+
<value>org.exoplatform.platform</value>
622+
</value-param>
623+
<value-param>
624+
<name>plugin.execution.order</name>
625+
<description>The plugin execution order</description>
626+
<value>2</value>
627+
</value-param>
628+
<value-param>
629+
<name>plugin.upgrade.execute.once</name>
630+
<description>Execute this upgrade pluginonly once</description>
631+
<value>true</value>
632+
</value-param>
633+
<value-param>
634+
<name>plugin.upgrade.target.version</name>
635+
<description>Target version of the plugin</description>
636+
<value>6.0.0</value>
637+
</value-param>
638+
</init-params>
639+
</component-plugin>
612640
</external-component-plugins>
613641
</configuration>

0 commit comments

Comments
 (0)