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