Search in sources :

Example 1 with GraphService

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("?")));
}
Also used : GraphService(odata.msgraph.client.container.GraphService) Arrays(java.util.Arrays) ObjectIdentity(odata.msgraph.client.complex.ObjectIdentity) GraphService(odata.msgraph.client.container.GraphService) Predicate(java.util.function.Predicate) Serializer(com.github.davidmoten.odata.client.Serializer) Drive(odata.msgraph.client.entity.Drive) RequestHeader(com.github.davidmoten.odata.client.RequestHeader) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) FileAttachment(odata.msgraph.client.entity.FileAttachment) User(odata.msgraph.client.entity.User) RequestOptions(com.github.davidmoten.odata.client.RequestOptions) DirectoryObject(odata.msgraph.client.entity.DirectoryObject) User(odata.msgraph.client.entity.User) ObjectIdentity(odata.msgraph.client.complex.ObjectIdentity) FileAttachment(odata.msgraph.client.entity.FileAttachment) Drive(odata.msgraph.client.entity.Drive) List(java.util.List) DirectoryObject(odata.msgraph.client.entity.DirectoryObject) Predicate(java.util.function.Predicate)

Example 2 with GraphService

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());
    }
}
Also used : GraphService(odata.msgraph.client.container.GraphService) User(odata.msgraph.client.entity.User) Test(org.junit.Test)

Example 3 with GraphService

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());
    }
}
Also used : GraphService(odata.msgraph.client.container.GraphService) User(odata.msgraph.client.entity.User) ClientException(com.github.davidmoten.odata.client.ClientException) Test(org.junit.Test)

Example 4 with GraphService

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());
}
Also used : GraphService(odata.msgraph.client.container.GraphService) UploadSession(odata.msgraph.client.complex.UploadSession) Test(org.junit.Test)

Example 5 with GraphService

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();
}
Also used : GraphService(odata.msgraph.client.container.GraphService) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

GraphService (odata.msgraph.client.container.GraphService)62 Test (org.junit.Test)57 Message (odata.msgraph.client.entity.Message)13 User (odata.msgraph.client.entity.User)13 Ignore (org.junit.Ignore)12 ItemAttachment (odata.msgraph.client.entity.ItemAttachment)10 FileAttachment (odata.msgraph.client.entity.FileAttachment)8 File (java.io.File)7 Attachment (odata.msgraph.client.entity.Attachment)7 AttachmentItem (odata.msgraph.client.complex.AttachmentItem)6 Contact (odata.msgraph.client.entity.Contact)6 DirectoryObject (odata.msgraph.client.entity.DirectoryObject)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 UploadSession (odata.msgraph.client.complex.UploadSession)5 ClientException (com.github.davidmoten.odata.client.ClientException)3 ObjectOrDeltaLink (com.github.davidmoten.odata.client.ObjectOrDeltaLink)3 RequestHeader (com.github.davidmoten.odata.client.RequestHeader)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 TimeUnit (java.util.concurrent.TimeUnit)3