Search in sources :

Example 1 with GoToErrorG2T

use of org.olat.modules.gotomeeting.model.GoToErrorG2T in project OpenOLAT by OpenOLAT.

the class GoToMeetingManagerImpl method deleteTraining.

private boolean deleteTraining(GoToMeeting meeting, GoToError error) {
    try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
        GoToOrganizer organizer = meeting.getOrganizer();
        String url = gotoTrainingUrl + "/organizers/" + organizer.getOrganizerKey() + "/trainings/" + meeting.getMeetingKey();
        HttpDelete delete = new HttpDelete(url);
        delete.addHeader("Accept", "application/json");
        delete.addHeader("Authorization", "OAuth oauth_token=" + organizer.getAccessToken());
        delete.addHeader("Content-type", "application/json");
        HttpResponse response = httpClient.execute(delete);
        int status = response.getStatusLine().getStatusCode();
        if (status == 204) {
            // deleted
            return true;
        } else if (status == 404 || status == 400) {
            String content = EntityUtils.toString(response.getEntity());
            GoToErrorG2T errorVo = GoToJsonUtil.parseError(content);
            if (errorVo.getErrorCode() == GoToErrors.NoSuchTraining || errorVo.getErrorCode() == GoToErrors.InvalidRequest) {
                error.setError(errorVo.getErrorCode());
                error.setDescription(errorVo.getDescription());
            } else {
                log.error("deleteTraining return " + status + ": " + content);
            }
        } else {
            logGoToError("deleteTraining", response, error);
        }
        return false;
    } catch (Exception e) {
        log.error("", e);
        return false;
    }
}
Also used : GoToOrganizer(org.olat.modules.gotomeeting.GoToOrganizer) GoToErrorG2T(org.olat.modules.gotomeeting.model.GoToErrorG2T) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpDelete(org.apache.http.client.methods.HttpDelete) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException)

Example 2 with GoToErrorG2T

use of org.olat.modules.gotomeeting.model.GoToErrorG2T in project OpenOLAT by OpenOLAT.

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 3 with GoToErrorG2T

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

the class GoToMeetingManagerImpl method deleteTraining.

private boolean deleteTraining(GoToMeeting meeting, GoToError error) {
    try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
        GoToOrganizer organizer = meeting.getOrganizer();
        String url = gotoTrainingUrl + "/organizers/" + organizer.getOrganizerKey() + "/trainings/" + meeting.getMeetingKey();
        HttpDelete delete = new HttpDelete(url);
        delete.addHeader("Accept", "application/json");
        delete.addHeader("Authorization", "OAuth oauth_token=" + organizer.getAccessToken());
        delete.addHeader("Content-type", "application/json");
        HttpResponse response = httpClient.execute(delete);
        int status = response.getStatusLine().getStatusCode();
        if (status == 204) {
            // deleted
            return true;
        } else if (status == 404 || status == 400) {
            String content = EntityUtils.toString(response.getEntity());
            GoToErrorG2T errorVo = GoToJsonUtil.parseError(content);
            if (errorVo.getErrorCode() == GoToErrors.NoSuchTraining || errorVo.getErrorCode() == GoToErrors.InvalidRequest) {
                error.setError(errorVo.getErrorCode());
                error.setDescription(errorVo.getDescription());
            } else {
                log.error("deleteTraining return " + status + ": " + content);
            }
        } else {
            logGoToError("deleteTraining", response, error);
        }
        return false;
    } catch (Exception e) {
        log.error("", e);
        return false;
    }
}
Also used : GoToOrganizer(org.olat.modules.gotomeeting.GoToOrganizer) GoToErrorG2T(org.olat.modules.gotomeeting.model.GoToErrorG2T) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpDelete(org.apache.http.client.methods.HttpDelete) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException)

Example 4 with GoToErrorG2T

use of org.olat.modules.gotomeeting.model.GoToErrorG2T in project OpenOLAT by OpenOLAT.

the class GoToJsonUtil method parseError.

/*
	{"errorCode":"DuplicateRegistrant","description":"Registration failed, email address already in use.","incident":3437843380023983360,"registrantKey":3019527584166801154} ^%^ cause:n/a
*/
protected static final GoToErrorG2T parseError(String content) {
    try {
        JSONObject json = new JSONObject(content);
        GoToErrorG2T error = new GoToErrorG2T();
        error.setErrorCode(GoToErrors.valueOfOrNull(json.optString("errorCode", null)));
        error.setDescription(json.optString("description", null));
        error.setRegistrantKey(json.optString("registrantKey", null));
        return error;
    } catch (Exception e) {
        log.error("", e);
        return null;
    }
}
Also used : GoToErrorG2T(org.olat.modules.gotomeeting.model.GoToErrorG2T) JSONObject(org.json.JSONObject) ParseException(java.text.ParseException)

Example 5 with GoToErrorG2T

use of org.olat.modules.gotomeeting.model.GoToErrorG2T in project OpenOLAT by OpenOLAT.

the class GoToMeetingManagerImpl method logGoToError.

private void logGoToError(String method, HttpResponse response, GoToError error) throws IOException {
    int status = response.getStatusLine().getStatusCode();
    error.setErrorCode(status);
    String responseString = EntityUtils.toString(response.getEntity());
    try {
        GoToErrorG2T errorVo = GoToJsonUtil.parseError(responseString);
        if (errorVo != null) {
            error.setError(errorVo.getErrorCode());
            error.setDescription(errorVo.getDescription());
        }
    } catch (Exception e) {
        log.error("", e);
    } finally {
        EntityUtils.consumeQuietly(response.getEntity());
        log.error(method + " return " + status + ": " + responseString);
    }
}
Also used : GoToErrorG2T(org.olat.modules.gotomeeting.model.GoToErrorG2T) IOException(java.io.IOException)

Aggregations

GoToErrorG2T (org.olat.modules.gotomeeting.model.GoToErrorG2T)8 IOException (java.io.IOException)6 HttpResponse (org.apache.http.HttpResponse)4 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)4 GoToOrganizer (org.olat.modules.gotomeeting.GoToOrganizer)4 ParseException (java.text.ParseException)2 HttpDelete (org.apache.http.client.methods.HttpDelete)2 HttpPost (org.apache.http.client.methods.HttpPost)2 StringEntity (org.apache.http.entity.StringEntity)2 JSONObject (org.json.JSONObject)2 GoToRegistrant (org.olat.modules.gotomeeting.GoToRegistrant)2 GoToRegistrantG2T (org.olat.modules.gotomeeting.model.GoToRegistrantG2T)2