Search in sources :

Example 1 with Option

use of com.microsoft.graph.options.Option in project msgraph-sdk-java by microsoftgraph.

the class BaseCollectionRequestTests method testFunctionAndQueryParameters.

@Test
public void testFunctionAndQueryParameters() {
    final Option f1 = new FunctionOption("f1", "fun1");
    final Option f2 = new FunctionOption("f2", null);
    final Option q1 = new QueryOption("q1", "option1 ");
    final Option q2 = new QueryOption("q2", "option2");
    final BaseCollectionRequest<String, String> request = new BaseCollectionRequest<String, String>("https://a.b.c", null, Arrays.asList(f1, f2, q1, q2), null, null) {
    };
    assertEquals("https://a.b.c(f1='fun1',f2=null)?q1=option1+&q2=option2", request.getRequestUrl().toString());
    assertEquals(5, request.getOptions().size());
}
Also used : FunctionOption(com.microsoft.graph.options.FunctionOption) QueryOption(com.microsoft.graph.options.QueryOption) QueryOption(com.microsoft.graph.options.QueryOption) Option(com.microsoft.graph.options.Option) FunctionOption(com.microsoft.graph.options.FunctionOption) Test(org.junit.Test)

Example 2 with Option

use of com.microsoft.graph.options.Option in project msgraph-sdk-java by microsoftgraph.

the class BaseRequestTests method testFunctionAndQueryParameters.

@Test
public void testFunctionAndQueryParameters() {
    final Option f1 = new FunctionOption("f1", "fun1");
    final Option f2 = new FunctionOption("f2", null);
    final Option q1 = new QueryOption("q1", "option1 ");
    final Option q2 = new QueryOption("q2", "option2");
    final BaseRequest request = new BaseRequest("https://a.b.c", null, Arrays.asList(f1, f2, q1, q2), null) {
    };
    assertEquals("https://a.b.c(f1='fun1',f2=null)?q1=option1+&q2=option2", request.getRequestUrl().toString());
    assertEquals(5, request.getOptions().size());
}
Also used : FunctionOption(com.microsoft.graph.options.FunctionOption) QueryOption(com.microsoft.graph.options.QueryOption) QueryOption(com.microsoft.graph.options.QueryOption) Option(com.microsoft.graph.options.Option) FunctionOption(com.microsoft.graph.options.FunctionOption) HeaderOption(com.microsoft.graph.options.HeaderOption) Test(org.junit.Test)

Example 3 with Option

use of com.microsoft.graph.options.Option in project android-java-snippets-sample by microsoftgraph.

the class MeSnippets method getMeSnippets.

static MeSnippets[] getMeSnippets() {
    return new MeSnippets[] { // Marker element
    new MeSnippets(null) {

        @Override
        public void request(ICallback callback) {
        // Not implemented
        }
    }, /* Get information about signed in user
                 * HTTP GET https://graph.microsoft.com/{version}/me
                 * @see https://graph.microsoft.io/docs/api-reference/v1.0/api/user_get
                 */
    new MeSnippets<JsonObject>(get_me) {

        @Override
        public void request(final ICallback<JsonObject> callback) {
            mGraphServiceClient.getMe().buildRequest().get(new ICallback<User>() {

                @Override
                public void success(User user) {
                    callback.success(user.getRawObject());
                }

                @Override
                public void failure(ClientException ex) {
                    callback.failure(ex);
                }
            });
        }
    }, /* Get responsibilities of signed in user
                 * HTTP GET https://graph.microsoft.com/{version}/me?$select=AboutMe,Responsibilities,Tags
                 * @see https://graph.microsoft.io/docs/api-reference/v1.0/resources/user
                 */
    new MeSnippets<JsonObject>(get_me_responsibilities) {

        @Override
        public void request(final ICallback<JsonObject> callback) {
            final List<Option> options = new LinkedList<>();
            options.add(new QueryOption("$select", "AboutMe,Responsibilities,Tags"));
            mGraphServiceClient.getMe().buildRequest(options).get(new ICallback<User>() {

                @Override
                public void success(User user) {
                    callback.success(user.getRawObject());
                }

                @Override
                public void failure(ClientException ex) {
                    callback.failure(ex);
                }
            });
        }
    }, /* Get the user's manager
                 * HTTP GET https://graph.microsoft.com/{version}/me/manager
                 * @see https://graph.microsoft.io/docs/api-reference/v1.0/resources/user
                 */
    new MeSnippets<JsonObject>(get_me_manager) {

        @Override
        public void request(final ICallback<JsonObject> callback) {
            mGraphServiceClient.getMe().getManager().buildRequest().get(new ICallback<DirectoryObject>() {

                @Override
                public void success(DirectoryObject directoryObject) {
                    callback.success(directoryObject.getRawObject());
                }

                @Override
                public void failure(ClientException ex) {
                    callback.failure(ex);
                }
            });
        }
    }, /* Get the user's direct reports
                 * HTTP GET https://graph.microsoft.com/{version}/me/directReports
                 * @see https://graph.microsoft.io/docs/api-reference/v1.0/resources/user
                 */
    new MeSnippets<JsonObject>(get_me_direct_reports) {

        @Override
        public void request(final ICallback<JsonObject> callback) {
            mGraphServiceClient.getMe().getDirectReports().buildRequest().get(new ICallback<IDirectoryObjectCollectionWithReferencesPage>() {

                @Override
                public void success(IDirectoryObjectCollectionWithReferencesPage iDirectoryObjectCollectionWithReferencesPage) {
                    callback.success(iDirectoryObjectCollectionWithReferencesPage.getRawObject());
                }

                @Override
                public void failure(ClientException ex) {
                    callback.failure(ex);
                }
            });
        }
    }, /* Get the group membership of the user
                 * HTTP GET https://graph.microsoft.com/{version}/me/memberOf
                 * @see https://graph.microsoft.io/docs/api-reference/v1.0/resources/user
                 */
    new MeSnippets<JsonObject>(get_me_group_membership) {

        @Override
        public void request(final ICallback<JsonObject> callback) {
            mGraphServiceClient.getMe().getMemberOf().buildRequest().get(new ICallback<IDirectoryObjectCollectionWithReferencesPage>() {

                @Override
                public void success(IDirectoryObjectCollectionWithReferencesPage iDirectoryObjectCollectionWithReferencesPage) {
                    callback.success(iDirectoryObjectCollectionWithReferencesPage.getRawObject());
                }

                @Override
                public void failure(ClientException ex) {
                    callback.failure(ex);
                }
            });
        }
    }, /* Get the photo of the user
                 * HTTP GET https://graph.microsoft.com/{version}/me/userPhoto
                 * @see https://graph.microsoft.io/docs/api-reference/v1.0/resources/user
                 */
    new MeSnippets<JsonObject>(get_me_photo) {

        @Override
        public void request(final ICallback<JsonObject> callback) {
            mGraphServiceClient.getMe().getPhoto().buildRequest().get(new ICallback<ProfilePhoto>() {

                @Override
                public void success(ProfilePhoto profilePhoto) {
                    callback.success(profilePhoto.getRawObject());
                }

                @Override
                public void failure(ClientException ex) {
                    callback.failure(ex);
                }
            });
        }
    } };
}
Also used : User(com.microsoft.graph.extensions.User) QueryOption(com.microsoft.graph.options.QueryOption) ProfilePhoto(com.microsoft.graph.extensions.ProfilePhoto) LinkedList(java.util.LinkedList) ICallback(com.microsoft.graph.concurrency.ICallback) IDirectoryObjectCollectionWithReferencesPage(com.microsoft.graph.extensions.IDirectoryObjectCollectionWithReferencesPage) QueryOption(com.microsoft.graph.options.QueryOption) Option(com.microsoft.graph.options.Option) ClientException(com.microsoft.graph.core.ClientException) DirectoryObject(com.microsoft.graph.extensions.DirectoryObject)

Example 4 with Option

use of com.microsoft.graph.options.Option in project android-java-snippets-sample by microsoftgraph.

the class UsersSnippets method getUsersSnippets.

static UsersSnippets[] getUsersSnippets() {
    return new UsersSnippets[] { // Marker element
    new UsersSnippets(null) {

        @Override
        public void request(ICallback callback) {
        // Not implemented
        }
    }, /*
                 * Gets all of the users in your tenant\'s directory.
                 * HTTP GET https://graph.microsoft.com/{version}/myOrganization/users
                 * @see https://graph.microsoft.io/docs/api-reference/v1.0/api/user_list
                 */
    new UsersSnippets<JsonObject>(get_organization_users) {

        @Override
        public void request(final ICallback<JsonObject> callback) {
            mGraphServiceClient.getUsers().buildRequest().get(new ICallback<IUserCollectionPage>() {

                @Override
                public void success(IUserCollectionPage iUserCollectionPage) {
                    callback.success(iUserCollectionPage.getRawObject());
                }

                @Override
                public void failure(ClientException ex) {
                    callback.failure(ex);
                }
            });
        }
    }, /*
                 * Gets all of the users in your tenant's directory who are from the United States, using $filter.
                 * HTTP GET https://graph.microsoft.com/{version}/myOrganization/users?$filter=country eq \'United States\'
                 * @see http://graph.microsoft.io/docs/overview/query_parameters
                 */
    new UsersSnippets<JsonObject>(get_organization_filtered_users) {

        @Override
        public void request(final ICallback<JsonObject> callback) {
            final List<Option> options = new LinkedList<>();
            options.add(new QueryOption("$filter", "country eq 'United States'"));
            mGraphServiceClient.getUsers().buildRequest(options).get(new ICallback<IUserCollectionPage>() {

                @Override
                public void success(IUserCollectionPage iUserCollectionPage) {
                    callback.success(iUserCollectionPage.getRawObject());
                }

                @Override
                public void failure(ClientException ex) {
                    callback.failure(ex);
                }
            });
        }
    }, /*
                 * Adds a new user to the tenant's directory
                 * HTTP POST https://graph.microsoft.com/{version}/myOrganization/users
                 * @see https://graph.microsoft.io/docs/api-reference/v1.0/api/user_post_users
                 */
    new UsersSnippets<JsonObject>(insert_organization_user) {

        @Override
        public void request(final ICallback<JsonObject> callback) {
            // Use a random UUID for the user name
            String randomUserName = UUID.randomUUID().toString();
            // create the user
            User user = new User();
            user.accountEnabled = true;
            user.displayName = "SAMPLE " + randomUserName;
            user.mailNickname = randomUserName;
            // get the tenant from preferences
            SharedPreferences prefs = SharedPrefsUtil.getSharedPreferences();
            String tenant = prefs.getString(PREF_USER_TENANT, "");
            user.userPrincipalName = randomUserName + "@" + tenant;
            // initialize a password & say whether or not the user must change it
            PasswordProfile password = new PasswordProfile();
            password.password = UUID.randomUUID().toString().substring(0, 16);
            password.forceChangePasswordNextSignIn = false;
            user.passwordProfile = password;
            mGraphServiceClient.getUsers().buildRequest().post(user, new ICallback<User>() {

                @Override
                public void success(User user) {
                    callback.success(user.getRawObject());
                }

                @Override
                public void failure(ClientException ex) {
                    callback.failure(ex);
                }
            });
        }
    } };
}
Also used : User(com.microsoft.graph.extensions.User) IUserCollectionPage(com.microsoft.graph.extensions.IUserCollectionPage) SharedPreferences(android.content.SharedPreferences) QueryOption(com.microsoft.graph.options.QueryOption) LinkedList(java.util.LinkedList) PasswordProfile(com.microsoft.graph.extensions.PasswordProfile) ICallback(com.microsoft.graph.concurrency.ICallback) QueryOption(com.microsoft.graph.options.QueryOption) Option(com.microsoft.graph.options.Option) ClientException(com.microsoft.graph.core.ClientException)

Example 5 with Option

use of com.microsoft.graph.options.Option in project msgraph-sdk-java by microsoftgraph.

the class SharePointTests method testSearch.

@Test
public void testSearch() {
    List<Option> requestOptions = new LinkedList<Option>();
    requestOptions.add(new QueryOption("search", "Contoso"));
    ISiteCollectionPage sites = testBase.graphClient.sites().buildRequest(requestOptions).get();
    assertNotNull(sites);
}
Also used : ISiteCollectionPage(com.microsoft.graph.requests.extensions.ISiteCollectionPage) QueryOption(com.microsoft.graph.options.QueryOption) Option(com.microsoft.graph.options.Option) QueryOption(com.microsoft.graph.options.QueryOption) LinkedList(java.util.LinkedList)

Aggregations

Option (com.microsoft.graph.options.Option)11 QueryOption (com.microsoft.graph.options.QueryOption)11 FunctionOption (com.microsoft.graph.options.FunctionOption)7 Test (org.junit.Test)7 HeaderOption (com.microsoft.graph.options.HeaderOption)4 LinkedList (java.util.LinkedList)4 ICallback (com.microsoft.graph.concurrency.ICallback)2 ClientException (com.microsoft.graph.core.ClientException)2 User (com.microsoft.graph.extensions.User)2 ISiteCollectionPage (com.microsoft.graph.requests.extensions.ISiteCollectionPage)2 SharedPreferences (android.content.SharedPreferences)1 DirectoryObject (com.microsoft.graph.extensions.DirectoryObject)1 IDirectoryObjectCollectionWithReferencesPage (com.microsoft.graph.extensions.IDirectoryObjectCollectionWithReferencesPage)1 IUserCollectionPage (com.microsoft.graph.extensions.IUserCollectionPage)1 PasswordProfile (com.microsoft.graph.extensions.PasswordProfile)1 ProfilePhoto (com.microsoft.graph.extensions.ProfilePhoto)1