Skip to content

Commit

Permalink
use RequestLifeCycle insted of entityManagerService
Browse files Browse the repository at this point in the history
  • Loading branch information
sofyenne committed Jan 4, 2024
1 parent bd3e991 commit 7118904
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
Expand All @@ -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 {
Expand All @@ -83,7 +81,6 @@ public void processUpgrade(String s, String s1) {
return;
}
List<String> usersContexts;
entityManagerService.startRequest(currentContainer);
long startTime = System.currentTimeMillis();
do {
LOG.info(" Progression of users {} Notifications settings initialisation : {} users", notificationPlugin, current);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ public class ImportDocumentsNotificationUpgradePluginTest {

private static final MockedStatic<PortalContainer> PORTAL_CONTAINER = mockStatic(PortalContainer.class);

@Mock
private EntityManagerService entityManagerService;

@Mock
private SettingService settingService;

Expand Down Expand Up @@ -74,7 +71,6 @@ public void processUpgrade() throws Exception {
new ImportDocumentsNotificationUpgradePlugin(settingService,
userSettingService,
pluginSettingService,
entityManagerService,
initParams);
notificationUpgradePlugin.processUpgrade(null, null);
//
Expand Down

0 comments on commit 7118904

Please sign in to comment.