Skip to content

Commit

Permalink
integration test (manually run) working on msgraph itemattachment
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmoten committed Feb 9, 2020
1 parent ab0ef7a commit 23eaf46
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.github.davidmoten.msgraph;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.concurrent.TimeUnit;

import odata.msgraph.client.container.GraphService;
Expand All @@ -25,10 +27,9 @@ public static void main(String[] args) {
.refreshBeforeExpiry(5, TimeUnit.MINUTES) //
.build();

if (true) {
if (false) {
String url = "https://graph.microsoft.com/v1.0/users('dnex001%40amsa.gov.au')/mailFolders('Inbox')/messages('AQMkADQ3YjdiNWUxLTBmYWQtNDMwYy04Yzc0LTI0MDdmOWQ4NDFjNgBGAAAD4Rwe0e6XOE6Ck412HUUUTwcAUb5I0z9LnUy3cpFj0m9MUgAAAgEMAAAA3NEVJKXfYEuEjYE7msyHXwACufIe7gAAAA%3D%3D')/attachments('AQMkADQ3YjdiNWUxLTBmYWQtNDMwYy04Yzc0LTI0MDdmOWQ4NDFjNgBGAAAD4Rwe0e6XOE6Ck412HUUUTwcAUb5I0z9LnUy3cpFj0m9MUgAAAgEMAAAA3NEVJKXfYEuEjYE7msyHXwACufIe7gAAAAESABAAJiKY2F6di02zkDDZ7TpVag%3D%3D')/$value";
String s = new String(client._service().getBytes(url));
System.out.println(url + "\n->\n" + s);
System.out.println(url + "\n->\n" + client._service().getStringUtf8(url));
System.exit(0);
}

Expand All @@ -53,7 +54,8 @@ public static void main(String[] args) {
.map(x -> (ItemAttachment) x) //
.map(x -> {
try (InputStream in = x.getStream().get().get()) {
System.out.println(new String(Util.read(in)));
byte[] b = Util.read(in);
System.out.println(new String(b));
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.davidmoten.odata.client;

import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
Expand Down Expand Up @@ -34,6 +35,10 @@ default InputStream getStream(String url) {
default byte[] getBytes(String url) {
return Util.toByteArray(getStream(url));
}

default String getStringUtf8(String url) {
return new String(getBytes(url), StandardCharsets.UTF_8);
}

public static HttpService createDefaultService(Path path,
Function<List<RequestHeader>, List<RequestHeader>> requestHeadersModifier) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public Path addSegment(String segment) {
u = append(u, segment);
return new Path(u, queries, style);
}

private static String addSegmentDelimiter(String url) {
if (url.charAt(url.length() - 1) != '/') {
return url + '/';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public static Optional<StreamProvider> createStream(ContextPath contextPath,
Context context = contextPath.context();
if (!editLink.startsWith(HTTPS)) {
// TODO should use the base path from @odata.context field?
editLink = contextPath.context().service().getBasePath().toUrl() + editLink;
editLink = concatenate(contextPath.context().service().getBasePath().toUrl(), editLink);
}
if ("true".equals(
contextPath.context().getProperty("modify.stream.edit.link"))) {
Expand All @@ -228,6 +228,25 @@ public static Optional<StreamProvider> createStream(ContextPath contextPath,
}
}

// concatenate two url parts making sure there is a / delimiter
private static String concatenate(String a, String b) {
StringBuilder s = new StringBuilder();
s.append(a);
if (a.endsWith("/")) {
if (b.startsWith("/")) {
s.append(b, 1, b.length());
} else {
s.append(b);
}
} else {
if (!b.startsWith("/")) {
s.append('/');
}
s.append(b);
}
return s.toString();
}

public static Optional<StreamProvider> createStreamForEdmStream(ContextPath contextPath,
ODataType item, String fieldName, String base64) {
Preconditions.checkNotNull(fieldName);
Expand Down

0 comments on commit 23eaf46

Please sign in to comment.