Skip to content

Commit fc7b563

Browse files
Merge pull request #28 from microsoftgraph/dev
GA Release master sync
2 parents e811740 + 2a30957 commit fc7b563

19 files changed

+526
-76
lines changed

CONTRIBUTING.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Contributing to the Microsoft Graph Core SDK for Java
2+
3+
The Microsoft Graph Core SDK for Java is available for all manner of contribution. There are a couple of different recommended paths to get contributions into the released version of this SDK.
4+
5+
__NOTE__ A signed a contribution license agreement is required for all contributions, and is checked automatically on new pull requests. Please read and sign the agreement https://cla.microsoft.com/ before starting any work for this repository.
6+
7+
## File issues
8+
9+
The best way to get started with a contribution is to start a dialog with the owners of this repository. Sometimes features will be under development or out of scope for this SDK and it's best to check before starting work on contribution.
10+
11+
## Submit pull requests for trivial changes
12+
13+
If you are making a change that does not affect the interface components and does not affect other downstream callers, feel free to make a pull request against the __dev__ branch. The dev branch will be updated frequently.
14+
15+
Revisions of this nature will result in a 0.0.X change of the version number.
16+
17+
## Submit pull requests for features
18+
19+
If major functionality is being added, or there will need to be gestation time for a change, it should be submitted against the __feature__ branch.
20+
21+
Revisions of this nature will result in a 0.X.X change of the version number.
22+
23+
## Add yourself as a contributor
24+
25+
This project follows the [all contributors](https://github.com/kentcdodds/all-contributors) specification. When making a contribution, please add yourself to the table of contributors:
26+
27+
1. In section 5. of the [README.md](https://github.com/microsoftgraph/msgraph-sdk-java-core/blob/dev/readme.md), after the last "|", copy and paste a new blank contributor element
28+
```html
29+
[<img src="https://avatars.githubusercontent.com/u/<your-uid>?v=4" width="100px;"/><br />
30+
<sub><b>Your Name</b></sub>](your website or github page)<br />
31+
[emoji](link "alt-text") |
32+
```
33+
34+
You can get your GitHub UID by inspecting your GitHub avatar image.
35+
36+
2. For each contribution type (see [emoji key](https://github.com/kentcdodds/all-contributors#emoji-key) for a list of contribution types), add an emoji and a relevant link and alt-text.
37+
38+
For example, if you write a blogpost on how to use the SDK, you would include:
39+
40+
```html
41+
[??]("https://myblog.com/using-the-java-sdk" "Blog Post")

THIRD PARTY NOTICES

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
This file is based on or incorporates material from the projects listed below
2+
(Third Party IP). The original copyright notice and the license under which
3+
Microsoft received such Third Party IP, are set forth below. Such licenses and
4+
notices are provided for informational purposes only. Microsoft licenses the
5+
Third Party IP to you under the licensing terms for the Microsoft product.
6+
Microsoft reserves all other rights not expressly granted under this agreement,
7+
whether by implication, estoppel or otherwise.
8+
9+
Gson
10+
Copyright 2008-2011 Google Inc.
11+
12+
Provided for Informational Purposes Only
13+
14+
Apache 2.0 License
15+
16+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
17+
this file except in compliance with the License. You may obtain a copy of the
18+
License at http://www.apache.org/licenses/LICENSE-2.0
19+
20+
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
21+
ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
22+
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
23+
MERCHANTABLITY OR NON-INFRINGEMENT.
24+
25+
See the Apache Version 2.0 License for specific language governing permissions
26+
and limitations under the License.

gradle.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
## linux requires 10G, OSX requires 11G
2222
org.gradle.jvmargs=-XX:MaxPermSize=512m -Xmx2g
2323

24-
mavenRepoUrl = https://api.bintray.com/content/microsoftgraph/Maven/microsoft-graph
24+
mavenRepoUrl = https://api.bintray.com/content/microsoftgraph/Maven/microsoft-graph-core
2525
mavenBintraySnapshotUrl = http://oss.jfrog.org/artifactory/oss-snapshot-local
2626
mavenGroupId = com.microsoft.graph
2727
mavenArtifactId = microsoft-graph-core
28-
mavenMajorVersion = 0
29-
mavenMinorVersion = 1
28+
mavenMajorVersion = 1
29+
mavenMinorVersion = 0
3030
mavenPatchVersion = 0
3131
mavenArtifactSuffix =
3232
nightliesUrl = http://dl.bintray.com/MicrosoftGraph/Maven

gradle/wrapper/gradle-wrapper.jar

53.5 KB
Binary file not shown.

readme.md

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
# Microsoft Graph Core Preview SDK for Java
1+
# Microsoft Graph Core SDK for Java
22

3-
Get started with the Microsoft Graph Core SDK for Java by integrating the [Microsoft Graph API](https://graph.microsoft.io/en-us/getting-started) into your Java application!
3+
Get started with the Microsoft Graph Core SDK for Java by integrating the [Microsoft Graph API](https://graph.microsoft.io/en-us/getting-started) into your Java and Android application!
44

5-
## Important Note about the Microsoft Graph Core Java Preview
6-
During the preview we may make changes to the API, and other mechanisms of this library, which you will be required to take along with bug fixes or feature improvements. This may impact your application. An API change may require you to update your code. When we provide the General Availability release we will require you to update to the General Availability version within six months, as applications written using a preview version of library may no longer work.
5+
## Samples and usage guide
6+
[Middleware usage](https://github.com/microsoftgraph/msgraph-sdk-java-core/wiki)</br>
7+
[Batching](https://github.com/microsoftgraph/msgraph-sdk-java-core/wiki/Batching)
78

89
## 1. Installation
910

@@ -14,14 +15,11 @@ Add the repository and a compile dependency for `microsoft-graph-core` to your p
1415
```gradle
1516
repository {
1617
jcenter()
17-
jcenter{
18-
url 'http://oss.jfrog.org/artifactory/oss-snapshot-local'
19-
}
2018
}
2119
2220
dependency {
2321
// Include the sdk as a dependency
24-
compile('com.microsoft.graph:microsoft-graph-core:0.1.0-SNAPSHOT')
22+
compile('com.microsoft.graph:microsoft-graph-core:1.0.0')
2523
}
2624
```
2725

@@ -31,34 +29,10 @@ Add the dependency in `dependencies` in pom.xml
3129
<dependency>
3230
<groupId>com.microsoft.graph</groupId>
3331
<artifactId>microsoft-graph-core</artifactId>
34-
<version>0.1.0-SNAPSHOT</version>
32+
<version>1.0.0</version>
3533
</dependency>
3634
```
3735

38-
Add `profiles` in `project` to download Snapshot release binary:
39-
```
40-
<profiles>
41-
<profile>
42-
<id>allow-snapshots</id>
43-
<activation>
44-
<activeByDefault>true</activeByDefault>
45-
</activation>
46-
<repositories>
47-
<repository>
48-
<id>snapshots-repo</id>
49-
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
50-
<releases>
51-
<enabled>false</enabled>
52-
</releases>
53-
<snapshots>
54-
<enabled>true</enabled>
55-
</snapshots>
56-
</repository>
57-
</repositories>
58-
</profile>
59-
</profiles>
60-
```
61-
6236
### 1.3 Enable ProGuard (Android)
6337
The nature of the Graph API is such that the SDK needs quite a large set of classes to describe its functionality. You need to ensure that [ProGuard](https://developer.android.com/studio/build/shrink-code.html) is enabled on your project. Otherwise, you will incur long build times for functionality that is not necessarily relevant to your particular application. If you are still hitting the 64K method limit, you can also enable [multidexing](https://developer.android.com/studio/build/multidex.html).
6438

@@ -70,7 +44,11 @@ Register your application by following the steps at [Register your app with the
7044

7145
### 2.2 Create an IAuthenticationProvider object
7246

73-
An instance of the **HttpClients** class handles building client. To create a new instance of this class, you need to provide an instance of `ICoreAuthenticationProvider`, which can authenticate requests to Microsoft Graph.
47+
An instance of the **HttpClients** class handles building client. To create a new instance of this class, you need to provide an instance of `ICoreAuthenticationProvider`, which can authenticate requests to Microsoft Graph.
48+
### To get instance of HttpClients
49+
Auth in Java app [here](https://github.com/microsoftgraph/msgraph-sdk-java-auth)
50+
51+
Auth in Android app [here](https://github.com/microsoftgraph/msgraph-sdk-android-auth)
7452

7553
### 2.3 Get a HttpClients object
7654
You must get a **HttpClients** object to make requests against the service.

src/main/java/com/microsoft/graph/content/MSBatchRequestStep.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public class MSBatchRequestStep {
1212
public MSBatchRequestStep(String requestId, Request request, List<String> arrayOfDependsOnIds) {
1313
if(requestId == null)
1414
throw new IllegalArgumentException("Request Id cannot be null.");
15+
if(requestId.length() == 0)
16+
throw new IllegalArgumentException("Request Id cannot be empty.");
1517
if(request == null)
1618
new IllegalArgumentException("Request cannot be null.");
1719

src/main/java/com/microsoft/graph/content/MSBatchResponseContent.java

Lines changed: 63 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.IOException;
44
import java.util.HashMap;
5+
import java.util.Iterator;
56
import java.util.Map;
67

78
import org.json.simple.JSONArray;
@@ -18,33 +19,17 @@
1819

1920
public class MSBatchResponseContent {
2021

21-
private JSONObject batchResponseObj;
2222
private Response batchResponse;
2323
private Map<String, Request> batchRequestsHashMap;
2424
private JSONArray batchResponseArray;
25+
private String nextLink;
2526

2627
/*
2728
* @param batchResponse OkHttp batch response on execution of batch requests
2829
*/
2930
public MSBatchResponseContent(Response batchResponse) {
30-
if(batchResponse == null)
31-
throw new IllegalArgumentException("Batch Response cannot be null");
32-
33-
this.batchRequestsHashMap = createBatchRequestsHashMap(batchResponse);
3431
this.batchResponse = batchResponse;
35-
if(batchResponse.body() != null) {
36-
try {
37-
String batchResponseData = batchResponse.body().string();
38-
if(batchResponseData != null) {
39-
batchResponseObj = stringToJSONObject(batchResponseData);
40-
if(batchResponseObj != null) {
41-
batchResponseArray = (JSONArray)batchResponseObj.get("responses");
42-
}
43-
}
44-
} catch (IOException e) {
45-
e.printStackTrace();
46-
}
47-
}
32+
update(batchResponse);
4833
}
4934

5035
/*
@@ -54,12 +39,9 @@ public MSBatchResponseContent(Response batchResponse) {
5439
* @return OkHttp Response corresponding to requestId
5540
*/
5641
public Response getResponseById(String requestId) {
57-
if(batchResponseObj == null)
58-
return null;
42+
if(batchResponseArray == null) return null;
5943

60-
JSONArray responses = (JSONArray)batchResponseObj.get("responses");
61-
if(responses == null)
62-
return null;
44+
JSONArray responses = batchResponseArray;
6345

6446
for(Object response : responses) {
6547
JSONObject jsonresponse = (JSONObject)response;
@@ -104,20 +86,71 @@ public Response getResponseById(String requestId) {
10486
return null;
10587
}
10688

107-
/*
108-
* @return responses as a string
89+
/**
90+
* Get map of id and responses
91+
*
92+
* @return responses in Map of id and response
10993
*/
110-
public String getResponses() {
111-
return batchResponseArray != null ? batchResponseArray.toJSONString() : null;
94+
public Map<String, Response> getResponses() {
95+
if(batchResponseArray == null)
96+
return null;
97+
Map<String, Response> responsesMap = new HashMap<>();
98+
for(String id : batchRequestsHashMap.keySet()) {
99+
responsesMap.put(id, getResponseById(id));
100+
}
101+
return responsesMap;
102+
}
103+
104+
/**
105+
* Get iterator over the responses
106+
*
107+
* @return iterator for responses
108+
*/
109+
public Iterator<Map.Entry<String, Response>> getResponsesIterator() {
110+
Map<String, Response> responsesMap = getResponses();
111+
return responsesMap != null ? responsesMap.entrySet().iterator() : null;
112+
}
113+
114+
public void update(Response batchResponse) {
115+
if(batchResponse == null)
116+
throw new IllegalArgumentException("Batch Response cannot be null");
117+
118+
Map<String, Request> requestMap = createBatchRequestsHashMap(batchResponse);
119+
if(batchRequestsHashMap == null)
120+
batchRequestsHashMap = new HashMap<>();
121+
if(requestMap != null)
122+
batchRequestsHashMap.putAll(requestMap);
123+
124+
if(batchResponse.body() != null) {
125+
try {
126+
String batchResponseData = batchResponse.body().string();
127+
if(batchResponseData != null) {
128+
JSONObject batchResponseObj = stringToJSONObject(batchResponseData);
129+
if(batchResponseObj != null) {
130+
131+
JSONObject nextLinkObject = (JSONObject) batchResponseObj.get("@odata.nextLink");
132+
if(nextLinkObject!=null)
133+
nextLink = nextLinkObject.toString();
134+
135+
if(batchResponseArray == null)
136+
batchResponseArray = new JSONArray();
137+
138+
JSONArray responseArray = (JSONArray)batchResponseObj.get("responses");
139+
if(responseArray!=null)
140+
batchResponseArray.addAll(responseArray);
141+
}
142+
}
143+
} catch (IOException e) {
144+
e.printStackTrace();
145+
}
146+
}
112147
}
113148

114149
/*
115150
* @return nextLink of batch response
116151
*/
117152
public String nextLink() {
118-
if(batchResponseObj == null) return null;
119-
Object nextLinkObject = batchResponseObj.get("nextLink");
120-
return nextLinkObject != null ? ((JSONObject)nextLinkObject).toString() : null;
153+
return nextLink;
121154
}
122155

123156
private Map<String, Request> createBatchRequestsHashMap(Response batchResponse) {

src/main/java/com/microsoft/graph/httpcore/AuthenticationHandler.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.IOException;
44

55
import com.microsoft.graph.httpcore.middlewareoption.MiddlewareType;
6+
import com.microsoft.graph.httpcore.middlewareoption.TelemetryOptions;
67

78
import okhttp3.Interceptor;
89
import okhttp3.Request;
@@ -21,6 +22,11 @@ public AuthenticationHandler(ICoreAuthenticationProvider authProvider) {
2122
@Override
2223
public Response intercept(Chain chain) throws IOException {
2324
Request originalRequest = chain.request();
25+
26+
if(originalRequest.tag(TelemetryOptions.class) == null)
27+
originalRequest = originalRequest.newBuilder().tag(TelemetryOptions.class, new TelemetryOptions()).build();
28+
originalRequest.tag(TelemetryOptions.class).setFeatureUsage(TelemetryOptions.AUTH_HANDLER_ENABLED_FLAG);
29+
2430
Request authenticatedRequest = authProvider.authenticateRequest(originalRequest);
2531
return chain.proceed(authenticatedRequest);
2632
}

src/main/java/com/microsoft/graph/httpcore/HttpClients.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.microsoft.graph.httpcore;
22

3+
import okhttp3.Interceptor;
34
import okhttp3.OkHttpClient;
45
import okhttp3.OkHttpClient.Builder;
56

@@ -15,7 +16,7 @@ private HttpClients() {
1516
* @return OkHttpClient.Builder() custom builder for developer to add its own interceptors to it
1617
*/
1718
public static Builder custom() {
18-
return new OkHttpClient.Builder();
19+
return new OkHttpClient.Builder().addInterceptor(new TelemetryHandler());
1920
}
2021

2122
/**
@@ -30,6 +31,24 @@ public static OkHttpClient createDefault(ICoreAuthenticationProvider auth) {
3031
.followRedirects(false)
3132
.addInterceptor(new RetryHandler())
3233
.addInterceptor(new RedirectHandler())
34+
.addInterceptor(new TelemetryHandler())
3335
.build();
3436
}
37+
38+
/**
39+
* Creates {@link OkHttpClient} instance with interceptors
40+
*
41+
* @param interceptors Use interceptors provided while constructing http client
42+
* @return OkHttpClient build with interceptors provided
43+
*/
44+
public static OkHttpClient createFromInterceptors(Interceptor[] interceptors) {
45+
OkHttpClient.Builder builder = new OkHttpClient.Builder();
46+
if(interceptors != null)
47+
for(Interceptor interceptor : interceptors) {
48+
if(interceptor != null)
49+
builder.addInterceptor(interceptor);
50+
}
51+
builder.addInterceptor(new TelemetryHandler());
52+
return builder.build();
53+
}
3554
}

0 commit comments

Comments
 (0)