Search in sources :

Example 1 with GoToRegistrantG2T

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

the class GoToJsonUtil method parseRegistrants.

/*
	[
	  {
	    "email": "string",
	    "givenName": "string",
	    "surname": "string",
	    "status": "WAITING",
	    "registrationDate": "2016-03-23T16:00:00Z",
	    "joinUrl": "string",
	    "confirmationUrl": "string",
	    "registrantKey": "string"
	  }
	]
*/
protected static final List<GoToRegistrantG2T> parseRegistrants(String content) {
    try {
        List<GoToRegistrantG2T> registrants = new ArrayList<>();
        JSONArray jsonArr = new JSONArray(content);
        for (int i = jsonArr.length(); i-- > 0; ) {
            JSONObject registrantJson = jsonArr.getJSONObject(i);
            GoToRegistrantG2T registrant = new GoToRegistrantG2T();
            registrant.setEmail(registrantJson.optString("email", null));
            registrant.setGivenName(registrantJson.optString("givenName", null));
            registrant.setSurname(registrantJson.optString("surname", null));
            registrant.setStatus(registrantJson.optString("status", null));
            registrant.setJoinUrl(registrantJson.optString("joinUrl", null));
            registrant.setConfirmationUrl(registrantJson.optString("confirmationUrl", null));
            registrant.setRegistrantKey(registrantJson.optString("registrantKey", null));
            registrants.add(registrant);
        }
        return registrants;
    } catch (Exception e) {
        log.error("", e);
        return null;
    }
}
Also used : JSONObject(org.json.JSONObject) GoToRegistrantG2T(org.olat.modules.gotomeeting.model.GoToRegistrantG2T) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) ParseException(java.text.ParseException)

Example 2 with GoToRegistrantG2T

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

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

use of org.olat.modules.gotomeeting.model.GoToRegistrantG2T 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 4 with GoToRegistrantG2T

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

the class GoToJsonUtil method parseRegistrants.

/*
	[
	  {
	    "email": "string",
	    "givenName": "string",
	    "surname": "string",
	    "status": "WAITING",
	    "registrationDate": "2016-03-23T16:00:00Z",
	    "joinUrl": "string",
	    "confirmationUrl": "string",
	    "registrantKey": "string"
	  }
	]
*/
protected static final List<GoToRegistrantG2T> parseRegistrants(String content) {
    try {
        List<GoToRegistrantG2T> registrants = new ArrayList<>();
        JSONArray jsonArr = new JSONArray(content);
        for (int i = jsonArr.length(); i-- > 0; ) {
            JSONObject registrantJson = jsonArr.getJSONObject(i);
            GoToRegistrantG2T registrant = new GoToRegistrantG2T();
            registrant.setEmail(registrantJson.optString("email", null));
            registrant.setGivenName(registrantJson.optString("givenName", null));
            registrant.setSurname(registrantJson.optString("surname", null));
            registrant.setStatus(registrantJson.optString("status", null));
            registrant.setJoinUrl(registrantJson.optString("joinUrl", null));
            registrant.setConfirmationUrl(registrantJson.optString("confirmationUrl", null));
            registrant.setRegistrantKey(registrantJson.optString("registrantKey", null));
            registrants.add(registrant);
        }
        return registrants;
    } catch (Exception e) {
        log.error("", e);
        return null;
    }
}
Also used : JSONObject(org.json.JSONObject) GoToRegistrantG2T(org.olat.modules.gotomeeting.model.GoToRegistrantG2T) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) ParseException(java.text.ParseException)

Example 5 with GoToRegistrantG2T

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

the class GoToJsonUtil method parseAddRegistrant.

/*
{
  "joinUrl": "string",
  "confirmationUrl": "string",
  "registrantKey": "string"
}
 */
protected static final GoToRegistrantG2T parseAddRegistrant(String content) {
    try {
        JSONObject json = new JSONObject(content);
        GoToRegistrantG2T registrant = new GoToRegistrantG2T();
        registrant.setRegistrantKey(json.optString("registrantKey", null));
        registrant.setJoinUrl(json.optString("joinUrl", null));
        registrant.setConfirmationUrl(json.optString("confirmationUrl", null));
        return registrant;
    } catch (Exception e) {
        log.error("", e);
        return null;
    }
}
Also used : JSONObject(org.json.JSONObject) GoToRegistrantG2T(org.olat.modules.gotomeeting.model.GoToRegistrantG2T) ParseException(java.text.ParseException)

Aggregations

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