Search in sources :

Example 36 with GoToOrganizer

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

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);
    }
}
Also used : GoToOrganizer(org.olat.modules.gotomeeting.GoToOrganizer) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) StringEntity(org.apache.http.entity.StringEntity) HttpResponse(org.apache.http.HttpResponse) HttpPut(org.apache.http.client.methods.HttpPut) IOException(java.io.IOException)

Example 37 with GoToOrganizer

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

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);
    }
}
Also used : GoToOrganizer(org.olat.modules.gotomeeting.GoToOrganizer) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) StringEntity(org.apache.http.entity.StringEntity) HttpResponse(org.apache.http.HttpResponse) HttpPut(org.apache.http.client.methods.HttpPut) IOException(java.io.IOException)

Example 38 with GoToOrganizer

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

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;
    }
}
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) IOException(java.io.IOException)

Example 39 with GoToOrganizer

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

the class GoToTrainingWebService method saveTraining.

private Response saveTraining(GoToTrainingVO training) {
    try {
        GoToMeeting meeting = null;
        GoToError error = new GoToError();
        if (training.getKey() == null) {
            boolean organizerFound = false;
            List<GoToOrganizer> organizers = meetingManager.getSystemOrganizers();
            for (GoToOrganizer organizer : organizers) {
                boolean available = meetingManager.checkOrganizerAvailability(organizer, training.getStart(), training.getEnd());
                if (available) {
                    meeting = meetingManager.scheduleTraining(organizer, training.getName(), training.getExternalId(), "-", training.getStart(), training.getEnd(), entry, subIdentifier, null, error);
                    organizerFound = true;
                    if (!error.hasError()) {
                        break;
                    }
                }
            }
            if (!organizerFound) {
                error.setError(GoToErrors.OrganizerOverlap);
            }
        } else {
            meeting = meetingManager.getMeetingByExternalId(training.getExternalId());
            if (meeting == null) {
                List<GoToOrganizer> organizers = meetingManager.getSystemOrganizers();
                for (GoToOrganizer organizer : organizers) {
                    meeting = meetingManager.scheduleTraining(organizer, training.getName(), training.getExternalId(), "-", training.getStart(), training.getEnd(), entry, subIdentifier, null, error);
                    if (!error.hasError()) {
                        break;
                    }
                }
            } else {
                meetingManager.updateTraining(meeting, training.getName(), "-", training.getStart(), training.getEnd(), error);
            }
        }
        Response response;
        if (error.hasError()) {
            response = handleGoToTrainingError(error);
        } else if (meeting == null) {
            response = handleUnexpectedException();
        } else {
            response = Response.ok(new GoToTrainingVO(meeting)).build();
        }
        return response;
    } catch (Exception e) {
        log.error("", e);
        return handleUnexpectedException();
    }
}
Also used : GoToOrganizer(org.olat.modules.gotomeeting.GoToOrganizer) Response(javax.ws.rs.core.Response) GoToError(org.olat.modules.gotomeeting.model.GoToError) GoToMeeting(org.olat.modules.gotomeeting.GoToMeeting)

Example 40 with GoToOrganizer

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

the class EditTrainingController method validateFormLogic.

@Override
protected boolean validateFormLogic(UserRequest ureq) {
    boolean allOk = true;
    if (meeting == null || meeting.getOrganizer() == null) {
        organizersEl.clearError();
        if (!organizersEl.isOneSelected()) {
            organizersEl.setErrorKey("form.mandatory.hover", null);
            allOk &= false;
        } else {
            Date start = startDateEl.getDate();
            Date end = endDateEl.getDate();
            String selectedKeyStr = organizersEl.getSelectedKey();
            int selectedIndex = Integer.parseInt(selectedKeyStr);
            GoToOrganizer organizer = availablesOrganizers.get(selectedIndex);
            if (start != null && end != null && organizer != null) {
                if (!meetingManager.checkOrganizerAvailability(organizer, start, end)) {
                    organizersEl.setErrorKey("error.organizer.overbooked", null);
                    allOk &= false;
                }
            }
        }
    }
    nameEl.clearError();
    if (!StringHelper.containsNonWhitespace(nameEl.getValue())) {
        nameEl.setErrorKey("form.mandatory.hover", null);
        allOk &= false;
    }
    startDateEl.clearError();
    if (startDateEl.getDate() == null) {
        startDateEl.setErrorKey("form.mandatory.hover", null);
        allOk &= false;
    }
    endDateEl.clearError();
    if (endDateEl.getDate() == null) {
        endDateEl.setErrorKey("form.mandatory.hover", null);
        allOk &= false;
    }
    if (startDateEl.getDate() != null && endDateEl.getDate() != null) {
        Date start = startDateEl.getDate();
        Date end = endDateEl.getDate();
        if (start.compareTo(end) >= 0) {
            startDateEl.setErrorKey("error.start.after.end", null);
        }
    }
    return allOk & super.validateFormLogic(ureq);
}
Also used : GoToOrganizer(org.olat.modules.gotomeeting.GoToOrganizer) Date(java.util.Date)

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