Browse code

Fix: repair does nothing when using login@domain, when using a single email, resolve all emails

Thomas Cataldo authored on 09/01/2019 09:22:13
Showing 2 changed files
... ...
@@ -9,7 +9,8 @@ Require-Bundle: org.eclipse.core.runtime,
9 9
  net.bluemind.cli.cmd.api,
10 10
  net.bluemind.cli.utils,
11 11
  net.bluemind.directory.api,
12
- net.bluemind.core.container.api
12
+ net.bluemind.core.container.api,
13
+ net.bluemind.mailbox.api
13 14
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
14 15
 Automatic-Module-Name: net.bluemind.cli.directory.common
15 16
 Bundle-ActivationPolicy: lazy
... ...
@@ -18,6 +18,8 @@ import net.bluemind.directory.api.BaseDirEntry.Kind;
18 18
 import net.bluemind.directory.api.DirEntry;
19 19
 import net.bluemind.directory.api.DirEntryQuery;
20 20
 import net.bluemind.directory.api.IDirectory;
21
+import net.bluemind.mailbox.api.IMailboxes;
22
+import net.bluemind.mailbox.api.Mailbox;
21 23
 
22 24
 public abstract class SingleOrDomainOperation implements ICmdLet, Runnable {
23 25
 
... ...
@@ -29,10 +31,10 @@ public abstract class SingleOrDomainOperation implements ICmdLet, Runnable {
29 31
 
30 32
 	@Option(name = "--workers", description = "run with X workers")
31 33
 	public int workers = 1;
32
-	
34
+
33 35
 	@Option(name = "--from", description = "offset for entity number")
34 36
 	public int from = 0;
35
-	
37
+
36 38
 	@Option(name = "--size", description = "number of entity to handle")
37 39
 	public int size = -1;
38 40
 
... ...
@@ -55,7 +57,13 @@ public abstract class SingleOrDomainOperation implements ICmdLet, Runnable {
55 57
 			if (!Regex.EMAIL.validate(target)) {
56 58
 				throw new ServerFault("Not an email");
57 59
 			}
58
-			email = target;
60
+			IMailboxes mboxApi = ctx.adminApi().instance(IMailboxes.class, domainUid);
61
+			ItemValue<Mailbox> resolved = mboxApi.byEmail(target);
62
+			if (resolved == null) {
63
+				ctx.error("No mailbox matches " + target);
64
+				return;
65
+			}
66
+			email = resolved.value.defaultEmail().address;
59 67
 		}
60 68
 
61 69
 		// create executor & completion service with workers thread
... ...
@@ -68,6 +76,10 @@ public abstract class SingleOrDomainOperation implements ICmdLet, Runnable {
68 76
 		q.hiddenFilter = false;
69 77
 		q.emailFilter = email;
70 78
 		ListResult<ItemValue<DirEntry>> entries = dirApi.search(q);
79
+		if (entries.total == 0) {
80
+			ctx.error("Your search for '" + email + "' did not match anything");
81
+			return;
82
+		}
71 83
 		for (ItemValue<DirEntry> de : entries.values) {
72 84
 			opsWatcher.submit(() -> {
73 85
 				synchronousDirOperation(domainUid, de);