use of fi.otavanopisto.muikku.calendar.CalendarServiceException in project muikku by otavanopisto.
the class GoogleCalendarClient method listEvents.
public List<CalendarEvent> listEvents(java.time.OffsetDateTime minTime, java.time.OffsetDateTime maxTime, String... calendarId) throws CalendarServiceException {
ArrayList<CalendarEvent> result = new ArrayList<>();
for (String calId : calendarId) {
try {
for (Event event : getClient().events().list(calId).setTimeMin(minTime != null ? new DateTime(minTime.toInstant().toEpochMilli()) : null).setTimeMax(maxTime != null ? new DateTime(maxTime.toInstant().toEpochMilli()) : null).execute().getItems()) {
result.add(toMuikkuEvent(calId, event));
logger.log(Level.INFO, event.toPrettyString());
}
} catch (GeneralSecurityException | IOException ex) {
throw new CalendarServiceException(ex);
}
}
return result;
}
use of fi.otavanopisto.muikku.calendar.CalendarServiceException in project muikku by otavanopisto.
the class CalendarRESTService method getEvents.
@GET
@Path("/calendars/{CALID}/events/")
@RESTPermitUnimplemented
public Response getEvents(@PathParam("CALID") Long calendarId, @QueryParam("timeMin") DateTimeParameter timeMin, @QueryParam("timeMax") DateTimeParameter timeMax) {
if (!sessionController.isLoggedIn()) {
return Response.status(Response.Status.FORBIDDEN).build();
}
if (calendarId == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
UserCalendar userCalendar = calendarController.findUserCalendar(calendarId);
if (userCalendar == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
if (!userCalendar.getUserId().equals(sessionController.getLoggedUserEntity().getId())) {
return Response.status(Response.Status.FORBIDDEN).build();
}
try {
List<CalendarEvent> result = new ArrayList<>();
List<fi.otavanopisto.muikku.calendar.CalendarEvent> calendarEvents = calendarController.listCalendarEvents(userCalendar, timeMin != null ? timeMin.getDateTime() : null, timeMax != null ? timeMax.getDateTime() : null);
for (fi.otavanopisto.muikku.calendar.CalendarEvent calendarEvent : calendarEvents) {
result.add(createEventRestModel(userCalendar, calendarEvent));
}
return Response.ok(result).build();
} catch (CalendarServiceException e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
}
}
use of fi.otavanopisto.muikku.calendar.CalendarServiceException in project muikku by otavanopisto.
the class CalendarController method updateCalendarEvent.
public CalendarEvent updateCalendarEvent(UserCalendar userCalendar, CalendarEvent calendarEvent) 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 (StringUtils.isBlank(calendarEvent.getId())) {
throw new CalendarServiceException("Cannot update event without id");
}
return provider.updateEvent(calendarEvent);
}
use of fi.otavanopisto.muikku.calendar.CalendarServiceException in project muikku by otavanopisto.
the class CalendarController method findCalendarEvent.
public fi.otavanopisto.muikku.calendar.CalendarEvent findCalendarEvent(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());
}
return provider.findEvent(calendar, eventId);
}
use of fi.otavanopisto.muikku.calendar.CalendarServiceException in project muikku by otavanopisto.
the class GoogleCalendarClient method listPublicCalendars.
public List<fi.otavanopisto.muikku.calendar.Calendar> listPublicCalendars() throws CalendarServiceException {
try {
Calendar client = getClient();
ArrayList<fi.otavanopisto.muikku.calendar.Calendar> result = new ArrayList<>();
for (CalendarListEntry entry : client.calendarList().list().execute().getItems()) {
result.add(new GoogleCalendar(entry.getSummary(), entry.getDescription(), entry.getId(), isWritable(entry)));
}
return result;
} catch (IOException | GeneralSecurityException ex) {
throw new CalendarServiceException(ex);
}
}
Aggregations