diff --git a/data-upgrade-notifications/src/main/java/org/exoplatform/portal/upgrade/notification/ImportDocumentsNotificationUpgradePlugin.java b/data-upgrade-notifications/src/main/java/org/exoplatform/portal/upgrade/notification/ImportDocumentsNotificationUpgradePlugin.java index 3dc5821e4..510b10d4d 100644 --- a/data-upgrade-notifications/src/main/java/org/exoplatform/portal/upgrade/notification/ImportDocumentsNotificationUpgradePlugin.java +++ b/data-upgrade-notifications/src/main/java/org/exoplatform/portal/upgrade/notification/ImportDocumentsNotificationUpgradePlugin.java @@ -14,6 +14,7 @@ import org.exoplatform.commons.upgrade.UpgradeProductPlugin; import org.exoplatform.container.ExoContainer; import org.exoplatform.container.ExoContainerContext; +import org.exoplatform.container.component.RequestLifeCycle; import org.exoplatform.container.xml.InitParams; import org.exoplatform.services.log.ExoLogger; import org.exoplatform.services.log.Log; @@ -30,20 +31,16 @@ public class ImportDocumentsNotificationUpgradePlugin extends UpgradeProductPlug private final PluginSettingService pluginSettingService; - private final EntityManagerService entityManagerService; - private String notificationPlugin; public ImportDocumentsNotificationUpgradePlugin(SettingService settingService, UserSettingService userSettingService, PluginSettingService pluginSettingService, - EntityManagerService entityManagerService, InitParams initParams) { super(settingService, initParams); this.settingService = settingService; this.userSettingService = userSettingService; this.pluginSettingService = pluginSettingService; - this.entityManagerService = entityManagerService; if (initParams.containsKey(NOTIFICATION_PLUGIN)) { notificationPlugin = initParams.getValueParam(NOTIFICATION_PLUGIN).getValue(); } @@ -64,6 +61,7 @@ public void processUpgrade(String s, String s1) { return; } ExoContainer currentContainer = ExoContainerContext.getCurrentContainer(); + RequestLifeCycle.begin(currentContainer); int pageSize = 20; int current = 0; try { @@ -83,7 +81,6 @@ public void processUpgrade(String s, String s1) { return; } List usersContexts; - entityManagerService.startRequest(currentContainer); long startTime = System.currentTimeMillis(); do { LOG.info(" Progression of users {} Notifications settings initialisation : {} users", notificationPlugin, current); @@ -92,8 +89,6 @@ public void processUpgrade(String s, String s1) { if (usersContexts != null) { for (String userName : usersContexts) { try { - entityManagerService.endRequest(currentContainer); - entityManagerService.startRequest(currentContainer); UserSetting userSetting = this.userSettingService.get(userName); if (userSetting != null) { updateSetting(userSetting, pluginTypeConfig); @@ -111,7 +106,7 @@ public void processUpgrade(String s, String s1) { } catch (Exception e) { LOG.error("Error while initialisation of users {} Notifications settings - Cause :", notificationPlugin, e.getMessage(), e); } finally { - entityManagerService.endRequest(currentContainer); + RequestLifeCycle.end(); } LOG.info("=== {} users with modified notifications settings have been found and processed successfully", current); LOG.info("=== End initialisation of {} Notifications settings", notificationPlugin); diff --git a/data-upgrade-notifications/src/test/java/org/exoplatform/portal/upgrade/notification/ImportDocumentsNotificationUpgradePluginTest.java b/data-upgrade-notifications/src/test/java/org/exoplatform/portal/upgrade/notification/ImportDocumentsNotificationUpgradePluginTest.java index 79c60b4c2..b690c413f 100644 --- a/data-upgrade-notifications/src/test/java/org/exoplatform/portal/upgrade/notification/ImportDocumentsNotificationUpgradePluginTest.java +++ b/data-upgrade-notifications/src/test/java/org/exoplatform/portal/upgrade/notification/ImportDocumentsNotificationUpgradePluginTest.java @@ -30,9 +30,6 @@ public class ImportDocumentsNotificationUpgradePluginTest { private static final MockedStatic PORTAL_CONTAINER = mockStatic(PortalContainer.class); - @Mock - private EntityManagerService entityManagerService; - @Mock private SettingService settingService; @@ -74,7 +71,6 @@ public void processUpgrade() throws Exception { new ImportDocumentsNotificationUpgradePlugin(settingService, userSettingService, pluginSettingService, - entityManagerService, initParams); notificationUpgradePlugin.processUpgrade(null, null); //