use of org.olat.modules.gotomeeting.GoToRegistrant 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.GoToRegistrant in project OpenOLAT by OpenOLAT.
the class GoToRegistrantDAOTest method getRegistrants.
@Test
public void getRegistrants() {
String token = UUID.randomUUID().toString();
Identity trainee = JunitTestHelper.createAndPersistIdentityAsRndUser("trainee-3");
GoToOrganizer organizer = organizerDao.createOrganizer(null, token, token, token, null, null, null, null, 10l, null);
Assert.assertNotNull(organizer);
Date start = new Date();
Date end = new Date();
String trainingKey = Long.toString(CodeHelper.getForeverUniqueID());
GoToMeeting training = meetingDao.createTraining("New training", null, "Very interessant", trainingKey, start, end, organizer, null, null, null);
dbInstance.commit();
// create registrant
String registrantKey = Long.toString(CodeHelper.getForeverUniqueID());
String joinUrl = "http://openolat.com/join/" + registrantKey;
String confirmUrl = "http://openolat.com/confirm/" + registrantKey;
GoToRegistrant registrant = registrantDao.createRegistrant(training, trainee, registrantKey, joinUrl, confirmUrl);
Assert.assertNotNull(registrant);
dbInstance.commit();
// load
List<GoToRegistrant> reloadRegistrants = registrantDao.getRegistrants(trainee, null, null, null);
Assert.assertNotNull(reloadRegistrants);
Assert.assertEquals(1, reloadRegistrants.size());
Assert.assertEquals(registrant, reloadRegistrants.get(0));
}
use of org.olat.modules.gotomeeting.GoToRegistrant in project openolat by klemens.
the class GoToRegistrantDAOTest method createRegistrant.
@Test
public void createRegistrant() {
String token = UUID.randomUUID().toString();
Identity trainee = JunitTestHelper.createAndPersistIdentityAsRndUser("trainee-2");
GoToOrganizer organizer = organizerDao.createOrganizer(null, token, token, token, null, null, null, null, 10l, null);
Assert.assertNotNull(organizer);
Date start = new Date();
Date end = new Date();
String trainingKey = Long.toString(CodeHelper.getForeverUniqueID());
GoToMeeting training = meetingDao.createTraining("New training", null, "Very interessant", trainingKey, start, end, organizer, null, null, null);
dbInstance.commit();
// create registrant
String registrantKey = Long.toString(CodeHelper.getForeverUniqueID());
String joinUrl = "http://openolat.com/join/" + registrantKey;
String confirmUrl = "http://openolat.com/confirm/" + registrantKey;
GoToRegistrant registrant = registrantDao.createRegistrant(training, trainee, registrantKey, joinUrl, confirmUrl);
Assert.assertNotNull(registrant);
dbInstance.commit();
// load
GoToRegistrant reloadRegistrant = registrantDao.getRegistrant(training, trainee);
Assert.assertNotNull(reloadRegistrant);
Assert.assertEquals(registrant, reloadRegistrant);
}
use of org.olat.modules.gotomeeting.GoToRegistrant in project openolat by klemens.
the class GoToRegistrantDAOTest method getRegistrants.
@Test
public void getRegistrants() {
String token = UUID.randomUUID().toString();
Identity trainee = JunitTestHelper.createAndPersistIdentityAsRndUser("trainee-3");
GoToOrganizer organizer = organizerDao.createOrganizer(null, token, token, token, null, null, null, null, 10l, null);
Assert.assertNotNull(organizer);
Date start = new Date();
Date end = new Date();
String trainingKey = Long.toString(CodeHelper.getForeverUniqueID());
GoToMeeting training = meetingDao.createTraining("New training", null, "Very interessant", trainingKey, start, end, organizer, null, null, null);
dbInstance.commit();
// create registrant
String registrantKey = Long.toString(CodeHelper.getForeverUniqueID());
String joinUrl = "http://openolat.com/join/" + registrantKey;
String confirmUrl = "http://openolat.com/confirm/" + registrantKey;
GoToRegistrant registrant = registrantDao.createRegistrant(training, trainee, registrantKey, joinUrl, confirmUrl);
Assert.assertNotNull(registrant);
dbInstance.commit();
// load
List<GoToRegistrant> reloadRegistrants = registrantDao.getRegistrants(trainee, null, null, null);
Assert.assertNotNull(reloadRegistrants);
Assert.assertEquals(1, reloadRegistrants.size());
Assert.assertEquals(registrant, reloadRegistrants.get(0));
}
use of org.olat.modules.gotomeeting.GoToRegistrant in project OpenOLAT by OpenOLAT.
the class GoToRegistrantDAOTest method createRegistrant.
@Test
public void createRegistrant() {
String token = UUID.randomUUID().toString();
Identity trainee = JunitTestHelper.createAndPersistIdentityAsRndUser("trainee-2");
GoToOrganizer organizer = organizerDao.createOrganizer(null, token, token, token, null, null, null, null, 10l, null);
Assert.assertNotNull(organizer);
Date start = new Date();
Date end = new Date();
String trainingKey = Long.toString(CodeHelper.getForeverUniqueID());
GoToMeeting training = meetingDao.createTraining("New training", null, "Very interessant", trainingKey, start, end, organizer, null, null, null);
dbInstance.commit();
// create registrant
String registrantKey = Long.toString(CodeHelper.getForeverUniqueID());
String joinUrl = "http://openolat.com/join/" + registrantKey;
String confirmUrl = "http://openolat.com/confirm/" + registrantKey;
GoToRegistrant registrant = registrantDao.createRegistrant(training, trainee, registrantKey, joinUrl, confirmUrl);
Assert.assertNotNull(registrant);
dbInstance.commit();
// load
GoToRegistrant reloadRegistrant = registrantDao.getRegistrant(training, trainee);
Assert.assertNotNull(reloadRegistrant);
Assert.assertEquals(registrant, reloadRegistrant);
}
Aggregations