Browse code

BM-15432 Fix: eas, filter soft deleted folders

David Phan authored on 29/11/2019 10:34:29
Showing 1 changed files
... ...
@@ -85,8 +85,8 @@ public class FolderBackend extends CoreConnect {
85 85
 		// ContainerNode internalId as collectionId
86 86
 		IContainersFlatHierarchy flatH = getService(bs, IContainersFlatHierarchy.class, bs.getUser().getDomain(),
87 87
 				bs.getUser().getUid());
88
-		String nodeUid = ContainerHierarchyNode.uidFor(IMailReplicaUids.mboxRecords(itemId.uid), "mailbox_records",
89
-				bs.getUser().getDomain());
88
+		String nodeUid = ContainerHierarchyNode.uidFor(IMailReplicaUids.mboxRecords(itemId.uid),
89
+				IMailReplicaUids.MAILBOX_RECORDS, bs.getUser().getDomain());
90 90
 		ItemValue<ContainerHierarchyNode> node = flatH.getComplete(nodeUid);
91 91
 
92 92
 		return node.internalId;
... ...
@@ -164,9 +164,9 @@ public class FolderBackend extends CoreConnect {
164 164
 		FolderChanges ret = new FolderChanges();
165 165
 
166 166
 		List<String> acceptedContainers = new ArrayList<String>();
167
-		acceptedContainers.add("calendar");
168
-		acceptedContainers.add("addressbook");
169
-		acceptedContainers.add("todolist");
167
+		acceptedContainers.add(ICalendarUids.TYPE);
168
+		acceptedContainers.add(IAddressBookUids.TYPE);
169
+		acceptedContainers.add(ITodoUids.TYPE);
170 170
 
171 171
 		IMailboxFolders mboxFolders = getIMailboxFoldersService(bs);
172 172
 
... ...
@@ -186,7 +186,7 @@ public class FolderBackend extends CoreConnect {
186 186
 				if (acceptedContainers.contains(h.value.containerType)) {
187 187
 					FolderChangeReference f = getHierarchyItemChange(bs, h, ChangeType.ADD, offlineContainers);
188 188
 					Optional.ofNullable(f).ifPresent(item -> ret.items.add(item));
189
-				} else if ("mailbox_records".equals(h.value.containerType)) {
189
+				} else if (IMailReplicaUids.MAILBOX_RECORDS.equals(h.value.containerType)) {
190 190
 					FolderChangeReference f = getMailHierarchyItemChange(bs, mboxFolders, flatH, h, ChangeType.ADD);
191 191
 					Optional.ofNullable(f).ifPresent(item -> ret.items.add(item));
192 192
 				}
... ...
@@ -200,7 +200,7 @@ public class FolderBackend extends CoreConnect {
200 200
 				if (acceptedContainers.contains(h.value.containerType)) {
201 201
 					FolderChangeReference f = getHierarchyItemChange(bs, h, ChangeType.CHANGE, offlineContainers);
202 202
 					Optional.ofNullable(f).ifPresent(item -> ret.items.add(item));
203
-				} else if ("mailbox_records".equals(h.value.containerType)) {
203
+				} else if (IMailReplicaUids.MAILBOX_RECORDS.equals(h.value.containerType)) {
204 204
 					FolderChangeReference f = getMailHierarchyItemChange(bs, mboxFolders, flatH, h, ChangeType.CHANGE);
205 205
 					Optional.ofNullable(f).ifPresent(item -> ret.items.add(item));
206 206
 				}
... ...
@@ -334,16 +334,20 @@ public class FolderBackend extends CoreConnect {
334 334
 				logger.error("Fail to fetch folder {}", uniqueId);
335 335
 				return null;
336 336
 			}
337
+			if (folder.flags.contains(ItemFlag.Deleted)) {
338
+				logger.error("Mail folder '{}' is marked as deleted", h.value.name);
339
+				return null;
340
+			}
337 341
 			if (folder.value.parentUid != null) {
338 342
 				String parentUid = ContainerHierarchyNode.uidFor(IMailReplicaUids.mboxRecords(folder.value.parentUid),
339
-						"mailbox_records", bs.getUser().getDomain());
343
+						IMailReplicaUids.MAILBOX_RECORDS, bs.getUser().getDomain());
340 344
 				parentId = flatH.getComplete(parentUid).internalId;
341 345
 			}
342 346
 		}
343 347
 		folderChangeRef.parentId = parentId;
344 348
 		folderChangeRef.folderId = h.internalId;
345 349
 
346
-		logger.debug("====> {} {}", changeType, folderChangeRef);
350
+		logger.debug("Add mail folder {} {}", changeType, folderChangeRef);
347 351
 
348 352
 		return folderChangeRef;
349 353
 	}
... ...
@@ -363,7 +367,7 @@ public class FolderBackend extends CoreConnect {
363 367
 		String name = "";
364 368
 		FolderType type = null;
365 369
 		switch (folder.value.containerType) {
366
-		case "calendar":
370
+		case ICalendarUids.TYPE:
367 371
 			if (ICalendarUids.defaultUserCalendar(bs.getUser().getUid()).equals(folder.value.containerUid)) {
368 372
 				type = FolderType.DEFAULT_CALENDAR_FOLDER;
369 373
 			} else {
... ...
@@ -381,7 +385,7 @@ public class FolderBackend extends CoreConnect {
381 385
 			}
382 386
 			name = folder.value.name;
383 387
 			break;
384
-		case "addressbook":
388
+		case IAddressBookUids.TYPE:
385 389
 			if (IAddressBookUids.defaultUserAddressbook(bs.getUser().getUid()).equals(folder.value.containerUid)) {
386 390
 				type = FolderType.DEFAULT_CONTACTS_FOLDER;
387 391
 			} else {
... ...
@@ -399,7 +403,7 @@ public class FolderBackend extends CoreConnect {
399 403
 			}
400 404
 			name = I18nLabels.getInstance().translate(bs.getLang(), folder.value.name);
401 405
 			break;
402
-		case "todolist":
406
+		case ITodoUids.TYPE:
403 407
 			if (ITodoUids.defaultUserTodoList(bs.getUser().getUid()).equals(folder.value.containerUid)) {
404 408
 				type = FolderType.DEFAULT_TASKS_FOLDER;
405 409
 			} else {
... ...
@@ -407,7 +411,7 @@ public class FolderBackend extends CoreConnect {
407 411
 			}
408 412
 			name = I18nLabels.getInstance().translate(bs.getLang(), folder.value.name);
409 413
 			break;
410
-		case "mailbox_record":
414
+		default:
411 415
 			break;
412 416
 		}
413 417
 
... ...
@@ -417,7 +421,7 @@ public class FolderBackend extends CoreConnect {
417 421
 		f.parentId = 0;
418 422
 		f.folderId = folder.internalId;
419 423
 
420
-		logger.debug("====> {} {}", changeType, f);
424
+		logger.debug("Add folder {} {}", changeType, f);
421 425
 
422 426
 		return f;
423 427
 	}
... ...
@@ -429,7 +433,7 @@ public class FolderBackend extends CoreConnect {
429 433
 		String name = "";
430 434
 		FolderType type = null;
431 435
 		switch (container.value.containerType) {
432
-		case "calendar":
436
+		case ICalendarUids.TYPE:
433 437
 			if (ICalendarUids.defaultUserCalendar(bs.getUser().getUid()).equals(container.value.containerUid)) {
434 438
 				type = FolderType.DEFAULT_CALENDAR_FOLDER;
435 439
 			} else {
... ...
@@ -442,7 +446,7 @@ public class FolderBackend extends CoreConnect {
442 446
 			}
443 447
 			name = h.value.name;
444 448
 			break;
445
-		case "addressbook":
449
+		case IAddressBookUids.TYPE:
446 450
 			if (IAddressBookUids.defaultUserAddressbook(bs.getUser().getUid()).equals(container.value.containerUid)) {
447 451
 				type = FolderType.DEFAULT_CONTACTS_FOLDER;
448 452
 			} else {
... ...
@@ -455,7 +459,7 @@ public class FolderBackend extends CoreConnect {
455 459
 			}
456 460
 			name = I18nLabels.getInstance().translate(bs.getLang(), h.value.name);
457 461
 			break;
458
-		case "todolist":
462
+		case ITodoUids.TYPE:
459 463
 			if (ITodoUids.defaultUserTodoList(bs.getUser().getUid()).equals(container.value.containerUid)) {
460 464
 				type = FolderType.DEFAULT_TASKS_FOLDER;
461 465
 			} else {
... ...
@@ -463,7 +467,7 @@ public class FolderBackend extends CoreConnect {
463 467
 			}
464 468
 			name = I18nLabels.getInstance().translate(bs.getLang(), h.value.name);
465 469
 			break;
466
-		case "mailbox_record":
470
+		default:
467 471
 			break;
468 472
 		}
469 473
 
... ...
@@ -473,7 +477,7 @@ public class FolderBackend extends CoreConnect {
473 477
 		f.parentId = 0;
474 478
 		f.folderId = h.internalId;
475 479
 
476
-		logger.debug("====> {} {}", f.changeType, f);
480
+		logger.debug("Add subscription {} {}", f.changeType, f);
477 481
 
478 482
 		return f;
479 483
 	}