Search in sources :

Example 56 with GoToOrganizer

use of org.olat.modules.gotomeeting.GoToOrganizer in project openolat by klemens.

the class GoToMeetingManagerImpl method registerTraining.

/**
 * Error code: 400 (Bad Request), 403 (Forbidden), 404 (Not Found), 409 (Conflict)
 */
@Override
public GoToRegistrant registerTraining(GoToMeeting meeting, Identity trainee, GoToError error) {
    GoToRegistrant registrant = registrantDao.getRegistrant(meeting, trainee);
    if (registrant == null) {
        try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
            GoToOrganizer organizer = meeting.getOrganizer();
            String url = gotoTrainingUrl + "/organizers/" + organizer.getOrganizerKey() + "/trainings/" + meeting.getMeetingKey() + "/registrants";
            HttpPost post = new HttpPost(url);
            post.addHeader("Accept", "application/json");
            post.addHeader("Authorization", "OAuth oauth_token=" + organizer.getAccessToken());
            post.addHeader("Content-type", "application/json");
            String traineeJson = GoToJsonUtil.registrant(trainee).toString();
            post.setEntity(new StringEntity(traineeJson, ContentType.APPLICATION_JSON));
            HttpResponse response = httpClient.execute(post);
            int status = response.getStatusLine().getStatusCode();
            if (status == 201) {
                // created
                String content = EntityUtils.toString(response.getEntity());
                GoToRegistrantG2T registrantVo = GoToJsonUtil.parseAddRegistrant(content);
                registrant = registrantDao.createRegistrant(meeting, trainee, registrantVo.getRegistrantKey(), registrantVo.getJoinUrl(), registrantVo.getConfirmationUrl());
            } else if (status == 409) {
                String content = EntityUtils.toString(response.getEntity());
                GoToErrorG2T errorVo = GoToJsonUtil.parseError(content);
                if (errorVo.getErrorCode() == GoToErrors.DuplicateRegistrant && StringHelper.containsNonWhitespace(errorVo.getRegistrantKey())) {
                    // already registrate but not in OpenOLAT
                    GoToRegistrantG2T registrantVo = getRegistrant(errorVo.getRegistrantKey(), meeting, error);
                    registrant = registrantDao.createRegistrant(meeting, trainee, registrantVo.getRegistrantKey(), registrantVo.getJoinUrl(), registrantVo.getConfirmationUrl());
                } else {
                    logGoToError("registerTraining", status, content, error);
                }
            } else {
                logGoToError("registerTraining", response, error);
            }
        } catch (Exception e) {
            log.error("", e);
        }
    }
    return registrant;
}
Also used : GoToOrganizer(org.olat.modules.gotomeeting.GoToOrganizer) GoToErrorG2T(org.olat.modules.gotomeeting.model.GoToErrorG2T) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) GoToRegistrantG2T(org.olat.modules.gotomeeting.model.GoToRegistrantG2T) GoToRegistrant(org.olat.modules.gotomeeting.GoToRegistrant) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException)

Example 57 with GoToOrganizer

use of org.olat.modules.gotomeeting.GoToOrganizer in project openolat by klemens.

the class GoToMeetingManagerImpl method updateNameDescription.

private void updateNameDescription(GoToMeetingImpl meeting, GoToTrainingG2T training, String name, String description, GoToError error) {
    try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
        GoToOrganizer organizer = meeting.getOrganizer();
        String url = gotoTrainingUrl + "/organizers/" + organizer.getOrganizerKey() + "/trainings/" + meeting.getMeetingKey() + "/nameDescription";
        HttpPut put = new HttpPut(url);
        put.addHeader("Accept", "application/json");
        put.addHeader("Authorization", "OAuth oauth_token=" + organizer.getAccessToken());
        put.addHeader("Content-type", "application/json");
        if (!StringHelper.containsNonWhitespace(description) || "-".equals(description)) {
            description = training.getDescription();
        }
        String payload = GoToJsonUtil.trainingNameDescription(name, description).toString();
        put.setEntity(new StringEntity(payload, ContentType.APPLICATION_JSON));
        HttpResponse response = httpClient.execute(put);
        int status = response.getStatusLine().getStatusCode();
        if (status == 204) {
            // created
            EntityUtils.consume(response.getEntity());
            meeting.setName(name);
            meeting.setDescription(description);
        } else {
            logGoToError("updateNameDescription", response, error);
        }
    } catch (Exception e) {
        log.error("", e);
    }
}
Also used : GoToOrganizer(org.olat.modules.gotomeeting.GoToOrganizer) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) StringEntity(org.apache.http.entity.StringEntity) HttpResponse(org.apache.http.HttpResponse) HttpPut(org.apache.http.client.methods.HttpPut) IOException(java.io.IOException)

Example 58 with GoToOrganizer

use of org.olat.modules.gotomeeting.GoToOrganizer in project openolat by klemens.

the class GoToMeetingManagerImpl method startTraining.

@Override
public String startTraining(GoToMeeting meeting, GoToError error) {
    try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
        GoToOrganizer organizer = meeting.getOrganizer();
        String url = gotoTrainingUrl + "/trainings/" + meeting.getMeetingKey() + "/start";
        HttpGet get = new HttpGet(url);
        get.addHeader("Accept", "application/json");
        get.addHeader("Authorization", "OAuth oauth_token=" + organizer.getAccessToken());
        get.addHeader("Content-type", "application/json");
        HttpResponse response = httpClient.execute(get);
        int status = response.getStatusLine().getStatusCode();
        if (status == 200) {
            // deleted
            String content = EntityUtils.toString(response.getEntity());
            String startUrl = GoToJsonUtil.parseHostUrl(content);
            return startUrl;
        } else {
            logGoToError("startTraining", response, error);
            return null;
        }
    } catch (Exception e) {
        log.error("", e);
        return null;
    }
}
Also used : GoToOrganizer(org.olat.modules.gotomeeting.GoToOrganizer) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException)

Example 59 with GoToOrganizer

use of org.olat.modules.gotomeeting.GoToOrganizer in project openolat by klemens.

the class GoToMeetingManagerImpl method getRegistrant.

private GoToRegistrantG2T getRegistrant(String registrantKey, GoToMeeting meeting, GoToError error) {
    try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
        GoToOrganizer organizer = meeting.getOrganizer();
        String url = gotoTrainingUrl + "/organizers/" + organizer.getOrganizerKey() + "/trainings/" + meeting.getMeetingKey() + "/registrants/" + registrantKey;
        HttpGet get = new HttpGet(url);
        get.addHeader("Accept", "application/json");
        get.addHeader("Authorization", "OAuth oauth_token=" + organizer.getAccessToken());
        get.addHeader("Content-type", "application/json");
        HttpResponse response = httpClient.execute(get);
        int status = response.getStatusLine().getStatusCode();
        if (status == 200) {
            String content = EntityUtils.toString(response.getEntity());
            GoToRegistrantG2T registrantVo = GoToJsonUtil.parseAddRegistrant(content);
            return registrantVo;
        } else {
            logGoToError("getRegistrant", response, error);
            return null;
        }
    } catch (Exception e) {
        log.error("", e);
        return null;
    }
}
Also used : GoToOrganizer(org.olat.modules.gotomeeting.GoToOrganizer) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) GoToRegistrantG2T(org.olat.modules.gotomeeting.model.GoToRegistrantG2T) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException)

Example 60 with GoToOrganizer

use of org.olat.modules.gotomeeting.GoToOrganizer in project openolat by klemens.

the class GoToMeetingManagerImpl method updateStartEnd.

private void updateStartEnd(GoToMeetingImpl meeting, Date start, Date end, GoToError error) {
    try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
        GoToOrganizer organizer = meeting.getOrganizer();
        String url = gotoTrainingUrl + "/organizers/" + organizer.getOrganizerKey() + "/trainings/" + meeting.getMeetingKey() + "/times";
        HttpPut put = new HttpPut(url);
        put.addHeader("Accept", "application/json");
        put.addHeader("Authorization", "OAuth oauth_token=" + organizer.getAccessToken());
        put.addHeader("Content-type", "application/json");
        String payload = GoToJsonUtil.trainingTimes(goToMeetingModule.getGoToTimeZoneId(), start, end).toString();
        put.setEntity(new StringEntity(payload, ContentType.APPLICATION_JSON));
        HttpResponse response = httpClient.execute(put);
        int status = response.getStatusLine().getStatusCode();
        if (status == 200) {
            // created
            EntityUtils.consume(response.getEntity());
            meeting.setStartDate(start);
            meeting.setEndDate(end);
        } else {
            logGoToError("updateStartEnd", response, error);
        }
    } catch (Exception e) {
        log.error("", e);
    }
}
Also used : GoToOrganizer(org.olat.modules.gotomeeting.GoToOrganizer) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) StringEntity(org.apache.http.entity.StringEntity) HttpResponse(org.apache.http.HttpResponse) HttpPut(org.apache.http.client.methods.HttpPut) IOException(java.io.IOException)

Aggregations

GoToOrganizer (org.olat.modules.gotomeeting.GoToOrganizer)60 Test (org.junit.Test)28 Date (java.util.Date)22 GoToMeeting (org.olat.modules.gotomeeting.GoToMeeting)18 IOException (java.io.IOException)16 HttpResponse (org.apache.http.HttpResponse)16 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)16 RepositoryEntry (org.olat.repository.RepositoryEntry)10 HttpGet (org.apache.http.client.methods.HttpGet)8 Identity (org.olat.core.id.Identity)8 StringEntity (org.apache.http.entity.StringEntity)6 GoToRegistrant (org.olat.modules.gotomeeting.GoToRegistrant)6 HttpPut (org.apache.http.client.methods.HttpPut)4 GoToError (org.olat.modules.gotomeeting.model.GoToError)4 GoToErrorG2T (org.olat.modules.gotomeeting.model.GoToErrorG2T)4 GoToRegistrantG2T (org.olat.modules.gotomeeting.model.GoToRegistrantG2T)4 Calendar (java.util.Calendar)2 Response (javax.ws.rs.core.Response)2 HttpDelete (org.apache.http.client.methods.HttpDelete)2 HttpPost (org.apache.http.client.methods.HttpPost)2