Browse code

BM-12638 Fix: remove tags before tag container

David Phan authored on 08/02/2018 14:31:37
Showing 3 changed files
... ...
@@ -14,6 +14,7 @@ Require-Bundle: org.junit,
14 14
  net.bluemind.core.container.service;bundle-version="1.0.0",
15 15
  org.eclipse.core.runtime;bundle-version="3.7.0",
16 16
  net.bluemind.directory.service;bundle-version="3.1.0",
17
- net.bluemind.tests.defaultdata
17
+ net.bluemind.tests.defaultdata,
18
+ net.bluemind.tag.persistance
18 19
 
19 20
 
... ...
@@ -36,10 +36,13 @@ import net.bluemind.core.container.model.acl.AccessControlEntry;
36 36
 import net.bluemind.core.container.model.acl.Verb;
37 37
 import net.bluemind.core.container.persistance.AclStore;
38 38
 import net.bluemind.core.container.persistance.ContainerStore;
39
+import net.bluemind.core.container.persistance.ItemStore;
39 40
 import net.bluemind.core.context.SecurityContext;
40 41
 import net.bluemind.core.jdbc.JdbcActivator;
41 42
 import net.bluemind.core.jdbc.JdbcTestHelper;
42 43
 import net.bluemind.core.tests.BmTestContext;
44
+import net.bluemind.tag.api.Tag;
45
+import net.bluemind.tag.persistance.TagStore;
43 46
 import net.bluemind.tests.defaultdata.PopulateHelper;
44 47
 import net.bluemind.user.api.User;
45 48
 
... ...
@@ -95,9 +98,21 @@ public class UserTagHookTests {
95 95
 		Container tagContainer = containerStore.get("tags_" + userItem.uid);
96 96
 		assertNotNull(tagContainer);
97 97
 
98
+		// create tag
99
+		ItemStore itemStore = new ItemStore(JdbcTestHelper.getInstance().getDataSource(), tagContainer,
100
+				SecurityContext.SYSTEM);
101
+		itemStore.create(Item.create("tag", null));
102
+		Item item = itemStore.get("tag");
103
+		Tag tag = new Tag();
104
+		tag.label = "test";
105
+		tag.color = "00ff00";
106
+		TagStore tagStore = new TagStore(JdbcTestHelper.getInstance().getDataSource(), tagContainer);
107
+		tagStore.create(item, tag);
108
+
98 109
 		userTagHook.onUserDeleted(bmContext, domainUid, userItem);
99 110
 		tagContainer = containerStore.get("tags_" + userItem.uid);
100 111
 		assertNull(tagContainer);
112
+		assertNull(tagStore.get(item));
101 113
 	}
102 114
 
103 115
 	private ItemValue<User> testUser() {
... ...
@@ -105,6 +120,6 @@ public class UserTagHookTests {
105 105
 		String uid = UUID.randomUUID().toString();
106 106
 		Item item = Item.create(uid, null);
107 107
 		item.displayName = "test";
108
-		return ItemValue.<User> create(item, user);
108
+		return ItemValue.<User>create(item, user);
109 109
 	}
110 110
 }
... ...
@@ -19,6 +19,7 @@
19 19
 package net.bluemind.tag.hooks;
20 20
 
21 21
 import java.util.Arrays;
22
+import java.util.List;
22 23
 
23 24
 import org.slf4j.Logger;
24 25
 import org.slf4j.LoggerFactory;
... ...
@@ -33,6 +34,8 @@ import net.bluemind.core.container.model.acl.Verb;
33 33
 import net.bluemind.core.context.SecurityContext;
34 34
 import net.bluemind.core.rest.BmContext;
35 35
 import net.bluemind.core.rest.ServerSideServiceProvider;
36
+import net.bluemind.tag.api.ITags;
37
+import net.bluemind.tag.api.Tag;
36 38
 import net.bluemind.tag.api.TagsContainerType;
37 39
 import net.bluemind.user.api.User;
38 40
 import net.bluemind.user.hook.DefaultUserHook;
... ...
@@ -78,6 +81,13 @@ public class UserTagHook extends DefaultUserHook {
78 78
 
79 79
 				String containerUid = getTagsContainerUid(previous);
80 80
 
81
+				ITags tagsService = ServerSideServiceProvider.getProvider(SecurityContext.SYSTEM).instance(ITags.class,
82
+						containerUid);
83
+				List<ItemValue<Tag>> tags = tagsService.all();
84
+				tags.forEach(tag -> {
85
+					tagsService.delete(tag.uid);
86
+				});
87
+
81 88
 				IContainers cm = ServerSideServiceProvider.getProvider(SecurityContext.SYSTEM)
82 89
 						.instance(IContainers.class);
83 90