Search in sources :

Example 1 with IDirectoryObjectCollectionWithReferencesPage

use of com.microsoft.graph.extensions.IDirectoryObjectCollectionWithReferencesPage in project android-java-snippets-sample by microsoftgraph.

the class GroupsSnippets method getGroupsSnippets.

static GroupsSnippets[] getGroupsSnippets() {
    return new GroupsSnippets[] { // Marker element
    new GroupsSnippets(null) {

        @Override
        public void request(ICallback callback) {
        // Not implemented
        }
    }, /*
                 * Get a group by id
                 * GET https://graph.microsoft.com/{version}/myOrganization/groups/{Group.objectId}
                 * @see https://graph.microsoft.io/docs/api-reference/v1.0/api/group_get
                 */
    new GroupsSnippets<JsonObject>(get_a_group) {

        @Override
        public void request(final ICallback<JsonObject> callback) {
            // create a group then query it
            Group group = createGroupObject();
            mGraphServiceClient.getGroups().buildRequest().post(group, new ICallback<Group>() {

                @Override
                public void success(Group group) {
                    mGraphServiceClient.getGroups().byId(group.id).buildRequest().get(new ICallback<Group>() {

                        @Override
                        public void success(Group group) {
                            callback.success(group.getRawObject());
                        }

                        @Override
                        public void failure(ClientException ex) {
                            callback.failure(ex);
                        }
                    });
                }

                @Override
                public void failure(ClientException ex) {
                    callback.failure(ex);
                }
            });
        }
    }, /* Get all of the members of a newly created organization group
                 * GET https://graph.microsoft.com/{version}/myOrganization/groups/{Group.objectId}/members
                 * @see https://graph.microsoft.io/docs/api-reference/v1.0/api/group_list_members
                 */
    new GroupsSnippets<JsonObject>(get_group_members) {

        @Override
        public void request(final ICallback<JsonObject> callback) {
            // create a group then ask for its members
            Group group = createGroupObject();
            mGraphServiceClient.getGroups().buildRequest().post(group, new ICallback<Group>() {

                @Override
                public void success(Group group) {
                    mGraphServiceClient.getGroups().byId(group.id).getMembers().buildRequest().get(new ICallback<IDirectoryObjectCollectionWithReferencesPage>() {

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

                        @Override
                        public void failure(ClientException ex) {
                            callback.failure(ex);
                        }
                    });
                }

                @Override
                public void failure(ClientException ex) {
                    callback.failure(ex);
                }
            });
        }
    }, /* Get all of a group's owners
                 * GET https://graph.microsoft.com/{version}/myOrganization/groups/{Group.objectId}/owners
                 * @see https://graph.microsoft.io/docs/api-reference/v1.0/api/group_list_owners
                 */
    new GroupsSnippets<JsonObject>(get_group_owners) {

        @Override
        public void request(final ICallback<JsonObject> callback) {
            // create a group and then request its owner
            Group group = createGroupObject();
            mGraphServiceClient.getGroups().buildRequest().post(group, new ICallback<Group>() {

                @Override
                public void success(Group group) {
                    mGraphServiceClient.getGroups().byId(group.id).getOwners().buildRequest().get(new ICallback<IDirectoryObjectCollectionWithReferencesPage>() {

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

                        @Override
                        public void failure(ClientException ex) {
                            callback.failure(ex);
                        }
                    });
                }

                @Override
                public void failure(ClientException ex) {
                    callback.failure(ex);
                }
            });
        }
    }, /* List all organization groups
                 * GET https://graph.microsoft.com/v1.0/groups
                 * @see https://graph.microsoft.io/docs/api-reference/v1.0/api/group_list
                 */
    new GroupsSnippets<JsonObject>(get_all_groups) {

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

                @Override
                public void success(IGroupCollectionPage iGroupCollectionPage) {
                    callback.success(iGroupCollectionPage.getRawObject());
                }

                @Override
                public void failure(ClientException ex) {
                    callback.failure(ex);
                }
            });
        }
    }, /* Create a new group with a random name
                 * POST https://graph.microsoft.com/{version}/myOrganization/groups
                 * @see https://graph.microsoft.io/docs/api-reference/v1.0/resources/group
                 */
    new GroupsSnippets<JsonObject>(insert_a_group) {

        @Override
        public void request(final ICallback<JsonObject> callback) {
            // create a new group
            Group group = createGroupObject();
            mGraphServiceClient.getGroups().buildRequest().post(group, new ICallback<Group>() {

                @Override
                public void success(Group group) {
                    callback.success(group.getRawObject());
                }

                @Override
                public void failure(ClientException ex) {
                    callback.failure(ex);
                }
            });
        }
    }, /* Delete a group
                 * DELETE https://graph.microsoft.com/{version}/myOrganization/groups/{Group.objectId}
                 * @see https://graph.microsoft.io/docs/api-reference/v1.0/api/group_delete
                 */
    new GroupsSnippets<JsonObject>(delete_a_group) {

        @Override
        public void request(final ICallback<JsonObject> callback) {
            // Create a group that we will delete
            // create a group and then request its owner
            Group group = createGroupObject();
            mGraphServiceClient.getGroups().buildRequest().post(group, new ICallback<Group>() {

                @Override
                public void success(Group group) {
                    mGraphServiceClient.getGroups().byId(group.id).buildRequest().delete(new ICallback<Void>() {

                        @Override
                        public void success(Void aVoid) {
                            callback.success(null);
                        }

                        @Override
                        public void failure(ClientException ex) {
                            callback.failure(ex);
                        }
                    });
                }

                @Override
                public void failure(ClientException ex) {
                    callback.failure(ex);
                }
            });
        }
    } };
}
Also used : Group(com.microsoft.graph.extensions.Group) ICallback(com.microsoft.graph.concurrency.ICallback) IGroupCollectionPage(com.microsoft.graph.extensions.IGroupCollectionPage) IDirectoryObjectCollectionWithReferencesPage(com.microsoft.graph.extensions.IDirectoryObjectCollectionWithReferencesPage) ClientException(com.microsoft.graph.core.ClientException)

Example 2 with IDirectoryObjectCollectionWithReferencesPage

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

Aggregations

ICallback (com.microsoft.graph.concurrency.ICallback)2 ClientException (com.microsoft.graph.core.ClientException)2 IDirectoryObjectCollectionWithReferencesPage (com.microsoft.graph.extensions.IDirectoryObjectCollectionWithReferencesPage)2 DirectoryObject (com.microsoft.graph.extensions.DirectoryObject)1 Group (com.microsoft.graph.extensions.Group)1 IGroupCollectionPage (com.microsoft.graph.extensions.IGroupCollectionPage)1 ProfilePhoto (com.microsoft.graph.extensions.ProfilePhoto)1 User (com.microsoft.graph.extensions.User)1 Option (com.microsoft.graph.options.Option)1 QueryOption (com.microsoft.graph.options.QueryOption)1 LinkedList (java.util.LinkedList)1