Search in sources :

Example 1 with GoToTrainingG2T

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

the class GoToJsonUtil method parseTraining.

/*
{
  "trainingId": "string",
  "name": "string",
  "description": "string",
  "timeZone": "string",
  "times": [
    {
      "startDate": "2016-03-24T10:00:00Z",
      "endDate": "2016-03-24T11:00:00Z"
    }
  ],
  "organizers": [
    {
      "organizerKey": "string",
      "email": "string",
      "givenName": "string",
      "surname": "string"
    }
  ],
  "registrationSettings": {
    "disableConfirmationEmail": true,
    "disableWebRegistration": true
  },
  "trainingKey": "string"
}
*/
protected static final GoToTrainingG2T parseTraining(String content) {
    try {
        JSONObject json = new JSONObject(content);
        GoToTrainingG2T training = new GoToTrainingG2T();
        training.setName(json.optString("name"));
        training.setDescription(json.optString("description"));
        training.setTrainingKey(json.optString("trainingKey", null));
        training.setTimeZoneId(json.optString("timeZone", null));
        JSONArray times = json.getJSONArray("times");
        JSONObject time = times.getJSONObject(0);
        String startDate = time.optString("startDate", null);
        Date start = parseDateTime(startDate);
        training.setStart(start);
        String endDate = time.optString("endDate", null);
        Date end = parseDateTime(endDate);
        training.setEnd(end);
        return training;
    } catch (Exception e) {
        log.error("", e);
        return null;
    }
}
Also used : JSONObject(org.json.JSONObject) GoToTrainingG2T(org.olat.modules.gotomeeting.model.GoToTrainingG2T) JSONArray(org.json.JSONArray) Date(java.util.Date) ParseException(java.text.ParseException)

Example 2 with GoToTrainingG2T

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

the class GoToJsonUtil method parseTraining.

/*
{
  "trainingId": "string",
  "name": "string",
  "description": "string",
  "timeZone": "string",
  "times": [
    {
      "startDate": "2016-03-24T10:00:00Z",
      "endDate": "2016-03-24T11:00:00Z"
    }
  ],
  "organizers": [
    {
      "organizerKey": "string",
      "email": "string",
      "givenName": "string",
      "surname": "string"
    }
  ],
  "registrationSettings": {
    "disableConfirmationEmail": true,
    "disableWebRegistration": true
  },
  "trainingKey": "string"
}
*/
protected static final GoToTrainingG2T parseTraining(String content) {
    try {
        JSONObject json = new JSONObject(content);
        GoToTrainingG2T training = new GoToTrainingG2T();
        training.setName(json.optString("name"));
        training.setDescription(json.optString("description"));
        training.setTrainingKey(json.optString("trainingKey", null));
        training.setTimeZoneId(json.optString("timeZone", null));
        JSONArray times = json.getJSONArray("times");
        JSONObject time = times.getJSONObject(0);
        String startDate = time.optString("startDate", null);
        Date start = parseDateTime(startDate);
        training.setStart(start);
        String endDate = time.optString("endDate", null);
        Date end = parseDateTime(endDate);
        training.setEnd(end);
        return training;
    } catch (Exception e) {
        log.error("", e);
        return null;
    }
}
Also used : JSONObject(org.json.JSONObject) GoToTrainingG2T(org.olat.modules.gotomeeting.model.GoToTrainingG2T) JSONArray(org.json.JSONArray) Date(java.util.Date) ParseException(java.text.ParseException)

Example 3 with GoToTrainingG2T

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

the class GoToMeetingManagerImpl method getTraining.

private GoToTrainingG2T getTraining(GoToMeeting meeting, GoToError error) {
    try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
        GoToOrganizer organizer = meeting.getOrganizer();
        String url = gotoTrainingUrl + "/organizers/" + organizer.getOrganizerKey() + "/trainings/" + meeting.getMeetingKey();
        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());
            GoToTrainingG2T trainingVo = GoToJsonUtil.parseTraining(content);
            return trainingVo;
        } else {
            logGoToError("getTraining", 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) GoToTrainingG2T(org.olat.modules.gotomeeting.model.GoToTrainingG2T) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException)

Example 4 with GoToTrainingG2T

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

the class GoToMeetingManagerImpl method getTraining.

private GoToTrainingG2T getTraining(GoToMeeting meeting, GoToError error) {
    try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
        GoToOrganizer organizer = meeting.getOrganizer();
        String url = gotoTrainingUrl + "/organizers/" + organizer.getOrganizerKey() + "/trainings/" + meeting.getMeetingKey();
        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());
            GoToTrainingG2T trainingVo = GoToJsonUtil.parseTraining(content);
            return trainingVo;
        } else {
            logGoToError("getTraining", 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) GoToTrainingG2T(org.olat.modules.gotomeeting.model.GoToTrainingG2T) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException)

Aggregations

GoToTrainingG2T (org.olat.modules.gotomeeting.model.GoToTrainingG2T)4 IOException (java.io.IOException)2 ParseException (java.text.ParseException)2 Date (java.util.Date)2 HttpResponse (org.apache.http.HttpResponse)2 HttpGet (org.apache.http.client.methods.HttpGet)2 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)2 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2 GoToOrganizer (org.olat.modules.gotomeeting.GoToOrganizer)2