Search in sources :

Example 1 with Organization

use of com.microsoft.graph.models.Organization in project OpenOLAT by OpenOLAT.

the class MicrosoftGraphDAO method check.

public ConnectionInfos check(String clientId, String clientSecret, String tenantGuid, String producerId, TeamsErrors errors) {
    try {
        MicrosoftGraphAccessTokenManager accessTokenManager = new MicrosoftGraphAccessTokenManager(clientId, clientSecret, tenantGuid);
        AuthenticationTokenProvider authProvider = new AuthenticationTokenProvider(accessTokenManager);
        GraphServiceClient<Request> client = client(authProvider);
        Organization org = getOrganisation(tenantGuid, client);
        String organisation = org == null ? null : org.displayName;
        String producerDisplayName = null;
        if (StringHelper.containsNonWhitespace(producerId)) {
            User producer = searchUserById(producerId, client, errors);
            producerDisplayName = producer == null ? null : producer.displayName;
        }
        return new ConnectionInfos(organisation, producerDisplayName);
    } catch (ClientException e) {
        errors.append(extractMsalFrom(e));
        log.error("", e);
        return null;
    } catch (NullPointerException | IllegalArgumentException e) {
        errors.append(new TeamsError(TeamsErrorCodes.httpClientError));
        log.error("", e);
        return null;
    } catch (Exception e) {
        errors.append(new TeamsError(e.getMessage()));
        log.error("", e);
        return null;
    }
}
Also used : Organization(com.microsoft.graph.models.Organization) User(com.microsoft.graph.models.User) TeamsError(org.olat.modules.teams.model.TeamsError) Request(okhttp3.Request) ClientException(com.microsoft.graph.core.ClientException) MsalException(com.microsoft.aad.msal4j.MsalException) ClientException(com.microsoft.graph.core.ClientException) ConnectionInfos(org.olat.modules.teams.model.ConnectionInfos)

Example 2 with Organization

use of com.microsoft.graph.models.Organization in project OpenOLAT by OpenOLAT.

the class MicrosoftGraphDAO method check.

public final ConnectionInfos check(TeamsErrors errors) {
    try {
        GraphServiceClient<Request> client = client();
        String tenantId = teamsModule.getTenantGuid();
        Organization org = getOrganisation(tenantId, client);
        String organisation = org == null ? null : org.displayName;
        String producerDisplayName = null;
        if (StringHelper.containsNonWhitespace(teamsModule.getProducerId())) {
            User producer = searchUserById(teamsModule.getProducerId(), client, errors);
            producerDisplayName = producer == null ? null : producer.displayName;
        }
        return new ConnectionInfos(organisation, producerDisplayName);
    } catch (ClientException | NullPointerException | IllegalArgumentException e) {
        errors.append(new TeamsError(TeamsErrorCodes.httpClientError));
        log.error("", e);
        return null;
    } catch (Exception e) {
        errors.append(new TeamsError(e.getMessage(), ""));
        log.error("", e);
        return null;
    }
}
Also used : Organization(com.microsoft.graph.models.Organization) User(com.microsoft.graph.models.User) TeamsError(org.olat.modules.teams.model.TeamsError) Request(okhttp3.Request) ClientException(com.microsoft.graph.core.ClientException) ConnectionInfos(org.olat.modules.teams.model.ConnectionInfos) ClientException(com.microsoft.graph.core.ClientException) MsalException(com.microsoft.aad.msal4j.MsalException)

Aggregations

MsalException (com.microsoft.aad.msal4j.MsalException)2 ClientException (com.microsoft.graph.core.ClientException)2 Organization (com.microsoft.graph.models.Organization)2 User (com.microsoft.graph.models.User)2 Request (okhttp3.Request)2 ConnectionInfos (org.olat.modules.teams.model.ConnectionInfos)2 TeamsError (org.olat.modules.teams.model.TeamsError)2