Search in sources :

Example 1 with ItemAttachment

use of odata.msgraph.client.entity.ItemAttachment in project odata-client by davidmoten.

the class GraphServiceTest method testCollectionWithDerivedTypeFilterAvailableInNextBuilder.

@Test
public void testCollectionWithDerivedTypeFilterAvailableInNextBuilder() {
    GraphService client = // 
    clientBuilder().expectRequest(// 
    "/users/fred/mailFolders/inbox/messages/1").withResponse(// 
    "/response-message-has-item-attachment.json").withRequestHeaders(RequestHeader.ODATA_VERSION, // 
    RequestHeader.ACCEPT_JSON_METADATA_FULL).expectRequest(// 
    "/users/fred/mailFolders/inbox/messages/1/attachments/microsoft.graph.itemAttachment").withResponse(// 
    "/response-attachments-one-item.json").withRequestHeaders(RequestHeader.ODATA_VERSION, // 
    RequestHeader.ACCEPT_JSON_METADATA_NONE).build();
    List<ItemAttachment> list = // 
    client.users(// 
    "fred").mailFolders(// 
    "inbox").messages(// 
    "1").metadataFull().get().getAttachments().metadataNone().filter(ItemAttachment.class).toList();
    assertEquals(1, list.size());
    assertTrue(list.get(0) instanceof ItemAttachment);
}
Also used : GraphService(odata.msgraph.client.container.GraphService) ItemAttachment(odata.msgraph.client.entity.ItemAttachment) Test(org.junit.Test)

Example 2 with ItemAttachment

use of odata.msgraph.client.entity.ItemAttachment in project odata-client by davidmoten.

the class GraphServiceTest method testCollectionWithDerivedType.

@Test
public void testCollectionWithDerivedType() {
    GraphService client = // 
    clientBuilder().expectRequest(// 
    "/users/fred/mailFolders/inbox/messages/1").withResponse(// 
    "/response-message-has-item-attachment.json").withRequestHeaders(RequestHeader.ODATA_VERSION, // 
    RequestHeader.ACCEPT_JSON_METADATA_FULL).expectRequest(// 
    "/users/fred/mailFolders/inbox/messages/1/attachments/microsoft.graph.itemAttachment").withResponse("/response-attachments-one-item.json").withRequestHeadersStandard().build();
    List<ItemAttachment> list = // 
    client.users(// 
    "fred").mailFolders(// 
    "inbox").messages(// 
    "1").metadataFull().get().getAttachments().filter(ItemAttachment.class).toList();
    assertEquals(1, list.size());
    assertTrue(list.get(0) instanceof ItemAttachment);
}
Also used : GraphService(odata.msgraph.client.container.GraphService) ItemAttachment(odata.msgraph.client.entity.ItemAttachment) Test(org.junit.Test)

Example 3 with ItemAttachment

use of odata.msgraph.client.entity.ItemAttachment in project odata-client by davidmoten.

the class GraphServiceTest method testGetStreamOnItemAttachment.

@Test
public void testGetStreamOnItemAttachment() throws IOException {
    GraphService client = // 
    clientBuilder().expectRequest(// 
    "/users/fred/mailFolders/Inbox/messages?$filter=isRead%20eq%20false&$orderBy=createdDateTime").withResponse(// 
    "/response-messages-with-item-attachment.json").withRequestHeadersStandard().expectRequest(// 
    "/users/fred/mailFolders/Inbox/messages/86/attachments").withResponse(// 
    "/response-attachments.json").withRequestHeaders(RequestHeader.ODATA_VERSION, // 
    RequestHeader.ACCEPT_JSON_METADATA_FULL).expectRequest(// 
    "/users/fred/mailFolders/Inbox/messages/86/attachments/123/%24value").withResponse(// 
    "/response-item-attachment-raw.txt").withRequestHeaders().build();
    Message m = // 
    client.users(// 
    "fred").mailFolders(// 
    "Inbox").messages().filter(// 
    "isRead eq false").orderBy(// 
    "createdDateTime").metadataMinimal().iterator().next();
    ItemAttachment a = (ItemAttachment) // 
    m.getAttachments().metadataFull().stream().findFirst().get();
    String s = new String(read(a.getStream().get().get()));
    assertEquals(60, s.length());
}
Also used : GraphService(odata.msgraph.client.container.GraphService) Message(odata.msgraph.client.entity.Message) ItemAttachment(odata.msgraph.client.entity.ItemAttachment) Test(org.junit.Test)

Example 4 with ItemAttachment

use of odata.msgraph.client.entity.ItemAttachment in project odata-client by davidmoten.

the class AdHocMain method main.

public static void main(String[] args) {
    String tenantName = System.getProperty("tenantName");
    String clientId = System.getProperty("clientId");
    String clientSecret = System.getProperty("clientSecret");
    String mailbox = System.getProperty("mailbox");
    GraphService client = // 
    MsGraph.tenantName(// 
    tenantName).clientId(// 
    clientId).clientSecret(// 
    clientSecret).refreshBeforeExpiry(5, // 
    TimeUnit.MINUTES).authenticationEndpoint(// is default
    AuthenticationEndpoint.GLOBAL).build();
    client.users(mailbox).messages().get().currentPage().forEach(System.out::println);
    // if (false) {
    // String url =
    // "https://graph.microsoft.com/v1.0/users('dnex001%40amsa.gov.au')/mailFolders('inbox')/messages('AQMkADQ3YjdiNWUxLTBmYWQtNDMwYy04Yzc0LTI0MDdmOWQ4NDFjNgBGAAAD4Rwe0e6XOE6Ck412HUUUTwcAUb5I0z9LnUy3cpFj0m9MUgAAAgEMAAAA3NEVJKXfYEuEjYE7msyHXwACvGHoMgAAAA%3D%3D')/attachments('AQMkADQ3YjdiNWUxLTBmYWQtNDMwYy04Yzc0LTI0MDdmOWQ4NDFjNgBGAAAD4Rwe0e6XOE6Ck412HUUUTwcAUb5I0z9LnUy3cpFj0m9MUgAAAgEMAAAA3NEVJKXfYEuEjYE7msyHXwACvGHoMgAAAAESABAAEk3MvTWvlkaZoyGmFgr4ag%3D%3D')";
    // System.out.println(url + "\n->\n" + client._service().getStringUtf8(url,
    // Arrays.asList(new RequestHeader("Accept",
    // "application/json;odata.metadata=full"))));
    // System.exit(0);
    // }
    String a = client._custom().getString("https://graph.microsoft.com/v1.0/users/dnex001%40amsa.gov.au/messages('AQMkADQ3YjdiNWUxLTBmYWQtNDMwYy04Yzc0LTI0MDdmOWQ4NDFjNgBGAAAD4Rwe0e6XOE6Ck412HUUUTwcAUb5I0z9LnUy3cpFj0m9MUgAAAgEMAAAA3NEVJKXfYEuEjYE7msyHXwACvxQL4gAAAA==')/$value", RequestOptions.EMPTY, RequestHeader.ACCEPT_JSON, RequestHeader.ODATA_VERSION);
    System.out.println(a);
    System.exit(1);
    String s = client.users(mailbox).messages(// 
    "AQMkADQ3YjdiNWUxLTBmYWQtNDMwYy04Yzc0LTI0MDdmOWQ4NDFjNgBGAAAD4Rwe0e6XOE6Ck412HUUUTwcAUb5I0z9LnUy3cpFj0m9MUgAAAgEMAAAA3NEVJKXfYEuEjYE7msyHXwACvxQL4gAAAA==").metadataFull().get().getStream().get().getStringUtf8();
    System.out.println(s);
    // System.out.println(client.users(mailbox).get().revokeSignInSessions());
    System.exit(0);
    System.out.println(client.sites("root").get().getDisplayName().orElse(""));
    // client.users(mailbox).get().revokeSignInSessions(null)
    // test raw value of service
    // String s = client.users(mailbox) //
    // .mailFolders("Inbox") //
    // .messages() //
    // .filter("isRead eq false") //
    // .metadataFull() //
    // .get() //
    // .stream() //
    // .findFirst() //
    // .get() //
    // .getStream() //
    // .get() //
    // .getStringUtf8();
    // System.out.println(s);
    // 
    client.users(// 
    mailbox).mailFolders(// 
    "Inbox").messages().filter(// 
    "isRead eq false and startsWith(subject, 'test contact')").stream().peek(// 
    x -> System.out.println(x.getSubject().orElse(""))).flatMap(// 
    x -> x.getAttachments().metadataFull().get().stream()).filter(// 
    x -> x instanceof ItemAttachment).map(// 
    x -> (ItemAttachment) x).map(// 
    x -> x.getStream().get().getStringUtf8()).peek(// 
    System.out::println).findFirst();
    // 
    client.users(// 
    mailbox).mailFolders(// 
    "Inbox").messages().filter(// 
    "isRead eq false").stream().filter(// 
    x -> x.getHasAttachments().orElse(false)).peek(// 
    x -> System.out.println("Subject: " + x.getSubject().orElse(""))).flatMap(// 
    x -> x.getAttachments().get().stream()).peek(x -> System.out.println(// 
    "  " + x.getName().orElse("?") + " [" + x.getSize().orElse(0) + "]")).count();
}
Also used : GraphService(odata.msgraph.client.container.GraphService) TimeUnit(java.util.concurrent.TimeUnit) GraphService(odata.msgraph.client.container.GraphService) ItemAttachment(odata.msgraph.client.entity.ItemAttachment) AuthenticationEndpoint(com.github.davidmoten.microsoft.authentication.AuthenticationEndpoint) RequestOptions(com.github.davidmoten.odata.client.RequestOptions) RequestHeader(com.github.davidmoten.odata.client.RequestHeader) ItemAttachment(odata.msgraph.client.entity.ItemAttachment)

Example 5 with ItemAttachment

use of odata.msgraph.client.entity.ItemAttachment in project odata-client by davidmoten.

the class GraphServiceTest method testCollectionTypesHonourInheritance.

@Test
public void testCollectionTypesHonourInheritance() {
    GraphService client = // 
    clientBuilder().expectRequest(// 
    "/users/fred/mailFolders/inbox/messages/1").withResponse(// 
    "/response-message-has-item-attachment.json").withRequestHeaders(RequestHeader.ODATA_VERSION, // 
    RequestHeader.ACCEPT_JSON_METADATA_FULL).expectRequest(// 
    "/users/fred/mailFolders/inbox/messages/1/attachments").withResponse(// 
    "/response-attachments-includes-item.json").withRequestHeadersStandard().build();
    List<Attachment> list = // 
    client.users(// 
    "fred").mailFolders(// 
    "inbox").messages(// 
    "1").metadataFull().get().getAttachments().toList();
    assertEquals(2, list.size());
    assertTrue(list.get(0) instanceof ItemAttachment);
    assertTrue(list.get(1) instanceof FileAttachment);
}
Also used : GraphService(odata.msgraph.client.container.GraphService) FileAttachment(odata.msgraph.client.entity.FileAttachment) FileAttachment(odata.msgraph.client.entity.FileAttachment) ItemAttachment(odata.msgraph.client.entity.ItemAttachment) Attachment(odata.msgraph.client.entity.Attachment) ItemAttachment(odata.msgraph.client.entity.ItemAttachment) Test(org.junit.Test)

Aggregations

GraphService (odata.msgraph.client.container.GraphService)5 ItemAttachment (odata.msgraph.client.entity.ItemAttachment)5 Test (org.junit.Test)4 AuthenticationEndpoint (com.github.davidmoten.microsoft.authentication.AuthenticationEndpoint)1 RequestHeader (com.github.davidmoten.odata.client.RequestHeader)1 RequestOptions (com.github.davidmoten.odata.client.RequestOptions)1 TimeUnit (java.util.concurrent.TimeUnit)1 Attachment (odata.msgraph.client.entity.Attachment)1 FileAttachment (odata.msgraph.client.entity.FileAttachment)1 Message (odata.msgraph.client.entity.Message)1