You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by as...@apache.org on 2021/09/08 14:14:26 UTC
[unomi] branch UNOMI-506 created (now 9d34ec7)
This is an automated email from the ASF dual-hosted git repository.
asi pushed a change to branch UNOMI-506
in repository https://gitbox.apache.org/repos/asf/unomi.git.
at 9d34ec7 UNOMI-506 Delete aliases when a profile is deleted
This branch includes the following new commits:
new 9d34ec7 UNOMI-506 Delete aliases when a profile is deleted
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[unomi] 01/01: UNOMI-506 Delete aliases when a profile is deleted
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
asi pushed a commit to branch UNOMI-506
in repository https://gitbox.apache.org/repos/asf/unomi.git
commit 9d34ec7e3bba59da4bd0578b12eff3e6fc1a551c
Author: Anatol Sialitski <as...@enonic.com>
AuthorDate: Wed Sep 8 17:14:02 2021 +0300
UNOMI-506 Delete aliases when a profile is deleted
---
.../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);
}
}