use of fi.otavanopisto.muikku.calendar.CalendarServiceException in project muikku by otavanopisto.
the class GoogleCalendarClient method createCalendar.
public fi.otavanopisto.muikku.calendar.Calendar createCalendar(String summary, String description) throws CalendarServiceException {
com.google.api.services.calendar.model.Calendar calendar = new com.google.api.services.calendar.model.Calendar();
calendar.setSummary(summary);
calendar.setDescription(description);
try {
calendar = getClient().calendars().insert(calendar).execute();
} catch (IOException | GeneralSecurityException ex) {
throw new CalendarServiceException(ex);
}
return new GoogleCalendar(summary, description, calendar.getId(), true);
}
use of fi.otavanopisto.muikku.calendar.CalendarServiceException in project muikku by otavanopisto.
the class GoogleCalendarLoginListener method onLogin.
public void onLogin(@Observes LoginEvent event) {
UserEntity userEntity = userEntityController.findUserEntityById(event.getUserEntityId());
if (userEntity != null) {
UserCalendar userCalendar = calendarController.findUserCalendarByUserAndProvider(userEntity, "google");
if (userCalendar == null) {
logger.info("User does not have a calendar, creating one");
try {
userCalendar = calendarController.createCalendar(userEntity, "google", CALENDAR_SUMMARY, CALENDAR_DESCRIPTION, Boolean.TRUE);
for (String email : userEmailEntityController.getUserEmailAddresses(event.getUserIdentifier())) {
try {
logger.info(String.format("Sharing Google calendar with %s", email));
googleCalendarClient.insertCalendarUserAclRule(userCalendar.getCalendarId(), email, "owner");
} catch (CalendarServiceException e) {
logger.log(Level.WARNING, String.format("Could not share calendar with %s", email), e);
}
}
} catch (CalendarServiceException e) {
logger.log(Level.SEVERE, "Failed to create new Google calendar", e);
}
}
}
}
use of fi.otavanopisto.muikku.calendar.CalendarServiceException in project muikku by otavanopisto.
the class CalendarController method createCalendarEvent.
public CalendarEvent createCalendarEvent(UserCalendar userCalendar, String summary, String description, CalendarEventStatus status, Date start, TimeZone startTimeZone, Date end, TimeZone endTimeZone, List<CalendarEventAttendee> attendees, List<CalendarEventReminder> reminders, String recurrence, boolean allDay, Map<String, String> extendedProperties) throws CalendarServiceException {
CalendarServiceProvider provider = getCalendarServiceProvider(userCalendar.getCalendarProvider());
Calendar calendar = provider.findCalendar(userCalendar.getCalendarId());
if (calendar == null) {
throw new CalendarServiceException("Could not find calendar for user calendar #" + userCalendar.getId());
}
return provider.createEvent(calendar.getId(), summary, description, status, attendees, new DefaultCalendarEventTemporalField(start, startTimeZone), new DefaultCalendarEventTemporalField(end, endTimeZone), reminders, recurrence, allDay);
}
use of fi.otavanopisto.muikku.calendar.CalendarServiceException in project muikku by otavanopisto.
the class CalendarController method listCalendarEvents.
public List<fi.otavanopisto.muikku.calendar.CalendarEvent> listCalendarEvents(UserCalendar userCalendar, OffsetDateTime timeMin, OffsetDateTime timeMax) throws CalendarServiceException {
CalendarServiceProvider provider = getCalendarServiceProvider(userCalendar.getCalendarProvider());
Calendar calendar = provider.findCalendar(userCalendar.getCalendarId());
if (calendar == null) {
throw new CalendarServiceException("Could not find calendar for user calendar #" + userCalendar.getId());
}
if (timeMin != null || timeMax != null) {
return provider.listEvents(timeMin, timeMax, calendar.getId());
} else {
return provider.listEvents(calendar.getId());
}
}
use of fi.otavanopisto.muikku.calendar.CalendarServiceException in project muikku by otavanopisto.
the class CalendarController method deleteCalendarEvent.
public void deleteCalendarEvent(UserCalendar userCalendar, String eventId) throws CalendarServiceException {
CalendarServiceProvider provider = getCalendarServiceProvider(userCalendar.getCalendarProvider());
Calendar calendar = provider.findCalendar(userCalendar.getCalendarId());
if (calendar == null) {
throw new CalendarServiceException("Could not find calendar for user calendar #" + userCalendar.getId());
}
provider.deleteEvent(calendar, eventId);
}
Aggregations