Search in sources :

Example 1 with Group

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

the class GroupsSnippets method createGroupObject.

private static Group createGroupObject() {
    String guid = UUID.randomUUID().toString();
    Group group = new Group();
    group.displayName = guid;
    group.mailNickname = guid;
    group.mailEnabled = false;
    group.securityEnabled = false;
    group.groupTypes = Collections.singletonList("Unified");
    return group;
}
Also used : Group(com.microsoft.graph.models.extensions.Group)

Example 2 with Group

use of com.microsoft.graph.models.extensions.Group 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.groups().buildRequest().post(group, new ICallback<Group>() {

                @Override
                public void success(Group group) {
                    mGraphServiceClient.groups().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.groups().buildRequest().post(group, new ICallback<Group>() {

                @Override
                public void success(Group group) {
                    mGraphServiceClient.groups().byId(group.id).members().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.groups().buildRequest().post(group, new ICallback<Group>() {

                @Override
                public void success(Group group) {
                    mGraphServiceClient.groups().byId(group.id).owners().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.groups().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.groups().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.groups().buildRequest().post(group, new ICallback<Group>() {

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

                        @Override
                        public void success(Group 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.models.extensions.Group) ICallback(com.microsoft.graph.concurrency.ICallback) IGroupCollectionPage(com.microsoft.graph.requests.extensions.IGroupCollectionPage) IDirectoryObjectCollectionWithReferencesPage(com.microsoft.graph.requests.extensions.IDirectoryObjectCollectionWithReferencesPage) ClientException(com.microsoft.graph.core.ClientException)

Aggregations

Group (com.microsoft.graph.models.extensions.Group)2 ICallback (com.microsoft.graph.concurrency.ICallback)1 ClientException (com.microsoft.graph.core.ClientException)1 IDirectoryObjectCollectionWithReferencesPage (com.microsoft.graph.requests.extensions.IDirectoryObjectCollectionWithReferencesPage)1 IGroupCollectionPage (com.microsoft.graph.requests.extensions.IGroupCollectionPage)1