From 51544d24ca740eb263293f74d110560d62667e42 Mon Sep 17 00:00:00 2001
From: Anwar khanfir <93767376+akhanfir@users.noreply.github.com>
Date: Tue, 26 Nov 2024 14:04:04 +0100
Subject: [PATCH] fix: Create a new upgrade plugin to add remove duplicated
favorite applications - EXO-75399. (#258)
Before this change, some users have duplicate favorite applications. To resolve this problem, create an upgrade plugin that fetches all duplicates and keeps one of each duplicate and removes the rest of the items. After this change, all duplicate favorite applications are removed for all users and one favorite application is kept from each duplicate.
---
data-upgrade-app-center/pom.xml | 39 ++++++++
.../upgrade/CleanFavoriteApplications.java | 97 +++++++++++++++++++
.../resources/conf/portal/configuration.xml | 62 ++++++++++++
.../CleanFavoriteApplicationsTest.java | 69 +++++++++++++
pom.xml | 1 +
5 files changed, 268 insertions(+)
create mode 100644 data-upgrade-app-center/pom.xml
create mode 100644 data-upgrade-app-center/src/main/java/org/exoplatform/upgrade/CleanFavoriteApplications.java
create mode 100644 data-upgrade-app-center/src/main/resources/conf/portal/configuration.xml
create mode 100644 data-upgrade-app-center/src/test/java/org/exoplatform/upgrade/CleanFavoriteApplicationsTest.java
diff --git a/data-upgrade-app-center/pom.xml b/data-upgrade-app-center/pom.xml
new file mode 100644
index 00000000..856d5181
--- /dev/null
+++ b/data-upgrade-app-center/pom.xml
@@ -0,0 +1,39 @@
+
+
+
+ 4.0.0
+
+ org.exoplatform.addons.upgrade
+ upgrade
+ 7.0.x-maintenance-SNAPSHOT
+
+ data-upgrade-app-center
+ jar
+ eXo Add-on:: Data Upgrade Add-on - App center
+
+ 0.84
+
+
+
+ io.meeds.commons
+ commons-component-upgrade
+ provided
+
+
+ io.meeds.app-center
+ app-center-services
+ compile
+
+
+
\ No newline at end of file
diff --git a/data-upgrade-app-center/src/main/java/org/exoplatform/upgrade/CleanFavoriteApplications.java b/data-upgrade-app-center/src/main/java/org/exoplatform/upgrade/CleanFavoriteApplications.java
new file mode 100644
index 00000000..92ce2c0a
--- /dev/null
+++ b/data-upgrade-app-center/src/main/java/org/exoplatform/upgrade/CleanFavoriteApplications.java
@@ -0,0 +1,97 @@
+package org.exoplatform.upgrade;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.exoplatform.commons.api.persistence.ExoTransactional;
+import org.exoplatform.commons.persistence.impl.EntityManagerService;
+import org.exoplatform.commons.upgrade.UpgradeProductPlugin;
+import org.exoplatform.container.xml.InitParams;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import io.meeds.appcenter.entity.ApplicationEntity;
+import io.meeds.appcenter.entity.FavoriteApplicationEntity;
+import jakarta.persistence.EntityManager;
+import jakarta.persistence.Query;
+
+public class CleanFavoriteApplications extends UpgradeProductPlugin {
+
+ private static final Log log = ExoLogger.getLogger(CleanFavoriteApplications.class.getName());
+
+ private EntityManagerService entityManagerService;
+
+ public CleanFavoriteApplications(InitParams initParams, EntityManagerService entityManagerService) {
+ super(initParams);
+ this.entityManagerService = entityManagerService;
+ }
+
+ @Override
+ public void processUpgrade(String oldVersion, String newVersion) {
+ long startupTime = System.currentTimeMillis();
+ EntityManager entityManager = this.entityManagerService.getEntityManager();
+ List