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;
}
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);
}
}
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;
}
}
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;
}
}
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);
}
}
Aggregations