You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by sh...@apache.org on 2021/09/14 11:00:42 UTC
[unomi] branch master updated: UNOMI-506 Delete aliases when a
profile is deleted (#336)
This is an automated email from the ASF dual-hosted git repository.
shuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/unomi.git
The following commit(s) were added to refs/heads/master by this push:
new d2b94cf UNOMI-506 Delete aliases when a profile is deleted (#336)
d2b94cf is described below
commit d2b94cfd6a9af3c5ddadc603a0d2e5649a56fdf8
Author: anatol-sialitski <53...@users.noreply.github.com>
AuthorDate: Tue Sep 14 14:00:38 2021 +0300
UNOMI-506 Delete aliases when a profile is deleted (#336)
---
.../org/apache/unomi/itests/ProfileServiceIT.java | 17 +++++++++++-
.../profileAliasesPropertyCondition.json | 31 ++++++++++++++++++++++
.../services/impl/profiles/ProfileServiceImpl.java | 6 +++++
3 files changed, 53 insertions(+), 1 deletion(-)
diff --git a/itests/src/test/java/org/apache/unomi/itests/ProfileServiceIT.java b/itests/src/test/java/org/apache/unomi/itests/ProfileServiceIT.java
index 9359d97..e9bf221 100644
--- a/itests/src/test/java/org/apache/unomi/itests/ProfileServiceIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/ProfileServiceIT.java
@@ -27,6 +27,7 @@ import org.apache.unomi.persistence.elasticsearch.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -57,6 +58,8 @@ public class ProfileServiceIT extends BaseIT {
private final static String TEST_PROFILE_ID = "test-profile-id";
+ private static final String TEST_PROFILE_ALIAS = "test-profile-alias";
+
@Inject @Filter(timeout = 600000)
protected ProfileService profileService;
@@ -74,12 +77,24 @@ public class ProfileServiceIT extends BaseIT {
}
@Test
- public void testProfileDelete() {
+ public void testProfileDelete() throws Exception {
Profile profile = new Profile();
profile.setItemId(TEST_PROFILE_ID);
profileService.save(profile);
+
+ refreshPersistence();
+
+ profileService.addAliasToProfile(profile.getItemId(), TEST_PROFILE_ALIAS, "defaultClientId");
+
+ refreshPersistence();
+
LOGGER.info("Profile saved, now testing profile delete...");
profileService.delete(TEST_PROFILE_ID, false);
+
+ refreshPersistence();
+
+ assertNull(profileService.load(TEST_PROFILE_ALIAS));
+
LOGGER.info("Profile deleted successfully.");
}
diff --git a/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/profileAliasesPropertyCondition.json b/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/profileAliasesPropertyCondition.json
new file mode 100644
index 0000000..50fa56b
--- /dev/null
+++ b/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/profileAliasesPropertyCondition.json
@@ -0,0 +1,31 @@
+{
+ "metadata": {
+ "id": "profileAliasesPropertyCondition",
+ "name": "profileAliasesPropertyCondition",
+ "description": "",
+ "systemTags": [
+ "condition",
+ "profileAliasesCondition"
+ ],
+ "readOnly": true
+ },
+ "conditionEvaluator": "propertyConditionEvaluator",
+ "queryBuilder": "propertyConditionESQueryBuilder",
+ "parameters": [
+ {
+ "id": "propertyName",
+ "type": "string",
+ "multivalued": false
+ },
+ {
+ "id": "comparisonOperator",
+ "type": "comparisonOperator",
+ "multivalued": false
+ },
+ {
+ "id": "propertyValue",
+ "type": "string",
+ "multivalued": false
+ }
+ ]
+}
diff --git a/services/src/main/java/org/apache/unomi/services/impl/profiles/ProfileServiceImpl.java b/services/src/main/java/org/apache/unomi/services/impl/profiles/ProfileServiceImpl.java
index d65479b..b241c44 100644
--- a/services/src/main/java/org/apache/unomi/services/impl/profiles/ProfileServiceImpl.java
+++ b/services/src/main/java/org/apache/unomi/services/impl/profiles/ProfileServiceImpl.java
@@ -637,6 +637,12 @@ public class ProfileServiceImpl implements ProfileService, SynchronousBundleList
mergeCondition.setParameter("propertyValue", profileId);
persistenceService.removeByQuery(mergeCondition, Profile.class);
+ Condition removeAliasesCondition = new Condition(definitionsService.getConditionType("profileAliasesPropertyCondition"));
+ removeAliasesCondition.setParameter("propertyName", "profileID");
+ removeAliasesCondition.setParameter("comparisonOperator", "equals");
+ removeAliasesCondition.setParameter("propertyValue", profileId);
+ persistenceService.removeByQuery(removeAliasesCondition, ProfileAlias.class);
+
persistenceService.remove(profileId, Profile.class);
}
}