Search in sources :

Example 6 with GoToOrganizer

use of org.olat.modules.gotomeeting.GoToOrganizer 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 7 with GoToOrganizer

use of org.olat.modules.gotomeeting.GoToOrganizer in project OpenOLAT by OpenOLAT.

the class GoToMeetingManagerImpl method getRecordings.

@Override
public List<GoToRecordingsG2T> getRecordings(GoToMeeting meeting, GoToError error) {
    try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
        GoToOrganizer organizer = meeting.getOrganizer();
        String url = gotoTrainingUrl + "/trainings/" + meeting.getMeetingKey() + "/recordings";
        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());
            List<GoToRecordingsG2T> recordings = GoToJsonUtil.parseRecordings(content);
            return recordings;
        } else {
            logGoToError("getRecordings", 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) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) GoToRecordingsG2T(org.olat.modules.gotomeeting.model.GoToRecordingsG2T) IOException(java.io.IOException)

Example 8 with GoToOrganizer

use of org.olat.modules.gotomeeting.GoToOrganizer in project OpenOLAT by OpenOLAT.

the class GoToMeetingDAOTest method getMeetingsOverlap.

/**
 * Check different overlap scenario
 */
@Test
public void getMeetingsOverlap() {
    RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
    String username = UUID.randomUUID().toString();
    String accessToken = UUID.randomUUID().toString();
    String organizerKey = UUID.randomUUID().toString();
    GoToOrganizer organizer = organizerDao.createOrganizer(null, username, accessToken, organizerKey, "Michael", "Wolgemut", null, null, 10l, null);
    Assert.assertNotNull(organizer);
    Calendar cal = Calendar.getInstance();
    cal.set(2016, 8, 12, 12, 0, 0);
    cal.set(Calendar.MILLISECOND, 0);
    Date start = cal.getTime();
    cal.set(2016, 8, 12, 18, 0, 0);
    Date end = cal.getTime();
    String trainingKey = Long.toString(CodeHelper.getForeverUniqueID());
    GoToMeeting training = meetingDao.createTraining("New training", null, "Very interessant", trainingKey, start, end, organizer, entry, "d9914", null);
    dbInstance.commit();
    Assert.assertNotNull(training);
    // check organizer availability (same date)
    List<GoToMeeting> overlaps = meetingDao.getMeetingsOverlap(GoToType.training, organizer, start, end);
    Assert.assertNotNull(overlaps);
    Assert.assertEquals(1, overlaps.size());
    // check organizer availability (end overlap)
    cal.set(2016, 8, 12, 10, 0, 0);
    Date start_1 = cal.getTime();
    cal.set(2016, 8, 12, 14, 0, 0);
    Date end_1 = cal.getTime();
    List<GoToMeeting> overlaps_1 = meetingDao.getMeetingsOverlap(GoToType.training, organizer, start_1, end_1);
    Assert.assertEquals(1, overlaps_1.size());
    // check organizer availability (start overlap)
    cal.set(2016, 8, 12, 14, 0, 0);
    Date start_2 = cal.getTime();
    cal.set(2016, 8, 12, 20, 0, 0);
    Date end_2 = cal.getTime();
    List<GoToMeeting> overlaps_2 = meetingDao.getMeetingsOverlap(GoToType.training, organizer, start_2, end_2);
    Assert.assertEquals(1, overlaps_2.size());
    // check organizer availability (within)
    cal.set(2016, 8, 12, 14, 0, 0);
    Date start_3 = cal.getTime();
    cal.set(2016, 8, 12, 15, 0, 0);
    Date end_3 = cal.getTime();
    List<GoToMeeting> overlaps_3 = meetingDao.getMeetingsOverlap(GoToType.training, organizer, start_3, end_3);
    Assert.assertNotNull(overlaps_3);
    Assert.assertEquals(1, overlaps_3.size());
    // check organizer availability (start before, end after)
    cal.set(2016, 8, 12, 10, 0, 0);
    Date start_4 = cal.getTime();
    cal.set(2016, 8, 12, 22, 0, 0);
    Date end_4 = cal.getTime();
    List<GoToMeeting> overlaps_4 = meetingDao.getMeetingsOverlap(GoToType.training, organizer, start_4, end_4);
    Assert.assertNotNull(overlaps_4);
    Assert.assertEquals(1, overlaps_4.size());
    // check organizer availability (in past)
    cal.set(2016, 8, 12, 9, 0, 0);
    Date start_5 = cal.getTime();
    cal.set(2016, 8, 12, 11, 0, 0);
    Date end_5 = cal.getTime();
    List<GoToMeeting> overlaps_5 = meetingDao.getMeetingsOverlap(GoToType.training, organizer, start_5, end_5);
    Assert.assertEquals(0, overlaps_5.size());
    // check organizer availability (in future)
    cal.set(2016, 8, 12, 20, 0, 0);
    Date start_6 = cal.getTime();
    cal.set(2016, 8, 12, 21, 0, 0);
    Date end_6 = cal.getTime();
    List<GoToMeeting> overlaps_6 = meetingDao.getMeetingsOverlap(GoToType.training, organizer, start_6, end_6);
    Assert.assertEquals(0, overlaps_6.size());
}
Also used : GoToOrganizer(org.olat.modules.gotomeeting.GoToOrganizer) GoToMeeting(org.olat.modules.gotomeeting.GoToMeeting) Calendar(java.util.Calendar) RepositoryEntry(org.olat.repository.RepositoryEntry) Date(java.util.Date) Test(org.junit.Test)

Example 9 with GoToOrganizer

use of org.olat.modules.gotomeeting.GoToOrganizer in project OpenOLAT by OpenOLAT.

the class GoToMeetingDAOTest method getMeetings_withRepositoryEntry.

@Test
public void getMeetings_withRepositoryEntry() {
    RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
    String username = UUID.randomUUID().toString();
    String accessToken = UUID.randomUUID().toString();
    String organizerKey = UUID.randomUUID().toString();
    GoToOrganizer organizer = organizerDao.createOrganizer(null, username, accessToken, organizerKey, "Michael", "Wolgemut", 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, entry, "d9912", null);
    dbInstance.commit();
    Assert.assertNotNull(training);
    List<GoToMeeting> meetings = meetingDao.getMeetings(GoToType.training, entry, "d9912", null);
    Assert.assertNotNull(meetings);
    Assert.assertEquals(1, meetings.size());
    Assert.assertTrue(meetings.contains(training));
}
Also used : GoToOrganizer(org.olat.modules.gotomeeting.GoToOrganizer) GoToMeeting(org.olat.modules.gotomeeting.GoToMeeting) RepositoryEntry(org.olat.repository.RepositoryEntry) Date(java.util.Date) Test(org.junit.Test)

Example 10 with GoToOrganizer

use of org.olat.modules.gotomeeting.GoToOrganizer in project OpenOLAT by OpenOLAT.

the class GoToMeetingDAOTest method loadMeetingByKey.

@Test
public void loadMeetingByKey() {
    RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
    String username = UUID.randomUUID().toString();
    String accessToken = UUID.randomUUID().toString();
    String organizerKey = UUID.randomUUID().toString();
    GoToOrganizer organizer = organizerDao.createOrganizer(null, username, accessToken, organizerKey, "Levinus", "Memminger", 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("Training by key", null, "Load training by key", trainingKey, start, end, organizer, entry, "d9915", null);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(training);
    GoToMeeting reloadedTraining = meetingDao.loadMeetingByKey(training.getKey());
    Assert.assertNotNull(reloadedTraining);
    Assert.assertEquals(training, reloadedTraining);
}
Also used : GoToOrganizer(org.olat.modules.gotomeeting.GoToOrganizer) GoToMeeting(org.olat.modules.gotomeeting.GoToMeeting) RepositoryEntry(org.olat.repository.RepositoryEntry) Date(java.util.Date) Test(org.junit.Test)

Aggregations

GoToOrganizer (org.olat.modules.gotomeeting.GoToOrganizer)60 Test (org.junit.Test)28 Date (java.util.Date)22 GoToMeeting (org.olat.modules.gotomeeting.GoToMeeting)18 IOException (java.io.IOException)16 HttpResponse (org.apache.http.HttpResponse)16 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)16 RepositoryEntry (org.olat.repository.RepositoryEntry)10 HttpGet (org.apache.http.client.methods.HttpGet)8 Identity (org.olat.core.id.Identity)8 StringEntity (org.apache.http.entity.StringEntity)6 GoToRegistrant (org.olat.modules.gotomeeting.GoToRegistrant)6 HttpPut (org.apache.http.client.methods.HttpPut)4 GoToError (org.olat.modules.gotomeeting.model.GoToError)4 GoToErrorG2T (org.olat.modules.gotomeeting.model.GoToErrorG2T)4 GoToRegistrantG2T (org.olat.modules.gotomeeting.model.GoToRegistrantG2T)4 Calendar (java.util.Calendar)2 Response (javax.ws.rs.core.Response)2 HttpDelete (org.apache.http.client.methods.HttpDelete)2 HttpPost (org.apache.http.client.methods.HttpPost)2