Search in sources :

Example 1 with UserCollectionPage

use of com.microsoft.graph.requests.UserCollectionPage in project msgraph-sdk-java by microsoftgraph.

the class UserTests method usersKeyPhotoValueTest.

@Test
public void usersKeyPhotoValueTest() {
    // GET users('<<key>>')/photo/$value
    final UserCollectionPage userCollectionPage = graphServiceClient.users().buildRequest().get();
    for (User user : userCollectionPage.getCurrentPage()) {
        if (user.photo != null) {
            InputStream stream = graphServiceClient.users(userCollectionPage.getCurrentPage().get(0).id).photo().content().buildRequest().get();
            assertNotNull(stream);
            break;
        }
    }
}
Also used : User(com.microsoft.graph.models.User) UserCollectionPage(com.microsoft.graph.requests.UserCollectionPage) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Test(org.junit.jupiter.api.Test)

Example 2 with UserCollectionPage

use of com.microsoft.graph.requests.UserCollectionPage in project msgraph-sdk-java by microsoftgraph.

the class OutlookTests method testGetFindMeetingTimes.

@Test
public void testGetFindMeetingTimes() {
    TestBase testBase = new TestBase();
    // Get the first user in the tenant
    User me = testBase.graphClient.me().buildRequest().get();
    UserCollectionPage users = testBase.graphClient.users().buildRequest().get();
    User tenantUser = users.getCurrentPage().get(0);
    // Ensure that the user grabbed is not the logged-in user
    if (tenantUser.mail.equals(me.mail)) {
        tenantUser = users.getCurrentPage().get(1);
    }
    ArrayList<AttendeeBase> attendees = new ArrayList<AttendeeBase>();
    AttendeeBase attendeeBase = new AttendeeBase();
    EmailAddress email = new EmailAddress();
    email.address = tenantUser.mail;
    attendeeBase.emailAddress = email;
    attendees.add(attendeeBase);
    try {
        DatatypeFactory.newInstance().newDuration("PT30M");
        Duration duration = DatatypeFactory.newInstance().newDuration("PT30M");
        MeetingTimeSuggestionsResult result = testBase.graphClient.me().findMeetingTimes(UserFindMeetingTimesParameterSet.newBuilder().withAttendees(attendees).withMeetingDuration(duration).withMaxCandidates(10).withReturnSuggestionReasons(true).withMinimumAttendeePercentage(10.0).build()).buildRequest().post();
        assertNotNull(result);
    } catch (Exception e) {
        fail("Duration could not be created from String");
    }
}
Also used : AttendeeBase(com.microsoft.graph.models.AttendeeBase) MeetingTimeSuggestionsResult(com.microsoft.graph.models.MeetingTimeSuggestionsResult) User(com.microsoft.graph.models.User) UserCollectionPage(com.microsoft.graph.requests.UserCollectionPage) ArrayList(java.util.ArrayList) Duration(javax.xml.datatype.Duration) EmailAddress(com.microsoft.graph.models.EmailAddress) ClientException(com.microsoft.graph.core.ClientException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 3 with UserCollectionPage

use of com.microsoft.graph.requests.UserCollectionPage in project OpenOLAT by OpenOLAT.

the class MicrosoftGraphDAO method searchUserByUserPrincipalName.

/**
 * @param mail
 * @param issuer
 * @return
 */
public User searchUserByUserPrincipalName(List<String> principals, TeamsErrors errors) {
    if (principals == null || principals.isEmpty())
        return null;
    StringBuilder sb = new StringBuilder();
    for (String principal : principals) {
        if (sb.length() > 0) {
            sb.append(" or ");
        }
        sb.append("userPrincipalName eq '").append(principal).append("'");
    }
    try {
        UserCollectionPage user = client().users().buildRequest().filter(sb.toString()).select("displayName,id,mail,otherMails").top(1).get();
        List<User> users = user.getCurrentPage();
        return users.isEmpty() ? null : users.get(0);
    } catch (ClientException | NullPointerException | IllegalArgumentException e) {
        errors.append(new TeamsError(TeamsErrorCodes.httpClientError));
        log.error("Cannot find user with principal names", e);
        return null;
    }
}
Also used : User(com.microsoft.graph.models.User) TeamsError(org.olat.modules.teams.model.TeamsError) UserCollectionPage(com.microsoft.graph.requests.UserCollectionPage) ClientException(com.microsoft.graph.core.ClientException)

Example 4 with UserCollectionPage

use of com.microsoft.graph.requests.UserCollectionPage in project OpenOLAT by OpenOLAT.

the class MicrosoftGraphDAO method searchUsersByMail.

/**
 * $filter=otherMails/any(x:x eq ‘xxx@abc.com’)
 *
 * @param email The E-mail (mandatory)
 * @param institutionalEmail The institutional E-mail (optional)
 * @return The first users found
 */
public List<User> searchUsersByMail(String email, String institutionalEmail, TeamsErrors errors) {
    StringBuilder sb = new StringBuilder();
    sb.append("mail eq '").append(email).append("'").append(" or otherMails/any(x:x eq '").append(email).append("')");
    if (StringHelper.containsNonWhitespace(institutionalEmail)) {
        sb.append(" or mail eq '").append(institutionalEmail).append("'").append(" or otherMails/any(x:x eq '").append(institutionalEmail).append("')");
    }
    try {
        UserCollectionPage user = client().users().buildRequest().filter(sb.toString()).select("displayName,id,mail,otherMails").get();
        return user.getCurrentPage();
    } catch (ClientException | NullPointerException | IllegalArgumentException e) {
        log.error("Cannot find user with email: {} {}", email, institutionalEmail, e);
        errors.append(new TeamsError(TeamsErrorCodes.httpClientError));
        return new ArrayList<>();
    }
}
Also used : TeamsError(org.olat.modules.teams.model.TeamsError) UserCollectionPage(com.microsoft.graph.requests.UserCollectionPage) ClientException(com.microsoft.graph.core.ClientException)

Example 5 with UserCollectionPage

use of com.microsoft.graph.requests.UserCollectionPage in project msgraph-beta-sdk-java by microsoftgraph.

the class UserTests method castTest.

@Test
public void castTest() {
    final GroupCollectionPage groups = graphServiceClient.groups().buildRequest().top(1).get();
    final Group group = groups.getCurrentPage().get(0);
    final UserCollectionPage usersPage = graphServiceClient.groups(group.id).membersAsUser().buildRequest().get();
    assertNotNull(usersPage);
    final DirectoryObjectCollectionWithReferencesPage testUserCollection = graphServiceClient.groups(group.id).members().buildRequest().top(1).get();
    final DirectoryObject testUser = testUserCollection.getCurrentPage().get(0);
    final User user = graphServiceClient.groups(group.id).membersAsUser(testUser.id).buildRequest().get();
    assertNotNull(user);
}
Also used : Group(com.microsoft.graph.models.Group) User(com.microsoft.graph.models.User) UserCollectionPage(com.microsoft.graph.requests.UserCollectionPage) GroupCollectionPage(com.microsoft.graph.requests.GroupCollectionPage) DirectoryObjectCollectionWithReferencesPage(com.microsoft.graph.requests.DirectoryObjectCollectionWithReferencesPage) DirectoryObject(com.microsoft.graph.models.DirectoryObject) Test(org.junit.jupiter.api.Test)

Aggregations

UserCollectionPage (com.microsoft.graph.requests.UserCollectionPage)17 User (com.microsoft.graph.models.User)14 Test (org.junit.jupiter.api.Test)14 ClientException (com.microsoft.graph.core.ClientException)4 HeaderOption (com.microsoft.graph.options.HeaderOption)4 Group (com.microsoft.graph.models.Group)3 GroupCollectionPage (com.microsoft.graph.requests.GroupCollectionPage)3 ArrayList (java.util.ArrayList)3 AttendeeBase (com.microsoft.graph.models.AttendeeBase)2 CalendarGetScheduleParameterSet (com.microsoft.graph.models.CalendarGetScheduleParameterSet)2 DateTimeTimeZone (com.microsoft.graph.models.DateTimeTimeZone)2 DirectoryObject (com.microsoft.graph.models.DirectoryObject)2 EmailAddress (com.microsoft.graph.models.EmailAddress)2 MeetingTimeSuggestionsResult (com.microsoft.graph.models.MeetingTimeSuggestionsResult)2 Option (com.microsoft.graph.options.Option)2 CalendarGetScheduleCollectionPage (com.microsoft.graph.requests.CalendarGetScheduleCollectionPage)2 DirectoryObjectCollectionWithReferencesPage (com.microsoft.graph.requests.DirectoryObjectCollectionWithReferencesPage)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2