Browse code

[bm-cli] BM-14718 Fix: Correctly resolve aliases

Arnaud Aujon Chevallier authored on 13/05/2019 07:57:19
Showing 2 changed files
... ...
@@ -12,7 +12,8 @@ Require-Bundle: org.eclipse.core.runtime,
12 12
  slf4j.api,
13 13
  net.bluemind.domain.api,
14 14
  net.bluemind.directory.api,
15
- net.bluemind.core.container.api
15
+ net.bluemind.core.container.apinet.bluemind.mailbox.api,
16
+ net.bluemind.mailbox.api
16 17
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
17 18
 Automatic-Module-Name: net.bluemind.cli.utils
18 19
 Bundle-ActivationPolicy: lazy
... ...
@@ -5,23 +5,19 @@ import java.io.InputStream;
5 5
 import java.io.UnsupportedEncodingException;
6 6
 import java.nio.file.Files;
7 7
 import java.nio.file.Paths;
8
-import java.util.Arrays;
9 8
 
10 9
 import org.vertx.java.core.buffer.Buffer;
11 10
 
12 11
 import net.bluemind.cli.cmd.api.CliContext;
13 12
 import net.bluemind.cli.cmd.api.CliException;
14
-import net.bluemind.core.api.ListResult;
15 13
 import net.bluemind.core.api.Stream;
16 14
 import net.bluemind.core.container.model.ItemValue;
17 15
 import net.bluemind.core.rest.base.GenericStream;
18 16
 import net.bluemind.core.rest.vertx.VertxStream;
19
-import net.bluemind.directory.api.BaseDirEntry.Kind;
20
-import net.bluemind.directory.api.DirEntry;
21
-import net.bluemind.directory.api.DirEntryQuery;
22
-import net.bluemind.directory.api.IDirectory;
23 17
 import net.bluemind.domain.api.Domain;
24 18
 import net.bluemind.domain.api.IDomains;
19
+import net.bluemind.mailbox.api.IMailboxes;
20
+import net.bluemind.mailbox.api.Mailbox;
25 21
 
26 22
 public class CliUtils {
27 23
 
... ...
@@ -57,15 +53,12 @@ public class CliUtils {
57 53
 
58 54
 	public String getUserUidFromEmail(String email) {
59 55
 		String domainUid = getDomainUidFromEmail(email);
60
-		IDirectory dirApi = cliContext.adminApi().instance(IDirectory.class, domainUid);
61
-		DirEntryQuery q = DirEntryQuery.filterEmail(email);
62
-		q.hiddenFilter = false;
63
-		q.kindsFilter = Arrays.asList(Kind.USER);
64
-		ListResult<ItemValue<DirEntry>> result = dirApi.search(q);
65
-		if (result.total == 0) {
56
+		IMailboxes mboxApi = cliContext.adminApi().instance(IMailboxes.class, domainUid);
57
+		ItemValue<Mailbox> resolved = mboxApi.byEmail(email);
58
+		if (resolved == null) {
66 59
 			throw new CliException("user " + email + " not found");
67 60
 		}
68
-		return result.values.get(0).uid;
61
+		return resolved.uid;
69 62
 	}
70 63
 
71 64
 	public String encodeFilename(String name) {