Search in sources :

Example 1 with DirectoryObject

use of com.microsoft.graph.models.extensions.DirectoryObject in project opencga by opencb.

the class AzureADAuthenticationManager method getUsersFromRemoteGroup.

@Override
public List<User> getUsersFromRemoteGroup(String groupId) throws CatalogException {
    IDirectoryObjectCollectionWithReferencesPage membersPage;
    try {
        membersPage = graphServiceClient.groups(groupId).members().buildRequest().get();
    } catch (GraphServiceException e) {
        logger.error("Group '{}' not found.", groupId);
        throw new CatalogException("Group '" + groupId + "' not found");
    } catch (ClientException e) {
        logger.error("Graph query could not be performed: {}", e.getMessage());
        throw e;
    }
    List<com.microsoft.graph.models.extensions.User> graphUserList = new ArrayList<>();
    ObjectMapper jsonObjectMapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    boolean moreElems = true;
    while (membersPage.getCurrentPage() != null && moreElems) {
        for (DirectoryObject directoryObject : membersPage.getCurrentPage()) {
            com.microsoft.graph.models.extensions.User graphUser;
            if ("#microsoft.graph.user".equals(directoryObject.oDataType)) {
                try {
                    graphUser = jsonObjectMapper.readValue(String.valueOf(directoryObject.getRawObject()), com.microsoft.graph.models.extensions.User.class);
                    graphUserList.add(graphUser);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        if (membersPage.getNextPage() != null) {
            membersPage = membersPage.getNextPage().buildRequest().get();
        } else {
            moreElems = false;
        }
    }
    return extractUserInformation(graphUserList);
}
Also used : GraphServiceException(com.microsoft.graph.http.GraphServiceException) CatalogException(org.opencb.opencga.catalog.exceptions.CatalogException) IOException(java.io.IOException) IDirectoryObjectCollectionWithReferencesPage(com.microsoft.graph.requests.extensions.IDirectoryObjectCollectionWithReferencesPage) ClientException(com.microsoft.graph.core.ClientException) DirectoryObject(com.microsoft.graph.models.extensions.DirectoryObject) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with DirectoryObject

use of com.microsoft.graph.models.extensions.DirectoryObject 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.me().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.me().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.me().manager().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.me().directReports().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.me().memberOf().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.me().photo().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.models.extensions.User) QueryOption(com.microsoft.graph.options.QueryOption) ProfilePhoto(com.microsoft.graph.models.extensions.ProfilePhoto) LinkedList(java.util.LinkedList) ICallback(com.microsoft.graph.concurrency.ICallback) IDirectoryObjectCollectionWithReferencesPage(com.microsoft.graph.requests.extensions.IDirectoryObjectCollectionWithReferencesPage) QueryOption(com.microsoft.graph.options.QueryOption) Option(com.microsoft.graph.options.Option) ClientException(com.microsoft.graph.core.ClientException) DirectoryObject(com.microsoft.graph.models.extensions.DirectoryObject)

Aggregations

ClientException (com.microsoft.graph.core.ClientException)2 DirectoryObject (com.microsoft.graph.models.extensions.DirectoryObject)2 IDirectoryObjectCollectionWithReferencesPage (com.microsoft.graph.requests.extensions.IDirectoryObjectCollectionWithReferencesPage)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ICallback (com.microsoft.graph.concurrency.ICallback)1 GraphServiceException (com.microsoft.graph.http.GraphServiceException)1 ProfilePhoto (com.microsoft.graph.models.extensions.ProfilePhoto)1 User (com.microsoft.graph.models.extensions.User)1 Option (com.microsoft.graph.options.Option)1 QueryOption (com.microsoft.graph.options.QueryOption)1 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 CatalogException (org.opencb.opencga.catalog.exceptions.CatalogException)1