Search in sources :

Example 1 with User

use of com.microsoft.graph.extensions.User 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 2 with User

use of com.microsoft.graph.extensions.User 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)

Aggregations

ICallback (com.microsoft.graph.concurrency.ICallback)2 ClientException (com.microsoft.graph.core.ClientException)2 User (com.microsoft.graph.extensions.User)2 Option (com.microsoft.graph.options.Option)2 QueryOption (com.microsoft.graph.options.QueryOption)2 LinkedList (java.util.LinkedList)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