Browse code

BM-12789 Fix: sql group containing members query

David Phan authored on 08/02/2018 07:20:00
Showing 2 changed files
... ...
@@ -110,7 +110,7 @@ public class VCardStore extends AbstractItemValueStore<VCard> {
110 110
 	public List<String> findGroupsContaining(String[] uid) throws SQLException {
111 111
 		String query = "select item.uid from t_addressbook_vcard card, t_container_item item where "
112 112
 				+ " item.container_id = ? AND card.item_id = item.id" //
113
-				+ " AND card.member_item_uid @> ( ?::text[] ) ";
113
+				+ " AND card.member_item_uid && ( ?::text[] ) ";
114 114
 
115 115
 		return select(query, StringCreator.FIRST, Collections.emptyList(), new Object[] { container.id, uid });
116 116
 
... ...
@@ -957,4 +957,49 @@ public class AddressBookServiceTests extends AbstractServiceTests {
957 957
 		assertEquals("moi et toi", gcardItem.value.organizational.member.get(1).commonName);
958 958
 	}
959 959
 
960
+	@Test
961
+	public void testMultipleUpadtesGroup() {
962
+		// Vcard 1 in group1
963
+		VCard card1 = defaultVCard();
964
+		cardStoreService.create("vcard1", card1.identification.formatedName.value, card1);
965
+		VCard gcard = new VCard();
966
+		gcard.identification.formatedName = VCard.Identification.FormatedName.create("group",
967
+				Arrays.<VCard.Parameter>asList());
968
+		gcard.organizational.member = Arrays.<VCard.Organizational.Member>asList(
969
+				Member.create(container.uid, "vcard1", "gg", "vcard1@toto.com"));
970
+		cardStoreService.create("gcard", "gcard", gcard);
971
+		long gcardVersion = getService(defaultSecurityContext).getComplete("gcard").version;
972
+
973
+		// VCard 2 in group2
974
+		VCard card2 = defaultVCard();
975
+		cardStoreService.create("vcard2", card2.identification.formatedName.value, card2);
976
+		VCard gcard2 = new VCard();
977
+		gcard2.identification.formatedName = VCard.Identification.FormatedName.create("group",
978
+				Arrays.<VCard.Parameter>asList());
979
+		gcard2.organizational.member = Arrays.<VCard.Organizational.Member>asList(
980
+				Member.create(container.uid, "vcard2", "gg2", "vcard2@toto.com"));
981
+		cardStoreService.create("gcard2", "gcard2", gcard2);
982
+		long gcard2Version = getService(defaultSecurityContext).getComplete("gcard2").version;
983
+
984
+		card1.communications.emails = Arrays.asList(Email.create("updated-card1@toto.com"));
985
+		card2.communications.emails = Arrays.asList(Email.create("updated-card2@toto.com"));
986
+
987
+		VCardChanges changes = VCardChanges.create(Collections.emptyList(),
988
+				Arrays.asList(VCardChanges.ItemModify.create("vcard1", card1),
989
+						VCardChanges.ItemModify.create("vcard2", card2)),
990
+				Collections.emptyList());
991
+
992
+		getService(defaultSecurityContext).updates(changes);
993
+
994
+		// both group updated
995
+		ItemValue<VCard> group1 = getService(defaultSecurityContext).getComplete("gcard");
996
+		assertTrue(group1.version > gcardVersion);
997
+		assertEquals(card1.communications.emails.get(0).value, group1.value.organizational.member.get(0).mailto);
998
+
999
+		ItemValue<VCard> group2 = getService(defaultSecurityContext).getComplete("gcard2");
1000
+		assertTrue(group2.version > gcard2Version);
1001
+		assertEquals(card2.communications.emails.get(0).value, group2.value.organizational.member.get(0).mailto);
1002
+
1003
+	}
1004
+
960 1005
 }