Search in sources :

Example 1 with GoToRegistrant

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;
}
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 2 with GoToRegistrant

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));
}
Also used : GoToOrganizer(org.olat.modules.gotomeeting.GoToOrganizer) GoToMeeting(org.olat.modules.gotomeeting.GoToMeeting) GoToRegistrant(org.olat.modules.gotomeeting.GoToRegistrant) Identity(org.olat.core.id.Identity) Date(java.util.Date) Test(org.junit.Test)

Example 3 with GoToRegistrant

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);
}
Also used : GoToOrganizer(org.olat.modules.gotomeeting.GoToOrganizer) GoToMeeting(org.olat.modules.gotomeeting.GoToMeeting) GoToRegistrant(org.olat.modules.gotomeeting.GoToRegistrant) Identity(org.olat.core.id.Identity) Date(java.util.Date) Test(org.junit.Test)

Example 4 with GoToRegistrant

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));
}
Also used : GoToOrganizer(org.olat.modules.gotomeeting.GoToOrganizer) GoToMeeting(org.olat.modules.gotomeeting.GoToMeeting) GoToRegistrant(org.olat.modules.gotomeeting.GoToRegistrant) Identity(org.olat.core.id.Identity) Date(java.util.Date) Test(org.junit.Test)

Example 5 with GoToRegistrant

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);
}
Also used : GoToOrganizer(org.olat.modules.gotomeeting.GoToOrganizer) GoToMeeting(org.olat.modules.gotomeeting.GoToMeeting) GoToRegistrant(org.olat.modules.gotomeeting.GoToRegistrant) Identity(org.olat.core.id.Identity) Date(java.util.Date) Test(org.junit.Test)

Aggregations

GoToOrganizer (org.olat.modules.gotomeeting.GoToOrganizer)6 GoToRegistrant (org.olat.modules.gotomeeting.GoToRegistrant)6 Date (java.util.Date)4 Test (org.junit.Test)4 Identity (org.olat.core.id.Identity)4 GoToMeeting (org.olat.modules.gotomeeting.GoToMeeting)4 IOException (java.io.IOException)2 HttpResponse (org.apache.http.HttpResponse)2 HttpPost (org.apache.http.client.methods.HttpPost)2 StringEntity (org.apache.http.entity.StringEntity)2 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)2 GoToErrorG2T (org.olat.modules.gotomeeting.model.GoToErrorG2T)2 GoToRegistrantG2T (org.olat.modules.gotomeeting.model.GoToRegistrantG2T)2