├── .gitignore
├── README.md
├── pom.xml
└── src
├── main
└── java
│ └── org
│ └── nuxeo
│ └── onedrive
│ └── client
│ ├── AbstractOneDriveAPI.java
│ ├── AbstractRequest.java
│ ├── AbstractResponse.java
│ ├── JsonObjectIterator.java
│ ├── OneDriveAPI.java
│ ├── OneDriveAPIException.java
│ ├── OneDriveBasicAPI.java
│ ├── OneDriveBusinessAPI.java
│ ├── OneDriveDeltaItemIterator.java
│ ├── OneDriveEmailAccount.java
│ ├── OneDriveExpand.java
│ ├── OneDriveFile.java
│ ├── OneDriveFolder.java
│ ├── OneDriveGraphAPI.java
│ ├── OneDriveIdentity.java
│ ├── OneDriveIdentitySet.java
│ ├── OneDriveItem.java
│ ├── OneDriveItemIterator.java
│ ├── OneDriveJsonObject.java
│ ├── OneDriveJsonRequest.java
│ ├── OneDriveJsonResponse.java
│ ├── OneDrivePermission.java
│ ├── OneDriveRequest.java
│ ├── OneDriveResource.java
│ ├── OneDriveResponse.java
│ ├── OneDriveRuntimeException.java
│ ├── OneDriveSharingLink.java
│ ├── OneDriveThumbnail.java
│ ├── OneDriveThumbnailSet.java
│ ├── OneDriveThumbnailSetIterator.java
│ ├── OneDriveThumbnailSize.java
│ ├── QueryStringBuilder.java
│ ├── QueryStringCommaParameter.java
│ └── URLTemplate.java
└── test
├── java
└── org
│ └── nuxeo
│ └── onedrive
│ └── client
│ ├── OneDriveTestCase.java
│ ├── TestJsonObjectIterator.java
│ ├── TestOneDriveEmailAccount.java
│ ├── TestOneDriveFolder.java
│ ├── TestQueryStringBuilder.java
│ └── TestURLTemplate.java
└── resources
└── org
└── nuxeo
└── onedrive
└── client
├── onedrive_business_email.json
├── onedrive_children_page_1.json
├── onedrive_children_page_2.json
├── onedrive_file.json
├── onedrive_folder.json
└── onedrive_folder_root_children.json
/.gitignore:
--------------------------------------------------------------------------------
1 | *~
2 | *_
3 | *~bak
4 | *-bak
5 | *.bak
6 | bin
7 | build.properties
8 | .checkstyle
9 | .classpath
10 | .DS_Store
11 | *.gpd.*
12 | .idea
13 | *.iml
14 | *.ipr
15 | *.iws
16 | *.log
17 | .metadata
18 | .mylar
19 | *.orig
20 | .pmd
21 | .project
22 | *.pyc
23 | .pydevproject
24 | *.rej
25 | .settings
26 | target
27 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Java Client Library for OneDrive & OneDrive for Business REST APIs
2 |
3 | The OneDrive & OneDrive for Business Java Client is a Java client library for REST API. It is designed to work with both OneDrive & OneDrive for Business and to have light dependencies.
4 |
5 | 
6 |
7 | ## Building
8 |
9 | `mvn clean install`
10 |
11 | ## Getting Started
12 |
13 | ### Maven
14 |
15 | To import the client as maven dependency, declare it as follow for latest release :
16 |
17 | ```xml
18 |
19 | org.nuxeo.onedrive
20 | onedrive-java-client
21 | 2.0
22 |
23 | ```
24 |
25 | If you want to use the on development version, declare :
26 |
27 | ```xml
28 |
29 | org.nuxeo.onedrive
30 | onedrive-java-client
31 | 2.1-SNAPSHOT
32 |
33 | ```
34 |
35 | Artifact is available in nuxeo repositories :
36 | - `http://maven.nuxeo.org/nexus/content/groups/public`
37 | - `http://maven.nuxeo.org/nexus/content/groups/public-snapshot`
38 |
39 | ### OneDrive
40 |
41 | To use the client with OneDrive you first need to create a `OneDriveBasicApi` to use it after with items of client :
42 |
43 | ```java
44 | OneDriveAPI api = new OneDriveBasicAPI("YOUR_ACCESS_TOKEN");
45 | ```
46 |
47 | ### OneDrive for Business
48 |
49 | To use the client with OneDrive for Business you need to create a `OneDriveBusinessAPI` to use it after with items of client :
50 |
51 | ```java
52 | OneDriveAPI api = new OneDriveBusinessAPI("YOUR_RESOURCE_URL", "YOUR_ACCESS_TOKEN");
53 | ```
54 |
55 | `YOUR_RESOURCE_URL` corresponds to your sharepoint resource url provided by microsoft, for example : `https://nuxeofr-my.sharepoint.com`.
56 |
57 | ### First calls
58 |
59 | Now you have your `api` object you can request the APIs, for example to get the root folder run :
60 |
61 | ```java
62 | OneDriveFolder root = OneDriveFolder.getRoot(api);
63 | ```
64 |
65 | Or just get a folder or file item :
66 |
67 | ```java
68 | OneDriveFolder folder = new OneDriveFolder(api, "FOLDER_ID");
69 | OneDriveFile file = new OneDriveFile(api, "FILE_ID");
70 | ```
71 |
72 | Then retrieve the metadata :
73 |
74 | ```java
75 | OneDriveFolder.Metadata folderMetadata = folder.getMetadata();
76 | OneDriveFile.Metadata fileMetadata = item.getMetadata();
77 | ```
78 |
79 | ## Features
80 |
81 | - Iterate over folder children, to get all temporary download urls for example :
82 | ```java
83 | public List getChildrenDownloadUrls(OneDriveFolder folder) {
84 | List urls = new ArrayList<>();
85 | for (OneDriveItem.Metadata metadata : folder) {
86 | if (metadata.isFile()) {
87 | urls.add(metadata.asFile().getDownloadUrl());
88 | } else if (metadata.isFolder()) {
89 | urls.addAll(getChildrenDownloadUrls(metadata.asFolder().getResource()));
90 | }
91 | }
92 | return urls;
93 | }
94 | ```
95 |
96 | - Download content of file :
97 | ```java
98 | InputStream stream = file.download();
99 | ```
100 |
101 | - Get ThumbnailSet :
102 | ```java
103 | Iterable folderThumbnail = folder.getThumbnailSets();
104 | OneDriveThumbnailSet.Metadata fileThumbnail = file.getThumbnailSet();
105 | String smallUrl = fileThumbnail.getSmall().getUrl(); // Get the small thumbnail url
106 | InputStream smallStream = fileThumbnail.getSmall().getResource().download(); // Download the content of small thumbnail
107 | ```
108 | You can also request thumbnail this way :
109 | ```java
110 | OneDriveThumbnail thumbnail = new OneDriveThumbnail(api, "FILE_ID", OneDriveThumbnailSize.SMALL);
111 | String smallUrl = thumbnail.getMetadata().getUrl();
112 | InputStream smallStream = thumbnail.download();
113 | ```
114 | Or while getting metadata with `expand` parameter :
115 | ```java
116 | OneDriveFile.Metadata metadata = file.getMetadata(OneDriveExpand.THUMBNAILS);
117 | ...
118 | OneDriveThumbnailSet.Metadata fileThumbnail = metadata.getThumbnailSet();
119 | ```
120 | - Get email of current user :
121 | ```String email = OneDriveEmailAccount.getCurrentUserEmailAccount(api);```
122 |
123 | ## Limitations
124 |
125 | Currently the OneDrive Java Client doesn't provide OAuth support to obtain or refresh an access token. You might obtain one before using the client.
126 |
127 | # Licensing
128 |
129 | [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html)
130 |
131 | # About Nuxeo
132 |
133 | Nuxeo dramatically improves how content-based applications are built, managed and deployed, making customers more agile, innovative and successful. Nuxeo provides a next generation, enterprise ready platform for building traditional and cutting-edge content oriented applications. Combining a powerful application development environment with
134 | SaaS-based tools and a modular architecture, the Nuxeo Platform and Products provide clear business value to some of the most recognizable brands including Verizon, Electronic Arts, Sharp, FICO, the U.S. Navy, and Boeing. Nuxeo is headquartered in New York and Paris.
135 | More information is available at [www.nuxeo.com](http://www.nuxeo.com).
136 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 | org.nuxeo.lib.onedrive
4 | onedrive-java-client
5 | 2.1-SNAPSHOT
6 | OneDrive Java client
7 | The OneDrive client for Java.
8 |
9 |
10 | The Apache License, Version 2.0
11 | http://www.apache.org/licenses/LICENSE-2.0.txt
12 |
13 |
14 |
15 | Nuxeo SA
16 | http://www.nuxeo.com
17 |
18 |
19 |
20 |
21 | Nuxeo ECM list
22 | ecm@lists.nuxeo.com
23 | http://lists.nuxeo.com/mailman/listinfo/ECM
24 | http://lists.nuxeo.com/mailman/listinfo/ECM
25 | http://lists.nuxeo.com/pipermail/ecm/
26 |
27 |
28 | http://dir.gmane.org/gmane.comp.cms.nuxeo.bugs
29 |
30 |
31 | http://www.mail-archive.com/ecm@lists.nuxeo.com/
32 |
33 |
34 |
35 |
36 | Nuxeo ECM checkins list
37 |
38 | http://lists.nuxeo.com/mailman/listinfo/ecm-checkins
39 |
40 |
41 | http://lists.nuxeo.com/mailman/listinfo/ecm-checkins
42 |
43 | http://lists.nuxeo.com/pipermail/ecm-checkins/
44 |
45 |
46 | Nuxeo ECM developers list
47 | nuxeo-dev@lists.nuxeo.com
48 | http://lists.nuxeo.com/mailman/listinfo/nuxeo-dev
49 |
50 | http://lists.nuxeo.com/mailman/listinfo/nuxeo-dev
51 |
52 | http://lists.nuxeo.com/pipermail/nuxeo-dev/
53 |
54 |
55 |
56 |
57 | jira
58 | http://jira.nuxeo.com/browse/NXP
59 |
60 |
61 |
62 | Jenkins
63 | http://qa.nuxeo.org/jenkins/
64 |
65 |
66 | mail
67 |
68 | ecm-qa@lists.nuxeo.com
69 |
70 |
71 |
72 |
73 |
74 |
75 | 3.1.1
76 |
77 |
78 |
79 | 1.6.4
80 |
81 |
82 |
83 |
84 | com.eclipsesource.minimal-json
85 | minimal-json
86 | 0.9.1
87 | compile
88 |
89 |
90 | junit
91 | junit
92 | 4.11
93 | test
94 |
95 |
96 | org.powermock
97 | powermock-module-junit4
98 | ${powermock.version}
99 | test
100 |
101 |
102 | org.powermock
103 | powermock-api-mockito
104 | ${powermock.version}
105 | test
106 |
107 |
108 | commons-io
109 | commons-io
110 | 2.4
111 |
112 |
113 |
114 |
115 |
116 |
117 | org.apache.maven.plugins
118 | maven-compiler-plugin
119 | 3.1
120 |
121 | 1.8
122 | 1.8
123 |
124 |
125 |
126 |
127 |
128 |
129 | scm:git:https://github.com/nuxeo/onedrive-java-client.git
130 | scm:git:https://github.com/nuxeo/onedrive-java-client.git
131 | https://github.com/nuxeo/onedrive-java-client
132 |
133 |
134 |
135 |
136 | public
137 | http://maven.nuxeo.org/nexus/content/groups/public
138 |
139 | true
140 |
141 |
142 | false
143 |
144 |
145 |
146 | public-snapshot
147 | http://maven.nuxeo.org/nexus/content/groups/public-snapshot
148 |
149 | false
150 |
151 |
152 | true
153 |
154 |
155 |
156 |
157 |
158 |
159 | maven-website
160 | scpexe://gironde.nuxeo.com/home/mavenweb/site/
161 |
162 |
163 | public-releases
164 | http://mavenin.nuxeo.com/nexus/content/repositories/public-releases
165 |
166 |
167 | public-snapshots
168 | http://mavenin.nuxeo.com/nexus/content/repositories/public-snapshots
169 | true
170 |
171 |
172 |
173 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/AbstractOneDriveAPI.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | /**
22 | * @since 1.0
23 | */
24 | abstract class AbstractOneDriveAPI implements OneDriveAPI {
25 |
26 | private final String accessToken;
27 |
28 | public AbstractOneDriveAPI(String accessToken) {
29 | this.accessToken = accessToken;
30 | }
31 |
32 | @Override
33 | public String getAccessToken() {
34 | return accessToken;
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/AbstractRequest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | import java.io.ByteArrayInputStream;
22 | import java.io.IOException;
23 | import java.io.InputStream;
24 | import java.io.OutputStream;
25 | import java.net.HttpURLConnection;
26 | import java.net.MalformedURLException;
27 | import java.net.ProtocolException;
28 | import java.net.URL;
29 | import java.nio.charset.StandardCharsets;
30 | import java.util.ArrayList;
31 | import java.util.List;
32 | import java.util.Objects;
33 |
34 | /**
35 | * @since 1.0
36 | */
37 | public abstract class AbstractRequest {
38 |
39 | private static final int MAX_REDIRECTS = 3;
40 |
41 | private static final String USER_AGENT = "Nuxeo OneDrive Java SDK v1.0";
42 |
43 | private final OneDriveAPI api;
44 |
45 | private final List headers;
46 |
47 | private final String method;
48 |
49 | private URL url;
50 |
51 | private int timeout;
52 |
53 | private InputStream body;
54 |
55 | private long bodyLength;
56 |
57 | private int numRedirects;
58 |
59 | /**
60 | * Constructs an unauthenticated request.
61 | */
62 | public AbstractRequest(URL url, String method) {
63 | this(null, url, method);
64 | }
65 |
66 | /**
67 | * Constructs an authenticated request using a provided OneDriveAPI.
68 | */
69 | public AbstractRequest(OneDriveAPI api, URL url, String method) {
70 | this.api = api;
71 | this.url = Objects.requireNonNull(url);
72 | this.method = Objects.requireNonNull(method);
73 | this.headers = new ArrayList<>();
74 |
75 | addHeader("Accept-Encoding", "gzip");
76 | addHeader("Accept-Charset", "utf-8");
77 | }
78 |
79 | public void addHeader(String key, String value) {
80 | this.headers.add(new RequestHeader(key, value));
81 | }
82 |
83 | public void setTimeout(int timeout) {
84 | this.timeout = timeout;
85 | }
86 |
87 | protected InputStream getBody() {
88 | return this.body;
89 | }
90 |
91 | protected void setBody(InputStream stream) {
92 | this.body = stream;
93 | }
94 |
95 | protected void setBody(InputStream stream, long length) {
96 | this.bodyLength = length;
97 | this.body = stream;
98 | }
99 |
100 | protected void setBody(String body) {
101 | byte[] bytes = body.getBytes(StandardCharsets.UTF_8);
102 | this.bodyLength = bytes.length;
103 | this.body = new ByteArrayInputStream(bytes);
104 | }
105 |
106 | protected void writeBody(HttpURLConnection connection) throws OneDriveAPIException {
107 | if (this.body == null) {
108 | return;
109 | }
110 |
111 | connection.setDoOutput(true);
112 | try (OutputStream output = connection.getOutputStream()) {
113 | int b = this.body.read();
114 | while (b != -1) {
115 | output.write(b);
116 | b = this.body.read();
117 | }
118 | } catch (IOException e) {
119 | throw new OneDriveAPIException("Couldn't connect to the OneDrive API due to a network error.", e);
120 | }
121 | }
122 |
123 | public R send() throws OneDriveAPIException {
124 | HttpURLConnection connection = createConnection();
125 |
126 | connection.setRequestProperty("User-Agent", USER_AGENT);
127 | if (api != null) {
128 | connection.addRequestProperty("Authorization", "Bearer " + api.getAccessToken());
129 | }
130 |
131 | writeBody(connection);
132 |
133 | try {
134 | connection.connect();
135 | } catch (IOException e) {
136 | throw new OneDriveAPIException("Couldn't connect to the OneDrive API due to a network error.", e);
137 | }
138 |
139 | // We need to manually handle redirects by creating a new HttpURLConnection so that connection pooling
140 | // happens correctly. There seems to be a bug in Oracle's Java implementation where automatically handled
141 | // redirects will not keep the connection alive.
142 | int responseCode;
143 | try {
144 | responseCode = connection.getResponseCode();
145 | } catch (IOException e) {
146 | throw new OneDriveAPIException("Couldn't connect to the OneDrive API due to a network error.", e);
147 | }
148 |
149 | if (isResponseRedirect(responseCode)) {
150 | return handleRedirect(connection);
151 | }
152 |
153 | return createResponse(connection);
154 | }
155 |
156 | private R handleRedirect(HttpURLConnection connection) throws OneDriveAPIException {
157 | if (this.numRedirects >= MAX_REDIRECTS) {
158 | throw new OneDriveAPIException("The OneDrive API responded with too many redirects.");
159 | }
160 | this.numRedirects++;
161 |
162 | // We need to read the InputStream of response, unless Java won't put the connection back in the connection pool
163 | try {
164 | AbstractResponse.readStream(connection.getInputStream());
165 | } catch (IOException e) {
166 | throw new OneDriveAPIException("Couldn't connect to the OneDrive API due to a network error.", e);
167 | }
168 |
169 | try {
170 | String redirect = connection.getHeaderField("Location");
171 | url = new URL(redirect);
172 | } catch (MalformedURLException e) {
173 | throw new OneDriveAPIException("The OneDrive API responded with an invalid redirect url.", e);
174 | }
175 | return send();
176 | }
177 |
178 | private HttpURLConnection createConnection() throws OneDriveAPIException {
179 | HttpURLConnection connection;
180 | try {
181 | connection = (HttpURLConnection) url.openConnection();
182 | } catch (IOException e) {
183 | throw new OneDriveAPIException("Couldn't connect to OneDrive API due to a network error.", e);
184 | }
185 |
186 | try {
187 | connection.setRequestMethod(method);
188 | } catch (ProtocolException e) {
189 | throw new OneDriveAPIException("Couldn't connect to OneDrive API because method is not correct.", e);
190 | }
191 |
192 | connection.setConnectTimeout(timeout);
193 | connection.setReadTimeout(timeout);
194 |
195 | // Disable redirects on connection because we handle it manually
196 | connection.setInstanceFollowRedirects(false);
197 |
198 | headers.forEach(header -> connection.addRequestProperty(header.getKey(), header.getValue()));
199 |
200 | return connection;
201 | }
202 |
203 | private static boolean isResponseRedirect(int responseCode) {
204 | return (responseCode == 301 || responseCode == 302);
205 | }
206 |
207 | protected abstract R createResponse(HttpURLConnection connection) throws OneDriveAPIException;
208 |
209 | private final class RequestHeader {
210 |
211 | private final String key;
212 |
213 | private final String value;
214 |
215 | public RequestHeader(String key, String value) {
216 | this.key = Objects.requireNonNull(key);
217 | this.value = Objects.requireNonNull(value);
218 | }
219 |
220 | public String getKey() {
221 | return key;
222 | }
223 |
224 | public String getValue() {
225 | return value;
226 | }
227 |
228 | }
229 |
230 | }
231 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/AbstractResponse.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | import java.io.Closeable;
22 | import java.io.IOException;
23 | import java.io.InputStream;
24 | import java.io.InputStreamReader;
25 | import java.net.HttpURLConnection;
26 | import java.nio.charset.StandardCharsets;
27 | import java.util.zip.GZIPInputStream;
28 |
29 | /**
30 | * @since 1.0
31 | */
32 | public abstract class AbstractResponse implements Closeable {
33 |
34 | private static final int BUFFER_SIZE = 8192;
35 |
36 | private final HttpURLConnection connection;
37 |
38 | private int responseCode;
39 |
40 | private String errorString;
41 |
42 | /** The regular InputStream is the right stream to read body with raw or gzip content. */
43 | private InputStream inputStream;
44 |
45 | private boolean closed;
46 |
47 | /**
48 | * @param connection a connection which has already sent a request to the API
49 | */
50 | public AbstractResponse(HttpURLConnection connection) throws OneDriveAPIException {
51 | this.connection = connection;
52 |
53 | try {
54 | responseCode = connection.getResponseCode();
55 | } catch (IOException e) {
56 | throw new OneDriveAPIException("Couldn't connect to the OneDrive API due to a network error.", e);
57 | }
58 |
59 | if (!isSuccess(responseCode)) {
60 | throw new OneDriveAPIException("The API returned an error code: " + responseCode, responseCode,
61 | getErrorString());
62 | }
63 | }
64 |
65 | public int getResponseCode() {
66 | return responseCode;
67 | }
68 |
69 | public abstract C getContent() throws OneDriveAPIException;
70 |
71 | protected InputStream getBody() throws OneDriveAPIException {
72 | if (inputStream == null) {
73 | try {
74 | inputStream = handleGZIPStream(connection.getInputStream());
75 | } catch (IOException e) {
76 | throw new OneDriveAPIException("Couldn't connect to the OneDrive API due to a network error.", e);
77 | }
78 | }
79 | return new ResponseInputStream();
80 | }
81 |
82 | /**
83 | * Returns a string representation of error. Method returns the content of error stream.
84 | */
85 | protected String getErrorString() {
86 | if (errorString == null && !isSuccess(responseCode)) {
87 | errorString = readErrorStream();
88 | }
89 | return errorString;
90 | }
91 |
92 | private String readErrorStream() {
93 | try {
94 | return readStream(getErrorStream());
95 | } catch (OneDriveAPIException e) {
96 | return null;
97 | }
98 | }
99 |
100 | private InputStream getErrorStream() {
101 | InputStream errorStream = connection.getErrorStream();
102 | try {
103 | return handleGZIPStream(errorStream);
104 | } catch (IOException e) {
105 | return errorStream;
106 | }
107 | }
108 |
109 | /**
110 | * Returns a gzip input stream if the connection has gzip content encoding, else returns input stream.
111 | */
112 | private InputStream handleGZIPStream(InputStream stream) throws IOException {
113 | if (stream != null && "gzip".equalsIgnoreCase(connection.getContentEncoding())) {
114 | return new GZIPInputStream(stream);
115 | }
116 | return stream;
117 | }
118 |
119 | /**
120 | * Disconnects the response, close the input stream, so body can no longer be read after.
121 | */
122 | @Override
123 | public void close() throws OneDriveAPIException {
124 | if (closed) {
125 | return;
126 | }
127 | try {
128 | InputStream stream = connection.getInputStream();
129 |
130 | // We need to manually read from the connection's input stream in case there are any remaining bytes.
131 | // Else JVM won't return the connection to the pool
132 | byte[] buffer = new byte[BUFFER_SIZE];
133 | int n = stream.read(buffer);
134 | while (n != -1) {
135 | n = stream.read(buffer);
136 | }
137 | stream.close();
138 |
139 | if (inputStream != null) {
140 | inputStream.close();
141 | }
142 |
143 | closed = true;
144 | } catch (IOException e) {
145 | throw new OneDriveAPIException("Couldn't close the connection to OneDrive API due to a network error.", e);
146 | }
147 | }
148 |
149 | private static boolean isSuccess(int responseCode) {
150 | return responseCode >= 200 && responseCode < 300;
151 | }
152 |
153 | /**
154 | * Returns the input stream as a string, then close it.
155 | */
156 | protected static String readStream(InputStream stream) throws OneDriveAPIException {
157 | if (stream == null) {
158 | return null;
159 | }
160 |
161 | InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8);
162 | StringBuilder builder = new StringBuilder();
163 | char[] buffer = new char[BUFFER_SIZE];
164 |
165 | try {
166 | int read;
167 | while ((read = reader.read(buffer, 0, BUFFER_SIZE)) != -1) {
168 | builder.append(buffer, 0, read);
169 | }
170 |
171 | stream.close();
172 | } catch (IOException e) {
173 | throw new OneDriveAPIException("Couldn't read the stream from OneDrive API.", e);
174 | }
175 | return builder.toString();
176 | }
177 |
178 | private class ResponseInputStream extends InputStream {
179 |
180 | @Override
181 | public int read() throws IOException {
182 | return inputStream.read();
183 | }
184 |
185 | @Override
186 | public void close() throws IOException {
187 | // Don't close the stream, it will be done by the response
188 | AbstractResponse.this.close();
189 | }
190 | }
191 |
192 | }
193 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/JsonObjectIterator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | import java.net.MalformedURLException;
22 | import java.net.URL;
23 | import java.util.Collections;
24 | import java.util.Iterator;
25 | import java.util.NoSuchElementException;
26 |
27 | import com.eclipsesource.json.JsonObject;
28 | import com.eclipsesource.json.JsonValue;
29 |
30 | /**
31 | * @since 1.0
32 | */
33 | class JsonObjectIterator implements Iterator {
34 |
35 | private final OneDriveAPI api;
36 |
37 | private URL url;
38 |
39 | private boolean hasMorePages;
40 |
41 | private Iterator currentPage;
42 |
43 | public JsonObjectIterator(OneDriveAPI api, URL url) {
44 | this.api = api;
45 | this.url = url;
46 | this.hasMorePages = true;
47 | }
48 |
49 | @Override
50 | public boolean hasNext() throws OneDriveRuntimeException {
51 | if (currentPage != null && currentPage.hasNext()) {
52 | return true;
53 | } else if (hasMorePages) {
54 | loadNextPage();
55 | return currentPage != null && currentPage.hasNext();
56 | }
57 | return false;
58 | }
59 |
60 | @Override
61 | public JsonObject next() throws OneDriveRuntimeException {
62 | if (hasNext()) {
63 | return currentPage.next().asObject();
64 | }
65 | throw new NoSuchElementException();
66 | }
67 |
68 | private void loadNextPage() throws OneDriveRuntimeException {
69 | try {
70 | OneDriveJsonRequest request = new OneDriveJsonRequest(api, url, "GET");
71 | OneDriveJsonResponse response = request.send();
72 | JsonObject json = response.getContent();
73 | onResponse(json);
74 |
75 | JsonValue values = json.get("value");
76 | if (values.isNull()) {
77 | currentPage = Collections.emptyIterator();
78 | } else {
79 | currentPage = values.asArray().iterator();
80 | }
81 |
82 | JsonValue nextUrl = json.get("@odata.nextLink");
83 | hasMorePages = nextUrl != null && !nextUrl.isNull();
84 | if (hasMorePages) {
85 | url = new URL(nextUrl.asString());
86 | }
87 | } catch (OneDriveAPIException e) {
88 | throw new OneDriveRuntimeException("An error occurred during connection with OneDrive API.", e);
89 | } catch (MalformedURLException e) {
90 | hasMorePages = false;
91 | throw new OneDriveRuntimeException("Next url returned from OneDrive API is malformed.", e);
92 | }
93 | }
94 |
95 | /**
96 | * @since 1.1
97 | */
98 | protected void onResponse(JsonObject response) {
99 | // Hook method
100 | }
101 |
102 | }
103 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/OneDriveAPI.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | /**
22 | * @since 1.0
23 | */
24 | public interface OneDriveAPI {
25 |
26 | boolean isBusinessConnection();
27 |
28 | /**
29 | * @since 1.1
30 | */
31 | boolean isGraphConnection();
32 |
33 | String getBaseURL();
34 |
35 | String getEmailURL();
36 |
37 | String getAccessToken();
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/OneDriveAPIException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | import java.io.IOException;
22 |
23 | /**
24 | * @since 1.0
25 | */
26 | public class OneDriveAPIException extends IOException {
27 |
28 | private static final long serialVersionUID = 1L;
29 |
30 | private final int responseCode;
31 |
32 | private final String response;
33 |
34 | public OneDriveAPIException(String message) {
35 | super(message);
36 |
37 | this.responseCode = -1;
38 | this.response = null;
39 | }
40 |
41 | public OneDriveAPIException(String message, int responseCode, String response) {
42 | super(message);
43 |
44 | this.responseCode = responseCode;
45 | this.response = response;
46 | }
47 |
48 | public OneDriveAPIException(String message, Throwable cause) {
49 | super(message, cause);
50 |
51 | this.responseCode = -1;
52 | this.response = null;
53 | }
54 |
55 | public OneDriveAPIException(String message, OneDriveRuntimeException cause) {
56 | super(message, cause);
57 |
58 | if (cause.getCause() instanceof OneDriveAPIException) {
59 | OneDriveAPIException subApiException = (OneDriveAPIException) cause.getCause();
60 | this.responseCode = subApiException.getResponseCode();
61 | this.response = subApiException.getResponse();
62 | } else {
63 | this.responseCode = -1;
64 | this.response = null;
65 | }
66 | }
67 |
68 | public OneDriveAPIException(String message, int responseCode, String response, Throwable cause) {
69 | super(message, cause);
70 |
71 | this.responseCode = responseCode;
72 | this.response = response;
73 | }
74 |
75 | public int getResponseCode() {
76 | return this.responseCode;
77 | }
78 |
79 | public String getResponse() {
80 | return this.response;
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/OneDriveBasicAPI.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | /**
22 | * @since 1.0
23 | */
24 | public class OneDriveBasicAPI extends AbstractOneDriveAPI {
25 |
26 | private static final String BASE_URL = "https://api.onedrive.com/v1.0";
27 |
28 | private static final String EMAIL_URL = "https://apis.live.net/v5.0/me";
29 |
30 | public OneDriveBasicAPI(String accessToken) {
31 | super(accessToken);
32 | }
33 |
34 | @Override
35 | public boolean isBusinessConnection() {
36 | return false;
37 | }
38 |
39 | @Override
40 | public boolean isGraphConnection() {
41 | return false;
42 | }
43 |
44 | @Override
45 | public String getBaseURL() {
46 | return BASE_URL;
47 | }
48 |
49 | @Override
50 | public String getEmailURL() {
51 | return EMAIL_URL;
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/OneDriveBusinessAPI.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | /**
22 | * @since 1.0
23 | */
24 | public class OneDriveBusinessAPI extends AbstractOneDriveAPI {
25 |
26 | private final String baseUrl;
27 |
28 | private final String emailUrl;
29 |
30 | public OneDriveBusinessAPI(String resourceURL, String accessToken) {
31 | super(accessToken);
32 | this.baseUrl = resourceURL + "_api/v2.0";
33 | this.emailUrl = resourceURL + "_api/SP.UserProfiles.PeopleManager/GetMyProperties";
34 | }
35 |
36 | @Override
37 | public boolean isBusinessConnection() {
38 | return true;
39 | }
40 |
41 | @Override
42 | public boolean isGraphConnection() {
43 | return false;
44 | }
45 |
46 | @Override
47 | public String getBaseURL() {
48 | return baseUrl;
49 | }
50 |
51 | @Override
52 | public String getEmailURL() {
53 | return emailUrl;
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/OneDriveDeltaItemIterator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | import java.net.URL;
22 |
23 | import com.eclipsesource.json.JsonObject;
24 | import com.eclipsesource.json.JsonValue;
25 |
26 | /**
27 | * @since 1.1
28 | */
29 | public class OneDriveDeltaItemIterator extends OneDriveItemIterator {
30 |
31 | private String deltaLink;
32 |
33 | public OneDriveDeltaItemIterator(OneDriveAPI api, URL url) {
34 | super(api, url);
35 | }
36 |
37 | public String getDeltaLink() {
38 | return deltaLink;
39 | }
40 |
41 | @Override
42 | protected void onResponse(JsonObject response) {
43 | JsonValue delta = response.get("@odata.deltaLink");
44 | deltaLink = delta != null && !delta.isNull() ? delta.asString() : null;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/OneDriveEmailAccount.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | import java.net.URL;
22 | import java.util.Optional;
23 | import java.util.stream.StreamSupport;
24 |
25 | import com.eclipsesource.json.JsonArray;
26 | import com.eclipsesource.json.JsonObject;
27 | import com.eclipsesource.json.JsonValue;
28 |
29 | /**
30 | * @since 1.0
31 | */
32 | public class OneDriveEmailAccount {
33 |
34 | public static String getCurrentUserEmailAccount(OneDriveAPI api) throws OneDriveAPIException {
35 | URL url = URLTemplate.EMPTY_TEMPLATE.build(api.getEmailURL());
36 | OneDriveJsonRequest request = new OneDriveJsonRequest(api, url, "GET");
37 | OneDriveJsonResponse response = request.send();
38 | JsonObject jsonObject = response.getContent();
39 | if (api.isBusinessConnection()) {
40 | return Optional.ofNullable(jsonObject.get("Email"))
41 | .filter(JsonValue::isString)
42 | .map(JsonValue::asString)
43 | .orElseGet(() -> searchBusinessEmail(jsonObject.get("UserProfileProperties").asArray()));
44 | } else if (api.isGraphConnection()) {
45 | return jsonObject.get("userPrincipalName").asString();
46 | }
47 | return jsonObject.get("emails").asObject().get("account").asString();
48 | }
49 |
50 | private static String searchBusinessEmail(JsonArray properties) {
51 | return StreamSupport.stream(properties.spliterator(), false)
52 | .map(JsonValue::asObject)
53 | .filter(obj -> "UserName".equals(obj.get("Key").asString()))
54 | .map(obj -> obj.get("Value").asString())
55 | .findFirst()
56 | .get();
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/OneDriveExpand.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | /**
22 | * @since 1.0
23 | */
24 | public enum OneDriveExpand implements QueryStringCommaParameter {
25 |
26 | THUMBNAILS("thumbnails");
27 |
28 | private String key;
29 |
30 | OneDriveExpand(String key) {
31 | this.key = key;
32 | }
33 |
34 | @Override
35 | public String getKey() {
36 | return key;
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/OneDriveFile.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | import java.io.InputStream;
22 | import java.net.URL;
23 |
24 | import com.eclipsesource.json.JsonObject;
25 | import com.eclipsesource.json.JsonValue;
26 | import com.eclipsesource.json.ParseException;
27 |
28 | /**
29 | * @since 1.0
30 | */
31 | public class OneDriveFile extends OneDriveItem {
32 |
33 | private static final URLTemplate GET_FILE_URL = new URLTemplate("/drive/items/%s");
34 |
35 | private static final URLTemplate GET_FILE_CONTENT_URL = new URLTemplate("/drive/items/%s/content");
36 |
37 | public OneDriveFile(OneDriveAPI api, String id) {
38 | super(api, id);
39 | }
40 |
41 | @Override
42 | public OneDriveFile.Metadata getMetadata(OneDriveExpand... expands) throws OneDriveAPIException {
43 | QueryStringBuilder query = new QueryStringBuilder().set("expand", expands);
44 | URL url = GET_FILE_URL.build(getApi().getBaseURL(), query, getId());
45 | OneDriveJsonRequest request = new OneDriveJsonRequest(getApi(), url, "GET");
46 | OneDriveJsonResponse response = request.send();
47 | return new OneDriveFile.Metadata(response.getContent());
48 | }
49 |
50 | public InputStream download() throws OneDriveAPIException {
51 | URL url = GET_FILE_CONTENT_URL.build(getApi().getBaseURL(), getId());
52 | OneDriveRequest request = new OneDriveRequest(getApi(), url, "GET");
53 | OneDriveResponse response = request.send();
54 | return response.getContent();
55 | }
56 |
57 | /** See documentation at https://dev.onedrive.com/resources/item.htm. */
58 | public class Metadata extends OneDriveItem.Metadata {
59 |
60 | private String cTag;
61 |
62 | private String mimeType;
63 |
64 | private String downloadUrl;
65 |
66 | /** Not available for business. */
67 | private String crc32Hash;
68 |
69 | /** Not available for business. */
70 | private String sha1Hash;
71 |
72 | public Metadata(JsonObject json) {
73 | super(json);
74 | }
75 |
76 | public String getCTag() {
77 | return cTag;
78 | }
79 |
80 | /**
81 | * Returns the current version of OneDrive file.
82 | * CAUTION: this value is known from cTag field, it doesn't rely on public field from OneDrive API.
83 | *
84 | * @return the current version of OneDrive file
85 | */
86 | public String getVersion() {
87 | return cTag == null ? null : cTag.substring(cTag.lastIndexOf(',') + 1);
88 | }
89 |
90 | public String getMimeType() {
91 | return mimeType;
92 | }
93 |
94 | public String getDownloadUrl() {
95 | return downloadUrl;
96 | }
97 |
98 | public String getCrc32Hash() {
99 | return crc32Hash;
100 | }
101 |
102 | public String getSha1Hash() {
103 | return sha1Hash;
104 | }
105 |
106 | @Override
107 | protected void parseMember(JsonObject.Member member) {
108 | super.parseMember(member);
109 | try {
110 | JsonValue value = member.getValue();
111 | String memberName = member.getName();
112 | if ("cTag".equals(memberName)) {
113 | cTag = value.asString();
114 | } else if ("@content.downloadUrl".equals(memberName)) {
115 | downloadUrl = value.asString();
116 | } else if ("file".equals(memberName)) {
117 | parseMember(value.asObject(), this::parseFileMember);
118 | }
119 | } catch (ParseException e) {
120 | throw new OneDriveRuntimeException("Parse failed, maybe a bug in client.", e);
121 | }
122 | }
123 |
124 | private void parseFileMember(JsonObject.Member member) {
125 | JsonValue value = member.getValue();
126 | String memberName = member.getName();
127 | if ("mimeType".equals(memberName)) {
128 | mimeType = value.asString();
129 | } else if ("hashes".equals(memberName)) {
130 | parseMember(value.asObject(), this::parseHashesMember);
131 | }
132 | }
133 |
134 | private void parseHashesMember(JsonObject.Member member) {
135 | JsonValue value = member.getValue();
136 | String memberName = member.getName();
137 | if ("crc32Hash".equals(memberName)) {
138 | crc32Hash = value.asString();
139 | } else if ("sha1Hash".equals(memberName)) {
140 | sha1Hash = value.asString();
141 | }
142 | }
143 |
144 | @Override
145 | public OneDriveFile getResource() {
146 | return OneDriveFile.this;
147 | }
148 |
149 | @Override
150 | public boolean isFile() {
151 | return true;
152 | }
153 |
154 | @Override
155 | public OneDriveFile.Metadata asFile() {
156 | return this;
157 | }
158 |
159 | }
160 |
161 | }
162 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/OneDriveFolder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | import java.net.MalformedURLException;
22 | import java.net.URL;
23 | import java.util.Iterator;
24 | import java.util.List;
25 |
26 | import com.eclipsesource.json.JsonObject;
27 | import com.eclipsesource.json.JsonValue;
28 | import com.eclipsesource.json.ParseException;
29 |
30 | /**
31 | * @since 1.0
32 | */
33 | public class OneDriveFolder extends OneDriveItem implements Iterable {
34 |
35 | private static final URLTemplate GET_FOLDER_ROOT_URL = new URLTemplate("/drive/root");
36 |
37 | private static final URLTemplate GET_CHILDREN_ROOT_URL = new URLTemplate("/drive/root/children");
38 |
39 | private static final URLTemplate SEARCH_IN_ROOT_URL = new URLTemplate("/drive/root/view.search");
40 |
41 | private static final URLTemplate DELTA_IN_ROOT_URL = new URLTemplate("/drive/root/view.delta");
42 |
43 | private static final URLTemplate GET_FOLDER_URL = new URLTemplate("/drive/items/%s");
44 |
45 | private static final URLTemplate GET_CHILDREN_URL = new URLTemplate("/drive/items/%s/children");
46 |
47 | private static final URLTemplate SEARCH_IN_FOLDER_URL = new URLTemplate("/drive/items/%s/view.search");
48 |
49 | private static final URLTemplate DELTA_IN_FOLDER_URL = new URLTemplate("/drive/items/%s/view.delta");
50 |
51 | OneDriveFolder(OneDriveAPI api) {
52 | super(api);
53 | }
54 |
55 | public OneDriveFolder(OneDriveAPI api, String id) {
56 | super(api, id);
57 | }
58 |
59 | @Override
60 | public OneDriveFolder.Metadata getMetadata(OneDriveExpand... expands) throws OneDriveAPIException {
61 | QueryStringBuilder query = new QueryStringBuilder().set("expand", expands);
62 | URL url;
63 | if (isRoot()) {
64 | url = GET_FOLDER_ROOT_URL.build(getApi().getBaseURL(), query);
65 | } else {
66 | url = GET_FOLDER_URL.build(getApi().getBaseURL(), query, getId());
67 | }
68 | OneDriveJsonRequest request = new OneDriveJsonRequest(getApi(), url, "GET");
69 | OneDriveJsonResponse response = request.send();
70 | return new OneDriveFolder.Metadata(response.getContent());
71 | }
72 |
73 | public static OneDriveFolder getRoot(OneDriveAPI api) {
74 | return new OneDriveFolder(api);
75 | }
76 |
77 | public Iterable getChildren() {
78 | return this;
79 | }
80 |
81 | public Iterable getChildren(OneDriveExpand... expands) {
82 | return () -> iterator(expands);
83 | }
84 |
85 | @Override
86 | public Iterator iterator() {
87 | return iterator(new OneDriveExpand[] {});
88 | }
89 |
90 | public Iterator iterator(OneDriveExpand... expands) {
91 | QueryStringBuilder query = new QueryStringBuilder().set("top", 200);
92 | URL url;
93 | if (isRoot()) {
94 | url = GET_CHILDREN_ROOT_URL.build(getApi().getBaseURL(), query);
95 | } else {
96 | url = GET_CHILDREN_URL.build(getApi().getBaseURL(), query, getId());
97 | }
98 | return new OneDriveItemIterator(getApi(), url);
99 | }
100 |
101 | public Iterable search(String search, OneDriveExpand... expands) {
102 | QueryStringBuilder query = new QueryStringBuilder().set("q", search).set("expand", expands);
103 | URL url;
104 | if (isRoot()) {
105 | url = SEARCH_IN_ROOT_URL.build(getApi().getBaseURL(), query);
106 | } else {
107 | url = SEARCH_IN_FOLDER_URL.build(getApi().getBaseURL(), query, getId());
108 | }
109 | return () -> new OneDriveItemIterator(getApi(), url);
110 | }
111 |
112 | /**
113 | * @since 1.1
114 | */
115 | public OneDriveDeltaItemIterator delta() {
116 | URL url;
117 | if (isRoot()) {
118 | url = DELTA_IN_ROOT_URL.build(getApi().getBaseURL());
119 | } else {
120 | url = DELTA_IN_FOLDER_URL.build(getApi().getBaseURL(), getId());
121 | }
122 | return new OneDriveDeltaItemIterator(getApi(), url);
123 | }
124 |
125 | /**
126 | * @since 1.1
127 | */
128 | public OneDriveItemIterator delta(String deltaLink) {
129 | if (deltaLink == null) {
130 | return delta();
131 | }
132 | try {
133 | URL url = new URL(deltaLink);
134 | return new OneDriveDeltaItemIterator(getApi(), url);
135 | } catch (MalformedURLException e) {
136 | throw new OneDriveRuntimeException("Wrong delta link: " + deltaLink, e);
137 | }
138 | }
139 |
140 | @Override
141 | public Iterable getThumbnailSets() {
142 | if (isRoot()) {
143 | return () -> new OneDriveThumbnailSetIterator(getApi());
144 | }
145 | return super.getThumbnailSets();
146 | }
147 |
148 | /** See documentation at https://dev.onedrive.com/resources/item.htm. */
149 | public class Metadata extends OneDriveItem.Metadata {
150 |
151 | private long childCount;
152 |
153 | @Override
154 | public List getThumbnailSets() {
155 | return super.getThumbnailSets();
156 | }
157 |
158 | public Metadata(JsonObject json) {
159 | super(json);
160 | }
161 |
162 | public long getChildCount() {
163 | return childCount;
164 | }
165 |
166 | @Override
167 | protected void parseMember(JsonObject.Member member) {
168 | super.parseMember(member);
169 | try {
170 | JsonValue value = member.getValue();
171 | String memberName = member.getName();
172 | if ("folder".equals(memberName)) {
173 | parseMember(value.asObject(), this::parseChildMember);
174 | }
175 | } catch (ParseException e) {
176 | throw new OneDriveRuntimeException("Parse failed, maybe a bug in client.", e);
177 | }
178 | }
179 |
180 | private void parseChildMember(JsonObject.Member member) {
181 | JsonValue value = member.getValue();
182 | String memberName = member.getName();
183 | if ("childCount".equals(memberName)) {
184 | childCount = value.asLong();
185 | }
186 | }
187 |
188 | @Override
189 | public OneDriveFolder getResource() {
190 | return OneDriveFolder.this;
191 | }
192 |
193 | @Override
194 | public boolean isFolder() {
195 | return true;
196 | }
197 |
198 | @Override
199 | public OneDriveFolder.Metadata asFolder() {
200 | return this;
201 | }
202 | }
203 |
204 | /** See documentation at https://dev.onedrive.com/resources/itemReference.htm. */
205 | public class Reference extends OneDriveResource.Metadata {
206 |
207 | /** Unique identifier for the Drive that contains the item. */
208 | private String driveId;
209 |
210 | /** Path that used to navigate to the item. */
211 | private String path;
212 |
213 | public Reference(JsonObject json) {
214 | super(json);
215 | }
216 |
217 | public String getDriveId() {
218 | return driveId;
219 | }
220 |
221 | public String getPath() {
222 | return path;
223 | }
224 |
225 | @Override
226 | protected void parseMember(JsonObject.Member member) {
227 | super.parseMember(member);
228 | try {
229 | JsonValue value = member.getValue();
230 | String memberName = member.getName();
231 | if ("driveId".equals(memberName)) {
232 | driveId = value.asString();
233 | } else if ("path".equals(memberName)) {
234 | path = value.asString();
235 | }
236 | } catch (ParseException e) {
237 | throw new OneDriveRuntimeException("Parse failed, maybe a bug in client.", e);
238 | }
239 | }
240 |
241 | @Override
242 | public OneDriveFolder getResource() {
243 | return OneDriveFolder.this;
244 | }
245 |
246 | }
247 |
248 | }
249 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/OneDriveGraphAPI.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2015-2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | *
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | /**
22 | * @since 1.1
23 | */
24 | public class OneDriveGraphAPI implements OneDriveAPI {
25 |
26 | protected String accessToken;
27 | protected String userId;
28 |
29 | public OneDriveGraphAPI(String accessToken) {
30 | this.accessToken = accessToken;
31 | }
32 |
33 | public OneDriveGraphAPI(String accessToken, String userId) {
34 | this.accessToken = accessToken;
35 | this.userId = userId;
36 | }
37 |
38 | @Override
39 | public boolean isBusinessConnection() {
40 | return false;
41 | }
42 |
43 | @Override
44 | public boolean isGraphConnection() {
45 | return true;
46 | }
47 |
48 | @Override
49 | public String getBaseURL() {
50 | return "https://graph.microsoft.com/v1.0/"+
51 | (userId ==null ? "me" : "/users/"+ userId);
52 | }
53 |
54 | @Override
55 | public String getEmailURL() {
56 | return "https://graph.microsoft.com/v1.0/"+
57 | (userId ==null ? "me" : "/users/"+ userId);
58 | }
59 |
60 | @Override
61 | public String getAccessToken() {
62 | return accessToken;
63 | }
64 |
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/OneDriveIdentity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | import com.eclipsesource.json.JsonObject;
22 | import com.eclipsesource.json.JsonValue;
23 | import com.eclipsesource.json.ParseException;
24 |
25 | /**
26 | * @since 1.0
27 | */
28 | public class OneDriveIdentity extends OneDriveJsonObject {
29 |
30 | private String id;
31 |
32 | private String displayName;
33 |
34 | public OneDriveIdentity(JsonObject json) {
35 | super(json);
36 | }
37 |
38 | public String getId() {
39 | return id;
40 | }
41 |
42 | public String getDisplayName() {
43 | return displayName;
44 | }
45 |
46 | @Override
47 | protected void parseMember(JsonObject.Member member) {
48 | super.parseMember(member);
49 | try {
50 | JsonValue value = member.getValue();
51 | String memberName = member.getName();
52 | if ("id".equals(memberName)) {
53 | id = value.asString();
54 | } else if ("displayName".equals(memberName)) {
55 | displayName = value.asString();
56 | }
57 | } catch (ParseException e) {
58 | throw new OneDriveRuntimeException("Parse failed, maybe a bug in client.", e);
59 | }
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/OneDriveIdentitySet.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | import com.eclipsesource.json.JsonObject;
22 | import com.eclipsesource.json.JsonValue;
23 | import com.eclipsesource.json.ParseException;
24 |
25 | /**
26 | * @since 1.0
27 | */
28 | public class OneDriveIdentitySet extends OneDriveJsonObject {
29 |
30 | private OneDriveIdentity user;
31 |
32 | private OneDriveIdentity application;
33 |
34 | private OneDriveIdentity device;
35 |
36 | public OneDriveIdentitySet(JsonObject json) {
37 | super(json);
38 | }
39 |
40 | public OneDriveIdentity getUser() {
41 | return user;
42 | }
43 |
44 | public OneDriveIdentity getApplication() {
45 | return application;
46 | }
47 |
48 | public OneDriveIdentity getDevice() {
49 | return device;
50 | }
51 |
52 | @Override
53 | protected void parseMember(JsonObject.Member member) {
54 | super.parseMember(member);
55 | try {
56 | JsonValue value = member.getValue();
57 | String memberName = member.getName();
58 | if ("user".equals(memberName)) {
59 | user = new OneDriveIdentity(value.asObject());
60 | } else if ("application".equals(memberName)) {
61 | application = new OneDriveIdentity(value.asObject());
62 | } else if ("device".equals(memberName)) {
63 | device = new OneDriveIdentity(value.asObject());
64 | }
65 | } catch (ParseException e) {
66 | throw new OneDriveRuntimeException("Parse failed, maybe a bug in client.", e);
67 | }
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/OneDriveItem.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | import java.io.InputStream;
22 | import java.net.URL;
23 | import java.time.ZonedDateTime;
24 | import java.util.ArrayList;
25 | import java.util.Collections;
26 | import java.util.Iterator;
27 | import java.util.List;
28 |
29 | import com.eclipsesource.json.JsonArray;
30 | import com.eclipsesource.json.JsonObject;
31 | import com.eclipsesource.json.JsonValue;
32 | import com.eclipsesource.json.ParseException;
33 |
34 | /**
35 | * @since 1.0
36 | */
37 | public abstract class OneDriveItem extends OneDriveResource {
38 |
39 | private static final URLTemplate CREATE_SHARED_LINK_URL = new URLTemplate("/drive/items/%s/action.createLink");
40 |
41 | private static final URLTemplate CREATE_SHARED_LINK_ROOT_URL = new URLTemplate("/drive/root/action.createLink");
42 |
43 | OneDriveItem(OneDriveAPI api) {
44 | super(api);
45 | }
46 |
47 | public OneDriveItem(OneDriveAPI api, String id) {
48 | super(api, id);
49 | }
50 |
51 | public abstract OneDriveItem.Metadata getMetadata(OneDriveExpand... expand) throws OneDriveAPIException;
52 |
53 | public OneDriveThumbnailSet.Metadata getThumbnailSet() throws OneDriveAPIException {
54 | try {
55 | Iterator iterator = getThumbnailSets().iterator();
56 | if (iterator.hasNext()) {
57 | return iterator.next();
58 | }
59 | } catch (OneDriveRuntimeException e) {
60 | throw new OneDriveAPIException(e.getMessage(), e);
61 | }
62 | return null;
63 | }
64 |
65 | public OneDriveThumbnail.Metadata getThumbnail(OneDriveThumbnailSize size) throws OneDriveAPIException {
66 | return new OneDriveThumbnail(getApi(), getId(), size).getMetadata();
67 | }
68 |
69 | public InputStream downloadThumbnail(OneDriveThumbnailSize size) throws OneDriveAPIException {
70 | return new OneDriveThumbnail(getApi(), getId(), size).download();
71 | }
72 |
73 | Iterable getThumbnailSets() {
74 | return () -> new OneDriveThumbnailSetIterator(getApi(), getId());
75 | }
76 |
77 | public OneDrivePermission.Metadata createSharedLink(OneDriveSharingLink.Type type) throws OneDriveAPIException {
78 | URL url;
79 | if (isRoot()) {
80 | url = CREATE_SHARED_LINK_ROOT_URL.build(getApi().getBaseURL());
81 | } else {
82 | url = CREATE_SHARED_LINK_URL.build(getApi().getBaseURL(), getId());
83 | }
84 | OneDriveJsonRequest request = new OneDriveJsonRequest(getApi(), url, "POST");
85 | request.setBody(new JsonObject().add("type", type.getType()));
86 | OneDriveJsonResponse response = request.send();
87 | String permissionId = response.getContent().asObject().get("id").asString();
88 | OneDrivePermission permission;
89 | if (isRoot()) {
90 | permission = new OneDrivePermission(getApi(), permissionId);
91 | } else {
92 | permission = new OneDrivePermission(getApi(), getId(), permissionId);
93 | }
94 | return permission.new Metadata(response.getContent());
95 | }
96 |
97 | /** See documentation at https://dev.onedrive.com/resources/item.htm. */
98 | public abstract class Metadata extends OneDriveResource.Metadata {
99 |
100 | private String name;
101 |
102 | private String eTag;
103 |
104 | private OneDriveIdentitySet createdBy;
105 |
106 | private ZonedDateTime createdDateTime;
107 |
108 | private OneDriveIdentitySet lastModifiedBy;
109 |
110 | private ZonedDateTime lastModifiedDateTime;
111 |
112 | private long size;
113 |
114 | private OneDriveFolder.Reference parentReference;
115 |
116 | private String webUrl;
117 |
118 | private String description;
119 |
120 | private boolean deleted;
121 |
122 | private List thumbnailSets = Collections.emptyList();
123 |
124 | public Metadata(JsonObject json) {
125 | super(json);
126 | }
127 |
128 | public String getName() {
129 | return name;
130 | }
131 |
132 | public String getETag() {
133 | return eTag;
134 | }
135 |
136 | public OneDriveIdentitySet getCreatedBy() {
137 | return createdBy;
138 | }
139 |
140 | public ZonedDateTime getCreatedDateTime() {
141 | return createdDateTime;
142 | }
143 |
144 | public OneDriveIdentitySet getLastModifiedBy() {
145 | return lastModifiedBy;
146 | }
147 |
148 | public ZonedDateTime getLastModifiedDateTime() {
149 | return lastModifiedDateTime;
150 | }
151 |
152 | public long getSize() {
153 | return size;
154 | }
155 |
156 | public OneDriveFolder.Reference getParentReference() {
157 | return parentReference;
158 | }
159 |
160 | public String getWebUrl() {
161 | return webUrl;
162 | }
163 |
164 | public String getDescription() {
165 | return description;
166 | }
167 |
168 | public boolean isDeleted() {
169 | return deleted;
170 | }
171 |
172 | public OneDriveThumbnailSet.Metadata getThumbnailSet() {
173 | return thumbnailSets.stream().findFirst().orElse(null);
174 | }
175 |
176 | List getThumbnailSets() {
177 | return Collections.unmodifiableList(thumbnailSets);
178 | }
179 |
180 | @Override
181 | protected void parseMember(JsonObject.Member member) {
182 | super.parseMember(member);
183 | try {
184 | JsonValue value = member.getValue();
185 | String memberName = member.getName();
186 | if ("name".equals(memberName)) {
187 | name = value.asString();
188 | } else if ("eTag".equals(memberName)) {
189 | eTag = value.asString();
190 | } else if ("createdBy".equals(memberName)) {
191 | createdBy = new OneDriveIdentitySet(value.asObject());
192 | } else if ("createdDateTime".equals(memberName)) {
193 | createdDateTime = ZonedDateTime.parse(value.asString());
194 | } else if ("lastModifiedBy".equals(memberName)) {
195 | lastModifiedBy = new OneDriveIdentitySet(value.asObject());
196 | } else if ("lastModifiedDateTime".equals(memberName)) {
197 | lastModifiedDateTime = ZonedDateTime.parse(value.asString());
198 | } else if ("size".equals(memberName)) {
199 | size = value.asLong();
200 | } else if ("parentReference".equals(memberName)) {
201 | JsonObject valueObject = value.asObject();
202 | String id = valueObject.get("id").asString();
203 | OneDriveFolder parentFolder = new OneDriveFolder(getApi(), id);
204 | parentReference = parentFolder.new Reference(valueObject);
205 | } else if ("webUrl".equals(memberName)) {
206 | webUrl = value.asString();
207 | } else if ("description".equals(memberName)) {
208 | description = value.asString();
209 | } else if ("deleted".equals(memberName)) {
210 | deleted = true;
211 | } else if ("thumbnailSets".equals(memberName)) {
212 | parseThumbnailsMember(value.asArray());
213 | }
214 | } catch (ParseException e) {
215 | throw new OneDriveRuntimeException("Parse failed, maybe a bug in client.", e);
216 | }
217 | }
218 |
219 | private void parseThumbnailsMember(JsonArray thumbnails) {
220 | thumbnailSets = new ArrayList<>(thumbnails.size());
221 | for (JsonValue value : thumbnails) {
222 | JsonObject thumbnail = value.asObject();
223 | int id = Integer.parseInt(thumbnail.get("id").asString());
224 | OneDriveThumbnailSet thumbnailSet = new OneDriveThumbnailSet(getApi(), getId(), id);
225 | thumbnailSets.add(thumbnailSet.new Metadata(thumbnail));
226 | }
227 | }
228 |
229 | public boolean isFolder() {
230 | return false;
231 | }
232 |
233 | public boolean isFile() {
234 | return false;
235 | }
236 |
237 | public OneDriveFolder.Metadata asFolder() {
238 | throw new UnsupportedOperationException("Not a folder.");
239 | }
240 |
241 | public OneDriveFile.Metadata asFile() {
242 | throw new UnsupportedOperationException("Not a file.");
243 | }
244 |
245 | }
246 |
247 | }
248 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/OneDriveItemIterator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | import java.net.URL;
22 | import java.util.Iterator;
23 | import java.util.Objects;
24 |
25 | import com.eclipsesource.json.JsonObject;
26 |
27 | /**
28 | * @since 1.0
29 | */
30 | public class OneDriveItemIterator implements Iterator {
31 |
32 | private final OneDriveAPI api;
33 |
34 | private final JsonObjectIterator jsonObjectIterator;
35 |
36 | public OneDriveItemIterator(OneDriveAPI api, URL url) {
37 | this.api = Objects.requireNonNull(api);
38 | this.jsonObjectIterator = new JsonObjectIterator(api, url) {
39 |
40 | @Override
41 | protected void onResponse(JsonObject response) {
42 | OneDriveItemIterator.this.onResponse(response);
43 | }
44 |
45 | };
46 | }
47 |
48 | @Override
49 | public boolean hasNext() throws OneDriveRuntimeException {
50 | return jsonObjectIterator.hasNext();
51 | }
52 |
53 | @Override
54 | public OneDriveItem.Metadata next() throws OneDriveRuntimeException {
55 | JsonObject nextObject = jsonObjectIterator.next();
56 | String id = nextObject.get("id").asString();
57 |
58 | OneDriveItem.Metadata nextMetadata;
59 | if (nextObject.get("folder") != null && !nextObject.get("folder").isNull()) {
60 | OneDriveFolder folder = new OneDriveFolder(api, id);
61 | nextMetadata = folder.new Metadata(nextObject);
62 | } else if (nextObject.get("file") != null && !nextObject.get("file").isNull()) {
63 | OneDriveFile file = new OneDriveFile(api, id);
64 | nextMetadata = file.new Metadata(nextObject);
65 | } else {
66 | throw new OneDriveRuntimeException("The object type is currently not handled.");
67 | }
68 | return nextMetadata;
69 | }
70 |
71 | /**
72 | * @since 1.1
73 | */
74 | protected void onResponse(JsonObject response) {
75 | // Hook method
76 | }
77 |
78 | }
79 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/OneDriveJsonObject.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | import java.util.function.Consumer;
22 |
23 | import com.eclipsesource.json.JsonObject;
24 |
25 | /**
26 | * @since 1.0
27 | */
28 | public abstract class OneDriveJsonObject {
29 |
30 | public OneDriveJsonObject(JsonObject json) {
31 | parseMember(json, this::parseMember);
32 | }
33 |
34 | protected void parseMember(JsonObject.Member member) {
35 | }
36 |
37 | protected static void parseMember(JsonObject json, Consumer consumer) {
38 | for (JsonObject.Member member : json) {
39 | if (member.getValue().isNull()) {
40 | continue;
41 | }
42 | consumer.accept(member);
43 | }
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/OneDriveJsonRequest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | import java.net.HttpURLConnection;
22 | import java.net.URL;
23 |
24 | import com.eclipsesource.json.JsonObject;
25 |
26 | /**
27 | * @since 1.0
28 | */
29 | public class OneDriveJsonRequest extends AbstractRequest {
30 |
31 | public OneDriveJsonRequest(URL url, String method) {
32 | super(url, method);
33 | }
34 |
35 | public OneDriveJsonRequest(OneDriveAPI api, URL url, String method) {
36 | super(api, url, method);
37 | if (!"GET".equals(method)) {
38 | addHeader("Content-Type", "application/json");
39 | }
40 | addHeader("accept", "application/json");
41 | }
42 |
43 | @Override
44 | protected OneDriveJsonResponse createResponse(HttpURLConnection connection) throws OneDriveAPIException {
45 | return new OneDriveJsonResponse(connection);
46 | }
47 |
48 | public void setBody(JsonObject body) {
49 | setBody(body.toString());
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/OneDriveJsonResponse.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | import java.io.IOException;
22 | import java.io.InputStream;
23 | import java.net.HttpURLConnection;
24 |
25 | import com.eclipsesource.json.JsonObject;
26 |
27 | /**
28 | * @since 1.0
29 | */
30 | public class OneDriveJsonResponse extends AbstractResponse {
31 |
32 | private JsonObject json;
33 |
34 | public OneDriveJsonResponse(HttpURLConnection connection) throws OneDriveAPIException {
35 | super(connection);
36 | }
37 |
38 | /**
39 | * Gets the body as JSON object. Once this method is called, the response will be disconnected.
40 | */
41 | @Override
42 | public JsonObject getContent() throws OneDriveAPIException {
43 | if (json != null) {
44 | return json;
45 | }
46 | try (InputStream body = getBody()) {
47 | String jsonString = readStream(body);
48 | json = JsonObject.readFrom(jsonString);
49 | return json;
50 | } catch (IOException e) {
51 | throw new OneDriveAPIException("Couldn't read the stream from OneDrive API.", e);
52 | }
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/OneDrivePermission.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | import java.util.Objects;
22 |
23 | import com.eclipsesource.json.JsonObject;
24 | import com.eclipsesource.json.JsonValue;
25 | import com.eclipsesource.json.ParseException;
26 |
27 | /**
28 | * See documentation at https://dev.onedrive.com/facets/permission_facet.htm
29 | *
30 | * @since 1.0
31 | */
32 | public class OneDrivePermission extends OneDriveResource {
33 |
34 | private static final URLTemplate PERMISSIONS_URL = new URLTemplate("/drive/items/%s/permissions/%s");
35 |
36 | private static final URLTemplate PERMISSIONS_ROOT_URL = new URLTemplate("/drive/root/permissions/%s");
37 |
38 | private final String itemId;
39 |
40 | private final String permissionId;
41 |
42 | OneDrivePermission(OneDriveAPI api, String permissionId) {
43 | super(api, "root$$" + permissionId);
44 | this.itemId = null;
45 | this.permissionId = Objects.requireNonNull(permissionId);
46 | }
47 |
48 | public OneDrivePermission(OneDriveAPI api, String itemId, String permissionId) {
49 | super(api, itemId + "$$" + permissionId);
50 | this.itemId = Objects.requireNonNull(itemId);
51 | this.permissionId = Objects.requireNonNull(permissionId);
52 | }
53 |
54 | public class Metadata extends OneDriveResource.Metadata {
55 |
56 | private boolean writable;
57 |
58 | private OneDriveSharingLink link;
59 |
60 | private OneDriveIdentitySet grantedTo;
61 |
62 | private OneDriveFolder.Reference inheritedFrom;
63 |
64 | private String shareId;
65 |
66 | public Metadata(JsonObject json) {
67 | super(json);
68 | }
69 |
70 | public boolean isWritable() {
71 | return writable;
72 | }
73 |
74 | public OneDriveSharingLink getLink() {
75 | return link;
76 | }
77 |
78 | public OneDriveIdentitySet getGrantedTo() {
79 | return grantedTo;
80 | }
81 |
82 | public OneDriveFolder.Reference getInheritedFrom() {
83 | return inheritedFrom;
84 | }
85 |
86 | public String getShareId() {
87 | return shareId;
88 | }
89 |
90 | @Override
91 | protected void parseMember(JsonObject.Member member) {
92 | super.parseMember(member);
93 | try {
94 | JsonValue value = member.getValue();
95 | String memberName = member.getName();
96 | if ("roles".equals(memberName)) {
97 | this.writable = value.asArray()
98 | .values()
99 | .stream()
100 | .filter(JsonValue::isString)
101 | .map(JsonValue::asString)
102 | .anyMatch("write"::equalsIgnoreCase);
103 | } else if ("link".equals(memberName)) {
104 | link = new OneDriveSharingLink(value.asObject());
105 | } else if ("grantedTo".equals(memberName)) {
106 | grantedTo = new OneDriveIdentitySet(value.asObject());
107 | } else if ("inheritedFrom".equals(memberName)) {
108 | JsonObject valueObject = value.asObject();
109 | String id = valueObject.get("id").asString();
110 | OneDriveFolder inheritedFromFolder = new OneDriveFolder(getApi(), id);
111 | inheritedFrom = inheritedFromFolder.new Reference(valueObject);
112 | } else if ("shareId".equals(memberName)) {
113 | shareId = value.asString();
114 | }
115 | } catch (ParseException e) {
116 | throw new OneDriveRuntimeException("Parse failed, maybe a bug in client.", e);
117 | }
118 | }
119 |
120 | @Override
121 | public OneDrivePermission getResource() {
122 | return OneDrivePermission.this;
123 | }
124 |
125 | }
126 |
127 | }
128 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/OneDriveRequest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | import java.net.HttpURLConnection;
22 | import java.net.URL;
23 |
24 | /**
25 | * @since 1.0
26 | */
27 | public class OneDriveRequest extends AbstractRequest {
28 |
29 | public OneDriveRequest(URL url, String method) {
30 | super(url, method);
31 | }
32 |
33 | public OneDriveRequest(OneDriveAPI api, URL url, String method) {
34 | super(api, url, method);
35 | addHeader("accept", "application/json");
36 | }
37 |
38 | @Override
39 | protected OneDriveResponse createResponse(HttpURLConnection connection) throws OneDriveAPIException {
40 | return new OneDriveResponse(connection);
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/OneDriveResource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | import java.util.Objects;
22 |
23 | import com.eclipsesource.json.JsonObject;
24 |
25 | /**
26 | * @since 1.0
27 | */
28 | public class OneDriveResource {
29 |
30 | private final OneDriveAPI api;
31 |
32 | private final String id;
33 |
34 | OneDriveResource(OneDriveAPI api) {
35 | this.api = Objects.requireNonNull(api);
36 | this.id = null;
37 | }
38 |
39 | public OneDriveResource(OneDriveAPI api, String id) {
40 | this.api = Objects.requireNonNull(api);
41 | this.id = Objects.requireNonNull(id);
42 | }
43 |
44 | public OneDriveAPI getApi() {
45 | return api;
46 | }
47 |
48 | public String getId() {
49 | return id;
50 | }
51 |
52 | public boolean isRoot() {
53 | return id == null;
54 | }
55 |
56 | @Override
57 | public boolean equals(Object obj) {
58 | if (obj == null || !getClass().equals(obj.getClass())) {
59 | return false;
60 | }
61 |
62 | if (this == obj) {
63 | return true;
64 | }
65 |
66 | OneDriveResource oDObj = (OneDriveResource) obj;
67 | return getId().equals(oDObj.getId());
68 | }
69 |
70 | @Override
71 | public int hashCode() {
72 | return getId().hashCode();
73 | }
74 |
75 | public abstract class Metadata extends OneDriveJsonObject {
76 |
77 | public Metadata(JsonObject json) {
78 | super(json);
79 | }
80 |
81 | public String getId() {
82 | return OneDriveResource.this.getId();
83 | }
84 |
85 | public abstract OneDriveResource getResource();
86 |
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/OneDriveResponse.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | import java.io.InputStream;
22 | import java.net.HttpURLConnection;
23 |
24 | /**
25 | * @since 1.0
26 | */
27 | public class OneDriveResponse extends AbstractResponse {
28 |
29 | public OneDriveResponse(HttpURLConnection connection) throws OneDriveAPIException {
30 | super(connection);
31 | }
32 |
33 | @Override
34 | public InputStream getContent() throws OneDriveAPIException {
35 | return getBody();
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/OneDriveRuntimeException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | /**
22 | * Thrown to indicate that an error occurred with client configuration.
23 | *
24 | * @since 1.0
25 | */
26 | public class OneDriveRuntimeException extends RuntimeException {
27 |
28 | private static final long serialVersionUID = 1L;
29 |
30 | public OneDriveRuntimeException(String message) {
31 | super(message);
32 | }
33 |
34 | public OneDriveRuntimeException(String message, Throwable cause) {
35 | super(message, cause);
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/OneDriveSharingLink.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | import com.eclipsesource.json.JsonObject;
22 | import com.eclipsesource.json.JsonValue;
23 | import com.eclipsesource.json.ParseException;
24 |
25 | /**
26 | * @since 1.0
27 | */
28 | public class OneDriveSharingLink extends OneDriveJsonObject {
29 |
30 | private boolean edit;
31 |
32 | private String webUrl;
33 |
34 | private OneDriveIdentity application;
35 |
36 | public OneDriveSharingLink(JsonObject json) {
37 | super(json);
38 | }
39 |
40 | public boolean isEdit() {
41 | return edit;
42 | }
43 |
44 | public String getWebUrl() {
45 | return webUrl;
46 | }
47 |
48 | public OneDriveIdentity getApplication() {
49 | return application;
50 | }
51 |
52 | @Override
53 | protected void parseMember(JsonObject.Member member) {
54 | super.parseMember(member);
55 | try {
56 | JsonValue value = member.getValue();
57 | String memberName = member.getName();
58 | if ("type".equals(memberName)) {
59 | edit = Type.EDIT.name().equalsIgnoreCase(value.asString());
60 | } else if ("webUrl".equals(memberName)) {
61 | webUrl = value.asString();
62 | } else if ("application".equals(memberName)) {
63 | application = new OneDriveIdentity(value.asObject());
64 | }
65 | } catch (ParseException e) {
66 | throw new OneDriveRuntimeException("Parse failed, maybe a bug in client.", e);
67 | }
68 | }
69 |
70 | public enum Type {
71 |
72 | VIEW("view"), EDIT("edit");
73 |
74 | private String type;
75 |
76 | Type(String type) {
77 | this.type = type;
78 | }
79 |
80 | public String getType() {
81 | return type;
82 | }
83 |
84 | }
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/OneDriveThumbnail.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | import java.io.InputStream;
22 | import java.net.URL;
23 | import java.util.Objects;
24 |
25 | import com.eclipsesource.json.JsonObject;
26 | import com.eclipsesource.json.JsonValue;
27 | import com.eclipsesource.json.ParseException;
28 |
29 | /**
30 | * See documentation at https://dev.onedrive.com/resources/thumbnail.htm
31 | *
32 | * @since 1.0
33 | */
34 | public class OneDriveThumbnail extends OneDriveResource {
35 |
36 | private static final URLTemplate GET_THUMBNAIL_URL = new URLTemplate("/drive/items/%s/thumbnails/%s/%s");
37 |
38 | private static final URLTemplate GET_THUMBNAIL_ROOT_URL = new URLTemplate("/drive/root/thumbnails/%s/%s");
39 |
40 | private static final URLTemplate GET_THUMBNAIL_CONTENT_URL = new URLTemplate(
41 | "/drive/items/%s/thumbnails/%s/%s/content");
42 |
43 | private static final URLTemplate GET_THUMBNAIL_CONTENT_ROOT_URL = new URLTemplate(
44 | "/drive/root/thumbnails/%s/%s/content");
45 |
46 | private final String itemId;
47 |
48 | private final int thumbId;
49 |
50 | private final OneDriveThumbnailSize size;
51 |
52 | OneDriveThumbnail(OneDriveAPI api, int thumbId, OneDriveThumbnailSize size) {
53 | super(api, "root$$" + thumbId + "$$" + size.getKey());
54 | this.itemId = null;
55 | this.thumbId = thumbId;
56 | this.size = Objects.requireNonNull(size);
57 | }
58 |
59 | public OneDriveThumbnail(OneDriveAPI api, String itemId, int thumbId, OneDriveThumbnailSize size) {
60 | super(api, itemId + "$$" + thumbId + "$$" + size.getKey());
61 | this.itemId = Objects.requireNonNull(itemId);
62 | this.thumbId = thumbId;
63 | this.size = Objects.requireNonNull(size);
64 | }
65 |
66 | public OneDriveThumbnail(OneDriveAPI api, String itemId, OneDriveThumbnailSize size) {
67 | this(api, itemId, 0, size);
68 | }
69 |
70 | public OneDriveThumbnail.Metadata getMetadata() throws OneDriveAPIException {
71 | URL url;
72 | if (isRoot()) {
73 | url = GET_THUMBNAIL_ROOT_URL.build(getApi().getBaseURL(), thumbId, size.getKey());
74 | } else {
75 | url = GET_THUMBNAIL_URL.build(getApi().getBaseURL(), itemId, thumbId, size.getKey());
76 | }
77 | OneDriveJsonRequest request = new OneDriveJsonRequest(getApi(), url, "GET");
78 | OneDriveJsonResponse response = request.send();
79 | return new OneDriveThumbnail.Metadata(response.getContent());
80 | }
81 |
82 | public InputStream download() throws OneDriveAPIException {
83 | URL url;
84 | if (isRoot()) {
85 | url = GET_THUMBNAIL_CONTENT_ROOT_URL.build(getApi().getBaseURL(), thumbId, size.getKey());
86 | } else {
87 | url = GET_THUMBNAIL_CONTENT_URL.build(getApi().getBaseURL(), itemId, thumbId, size.getKey());
88 | }
89 | OneDriveRequest request = new OneDriveRequest(getApi(), url, "GET");
90 | OneDriveResponse response = request.send();
91 | return response.getContent();
92 | }
93 |
94 | @Override
95 | public boolean isRoot() {
96 | return itemId == null;
97 | }
98 |
99 | public class Metadata extends OneDriveResource.Metadata {
100 |
101 | private int height;
102 |
103 | private int width;
104 |
105 | private String url;
106 |
107 | public Metadata(JsonObject json) {
108 | super(json);
109 | }
110 |
111 | public int getHeight() {
112 | return height;
113 | }
114 |
115 | public int getWidth() {
116 | return width;
117 | }
118 |
119 | public String getUrl() {
120 | return url;
121 | }
122 |
123 | @Override
124 | protected void parseMember(JsonObject.Member member) {
125 | super.parseMember(member);
126 | try {
127 | JsonValue value = member.getValue();
128 | String memberName = member.getName();
129 | if ("height".equals(memberName)) {
130 | height = value.asInt();
131 | } else if ("width".equals(memberName)) {
132 | width = value.asInt();
133 | } else if ("url".equals(memberName)) {
134 | url = value.asString();
135 | }
136 | } catch (ParseException e) {
137 | throw new OneDriveRuntimeException("Parse failed, maybe a bug in client.", e);
138 | }
139 | }
140 |
141 | @Override
142 | public OneDriveThumbnail getResource() {
143 | return OneDriveThumbnail.this;
144 | }
145 |
146 | }
147 |
148 | }
149 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/OneDriveThumbnailSet.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | import java.util.Objects;
22 |
23 | import com.eclipsesource.json.JsonObject;
24 | import com.eclipsesource.json.JsonValue;
25 | import com.eclipsesource.json.ParseException;
26 |
27 | /**
28 | * See documentation at https://dev.onedrive.com/resources/thumbnailSet.htm.
29 | *
30 | * @since 1.0
31 | */
32 | public class OneDriveThumbnailSet extends OneDriveResource {
33 |
34 | private final String itemId;
35 |
36 | private final int thumbId;
37 |
38 | OneDriveThumbnailSet(OneDriveAPI api, int thumbId) {
39 | super(api, "root$$" + thumbId);
40 | this.itemId = null;
41 | this.thumbId = thumbId;
42 | }
43 |
44 | OneDriveThumbnailSet(OneDriveAPI api, String itemId, int thumbId) {
45 | super(api, itemId + "$$" + thumbId);
46 | this.itemId = Objects.requireNonNull(itemId);
47 | this.thumbId = thumbId;
48 | }
49 |
50 | @Override
51 | public boolean isRoot() {
52 | return itemId == null;
53 | }
54 |
55 | public class Metadata extends OneDriveResource.Metadata {
56 |
57 | /**
58 | * A 48x48 cropped thumbnail.
59 | */
60 | private OneDriveThumbnail.Metadata small;
61 |
62 | /**
63 | * A 176x176 scaled thumbnail.
64 | */
65 | private OneDriveThumbnail.Metadata medium;
66 |
67 | /**
68 | * A 1920x1920 scaled thumbnail.
69 | */
70 | private OneDriveThumbnail.Metadata large;
71 |
72 | /**
73 | * A custom thumbnail image or the original image used to generate other thumbnails.
74 | */
75 | private OneDriveThumbnail.Metadata source;
76 |
77 | public Metadata(JsonObject json) {
78 | super(json);
79 | }
80 |
81 | public String getItemId() {
82 | return itemId;
83 | }
84 |
85 | public int getThumbId() {
86 | return thumbId;
87 | }
88 |
89 | public OneDriveThumbnail.Metadata getSmall() {
90 | return small;
91 | }
92 |
93 | public OneDriveThumbnail.Metadata getMedium() {
94 | return medium;
95 | }
96 |
97 | public OneDriveThumbnail.Metadata getLarge() {
98 | return large;
99 | }
100 |
101 | public OneDriveThumbnail.Metadata getSource() {
102 | return source;
103 | }
104 |
105 | @Override
106 | protected void parseMember(JsonObject.Member member) {
107 | super.parseMember(member);
108 | try {
109 | JsonValue value = member.getValue();
110 | String memberName = member.getName();
111 | if ("small".equals(memberName)) {
112 | OneDriveThumbnail thumbnail = initThumbnail(OneDriveThumbnailSize.SMALL);
113 | small = thumbnail.new Metadata(value.asObject());
114 | } else if ("medium".equals(memberName)) {
115 | OneDriveThumbnail thumbnail = initThumbnail(OneDriveThumbnailSize.MEDIUM);
116 | medium = thumbnail.new Metadata(value.asObject());
117 | } else if ("large".equals(memberName)) {
118 | OneDriveThumbnail thumbnail = initThumbnail(OneDriveThumbnailSize.LARGE);
119 | large = thumbnail.new Metadata(value.asObject());
120 | } else if ("source".equals(memberName)) {
121 | OneDriveThumbnail thumbnail = initThumbnail(OneDriveThumbnailSize.SOURCE);
122 | source = thumbnail.new Metadata(value.asObject());
123 | }
124 | } catch (ParseException e) {
125 | throw new OneDriveRuntimeException("Parse failed, maybe a bug in client.", e);
126 | }
127 | }
128 |
129 | private OneDriveThumbnail initThumbnail(OneDriveThumbnailSize size) {
130 | if (itemId == null) {
131 | return new OneDriveThumbnail(getApi(), thumbId, size);
132 | }
133 | return new OneDriveThumbnail(getApi(), itemId, thumbId, size);
134 | }
135 |
136 | @Override
137 | public OneDriveResource getResource() {
138 | return OneDriveThumbnailSet.this;
139 | }
140 |
141 | }
142 |
143 | }
144 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/OneDriveThumbnailSetIterator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | import java.util.Iterator;
22 | import java.util.Objects;
23 |
24 | import com.eclipsesource.json.JsonObject;
25 |
26 | /**
27 | * @since 1.0
28 | */
29 | public class OneDriveThumbnailSetIterator implements Iterator {
30 |
31 | private static final URLTemplate GET_THUMBNAILS_URL = new URLTemplate("/drive/items/%s/thumbnails");
32 |
33 | private static final URLTemplate GET_THUMBNAILS_ROOT_URL = new URLTemplate("/drive/items/%s/thumbnails");
34 |
35 | private final OneDriveAPI api;
36 |
37 | private final String itemId;
38 |
39 | private final JsonObjectIterator jsonObjectIterator;
40 |
41 | OneDriveThumbnailSetIterator(OneDriveAPI api) {
42 | this.api = Objects.requireNonNull(api);
43 | this.itemId = null;
44 | this.jsonObjectIterator = new JsonObjectIterator(api, GET_THUMBNAILS_ROOT_URL.build(api.getBaseURL()));
45 | }
46 |
47 | public OneDriveThumbnailSetIterator(OneDriveAPI api, String itemId) {
48 | this.api = Objects.requireNonNull(api);
49 | this.itemId = Objects.requireNonNull(itemId);
50 | this.jsonObjectIterator = new JsonObjectIterator(api, GET_THUMBNAILS_URL.build(api.getBaseURL(), itemId));
51 | }
52 |
53 | @Override
54 | public boolean hasNext() throws OneDriveRuntimeException {
55 | return jsonObjectIterator.hasNext();
56 | }
57 |
58 | @Override
59 | public OneDriveThumbnailSet.Metadata next() throws OneDriveRuntimeException {
60 | JsonObject nextObject = jsonObjectIterator.next();
61 | int id = Integer.parseInt(nextObject.get("id").asString());
62 |
63 | OneDriveThumbnailSet thumbnail;
64 | if (itemId == null) {
65 | thumbnail = new OneDriveThumbnailSet(api, id);
66 | } else {
67 | thumbnail = new OneDriveThumbnailSet(api, itemId, id);
68 | }
69 | return thumbnail.new Metadata(nextObject);
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/OneDriveThumbnailSize.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | /**
22 | * @since 1.0
23 | */
24 | public enum OneDriveThumbnailSize implements QueryStringCommaParameter {
25 |
26 | SMALL("small"),
27 |
28 | MEDIUM("medium"),
29 |
30 | LARGE("large"),
31 |
32 | SMALL_SQUARE("smallSquare"),
33 |
34 | MEDIUM_SQUARE("mediumSquare"),
35 |
36 | LARGE_SQUARE("largeSquare"),
37 |
38 | SOURCE("source");
39 |
40 | private String key;
41 |
42 | OneDriveThumbnailSize(String key) {
43 | this.key = key;
44 | }
45 |
46 | @Override
47 | public String getKey() {
48 | return key;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/QueryStringBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | import java.io.UnsupportedEncodingException;
22 | import java.net.URLEncoder;
23 | import java.nio.charset.StandardCharsets;
24 | import java.util.HashMap;
25 | import java.util.Map;
26 | import java.util.Map.Entry;
27 |
28 | /**
29 | * @since 1.0
30 | */
31 | class QueryStringBuilder {
32 |
33 | private Map parameters = new HashMap<>();
34 |
35 | public QueryStringBuilder set(String key, int value) {
36 | return set(key, Integer.toString(value));
37 | }
38 |
39 | public QueryStringBuilder set(String key, long value) {
40 | return set(key, Long.toString(value));
41 | }
42 |
43 | public QueryStringBuilder set(String key, boolean value) {
44 | return set(key, Boolean.toString(value));
45 | }
46 |
47 | public QueryStringBuilder set(String key, String value) {
48 | parameters.put(key, value);
49 | return this;
50 | }
51 |
52 | public QueryStringBuilder set(String key, QueryStringCommaParameter... parameters) {
53 | if (parameters != null && parameters.length > 0) {
54 | StringBuilder builder = new StringBuilder();
55 | for (QueryStringCommaParameter parameter : parameters) {
56 | if (builder.length() > 0) {
57 | builder.append(",");
58 | }
59 | builder.append(parameter.getKey());
60 | }
61 | this.parameters.put(key, builder.toString());
62 | }
63 | return this;
64 | }
65 |
66 | @Override
67 | public String toString() {
68 | if (parameters.isEmpty()) {
69 | return "";
70 | }
71 | try {
72 | StringBuilder builder = new StringBuilder("?");
73 | for (Entry entry : parameters.entrySet()) {
74 | if (builder.length() != 1) {
75 | builder.append("&");
76 | }
77 | builder.append(entry.getKey())
78 | .append("=")
79 | .append(URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8.name()));
80 | }
81 | return builder.toString();
82 | } catch (UnsupportedEncodingException e) {
83 | throw new OneDriveRuntimeException("Error during construction of query string.", e);
84 | }
85 | }
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/QueryStringCommaParameter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | /**
22 | * @since 1.0
23 | */
24 | public interface QueryStringCommaParameter {
25 |
26 | String getKey();
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/org/nuxeo/onedrive/client/URLTemplate.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | import java.net.MalformedURLException;
22 | import java.net.URL;
23 | import java.util.Objects;
24 |
25 | /**
26 | * @since 1.0
27 | */
28 | class URLTemplate {
29 |
30 | public static final URLTemplate EMPTY_TEMPLATE = new URLTemplate("");
31 |
32 | private String template;
33 |
34 | URLTemplate(String template) {
35 | this.template = Objects.requireNonNull(template);
36 | }
37 |
38 | URL build(String base, Object... values) {
39 | String urlString = String.format(base + this.template, values);
40 | try {
41 | return new URL(urlString);
42 | } catch (MalformedURLException e) {
43 | throw new OneDriveRuntimeException("Template produced an invalid URL (maybe a bug in client).", e);
44 | }
45 | }
46 |
47 | URL build(String base, QueryStringBuilder query, Object... values) {
48 | String urlString = String.format(base + this.template, values) + query.toString();
49 | try {
50 | return new URL(urlString);
51 | } catch (MalformedURLException e) {
52 | throw new OneDriveRuntimeException("Template produced an invalid URL (maybe a bug in client).", e);
53 | }
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/src/test/java/org/nuxeo/onedrive/client/OneDriveTestCase.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | import static org.mockito.Matchers.any;
22 | import static org.mockito.Matchers.eq;
23 | import static org.mockito.Mockito.when;
24 | import static org.powermock.api.mockito.PowerMockito.mock;
25 | import static org.powermock.api.mockito.PowerMockito.whenNew;
26 |
27 | import java.net.URL;
28 |
29 | import org.apache.commons.io.IOUtils;
30 | import org.junit.Ignore;
31 | import org.junit.runner.RunWith;
32 | import org.powermock.modules.junit4.PowerMockRunner;
33 |
34 | import com.eclipsesource.json.JsonObject;
35 |
36 | /**
37 | * @since 1.0
38 | */
39 | @Ignore
40 | @RunWith(PowerMockRunner.class)
41 | public class OneDriveTestCase {
42 |
43 | protected OneDriveAPI api = new OneDriveBasicAPI("ACCESS_TOKEN_TEST");
44 |
45 | protected OneDriveAPI businessApi = new OneDriveBusinessAPI("https://nuxeofr-my.sharepoint.com/",
46 | "ACCESS_TOKEN_TEST");
47 |
48 | protected void mockJsonRequest(String jsonResponseFile) throws Exception {
49 | OneDriveJsonRequest jsonRequest = mock(OneDriveJsonRequest.class);
50 | whenNew(OneDriveJsonRequest.class).withAnyArguments().thenReturn(jsonRequest);
51 |
52 | OneDriveJsonResponse jsonResponse = mock(OneDriveJsonResponse.class);
53 | when(jsonRequest.send()).thenReturn(jsonResponse);
54 |
55 | String jsonString = IOUtils.toString(getClass().getResource(jsonResponseFile));
56 | when(jsonResponse.getContent()).thenReturn(JsonObject.readFrom(jsonString));
57 | }
58 |
59 | protected void mockJsonRequest(URL url, String jsonResponseFile) throws Exception {
60 | OneDriveJsonRequest jsonRequest = mock(OneDriveJsonRequest.class);
61 | whenNew(OneDriveJsonRequest.class).withArguments(any(), eq(url), any()).thenReturn(jsonRequest);
62 |
63 | OneDriveJsonResponse jsonResponse = mock(OneDriveJsonResponse.class);
64 | when(jsonRequest.send()).thenReturn(jsonResponse);
65 |
66 | String jsonString = IOUtils.toString(getClass().getResource(jsonResponseFile));
67 | when(jsonResponse.getContent()).thenReturn(JsonObject.readFrom(jsonString));
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/src/test/java/org/nuxeo/onedrive/client/TestJsonObjectIterator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | import static org.junit.Assert.assertEquals;
22 | import static org.junit.Assert.assertFalse;
23 | import static org.junit.Assert.assertTrue;
24 |
25 | import java.net.URL;
26 | import java.util.NoSuchElementException;
27 |
28 | import org.junit.Rule;
29 | import org.junit.Test;
30 | import org.junit.rules.ExpectedException;
31 | import org.powermock.core.classloader.annotations.PrepareForTest;
32 |
33 | import com.eclipsesource.json.JsonObject;
34 |
35 | /**
36 | * @since 1.0
37 | */
38 | @PrepareForTest(JsonObjectIterator.class)
39 | public class TestJsonObjectIterator extends OneDriveTestCase {
40 |
41 | @Rule
42 | private final ExpectedException expectedException = ExpectedException.none();
43 |
44 | @Test
45 | public void testIterator() throws Exception {
46 | // Mock
47 | String stringUrl = "https://nuxeofr-my.sharepoint.com/_api/v2.0";
48 | URL url = new URL(stringUrl);
49 | mockJsonRequest(url, "onedrive_children_page_1.json");
50 | mockJsonRequest(new URL(stringUrl + "?p=2"), "onedrive_children_page_2.json");
51 |
52 | // Test
53 | JsonObjectIterator iterator = new JsonObjectIterator(api, url);
54 |
55 | assertTrue(iterator.hasNext());
56 | JsonObject item = iterator.next();
57 | assertEquals("01YOWJ6CQSJ5S3PYEERFBLEDREVCLCBNPU", item.get("id").asString());
58 |
59 | assertTrue(iterator.hasNext());
60 | item = iterator.next();
61 | assertEquals("01YOWJ6CT42I3ABB3ZFBGJ2E5ZRUGXXVJ4", item.get("id").asString());
62 |
63 | assertTrue(iterator.hasNext());
64 | item = iterator.next();
65 | assertEquals("01YOWJ6CSJ32VK4TN5PRCIR3Y2KDWQA4ZZ", item.get("id").asString());
66 |
67 | assertTrue(iterator.hasNext());
68 | item = iterator.next();
69 | assertEquals("01YOWJ6CRVBPTPEKUL6JFIGM7D6V3UZN2N", item.get("id").asString());
70 |
71 | assertFalse(iterator.hasNext());
72 | expectedException.expect(NoSuchElementException.class);
73 | iterator.next();
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/src/test/java/org/nuxeo/onedrive/client/TestOneDriveEmailAccount.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | import static org.junit.Assert.assertEquals;
22 |
23 | import org.junit.Test;
24 | import org.powermock.core.classloader.annotations.PrepareForTest;
25 |
26 | /**
27 | * @since 1.0
28 | */
29 | @PrepareForTest(OneDriveEmailAccount.class)
30 | public class TestOneDriveEmailAccount extends OneDriveTestCase {
31 |
32 | @Test
33 | public void testGetBusinessEmail() throws Exception {
34 | // Mock
35 | mockJsonRequest("onedrive_business_email.json");
36 |
37 | // Test
38 | String email = OneDriveEmailAccount.getCurrentUserEmailAccount(businessApi);
39 | assertEquals("nuxeo@nuxeofr.onmicrosoft.com", email);
40 |
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src/test/java/org/nuxeo/onedrive/client/TestOneDriveFolder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | import static org.junit.Assert.assertEquals;
22 | import static org.junit.Assert.assertNotNull;
23 | import static org.junit.Assert.assertNull;
24 | import static org.junit.Assert.assertTrue;
25 |
26 | import org.junit.Test;
27 | import org.powermock.core.classloader.annotations.PrepareForTest;
28 |
29 | /**
30 | * @since 1.0
31 | */
32 | @PrepareForTest(OneDriveFolder.class)
33 | public class TestOneDriveFolder extends OneDriveTestCase {
34 |
35 | @Test
36 | public void testGetMetadata() throws Exception {
37 | // Mock
38 | mockJsonRequest("onedrive_folder.json");
39 |
40 | // Test
41 | OneDriveFolder folder = new OneDriveFolder(api, "5FGB3N6V49HN725573R8LG588VRDPMJV36");
42 | OneDriveFolder.Metadata metadata = folder.getMetadata();
43 | assertTrue(metadata.isFolder());
44 | assertEquals("Test", metadata.getName());
45 | assertNotNull(metadata.getParentReference());
46 | assertEquals("4K4Q87486LMKRP9X82Y2YJ2N2NFVD2F596", metadata.getParentReference().getId());
47 | assertEquals("/drive/root:", metadata.getParentReference().getPath());
48 | assertNotNull(metadata.getCreatedBy());
49 | assertNull(metadata.getCreatedBy().getApplication());
50 | assertNull(metadata.getCreatedBy().getDevice());
51 | assertNotNull(metadata.getCreatedBy().getUser());
52 | assertEquals("Nuxeo User", metadata.getCreatedBy().getUser().getDisplayName());
53 | assertEquals(3, metadata.getChildCount());
54 | assertEquals(0L, metadata.getSize());
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/src/test/java/org/nuxeo/onedrive/client/TestQueryStringBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | import static org.junit.Assert.assertEquals;
22 | import static org.powermock.api.mockito.PowerMockito.doThrow;
23 | import static org.powermock.api.mockito.PowerMockito.mockStatic;
24 |
25 | import java.io.UnsupportedEncodingException;
26 | import java.net.URLEncoder;
27 | import java.nio.charset.StandardCharsets;
28 |
29 | import org.junit.Test;
30 | import org.powermock.core.classloader.annotations.PrepareForTest;
31 |
32 | /**
33 | * @since 1.0
34 | */
35 | @PrepareForTest(QueryStringBuilder.class)
36 | public class TestQueryStringBuilder extends OneDriveTestCase {
37 |
38 | @Test
39 | public void testWithParameters() {
40 | String queryString = new QueryStringBuilder().set("param1", "value1")
41 | .set("param2", true)
42 | .set("param3", 10L)
43 | .set("param4", 20)
44 | .set("param1", "value2")
45 | .toString();
46 | assertEquals("?param3=10¶m4=20¶m1=value2¶m2=true", queryString);
47 | }
48 |
49 | @Test
50 | public void testWithoutParameters() {
51 | String queryString = new QueryStringBuilder().toString();
52 | assertEquals("", queryString);
53 | }
54 |
55 | @Test(expected = OneDriveRuntimeException.class)
56 | public void testURLEncoderError() throws Exception {
57 | mockStatic(URLEncoder.class);
58 | doThrow(new UnsupportedEncodingException()).when(URLEncoder.class);
59 | URLEncoder.encode("error", StandardCharsets.UTF_8.name());
60 | new QueryStringBuilder().set("param1", "test").set("param2", "error").toString();
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/src/test/java/org/nuxeo/onedrive/client/TestURLTemplate.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * Kevin Leturc
18 | */
19 | package org.nuxeo.onedrive.client;
20 |
21 | import static org.junit.Assert.assertEquals;
22 |
23 | import org.junit.Test;
24 |
25 | /**
26 | * @since 1.0
27 | */
28 | public class TestURLTemplate extends OneDriveTestCase {
29 |
30 | @Test
31 | public void testBuild() {
32 | URLTemplate template = new URLTemplate("/drive/%s");
33 | assertEquals("https://api.onedrive.com/v1.0/drive/root", template.build(api.getBaseURL(), "root").toString());
34 | }
35 |
36 | @Test(expected = OneDriveRuntimeException.class)
37 | public void testBuildWithError() {
38 | URLTemplate template = new URLTemplate("/drive/%s");
39 | assertEquals("https://api.onedrive.com/v1.0/drive/root", template.build("", "root").toString());
40 | }
41 |
42 | @Test
43 | public void testBuildWithQueryString() {
44 | URLTemplate template = new URLTemplate("/drive/%s");
45 | QueryStringBuilder queryString = new QueryStringBuilder().set("top", 100);
46 | assertEquals("https://api.onedrive.com/v1.0/drive/root?top=100",
47 | template.build(api.getBaseURL(), queryString, "root").toString());
48 | }
49 |
50 | @Test(expected = OneDriveRuntimeException.class)
51 | public void testBuildWithQueryStringAndError() {
52 | URLTemplate template = new URLTemplate("/drive/%s");
53 | QueryStringBuilder queryString = new QueryStringBuilder().set("top", 100);
54 | assertEquals("https://api.onedrive.com/v1.0/drive/root?top=100", template.build("", queryString, "root")
55 | .toString());
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/src/test/resources/org/nuxeo/onedrive/client/onedrive_business_email.json:
--------------------------------------------------------------------------------
1 | {
2 | "odata.metadata": "https://nuxeofr-my.sharepoint.com/_api/$metadata#SP.ApiData.PersonPropertiess/@Element",
3 | "odata.type": "SP.UserProfiles.PersonProperties",
4 | "odata.id": "https://nuxeofr-my.sharepoint.com/_api/SP.UserProfiles.PeopleManager/GetMyProperties",
5 | "odata.editLink": "SP.UserProfiles.PeopleManager/GetMyProperties",
6 | "AccountName": "i:0#.f|membership|nuxeo@nuxeofr.onmicrosoft.com",
7 | "DirectReports": [],
8 | "DisplayName": "Kevin Leturc",
9 | "Email": null,
10 | "ExtendedManagers": [],
11 | "ExtendedReports": ["i:0#.f|membership|nuxeo@nuxeofr.onmicrosoft.com"],
12 | "IsFollowed": false,
13 | "LatestPost": null,
14 | "Peers": [],
15 | "PersonalUrl": "https://nuxeofr-my.sharepoint.com/personal/nuxeo_nuxeofr_onmicrosoft_com/",
16 | "PictureUrl": null,
17 | "Title": null,
18 | "UserProfileProperties": [{
19 | "Key": "UserProfile_GUID",
20 | "Value": null,
21 | "ValueType": "Edm.String"
22 | }, {
23 | "Key": "SID",
24 | "Value": null,
25 | "ValueType": "Edm.String"
26 | }, {
27 | "Key": "ADGuid",
28 | "Value": "System.Byte[]",
29 | "ValueType": "Edm.String"
30 | }, {
31 | "Key": "AccountName",
32 | "Value": "i:0#.f|membership|nuxeo@nuxeofr.onmicrosoft.com",
33 | "ValueType": "Edm.String"
34 | }, {
35 | "Key": "FirstName",
36 | "Value": "FirstName",
37 | "ValueType": "Edm.String"
38 | }, {
39 | "Key": "SPS-PhoneticFirstName",
40 | "Value": "",
41 | "ValueType": "Edm.String"
42 | }, {
43 | "Key": "LastName",
44 | "Value": "LastName",
45 | "ValueType": "Edm.String"
46 | }, {
47 | "Key": "SPS-PhoneticLastName",
48 | "Value": "",
49 | "ValueType": "Edm.String"
50 | }, {
51 | "Key": "PreferredName",
52 | "Value": "PreferredName",
53 | "ValueType": "Edm.String"
54 | }, {
55 | "Key": "SPS-PhoneticDisplayName",
56 | "Value": "",
57 | "ValueType": "Edm.String"
58 | }, {
59 | "Key": "WorkPhone",
60 | "Value": "",
61 | "ValueType": "Edm.String"
62 | }, {
63 | "Key": "Department",
64 | "Value": "",
65 | "ValueType": "Edm.String"
66 | }, {
67 | "Key": "Title",
68 | "Value": "",
69 | "ValueType": "Edm.String"
70 | }, {
71 | "Key": "SPS-Department",
72 | "Value": "",
73 | "ValueType": "Edm.String"
74 | }, {
75 | "Key": "Manager",
76 | "Value": "",
77 | "ValueType": "Edm.String"
78 | }, {
79 | "Key": "AboutMe",
80 | "Value": "",
81 | "ValueType": "Edm.String"
82 | }, {
83 | "Key": "PersonalSpace",
84 | "Value": "/personal/nuxeo_nuxeofr_onmicrosoft_com/",
85 | "ValueType": "Edm.String"
86 | }, {
87 | "Key": "PictureURL",
88 | "Value": "",
89 | "ValueType": "Edm.String"
90 | }, {
91 | "Key": "UserName",
92 | "Value": "nuxeo@nuxeofr.onmicrosoft.com",
93 | "ValueType": "Edm.String"
94 | }, {
95 | "Key": "QuickLinks",
96 | "Value": "",
97 | "ValueType": "Edm.String"
98 | }, {
99 | "Key": "WebSite",
100 | "Value": "",
101 | "ValueType": "Edm.String"
102 | }, {
103 | "Key": "PublicSiteRedirect",
104 | "Value": "",
105 | "ValueType": "Edm.String"
106 | }, {
107 | "Key": "SPS-JobTitle",
108 | "Value": "",
109 | "ValueType": "Edm.String"
110 | }, {
111 | "Key": "SPS-DataSource",
112 | "Value": "",
113 | "ValueType": "Edm.String"
114 | }, {
115 | "Key": "SPS-MemberOf",
116 | "Value": "",
117 | "ValueType": "Edm.String"
118 | }, {
119 | "Key": "SPS-Dotted-line",
120 | "Value": "",
121 | "ValueType": "Edm.String"
122 | }, {
123 | "Key": "SPS-Peers",
124 | "Value": "",
125 | "ValueType": "Edm.String"
126 | }, {
127 | "Key": "SPS-Responsibility",
128 | "Value": "",
129 | "ValueType": "Edm.String"
130 | }, {
131 | "Key": "SPS-SipAddress",
132 | "Value": "",
133 | "ValueType": "Edm.String"
134 | }, {
135 | "Key": "SPS-MySiteUpgrade",
136 | "Value": "",
137 | "ValueType": "Edm.String"
138 | }, {
139 | "Key": "SPS-DontSuggestList",
140 | "Value": "",
141 | "ValueType": "Edm.String"
142 | }, {
143 | "Key": "SPS-ProxyAddresses",
144 | "Value": "",
145 | "ValueType": "Edm.String"
146 | }, {
147 | "Key": "SPS-HireDate",
148 | "Value": "",
149 | "ValueType": "Edm.String"
150 | }, {
151 | "Key": "SPS-DisplayOrder",
152 | "Value": "",
153 | "ValueType": "Edm.String"
154 | }, {
155 | "Key": "SPS-ClaimID",
156 | "Value": "nuxeo@nuxeofr.onmicrosoft.com",
157 | "ValueType": "Edm.String"
158 | }, {
159 | "Key": "SPS-ClaimProviderID",
160 | "Value": "membership",
161 | "ValueType": "Edm.String"
162 | }, {
163 | "Key": "SPS-LastColleagueAdded",
164 | "Value": "",
165 | "ValueType": "Edm.String"
166 | }, {
167 | "Key": "SPS-OWAUrl",
168 | "Value": "",
169 | "ValueType": "Edm.String"
170 | }, {
171 | "Key": "SPS-ResourceSID",
172 | "Value": "",
173 | "ValueType": "Edm.String"
174 | }, {
175 | "Key": "SPS-ResourceAccountName",
176 | "Value": "",
177 | "ValueType": "Edm.String"
178 | }, {
179 | "Key": "SPS-MasterAccountName",
180 | "Value": "",
181 | "ValueType": "Edm.String"
182 | }, {
183 | "Key": "SPS-UserPrincipalName",
184 | "Value": "nuxeo@nuxeofr.onmicrosoft.com",
185 | "ValueType": "Edm.String"
186 | }, {
187 | "Key": "SPS-O15FirstRunExperience",
188 | "Value": "O15FirstRunExperience",
189 | "ValueType": "Edm.String"
190 | }, {
191 | "Key": "SPS-PersonalSiteInstantiationState",
192 | "Value": "2",
193 | "ValueType": "Edm.String"
194 | }, {
195 | "Key": "SPS-DistinguishedName",
196 | "Value": "",
197 | "ValueType": "Edm.String"
198 | }, {
199 | "Key": "SPS-SourceObjectDN",
200 | "Value": "",
201 | "ValueType": "Edm.String"
202 | }, {
203 | "Key": "SPS-LastKeywordAdded",
204 | "Value": "",
205 | "ValueType": "Edm.String"
206 | }, {
207 | "Key": "SPS-ClaimProviderType",
208 | "Value": "Forms",
209 | "ValueType": "Edm.String"
210 | }, {
211 | "Key": "SPS-SavedAccountName",
212 | "Value": "i:0#.f|membership|nuxeo@nuxeofr.onmicrosoft.com",
213 | "ValueType": "Edm.String"
214 | }, {
215 | "Key": "SPS-SavedSID",
216 | "Value": "System.Byte[]",
217 | "ValueType": "Edm.String"
218 | }, {
219 | "Key": "SPS-ObjectExists",
220 | "Value": "",
221 | "ValueType": "Edm.String"
222 | }, {
223 | "Key": "SPS-PersonalSiteCapabilities",
224 | "Value": "4",
225 | "ValueType": "Edm.String"
226 | }, {
227 | "Key": "SPS-PersonalSiteFirstCreationTime",
228 | "Value": "01/01/1970 00:00:00",
229 | "ValueType": "Edm.String"
230 | }, {
231 | "Key": "SPS-PersonalSiteLastCreationTime",
232 | "Value": "01/01/1970 00:00:00",
233 | "ValueType": "Edm.String"
234 | }, {
235 | "Key": "SPS-PersonalSiteNumberOfRetries",
236 | "Value": "1",
237 | "ValueType": "Edm.String"
238 | }, {
239 | "Key": "SPS-PersonalSiteFirstCreationError",
240 | "Value": "",
241 | "ValueType": "Edm.String"
242 | }, {
243 | "Key": "SPS-FeedIdentifier",
244 | "Value": "",
245 | "ValueType": "Edm.String"
246 | }, {
247 | "Key": "WorkEmail",
248 | "Value": "",
249 | "ValueType": "Edm.String"
250 | }, {
251 | "Key": "CellPhone",
252 | "Value": "",
253 | "ValueType": "Edm.String"
254 | }, {
255 | "Key": "Fax",
256 | "Value": "",
257 | "ValueType": "Edm.String"
258 | }, {
259 | "Key": "HomePhone",
260 | "Value": "",
261 | "ValueType": "Edm.String"
262 | }, {
263 | "Key": "Office",
264 | "Value": "",
265 | "ValueType": "Edm.String"
266 | }, {
267 | "Key": "SPS-Location",
268 | "Value": "",
269 | "ValueType": "Edm.String"
270 | }, {
271 | "Key": "Assistant",
272 | "Value": "",
273 | "ValueType": "Edm.String"
274 | }, {
275 | "Key": "SPS-PastProjects",
276 | "Value": "",
277 | "ValueType": "Edm.String"
278 | }, {
279 | "Key": "SPS-Skills",
280 | "Value": "",
281 | "ValueType": "Edm.String"
282 | }, {
283 | "Key": "SPS-School",
284 | "Value": "",
285 | "ValueType": "Edm.String"
286 | }, {
287 | "Key": "SPS-Birthday",
288 | "Value": "",
289 | "ValueType": "Edm.String"
290 | }, {
291 | "Key": "SPS-StatusNotes",
292 | "Value": "",
293 | "ValueType": "Edm.String"
294 | }, {
295 | "Key": "SPS-Interests",
296 | "Value": "",
297 | "ValueType": "Edm.String"
298 | }, {
299 | "Key": "SPS-HashTags",
300 | "Value": "",
301 | "ValueType": "Edm.String"
302 | }, {
303 | "Key": "SPS-EmailOptin",
304 | "Value": "",
305 | "ValueType": "Edm.String"
306 | }, {
307 | "Key": "SPS-PrivacyPeople",
308 | "Value": "True",
309 | "ValueType": "Edm.String"
310 | }, {
311 | "Key": "SPS-PrivacyActivity",
312 | "Value": "",
313 | "ValueType": "Edm.String"
314 | }, {
315 | "Key": "SPS-PictureTimestamp",
316 | "Value": "",
317 | "ValueType": "Edm.String"
318 | }, {
319 | "Key": "SPS-PicturePlaceholderState",
320 | "Value": "",
321 | "ValueType": "Edm.String"
322 | }, {
323 | "Key": "SPS-PictureExchangeSyncState",
324 | "Value": "",
325 | "ValueType": "Edm.String"
326 | }, {
327 | "Key": "SPS-MUILanguages",
328 | "Value": "en-US",
329 | "ValueType": "Edm.String"
330 | }, {
331 | "Key": "SPS-ContentLanguages",
332 | "Value": "",
333 | "ValueType": "Edm.String"
334 | }, {
335 | "Key": "SPS-TimeZone",
336 | "Value": "",
337 | "ValueType": "Edm.String"
338 | }, {
339 | "Key": "SPS-RegionalSettings-FollowWeb",
340 | "Value": "",
341 | "ValueType": "Edm.String"
342 | }, {
343 | "Key": "SPS-Locale",
344 | "Value": "",
345 | "ValueType": "Edm.String"
346 | }, {
347 | "Key": "SPS-CalendarType",
348 | "Value": "",
349 | "ValueType": "Edm.String"
350 | }, {
351 | "Key": "SPS-AltCalendarType",
352 | "Value": "",
353 | "ValueType": "Edm.String"
354 | }, {
355 | "Key": "SPS-AdjustHijriDays",
356 | "Value": "",
357 | "ValueType": "Edm.String"
358 | }, {
359 | "Key": "SPS-ShowWeeks",
360 | "Value": "",
361 | "ValueType": "Edm.String"
362 | }, {
363 | "Key": "SPS-WorkDays",
364 | "Value": "",
365 | "ValueType": "Edm.String"
366 | }, {
367 | "Key": "SPS-WorkDayStartHour",
368 | "Value": "",
369 | "ValueType": "Edm.String"
370 | }, {
371 | "Key": "SPS-WorkDayEndHour",
372 | "Value": "",
373 | "ValueType": "Edm.String"
374 | }, {
375 | "Key": "SPS-Time24",
376 | "Value": "",
377 | "ValueType": "Edm.String"
378 | }, {
379 | "Key": "SPS-FirstDayOfWeek",
380 | "Value": "",
381 | "ValueType": "Edm.String"
382 | }, {
383 | "Key": "SPS-FirstWeekOfYear",
384 | "Value": "",
385 | "ValueType": "Edm.String"
386 | }, {
387 | "Key": "SPS-RegionalSettings-Initialized",
388 | "Value": "True",
389 | "ValueType": "Edm.String"
390 | }, {
391 | "Key": "OfficeGraphEnabled",
392 | "Value": "",
393 | "ValueType": "Edm.String"
394 | }, {
395 | "Key": "SPS-UserType",
396 | "Value": "0",
397 | "ValueType": "Edm.String"
398 | }, {
399 | "Key": "SPS-HideFromAddressLists",
400 | "Value": "",
401 | "ValueType": "Edm.String"
402 | }, {
403 | "Key": "SPS-RecipientTypeDetails",
404 | "Value": "",
405 | "ValueType": "Edm.String"
406 | }, {
407 | "Key": "DelveFlags",
408 | "Value": "",
409 | "ValueType": "Edm.String"
410 | }, {
411 | "Key": "PulseMRUPeople",
412 | "Value": "",
413 | "ValueType": "Edm.String"
414 | }, {
415 | "Key": "msOnline-ObjectId",
416 | "Value": "28ba6c81-06ee-45e9-9396-279f7eba27a0",
417 | "ValueType": "Edm.String"
418 | }, {
419 | "Key": "SPS-PointPublishingUrl",
420 | "Value": "",
421 | "ValueType": "Edm.String"
422 | }, {
423 | "Key": "SPS-TenantInstanceId",
424 | "Value": "",
425 | "ValueType": "Edm.String"
426 | }],
427 | "UserUrl": "https://nuxeofr-my.sharepoint.com:443/PersonImmersive.aspx?accountname=i%3A0%23%2Ef%7Cmembership%7Cnuxeo%40nuxeofr%2Eonmicrosoft%2Ecom"
428 | }
429 |
--------------------------------------------------------------------------------
/src/test/resources/org/nuxeo/onedrive/client/onedrive_children_page_1.json:
--------------------------------------------------------------------------------
1 | {
2 | "@odata.context": "https://nuxeofr-my.sharepoint.com/_api/v2.0/$metadata#items",
3 | "@odata.nextLink": "https://nuxeofr-my.sharepoint.com/_api/v2.0?p=2",
4 | "value": [
5 | {
6 | "@odata.type": "#oneDrive.item",
7 | "@odata.id": "https://nuxeofr-my.sharepoint.com/_api/v2.0/drive/items/01YOWJ6CQSJ5S3PYEERFBLEDREVCLCBNPU",
8 | "@odata.etag": "\"{B7654F12-84E0-4289-B20E-24A89620B5F4},1\"",
9 | "@odata.editLink": "drive/items/01YOWJ6CQSJ5S3PYEERFBLEDREVCLCBNPU",
10 | "createdBy": {
11 | "user": {
12 | "id": "1234abcd-12ab-12ab-12ab-1234abcd",
13 | "displayName": "Nuxeo User"
14 | }
15 | },
16 | "createdDateTime": "2016-01-26T08:47:50Z",
17 | "eTag": "\"{B7654F12-84E0-4289-B20E-24A89620B5F4},1\"",
18 | "folder": {
19 | "childCount": 3
20 | },
21 | "id": "01YOWJ6CQSJ5S3PYEERFBLEDREVCLCBNPU",
22 | "lastModifiedBy": {
23 | "user": {
24 | "id": "1234abcd-12ab-12ab-12ab-1234abcd",
25 | "displayName": "Nuxeo User"
26 | }
27 | },
28 | "lastModifiedDateTime": "2016-01-26T10:43:01Z",
29 | "name": "Test",
30 | "parentReference": {
31 | "driveId": "b!X-6e_1234abcd_1234abcd-1234abcd",
32 | "id": "4K4Q87486LMKRP9X82Y2YJ2N2NFVD2F596",
33 | "path": "/drive/root:"
34 | },
35 | "size": 0,
36 | "webUrl": "https://nuxeofr-my.sharepoint.com/personal/kleturc_nuxeofr_onmicrosoft_com/Documents/Test"
37 | },
38 | {
39 | "@odata.type": "#oneDrive.item",
40 | "@odata.id": "https://nuxeofr-my.sharepoint.com/_api/v2.0/drive/items/01YOWJ6CT42I3ABB3ZFBGJ2E5ZRUGXXVJ4",
41 | "@odata.etag": "\"{0036D27C-7987-4C28-9D13-B98D0D7BD53C},1\"",
42 | "@odata.editLink": "drive/items/01YOWJ6CT42I3ABB3ZFBGJ2E5ZRUGXXVJ4",
43 | "@content.downloadUrl": "https://nuxeofr-my.sharepoint.com/personal/kleturc_nuxeofr_onmicrosoft_com/_layouts/15/download.aspx?guestaccesstoken=kXObvb6dE8CEruTh%2fNcrbizoeQMEmpmYs%2fOTmT5XacE%3d&docid=00036d27c79874c289d13b98d0d7bd53c&expiration=26%2f01%2f2016+14%3a34%3a17&userid=3&authurl=True&NeverAuth=True",
44 | "createdBy": {
45 | "user": {
46 | "id": "1234abcd-12ab-12ab-12ab-1234abcd",
47 | "displayName": "Nuxeo User"
48 | }
49 | },
50 | "createdDateTime": "2016-01-26T09:03:41Z",
51 | "cTag": "\"c:{0036D27C-7987-4C28-9D13-B98D0D7BD53C},1\"",
52 | "eTag": "\"{0036D27C-7987-4C28-9D13-B98D0D7BD53C},1\"",
53 | "file": {},
54 | "id": "01YOWJ6CT42I3ABB3ZFBGJ2E5ZRUGXXVJ4",
55 | "image": {},
56 | "lastModifiedBy": {
57 | "user": {
58 | "id": "1234abcd-12ab-12ab-12ab-1234abcd",
59 | "displayName": "Nuxeo User"
60 | }
61 | },
62 | "lastModifiedDateTime": "2016-01-26T09:03:41Z",
63 | "name": "dummy-480x270-Mosque (1).jpg",
64 | "parentReference": {
65 | "driveId": "b!X-6e_1234abcd_1234abcd-1234abcd",
66 | "id": "4K4Q87486LMKRP9X82Y2YJ2N2NFVD2F596",
67 | "path": "/drive/root:"
68 | },
69 | "size": 90081,
70 | "webUrl": "https://nuxeofr-my.sharepoint.com/personal/kleturc_nuxeofr_onmicrosoft_com/Documents/dummy-480x270-Mosque%20(1).jpg"
71 | }
72 | ]
73 | }
74 |
--------------------------------------------------------------------------------
/src/test/resources/org/nuxeo/onedrive/client/onedrive_children_page_2.json:
--------------------------------------------------------------------------------
1 | {
2 | "@odata.context": "https://nuxeofr-my.sharepoint.com/_api/v2.0/$metadata#items",
3 | "value": [
4 | {
5 | "@odata.type": "#oneDrive.item",
6 | "@odata.id": "https://nuxeofr-my.sharepoint.com/_api/v2.0/drive/items/01YOWJ6CSJ32VK4TN5PRCIR3Y2KDWQA4ZZ",
7 | "@odata.etag": "\"{AEAADE49-BD4D-447C-88EF-1A50ED007339},1\"",
8 | "@odata.editLink": "drive/items/01YOWJ6CSJ32VK4TN5PRCIR3Y2KDWQA4ZZ",
9 | "@content.downloadUrl": "https://nuxeofr-my.sharepoint.com/personal/kleturc_nuxeofr_onmicrosoft_com/_layouts/15/download.aspx?guestaccesstoken=DWUjDcMKWiqh0ibgoQ6le409kEpaj0dhYtGdclpL4oY%3d&docid=0aeaade49bd4d447c88ef1a50ed007339&expiration=26%2f01%2f2016+14%3a34%3a17&userid=3&authurl=True&NeverAuth=True",
10 | "createdBy": {
11 | "user": {
12 | "id": "1234abcd-12ab-12ab-12ab-1234abcd",
13 | "displayName": "Nuxeo User"
14 | }
15 | },
16 | "createdDateTime": "2016-01-26T09:03:41Z",
17 | "cTag": "\"c:{AEAADE49-BD4D-447C-88EF-1A50ED007339},1\"",
18 | "eTag": "\"{AEAADE49-BD4D-447C-88EF-1A50ED007339},1\"",
19 | "file": {},
20 | "id": "01YOWJ6CSJ32VK4TN5PRCIR3Y2KDWQA4ZZ",
21 | "image": {},
22 | "lastModifiedBy": {
23 | "user": {
24 | "id": "1234abcd-12ab-12ab-12ab-1234abcd",
25 | "displayName": "Nuxeo User"
26 | }
27 | },
28 | "lastModifiedDateTime": "2016-01-26T09:03:41Z",
29 | "name": "dummy-480x270-Mosque (2).jpg",
30 | "parentReference": {
31 | "driveId": "b!X-6e_1234abcd_1234abcd-1234abcd",
32 | "id": "4K4Q87486LMKRP9X82Y2YJ2N2NFVD2F596",
33 | "path": "/drive/root:"
34 | },
35 | "size": 90081,
36 | "webUrl": "https://nuxeofr-my.sharepoint.com/personal/kleturc_nuxeofr_onmicrosoft_com/Documents/dummy-480x270-Mosque%20(2).jpg"
37 | },
38 | {
39 | "@odata.type": "#oneDrive.item",
40 | "@odata.id": "https://nuxeofr-my.sharepoint.com/_api/v2.0/drive/items/01YOWJ6CRVBPTPEKUL6JFIGM7D6V3UZN2N",
41 | "@odata.etag": "\"{F2E60B35-8B2A-4AF2-8333-E3F5774CB74D},1\"",
42 | "@odata.editLink": "drive/items/01YOWJ6CRVBPTPEKUL6JFIGM7D6V3UZN2N",
43 | "@content.downloadUrl": "https://nuxeofr-my.sharepoint.com/personal/kleturc_nuxeofr_onmicrosoft_com/_layouts/15/download.aspx?guestaccesstoken=BNyleHdyIKd3jSWRpnidOjYKd6Yr0oH7htP2vxJy2BU%3d&docid=0f2e60b358b2a4af28333e3f5774cb74d&expiration=26%2f01%2f2016+14%3a34%3a17&userid=3&authurl=True&NeverAuth=True",
44 | "createdBy": {
45 | "user": {
46 | "id": "1234abcd-12ab-12ab-12ab-1234abcd",
47 | "displayName": "Nuxeo User"
48 | }
49 | },
50 | "createdDateTime": "2016-01-26T09:03:41Z",
51 | "cTag": "\"c:{F2E60B35-8B2A-4AF2-8333-E3F5774CB74D},1\"",
52 | "eTag": "\"{F2E60B35-8B2A-4AF2-8333-E3F5774CB74D},1\"",
53 | "file": {},
54 | "id": "01YOWJ6CRVBPTPEKUL6JFIGM7D6V3UZN2N",
55 | "image": {},
56 | "lastModifiedBy": {
57 | "user": {
58 | "id": "1234abcd-12ab-12ab-12ab-1234abcd",
59 | "displayName": "Nuxeo User"
60 | }
61 | },
62 | "lastModifiedDateTime": "2016-01-26T09:03:41Z",
63 | "name": "dummy-480x270-Mosque.jpg",
64 | "parentReference": {
65 | "driveId": "b!X-6e_1234abcd_1234abcd-1234abcd",
66 | "id": "4K4Q87486LMKRP9X82Y2YJ2N2NFVD2F596",
67 | "path": "/drive/root:"
68 | },
69 | "size": 90081,
70 | "webUrl": "https://nuxeofr-my.sharepoint.com/personal/kleturc_nuxeofr_onmicrosoft_com/Documents/dummy-480x270-Mosque.jpg"
71 | }
72 | ]
73 | }
74 |
--------------------------------------------------------------------------------
/src/test/resources/org/nuxeo/onedrive/client/onedrive_file.json:
--------------------------------------------------------------------------------
1 | {
2 | "id": "string (identifier)",
3 | "name": "string",
4 | "eTag": "string (etag)",
5 | "cTag": "string (etag)",
6 | "createdBy": { "@odata.type": "oneDrive.identitySet" },
7 | "createdDateTime": "string (timestamp)",
8 | "lastModifiedBy": { "@odata.type": "oneDrive.identitySet" },
9 | "lastModifiedDateTime": "string (timestamp)",
10 | "size": 1024,
11 | "webUrl": "url",
12 | "description": "string",
13 | "parentReference": { "@odata.type": "oneDrive.itemReference"},
14 | "children": [ { "@odata.type": "oneDrive.item" } ],
15 | "file": { "@odata.type": "oneDrive.file" },
16 | "fileSystemInfo": {"@odata.type": "oneDrive.fileSystemInfo"},
17 | "image": { "@odata.type": "oneDrive.image" },
18 | "photo": { "@odata.type": "oneDrive.photo" },
19 | "audio": { "@odata.type": "oneDrive.audio" },
20 | "video": { "@odata.type": "oneDrive.video" },
21 | "location": { "@odata.type": "oneDrive.location" },
22 | "remoteItem": { "@odata.type": "oneDrive.remoteItem"},
23 | "searchResult": { "@odata.type": "oneDrive.searchResult"},
24 | "deleted": { "@odata.type": "oneDrive.deleted"},
25 | "specialFolder": { "@odata.type": "oneDrive.specialFolder" },
26 | "thumbnails": [ {"@odata.type": "oneDrive.thumbnailSet"} ],
27 | "shared": {"@odata.type": "oneDrive.shared" },
28 | "@name.conflictBehavior": "string",
29 | "@content.downloadUrl": "url",
30 | "@content.sourceUrl": "url"
31 | }
32 |
--------------------------------------------------------------------------------
/src/test/resources/org/nuxeo/onedrive/client/onedrive_folder.json:
--------------------------------------------------------------------------------
1 | {
2 | "@odata.type": "#oneDrive.item",
3 | "@odata.id": "https://nuxeofr-my.sharepoint.com/_api/v2.0/drive/items/01YOWJ6CQSJ5S3PYEERFBLEDREVCLCBNPU",
4 | "@odata.etag": "\"{B7654F12-84E0-4289-B20E-24A89620B5F4},1\"",
5 | "@odata.editLink": "drive/items/01YOWJ6CQSJ5S3PYEERFBLEDREVCLCBNPU",
6 | "createdBy": {
7 | "user": {
8 | "id": "1234abcd-12ab-12ab-12ab-1234abcd",
9 | "displayName": "Nuxeo User"
10 | }
11 | },
12 | "createdDateTime": "2016-01-26T08:47:50Z",
13 | "eTag": "\"{B7654F12-84E0-4289-B20E-24A89620B5F4},1\"",
14 | "folder": {
15 | "childCount": 3
16 | },
17 | "id": "5FGB3N6V49HN725573R8LG588VRDPMJV36",
18 | "lastModifiedBy": {
19 | "user": {
20 | "id": "1234abcd-12ab-12ab-12ab-1234abcd",
21 | "displayName": "Nuxeo User"
22 | }
23 | },
24 | "lastModifiedDateTime": "2016-01-26T10:43:01Z",
25 | "name": "Test",
26 | "parentReference": {
27 | "driveId": "b!X-6e_1234abcd_1234abcd-1234abcd",
28 | "id": "4K4Q87486LMKRP9X82Y2YJ2N2NFVD2F596",
29 | "path": "/drive/root:"
30 | },
31 | "size": 0,
32 | "webUrl": "https://nuxeofr-my.sharepoint.com/personal/kleturc_nuxeofr_onmicrosoft_com/Documents/Test"
33 | }
34 |
--------------------------------------------------------------------------------
/src/test/resources/org/nuxeo/onedrive/client/onedrive_folder_root_children.json:
--------------------------------------------------------------------------------
1 | {
2 | "@odata.context": "https://nuxeofr-my.sharepoint.com/_api/v2.0/$metadata#items",
3 | "value": [
4 | {
5 | "@odata.type": "#oneDrive.item",
6 | "@odata.id": "https://nuxeofr-my.sharepoint.com/_api/v2.0/drive/items/01YOWJ6CQSJ5S3PYEERFBLEDREVCLCBNPU",
7 | "@odata.etag": "\"{B7654F12-84E0-4289-B20E-24A89620B5F4},1\"",
8 | "@odata.editLink": "drive/items/01YOWJ6CQSJ5S3PYEERFBLEDREVCLCBNPU",
9 | "createdBy": {
10 | "user": {
11 | "id": "1234abcd-12ab-12ab-12ab-1234abcd",
12 | "displayName": "Nuxeo User"
13 | }
14 | },
15 | "createdDateTime": "2016-01-26T08:47:50Z",
16 | "eTag": "\"{B7654F12-84E0-4289-B20E-24A89620B5F4},1\"",
17 | "folder": {
18 | "childCount": 3
19 | },
20 | "id": "5FGB3N6V49HN725573R8LG588VRDPMJV36",
21 | "lastModifiedBy": {
22 | "user": {
23 | "id": "1234abcd-12ab-12ab-12ab-1234abcd",
24 | "displayName": "Nuxeo User"
25 | }
26 | },
27 | "lastModifiedDateTime": "2016-01-26T10:43:01Z",
28 | "name": "Test",
29 | "parentReference": {
30 | "driveId": "b!X-6e_1234abcd_1234abcd-1234abcd",
31 | "id": "01YOWJ6CV6Y2GOVW7725BZO354PWSELRRZ",
32 | "path": "/drive/root:"
33 | },
34 | "size": 0,
35 | "webUrl": "https://nuxeofr-my.sharepoint.com/personal/kleturc_nuxeofr_onmicrosoft_com/Documents/Test"
36 | },
37 | {
38 | "@odata.type": "#oneDrive.item",
39 | "@odata.id": "https://nuxeofr-my.sharepoint.com/_api/v2.0/drive/items/01YOWJ6CT42I3ABB3ZFBGJ2E5ZRUGXXVJ4",
40 | "@odata.etag": "\"{0036D27C-7987-4C28-9D13-B98D0D7BD53C},1\"",
41 | "@odata.editLink": "drive/items/01YOWJ6CT42I3ABB3ZFBGJ2E5ZRUGXXVJ4",
42 | "@content.downloadUrl": "https://nuxeofr-my.sharepoint.com/personal/kleturc_nuxeofr_onmicrosoft_com/_layouts/15/download.aspx?guestaccesstoken=kXObvb6dE8CEruTh%2fNcrbizoeQMEmpmYs%2fOTmT5XacE%3d&docid=00036d27c79874c289d13b98d0d7bd53c&expiration=26%2f01%2f2016+14%3a34%3a17&userid=3&authurl=True&NeverAuth=True",
43 | "createdBy": {
44 | "user": {
45 | "id": "1234abcd-12ab-12ab-12ab-1234abcd",
46 | "displayName": "Nuxeo User"
47 | }
48 | },
49 | "createdDateTime": "2016-01-26T09:03:41Z",
50 | "cTag": "\"c:{0036D27C-7987-4C28-9D13-B98D0D7BD53C},1\"",
51 | "eTag": "\"{0036D27C-7987-4C28-9D13-B98D0D7BD53C},1\"",
52 | "file": {},
53 | "id": "5FGB3N6V49HN725573R8LG588VRDPMJV36",
54 | "image": {},
55 | "lastModifiedBy": {
56 | "user": {
57 | "id": "1234abcd-12ab-12ab-12ab-1234abcd",
58 | "displayName": "Nuxeo User"
59 | }
60 | },
61 | "lastModifiedDateTime": "2016-01-26T09:03:41Z",
62 | "name": "dummy-480x270-Mosque (1).jpg",
63 | "parentReference": {
64 | "driveId": "b!X-6e_1234abcd_1234abcd-1234abcd",
65 | "id": "01YOWJ6CV6Y2GOVW7725BZO354PWSELRRZ",
66 | "path": "/drive/root:"
67 | },
68 | "size": 90081,
69 | "webUrl": "https://nuxeofr-my.sharepoint.com/personal/kleturc_nuxeofr_onmicrosoft_com/Documents/dummy-480x270-Mosque%20(1).jpg"
70 | },
71 | {
72 | "@odata.type": "#oneDrive.item",
73 | "@odata.id": "https://nuxeofr-my.sharepoint.com/_api/v2.0/drive/items/01YOWJ6CSJ32VK4TN5PRCIR3Y2KDWQA4ZZ",
74 | "@odata.etag": "\"{AEAADE49-BD4D-447C-88EF-1A50ED007339},1\"",
75 | "@odata.editLink": "drive/items/01YOWJ6CSJ32VK4TN5PRCIR3Y2KDWQA4ZZ",
76 | "@content.downloadUrl": "https://nuxeofr-my.sharepoint.com/personal/kleturc_nuxeofr_onmicrosoft_com/_layouts/15/download.aspx?guestaccesstoken=DWUjDcMKWiqh0ibgoQ6le409kEpaj0dhYtGdclpL4oY%3d&docid=0aeaade49bd4d447c88ef1a50ed007339&expiration=26%2f01%2f2016+14%3a34%3a17&userid=3&authurl=True&NeverAuth=True",
77 | "createdBy": {
78 | "user": {
79 | "id": "1234abcd-12ab-12ab-12ab-1234abcd",
80 | "displayName": "Nuxeo User"
81 | }
82 | },
83 | "createdDateTime": "2016-01-26T09:03:41Z",
84 | "cTag": "\"c:{AEAADE49-BD4D-447C-88EF-1A50ED007339},1\"",
85 | "eTag": "\"{AEAADE49-BD4D-447C-88EF-1A50ED007339},1\"",
86 | "file": {},
87 | "id": "5FGB3N6V49HN725573R8LG588VRDPMJV36",
88 | "image": {},
89 | "lastModifiedBy": {
90 | "user": {
91 | "id": "1234abcd-12ab-12ab-12ab-1234abcd",
92 | "displayName": "Nuxeo User"
93 | }
94 | },
95 | "lastModifiedDateTime": "2016-01-26T09:03:41Z",
96 | "name": "dummy-480x270-Mosque (2).jpg",
97 | "parentReference": {
98 | "driveId": "b!X-6e_1234abcd_1234abcd-1234abcd",
99 | "id": "01YOWJ6CV6Y2GOVW7725BZO354PWSELRRZ",
100 | "path": "/drive/root:"
101 | },
102 | "size": 90081,
103 | "webUrl": "https://nuxeofr-my.sharepoint.com/personal/kleturc_nuxeofr_onmicrosoft_com/Documents/dummy-480x270-Mosque%20(2).jpg"
104 | },
105 | {
106 | "@odata.type": "#oneDrive.item",
107 | "@odata.id": "https://nuxeofr-my.sharepoint.com/_api/v2.0/drive/items/01YOWJ6CRVBPTPEKUL6JFIGM7D6V3UZN2N",
108 | "@odata.etag": "\"{F2E60B35-8B2A-4AF2-8333-E3F5774CB74D},1\"",
109 | "@odata.editLink": "drive/items/01YOWJ6CRVBPTPEKUL6JFIGM7D6V3UZN2N",
110 | "@content.downloadUrl": "https://nuxeofr-my.sharepoint.com/personal/kleturc_nuxeofr_onmicrosoft_com/_layouts/15/download.aspx?guestaccesstoken=BNyleHdyIKd3jSWRpnidOjYKd6Yr0oH7htP2vxJy2BU%3d&docid=0f2e60b358b2a4af28333e3f5774cb74d&expiration=26%2f01%2f2016+14%3a34%3a17&userid=3&authurl=True&NeverAuth=True",
111 | "createdBy": {
112 | "user": {
113 | "id": "1234abcd-12ab-12ab-12ab-1234abcd",
114 | "displayName": "Nuxeo User"
115 | }
116 | },
117 | "createdDateTime": "2016-01-26T09:03:41Z",
118 | "cTag": "\"c:{F2E60B35-8B2A-4AF2-8333-E3F5774CB74D},1\"",
119 | "eTag": "\"{F2E60B35-8B2A-4AF2-8333-E3F5774CB74D},1\"",
120 | "file": {},
121 | "id": "5FGB3N6V49HN725573R8LG588VRDPMJV36",
122 | "image": {},
123 | "lastModifiedBy": {
124 | "user": {
125 | "id": "1234abcd-12ab-12ab-12ab-1234abcd",
126 | "displayName": "Nuxeo User"
127 | }
128 | },
129 | "lastModifiedDateTime": "2016-01-26T09:03:41Z",
130 | "name": "dummy-480x270-Mosque.jpg",
131 | "parentReference": {
132 | "driveId": "b!X-6e_1234abcd_1234abcd-1234abcd",
133 | "id": "01YOWJ6CV6Y2GOVW7725BZO354PWSELRRZ",
134 | "path": "/drive/root:"
135 | },
136 | "size": 90081,
137 | "webUrl": "https://nuxeofr-my.sharepoint.com/personal/kleturc_nuxeofr_onmicrosoft_com/Documents/dummy-480x270-Mosque.jpg"
138 | },
139 | {
140 | "@odata.type": "#oneDrive.item",
141 | "@odata.id": "https://nuxeofr-my.sharepoint.com/_api/v2.0/drive/items/01YOWJ6CV37GIRVKB3R5E3W2UWPO6U7RWG",
142 | "@odata.etag": "\"{1A91F9BB-3BA8-498F-BB6A-967BBD4FC6C6},1\"",
143 | "@odata.editLink": "drive/items/01YOWJ6CV37GIRVKB3R5E3W2UWPO6U7RWG",
144 | "@content.downloadUrl": "https://nuxeofr-my.sharepoint.com/personal/kleturc_nuxeofr_onmicrosoft_com/_layouts/15/download.aspx?guestaccesstoken=EM3jUIrTqC98p%2f4lYqdBjMm9BXSOaZjPbFqT%2fBgTa9A%3d&docid=01a91f9bb3ba8498fbb6a967bbd4fc6c6&expiration=26%2f01%2f2016+14%3a34%3a17&userid=3&authurl=True&NeverAuth=True",
145 | "createdBy": {
146 | "user": {
147 | "id": "1234abcd-12ab-12ab-12ab-1234abcd",
148 | "displayName": "Nuxeo User"
149 | }
150 | },
151 | "createdDateTime": "2016-01-25T16:31:18Z",
152 | "cTag": "\"c:{1A91F9BB-3BA8-498F-BB6A-967BBD4FC6C6},1\"",
153 | "eTag": "\"{1A91F9BB-3BA8-498F-BB6A-967BBD4FC6C6},1\"",
154 | "file": {},
155 | "id": "5FGB3N6V49HN725573R8LG588VRDPMJV36",
156 | "lastModifiedBy": {
157 | "user": {
158 | "id": "1234abcd-12ab-12ab-12ab-1234abcd",
159 | "displayName": "Nuxeo User"
160 | }
161 | },
162 | "lastModifiedDateTime": "2016-01-25T16:31:18Z",
163 | "name": "testFile.txt",
164 | "parentReference": {
165 | "driveId": "b!X-6e_1234abcd_1234abcd-1234abcd",
166 | "id": "01YOWJ6CV6Y2GOVW7725BZO354PWSELRRZ",
167 | "path": "/drive/root:"
168 | },
169 | "size": 15,
170 | "webUrl": "https://nuxeofr-my.sharepoint.com/personal/kleturc_nuxeofr_onmicrosoft_com/Documents/testFile.txt"
171 | }
172 | ]
173 | }
174 |
--------------------------------------------------------------------------------