Skip to content
This repository was archived by the owner on Sep 4, 2020. It is now read-only.

Commit ceadb49

Browse files
author
Caitlin Bales (MSFT)
committed
Merge remote-tracking branch 'refs/remotes/origin/dev' into caitbal/working
2 parents 3fe505a + d1bee8b commit ceadb49

File tree

375 files changed

+16531
-119
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

375 files changed

+16531
-119
lines changed

docs/custom-queries.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Making Custom Calls to Graph
2+
3+
The Graph SDK attempts to enable all available scenarios through Microsoft Graph. There are times, however, through errors or custom Graph functionality, that makes calling the desired endpoint is not possible through the provided requests and builders.
4+
5+
## Creating a custom request
6+
You can extend BaseRequest to create a custom request:
7+
8+
```Java
9+
public class CustomRequest extends BaseRequest {
10+
11+
public CustomRequest(final String requestUrl, final IBaseClient client, final java.util.List<Option> requestOptions) {
12+
super(requestUrl, client, requestOptions, Void.class);
13+
}
14+
15+
public String get() throws ClientException {
16+
return send(HttpMethod.GET, null);
17+
}
18+
}
19+
```
20+
Then you can instantiate a new request to use to call Graph:
21+
22+
```Java
23+
CustomRequest request = new CustomRequest("https://graph.microsoft.com/v1.0/custom", graphServiceClient, requestOptions);
24+
request.get();
25+
```

docs/known-issues.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Known Issues
2+
Because of our close partnership with workload teams who surface API functionality through Graph, it is not always appropriate or feasible to introduce fixes to missing or broken functionality.
3+
4+
## No Annotation Support
5+
[OData](http://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/part3-csdl/odata-v4.0-errata03-os-part3-csdl-complete.html#_Toc453752630) allows workloads to specify additional information about their API surface including both functional and non-functional stipulations. We currently do not support these annotations in the [Generator](https://github.com/microsoftgraph/MSGraph-SDK-Code-Generator), due to hierarchical inheritance issues regarding said annotations. Therefore, there may be methods that do not produce valid queries to Graph. Please refer to the [Graph Docs](https://developer.microsoft.com/en-us/graph/docs/concepts/overview) as the source of truth in these discrepancies.
6+
7+
## PATCH of OneNote Pages
8+
OneNote currently defines the ability to PATCH a page's content (```PATCH https://graph.microsoft.com/v1.0/me/onenote/pages/id/content```), which is currently not supported by the Android SDK. If you are looking to PATCH JSON to a page, you can use the ```getOnenotePatchContent``` method to submit JSON data. If you are looking to PATCH multipart data, you cannot use the request builders given. Refer to the [documentation on making custom queries](https://github.com/microsoftgraph/msgraph-sdk-android/blob/master/docs/custom-queries.md) using the SDK.
Lines changed: 295 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,295 @@
1+
package com.microsoft.graph.functional;
2+
3+
import android.test.AndroidTestCase;
4+
import android.test.suitebuilder.annotation.Suppress;
5+
6+
import com.microsoft.graph.extensions.INotebookCollectionPage;
7+
import com.microsoft.graph.extensions.INotebookGetRecentNotebooksCollectionPage;
8+
import com.microsoft.graph.extensions.IOnenotePageCollectionPage;
9+
import com.microsoft.graph.extensions.IOnenoteSectionCollectionPage;
10+
import com.microsoft.graph.extensions.ISectionGroupCollectionPage;
11+
import com.microsoft.graph.extensions.Notebook;
12+
import com.microsoft.graph.extensions.OnenoteOperation;
13+
import com.microsoft.graph.extensions.OnenotePage;
14+
import com.microsoft.graph.extensions.OnenotePagePreview;
15+
import com.microsoft.graph.extensions.OnenotePatchActionType;
16+
import com.microsoft.graph.extensions.OnenotePatchContentCommand;
17+
import com.microsoft.graph.extensions.OnenotePatchInsertPosition;
18+
import com.microsoft.graph.extensions.OnenoteSection;
19+
import com.microsoft.graph.extensions.SectionGroup;
20+
import com.microsoft.graph.options.HeaderOption;
21+
import com.microsoft.graph.options.Option;
22+
import com.microsoft.graph.options.QueryOption;
23+
24+
import org.junit.*;
25+
26+
import java.io.BufferedReader;
27+
import java.io.ByteArrayOutputStream;
28+
import java.io.InputStream;
29+
import java.io.InputStreamReader;
30+
import java.math.BigInteger;
31+
import java.security.SecureRandom;
32+
import java.util.ArrayList;
33+
import java.util.List;
34+
35+
@Suppress
36+
public class OneNoteTests extends AndroidTestCase {
37+
38+
private TestBase testBase;
39+
private Notebook testNotebook;
40+
private OnenoteSection testSection;
41+
private OnenotePage testPage;
42+
private Notebook testNotebook2;
43+
private SectionGroup testSectionGroup2;
44+
45+
@Before
46+
public void setUp() {
47+
testBase = new TestBase();
48+
testNotebook = testBase.graphClient.getMe().getOnenote().getNotebooks("1-525fe350-0199-4c02-879d-e5b142ae8632").buildRequest().get();
49+
testSection = testBase.graphClient.getMe().getOnenote().getNotebooks(testNotebook.id).getSections().buildRequest().get().getCurrentPage().get(0);
50+
testPage = testBase.graphClient.getMe().getOnenote().getPages().buildRequest().get().getCurrentPage().get(0);
51+
52+
// For copy scenarios
53+
testNotebook2 = testBase.graphClient.getMe().getOnenote().getNotebooks("1-491df90f-b45b-477f-b297-032f000e6f1e").buildRequest().get();
54+
testSectionGroup2 = testBase.graphClient.getMe().getOnenote().getNotebooks(testNotebook2.id).getSectionGroups().buildRequest().get().getCurrentPage().get(0);
55+
}
56+
57+
@Test
58+
public void testGetNotebookData() {
59+
INotebookCollectionPage books = testBase.graphClient.getMe().getOnenote().getNotebooks().buildRequest().get();
60+
assertNotNull(books);
61+
62+
// Get pages from the OneNote object
63+
IOnenotePageCollectionPage pages = testBase.graphClient.getMe().getOnenote().getPages().buildRequest().get();
64+
assertNotNull(pages);
65+
66+
// Get sections from a specific notebook
67+
IOnenoteSectionCollectionPage notebookSections = testBase.graphClient.getMe().getOnenote().getNotebooks(testNotebook.id).getSections().buildRequest().get();
68+
assertNotNull(notebookSections);
69+
70+
// Get sections from the OneNote object
71+
IOnenoteSectionCollectionPage sections = testBase.graphClient.getMe().getOnenote().getSections().buildRequest().get();
72+
assertNotNull(sections);
73+
74+
// Get section groups from a specific notebook
75+
ISectionGroupCollectionPage notebookGroups = testBase.graphClient.getMe().getOnenote().getNotebooks(testNotebook.id).getSectionGroups().buildRequest().get();
76+
assertNotNull(notebookGroups);
77+
78+
// Get section groups from the OneNote object
79+
ISectionGroupCollectionPage groups = testBase.graphClient.getMe().getOnenote().getSectionGroups().buildRequest().get();
80+
assertNotNull(groups);
81+
82+
// Get pages from a specific section
83+
IOnenotePageCollectionPage sectionPages = testBase.graphClient.getMe().getOnenote().getSections(sections.getCurrentPage().get(0).id).getPages().buildRequest().get();
84+
assertNotNull(sectionPages);
85+
}
86+
87+
@Test
88+
public void testODataQueries() {
89+
INotebookCollectionPage books = testBase.graphClient.getMe().getOnenote().getNotebooks().buildRequest().expand("sections").get();
90+
Notebook book = books.getCurrentPage().get(0);
91+
assertNotNull(book.sections);
92+
93+
INotebookCollectionPage idBooks = testBase.graphClient.getMe().getOnenote().getNotebooks().buildRequest().select("id").get();
94+
Notebook idBook = books.getCurrentPage().get(0);
95+
assertNotNull(idBook.id);
96+
97+
IOnenotePageCollectionPage pages = testBase.graphClient.getMe().getOnenote().getPages().buildRequest().select("title").get();
98+
OnenotePage page = pages.getCurrentPage().get(0);
99+
assertNotNull(page.title);
100+
101+
List<Option> options = new ArrayList<Option>();
102+
options.add(new QueryOption("count", "true"));
103+
INotebookCollectionPage countedBooks = testBase.graphClient.getMe().getOnenote().getNotebooks().buildRequest(options).get();
104+
assert(countedBooks.getRawObject().get("@odata.count").getAsInt() > 0);
105+
106+
List<Option> pageLevelOptions = new ArrayList<Option>();
107+
pageLevelOptions.add(new QueryOption("pagelevel", "true"));
108+
IOnenotePageCollectionPage pageLevelPages = testBase.graphClient.getMe().getOnenote().getSections(testSection.id).getPages().buildRequest(pageLevelOptions).get();
109+
assertNotNull(pageLevelPages.getCurrentPage().get(0).level);
110+
}
111+
112+
@Test
113+
public void testRecentNotebooks() {
114+
INotebookGetRecentNotebooksCollectionPage books = testBase.graphClient.getMe().getOnenote().getNotebooks().getGetRecentNotebooks(true).buildRequest().get();
115+
assertNotNull(books);
116+
117+
INotebookGetRecentNotebooksCollectionPage noPersonalBooks = testBase.graphClient.getMe().getOnenote().getNotebooks().getGetRecentNotebooks(false).buildRequest().get();
118+
assertNotNull(noPersonalBooks);
119+
}
120+
121+
@Test
122+
public void testGetPageContent() {
123+
InputStream pageStream = testBase.graphClient.getMe().getOnenote().getPages(testPage.id).getContent().buildRequest().get();
124+
125+
BufferedReader r = new BufferedReader(new InputStreamReader(pageStream));
126+
StringBuilder content = new StringBuilder();
127+
String line;
128+
129+
try {
130+
while ((line = r.readLine()) != null) {
131+
content.append(line).append('\n');
132+
}
133+
} catch (Exception e) {
134+
assertEquals(0,1);
135+
}
136+
assertNotNull(content);
137+
138+
//Hardcoding for now since it requires parsing out of the page
139+
String resourceId = "1-ff7e33cbba1a4cda8f7313abe32420a1!1-db1705d5-fc30-4b3b-8dfb-191981428c65";
140+
InputStream resourceStream = testBase.graphClient.getMe().getOnenote().getResources(resourceId).getContent().buildRequest().get();
141+
142+
r = new BufferedReader(new InputStreamReader(resourceStream));
143+
content = new StringBuilder();
144+
145+
try {
146+
while ((line = r.readLine()) != null) {
147+
content.append(line).append('\n');
148+
}
149+
} catch (Exception e) {
150+
assertEquals(0,1);
151+
}
152+
assertNotNull(content);
153+
154+
}
155+
156+
@Test
157+
public void testGetPreview() {
158+
OnenotePagePreview preview = testBase.graphClient.getMe().getOnenote().getPages(testPage.id).getPreview().buildRequest().get();
159+
assertNotNull(preview);
160+
}
161+
162+
@Test
163+
// Currently there is no way to delete notebooks, sections, or pages
164+
public void testPostToNotebook() {
165+
SectionGroup sectionGroup = new SectionGroup();
166+
sectionGroup.displayName = "Test Section Group";
167+
168+
SectionGroup newSectionGroup = testBase.graphClient.getMe().getOnenote().getNotebooks(testNotebook.id).getSectionGroups().buildRequest().post(sectionGroup);
169+
assertEquals(sectionGroup.displayName, newSectionGroup.displayName);
170+
171+
OnenoteSection section = new OnenoteSection();
172+
section.displayName = "New Test Section";
173+
174+
OnenoteSection newSection = testBase.graphClient.getMe().getOnenote().getNotebooks(testNotebook.id).getSections().buildRequest().post(section);
175+
assertEquals(section.displayName, newSection.displayName);
176+
177+
String content = "<html><head><title>Test Title</title></head><body>Test body</body></html>";
178+
179+
byte[] pageStream = content.getBytes();
180+
List<Option> options = new ArrayList<Option>();
181+
options.add(new HeaderOption("Content-Type", "application/xhtml+xml"));
182+
OnenotePage newPage = testBase.graphClient.getMe().getOnenote().getSections(newSection.id).getPages().buildRequest(options).post(pageStream);
183+
assertEquals("Test Title", newPage.title);
184+
185+
testBase.graphClient.getMe().getOnenote().getPages(newPage.id).buildRequest().delete();
186+
187+
// testBase.graphClient.getMe().getOnenote().getSections(newSection.id).buildRequest().delete();
188+
}
189+
190+
@Test
191+
public void testCopyTo(){
192+
OnenoteOperation operation1 = testBase.graphClient.getMe().getOnenote().getSections(testSection.id).getCopyToNotebook(testNotebook2.id, null, null).buildRequest().post();
193+
assertNotNull(operation1);
194+
195+
OnenoteOperation operation = testBase.graphClient.getMe().getOnenote().getSections(testSection.id).getCopyToSectionGroup(testSectionGroup2.id, null, null).buildRequest().post();
196+
assertNotNull(operation);
197+
198+
OnenoteSection section = new OnenoteSection();
199+
section.displayName = "Test Copy Section";
200+
OnenoteSection newSection = testBase.graphClient.getMe().getOnenote().getNotebooks(testNotebook2.id).getSections().buildRequest().post(section);
201+
operation = testBase.graphClient.getMe().getOnenote().getPages(testPage.id).getCopyToSection(newSection.id, null).buildRequest().post();
202+
assertNotNull(operation);
203+
204+
operation = testBase.graphClient.getMe().getOnenote().getOperations(operation1.id).buildRequest().get();
205+
assertFalse(operation1.status.equals("not started"));
206+
}
207+
208+
@Test
209+
public void testMultipartPost(){
210+
String multipartBoundary = "part_" + new BigInteger(130, new SecureRandom()).toString();
211+
try {
212+
String html =
213+
"--" + multipartBoundary + "\r\n" +
214+
"Content-Disposition:form-data; name=\"Presentation\"" + "\r\n" +
215+
"Content-Type: text/html" + "\r\n" +
216+
"\r\n" +
217+
"<!DOCTYPE html>\r\n" +
218+
"<html lang=\"en-US\">\r\n" +
219+
"<head>\r\n" +
220+
"<title>Test Multipart Page</title>\r\n" +
221+
"<meta name=\"created\" content=\"2001-01-01T01:01+0100\">\r\n" +
222+
"</head>\r\n" +
223+
"<body>\r\n" +
224+
"<p>\r\n" +
225+
"<img src=\"name:image\" />\r\n" +
226+
"</p>\r\n" +
227+
"<p>\r\n" +
228+
"<object data=\"name:attachment\" data-attachment=\"document.pdf\" /></p>\r\n" +
229+
"\r\n" +
230+
"</body>\r\n" +
231+
"</html>\r\n" +
232+
"\r\n" +
233+
"--" + multipartBoundary + "\r\n" +
234+
"Content-Disposition:form-data; name=\"image\"\r\n" +
235+
"Content-Type: image/jpeg\r\n\r\n";
236+
String doc = "\r\n\r\n" +
237+
"--" + multipartBoundary + "\r\n" +
238+
"Content-Disposition:form-data; name=\"attachment\"\r\n" +
239+
"Content-Type:application/pdf\r\n\r\n";
240+
241+
String end = "\r\n\r\n" +
242+
"--" + multipartBoundary + "--";
243+
244+
InputStream imageStream = this.getClass().getClassLoader().getResourceAsStream("hamilton.jpg");
245+
byte[] imgArray = getByteArray(imageStream);
246+
247+
InputStream docStream = this.getClass().getClassLoader().getResourceAsStream("document.pdf");
248+
byte[] docArray = getByteArray(docStream);
249+
250+
ByteArrayOutputStream out = new ByteArrayOutputStream();
251+
out.write(html.getBytes());
252+
out.write(imgArray);
253+
out.write(doc.getBytes());
254+
out.write(docArray);
255+
out.write(end.getBytes());
256+
257+
byte finalData[] = out.toByteArray();
258+
259+
List<Option> options = new ArrayList<Option>();
260+
options.add(new HeaderOption("Content-Type", "multipart/form-data; boundary=\"" + multipartBoundary + "\""));
261+
OnenotePage newPage = testBase.graphClient.getMe().getOnenote().getSections(testSection.id).getPages().buildRequest(options).post(finalData);
262+
assertNotNull(newPage);
263+
} catch (Exception e) {
264+
Assert.fail("Unable to write to output stream");
265+
}
266+
}
267+
268+
@Test
269+
public void testPatchContent() {
270+
List<OnenotePatchContentCommand> commands = new ArrayList<>();
271+
OnenotePatchContentCommand command = new OnenotePatchContentCommand();
272+
command.target = "body";
273+
command.action = OnenotePatchActionType.Append;
274+
command.position = OnenotePatchInsertPosition.After;
275+
command.content = "<img src=\"https://en.wikipedia.org/wiki/File:Alexander_Hamilton_portrait_by_John_Trumbull_1806.jpg\" alt=\"New image from a URL\" />";
276+
commands.add(command);
277+
testBase.graphClient.getMe().getOnenote().getPages(testPage.id).getOnenotePatchContent(commands).buildRequest().post();
278+
}
279+
280+
public byte[] getByteArray(InputStream in) {
281+
try {
282+
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
283+
int nRead;
284+
byte[] data = new byte[16384];
285+
while ((nRead = in.read(data, 0, data.length)) != -1) {
286+
buffer.write(data, 0, nRead);
287+
}
288+
buffer.flush();
289+
return buffer.toByteArray();
290+
} catch (Exception e) {
291+
Assert.fail("Unable to open document");
292+
}
293+
return null;
294+
}
295+
}

graphsdk/src/androidTest/java/com/microsoft/graph/http/MockHttpRequest.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class MockHttpRequest implements IHttpRequest {
2020
private HttpMethod mHttpMethod = HttpMethod.GET;
2121
private List<HeaderOption> mHeaders = new ArrayList<HeaderOption>();
2222
private List<Option> mOptions = new ArrayList<Option>();
23+
private boolean mUseCaches;
2324

2425
@Override
2526
public URL getRequestUrl() {
@@ -47,10 +48,20 @@ public List<Option> getOptions() {
4748

4849
@Override
4950
public void addHeader(String header, String value) {
50-
mHeaders.add(new HeaderOption(header,value));
51+
mHeaders.add(new HeaderOption(header, value));
5152
}
5253

53-
public void setHttpMethod(HttpMethod method){
54+
@Override
55+
public void setUseCaches(boolean useCaches) {
56+
mUseCaches = useCaches;
57+
}
58+
59+
@Override
60+
public boolean getUseCaches() {
61+
return mUseCaches;
62+
}
63+
64+
public void setHttpMethod(HttpMethod method) {
5465
mHttpMethod = method;
5566
}
5667
}

graphsdk/src/androidTest/java/com/microsoft/graph/http/MockRequest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,14 @@ public List<Option> getOptions() {
6262
@Override
6363
public void addHeader(final String header, final String value) {
6464
}
65+
66+
@Override
67+
public void setUseCaches(boolean useCaches) {
68+
// Don't set it for Mock request.
69+
}
70+
71+
@Override
72+
public boolean getUseCaches() {
73+
return false;
74+
}
6575
}
237 KB
Binary file not shown.
174 KB
Loading

graphsdk/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
44
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>
55
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS"/>
6-
<uses-permission android:name="android.permission.INTERNET"/>
6+
<!--<uses-permission android:name="android.permission.INTERNET"/>-->
7+
<!--<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>-->
78

89
</manifest>

0 commit comments

Comments
 (0)