Browse code

BM-14889 Fix: check and repair

Thomas Fricker authored on 05/06/2019 12:41:03
Showing 1 changed files
... ...
@@ -34,9 +34,15 @@ import net.bluemind.authentication.api.LoginResponse;
34 34
 import net.bluemind.backend.mail.api.IMailboxFoldersByContainer;
35 35
 import net.bluemind.backend.mail.api.IMailboxItems;
36 36
 import net.bluemind.backend.mail.api.MailboxFolder;
37
+import net.bluemind.backend.mail.replica.api.IDbReplicatedMailboxes;
38
+import net.bluemind.backend.mail.replica.api.IMailReplicaUids;
37 39
 import net.bluemind.backend.mail.replica.api.MailboxReplicaRootDescriptor.Namespace;
38 40
 import net.bluemind.backend.mail.replica.utils.SubtreeContainer;
39 41
 import net.bluemind.core.api.report.DiagnosticReport;
42
+import net.bluemind.core.container.api.IContainers;
43
+import net.bluemind.core.container.model.ContainerDescriptor;
44
+import net.bluemind.core.container.model.ContainerModifiableDescriptor;
45
+import net.bluemind.core.container.model.ItemFlag;
40 46
 import net.bluemind.core.container.model.ItemValue;
41 47
 import net.bluemind.core.rest.BmContext;
42 48
 import net.bluemind.core.task.service.IServerTaskMonitor;
... ...
@@ -110,6 +116,12 @@ public class ReApplyDeletionsRepair extends InternalMaintenanceOperation {
110 116
 			public void applyDeletion(Collection<Integer> uids, String flag, StoreClient sc, ListInfo listInfo) {
111 117
 				monitor.log("Should re-flag " + uids.size() + " message(s)");
112 118
 			}
119
+
120
+			@Override
121
+			public void markContainerAsDeleted(IContainers service, String containerUid,
122
+					ContainerDescriptor containerDescriptor) {
123
+				monitor.log("Should mark container " + containerUid + " as deleted");
124
+			}
113 125
 		};
114 126
 		run(op, domainUid, entry, monitor);
115 127
 	}
... ...
@@ -158,6 +170,17 @@ public class ReApplyDeletionsRepair extends InternalMaintenanceOperation {
158 170
 				}
159 171
 			}
160 172
 
173
+			@Override
174
+			public void markContainerAsDeleted(IContainers service, String containerUid,
175
+					ContainerDescriptor containerDescriptor) {
176
+				monitor.log("Marking container " + containerUid + " as deleted");
177
+				ContainerModifiableDescriptor desc = new ContainerModifiableDescriptor();
178
+				desc.defaultContainer = containerDescriptor.defaultContainer;
179
+				desc.name = containerDescriptor.name;
180
+				desc.deleted = true;
181
+				service.update(containerUid, desc);
182
+			}
183
+
161 184
 		};
162 185
 
163 186
 		run(op, domainUid, entry, monitor);
... ...
@@ -180,6 +203,9 @@ public class ReApplyDeletionsRepair extends InternalMaintenanceOperation {
180 203
 			return;
181 204
 		}
182 205
 		op.info(entry);
206
+
207
+		processDbMailboxData(op, domainUid, mbox);
208
+
183 209
 		String latd = mbox.value.name + "@" + domainUid;
184 210
 		LoginResponse resp = context.provider().instance(IAuthentication.class).su(latd);
185 211
 		if (resp.authKey != null) {
... ...
@@ -215,6 +241,29 @@ public class ReApplyDeletionsRepair extends InternalMaintenanceOperation {
215 241
 
216 242
 	}
217 243
 
244
+	private void processDbMailboxData(ReApplyDeletion op, String domainUid, ItemValue<Mailbox> mbox) {
245
+		IDbReplicatedMailboxes mboxFolders = context.provider().instance(IDbReplicatedMailboxes.class,
246
+				partition(domainUid), mboxRoot(mbox));
247
+		IContainers service = context.provider().instance(IContainers.class);
248
+		mboxFolders.all().forEach(folder -> {
249
+			if (folder.flags.contains(ItemFlag.Deleted)) {
250
+				String containerUid = IMailReplicaUids.mboxRecords(folder.uid);
251
+				ContainerDescriptor containerDescriptor = service.get(containerUid);
252
+				if (containerDescriptor != null && !containerDescriptor.deleted) {
253
+					op.markContainerAsDeleted(service, containerUid, containerDescriptor);
254
+				}
255
+			}
256
+		});
257
+	}
258
+
259
+	private String mboxRoot(ItemValue<Mailbox> mbox) {
260
+		return "user." + mbox.value.name.replace(".", "^");
261
+	}
262
+
263
+	private String partition(String domainUid) {
264
+		return domainUid.replace(".", "_");
265
+	}
266
+
218 267
 	private void processFolders(ReApplyDeletion op, UserMailApi mailApi, IServerTaskMonitor monitor, String flag,
219 268
 			StoreClient sc, List<ListInfo> folders) throws IMAPException {
220 269
 		monitor.begin(2d * folders.size(), "Processing " + folders.size() + " folder(s)");
... ...
@@ -242,6 +291,9 @@ public class ReApplyDeletionsRepair extends InternalMaintenanceOperation {
242 291
 				throws IMAPException {
243 292
 		}
244 293
 
294
+		public void markContainerAsDeleted(IContainers service, String containerUid,
295
+				ContainerDescriptor containerDescriptor);
296
+
245 297
 	}
246 298
 
247 299
 }