use of odata.msgraph.client.container.GraphService in project odata-client by davidmoten.
the class GraphExplorerMain method main.
public static void main(String[] args) {
GraphService client = MsGraph.explorer().build();
{
client.me().messages().get().stream().findFirst().ifPresent(a -> System.out.println(a.getSubject().orElse("?")));
System.exit(0);
}
{
String count = //
client._custom().withRelativeUrls().getString("me/mailFolders/inbox/messages?$select=id&count=true", RequestOptions.EMPTY, RequestHeader.ODATA_VERSION);
System.out.println(count);
System.exit(0);
}
{
String count = client._custom().getString("https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messages?$select=id&count=true", RequestOptions.EMPTY, RequestHeader.ODATA_VERSION);
System.out.println(count);
System.exit(0);
}
{
//
client.me().calendar().calendarView().query("startDateTime", //
"2019-11-25T15:00:00+00:00").query("endDateTime", //
"2019-11-27T20:00:00+00:00").get().stream().limit(//
40).forEach(x -> System.out.println(x.getStart()));
System.exit(0);
}
{
String count = client._custom().getString("https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messages?$select=id&count=true", RequestOptions.EMPTY, RequestHeader.ODATA_VERSION);
System.out.println(count);
System.exit(0);
}
{
String mimeMessage = client.me().messages().stream().findFirst().get().getStream().get().getStringUtf8();
System.out.println(mimeMessage);
System.exit(0);
}
{
Drive drive = client.me().metadataMinimal().get().getDrive().get();
System.out.println(Serializer.INSTANCE.serialize(drive));
System.exit(0);
}
{
User delta = client.users().delta().streamWithDeltaLink().findFirst().get().object().get();
System.out.println(Serializer.INSTANCE.serialize(delta));
}
System.exit(0);
{
Predicate<ObjectIdentity> hasUserPrincipalName = id -> id.getSignInType().orElse("").equals("userPrincipalName");
// for compilation only, not running
User u = //
client.users().select(//
"id,identities").get().stream().filter(x -> //
x.getIdentities().stream().anyMatch(//
hasUserPrincipalName)).findFirst().get();
List<ObjectIdentity> ids = u.getIdentities().toList();
System.out.println(ids);
ObjectIdentity id = //
ids.stream().filter(//
hasUserPrincipalName).findFirst().get();
ObjectIdentity id2 = //
ObjectIdentity.builder().signInType(//
"userPrincipalName").issuer(//
id.getIssuer().orElse(null)).issuerAssignedId(//
id.getIssuerAssignedId().orElse(null)).build();
ids.add(id2);
// no real change but see if patch works
u.withIdentities(ids).patch();
}
System.exit(0);
{
//
client.me().messages().stream().peek(//
x -> System.out.println(x.getId().orElse("?"))).flatMap(//
m -> m.getAttachments().metadataFull().stream()).filter(//
x -> x instanceof FileAttachment).map(//
x -> (FileAttachment) x).limit(//
1).peek(//
x -> System.out.println(x.getName().orElse("?"))).map(//
x -> x.getStream().get().getBytes().length).forEach(System.out::println);
}
System.exit(0);
DirectoryObject u = //
client.directoryObjects().getByIds(//
Arrays.asList("6e7b768e-07e2-4810-8459-485f84f8f204"), //
Arrays.asList("user")).select(//
"id,mail").connectTimeout(1, //
TimeUnit.MILLISECONDS).stream().findFirst().get();
System.out.println(u);
System.exit(0);
//
client.me().messages().select(//
"id").stream().flatMap(//
m -> m.getAttachments().select("name, size").stream()).limit(//
5).map(//
a -> a.getName().orElse("?") + " " + a.getSize().orElse(-1) + "B").forEach(System.out::println);
System.exit(0);
//
client.users().select(//
"displayName").maxPageSize(10).stream().limit(//
10).map(//
user -> user.getDisplayName().orElse("?")).forEach(System.out::println);
System.exit(0);
String id = client.me().messages().select("id").stream().limit(1).findFirst().get().getId().get();
//
client.me().messages(//
id).attachments().maxPageSize(//
2).select(//
"name,size").stream().filter(//
att -> att instanceof FileAttachment).limit(//
2).map(//
att -> att.getName().orElse("") + " " + att.getSize().orElse(0) + "B").forEach(System.out::println);
System.exit(0);
//
client.groups().top(//
3).select(//
"id,displayName,groupTypes").stream().limit(//
3).filter(g -> g.getGroupTypes().toList().contains("Unified")).peek(//
g -> System.out.println(g.getDisplayName().orElse("?"))).flatMap(group -> //
group.getMembers().select(//
"id,displayName,userType").filter(//
User.class).stream()).filter(user -> "Member".equalsIgnoreCase(user.getUserType().orElse(""))).forEach(user -> System.out.println(" " + user.getDisplayName().orElse("?")));
}
use of odata.msgraph.client.container.GraphService in project odata-client by davidmoten.
the class GraphExplorerSystemIntegrationTest method testGetMeUser.
@Test
public void testGetMeUser() {
if (Util.sysIntEnabled()) {
GraphService client = MsGraph.explorer().build();
User user = client.me().select("id,identities").get();
assertTrue(!user.getIdentities().toList().isEmpty());
}
}
use of odata.msgraph.client.container.GraphService in project odata-client by davidmoten.
the class GraphServiceTest method testPatchOfResourceNotFound.
@Test
public void testPatchOfResourceNotFound() {
GraphService client = //
clientBuilder().expectRequest(//
"/users/1").withResponse(//
"/response-user.json").withRequestHeadersStandard().expectRequest(//
"/users/1").withPayload(//
"/request-user-patch.json").withResponseStatusCode(//
HttpURLConnection.HTTP_NOT_FOUND).withMethod(//
HttpMethod.PATCH).withRequestHeaders(RequestHeader.CONTENT_TYPE_JSON, RequestHeader.ODATA_VERSION, //
RequestHeader.ACCEPT_JSON).build();
User user = client.users("1").get();
try {
user.withCity("Canberra").patch();
} catch (ClientException e) {
assertEquals(HttpURLConnection.HTTP_NOT_FOUND, (int) e.getStatusCode().get());
}
}
use of odata.msgraph.client.container.GraphService in project odata-client by davidmoten.
the class GraphServiceTest method testDriveIssue173Post.
@Test
public void testDriveIssue173Post() {
GraphService client = clientBuilder().expectRequest("/drives/123/items/456:/filename.txt:/createuploadsession").withMethod(//
HttpMethod.POST).withRequestHeaders(RequestHeader.ODATA_VERSION, RequestHeader.CONTENT_TYPE_JSON, RequestHeader.ACCEPT_JSON).withResponse(//
"/response-drive.json").build();
UploadSession u = //
client._custom().post(//
"https://graph.microsoft.com/v1.0/drives/123/items/456:/filename.txt:/createuploadsession", //
null, //
UploadSession.class, //
HttpRequestOptions.EMPTY, //
RequestHeader.ODATA_VERSION, RequestHeader.CONTENT_TYPE_JSON);
assertEquals("https://blah", u.getUploadUrl().get());
}
use of odata.msgraph.client.container.GraphService in project odata-client by davidmoten.
the class GraphServiceTest method testDownloadWholeEmailCompiles.
@Test
@Ignore
public void testDownloadWholeEmailCompiles() {
GraphService client = clientBuilder().build();
//
client.me().messages("123").get().getStream().get().getBytes();
}
Aggregations