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