Search in sources :

Example 1 with CalendarServiceException

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;
}
Also used : CalendarServiceException(fi.otavanopisto.muikku.calendar.CalendarServiceException) GeneralSecurityException(java.security.GeneralSecurityException) ArrayList(java.util.ArrayList) DefaultCalendarEvent(fi.otavanopisto.muikku.calendar.DefaultCalendarEvent) CalendarEvent(fi.otavanopisto.muikku.calendar.CalendarEvent) Event(com.google.api.services.calendar.model.Event) DefaultCalendarEvent(fi.otavanopisto.muikku.calendar.DefaultCalendarEvent) CalendarEvent(fi.otavanopisto.muikku.calendar.CalendarEvent) IOException(java.io.IOException) DateTime(com.google.api.client.util.DateTime)

Example 2 with CalendarServiceException

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();
    }
}
Also used : CalendarServiceException(fi.otavanopisto.muikku.calendar.CalendarServiceException) ArrayList(java.util.ArrayList) DefaultCalendarEvent(fi.otavanopisto.muikku.calendar.DefaultCalendarEvent) CalendarEvent(fi.otavanopisto.muikku.plugins.calendar.rest.model.CalendarEvent) UserCalendar(fi.otavanopisto.muikku.plugins.calendar.model.UserCalendar) Path(javax.ws.rs.Path) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented) GET(javax.ws.rs.GET)

Example 3 with CalendarServiceException

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);
}
Also used : CalendarServiceException(fi.otavanopisto.muikku.calendar.CalendarServiceException) CalendarServiceProvider(fi.otavanopisto.muikku.calendar.CalendarServiceProvider) Calendar(fi.otavanopisto.muikku.calendar.Calendar) UserCalendar(fi.otavanopisto.muikku.plugins.calendar.model.UserCalendar)

Example 4 with CalendarServiceException

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);
}
Also used : CalendarServiceException(fi.otavanopisto.muikku.calendar.CalendarServiceException) CalendarServiceProvider(fi.otavanopisto.muikku.calendar.CalendarServiceProvider) Calendar(fi.otavanopisto.muikku.calendar.Calendar) UserCalendar(fi.otavanopisto.muikku.plugins.calendar.model.UserCalendar)

Example 5 with CalendarServiceException

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);
    }
}
Also used : CalendarServiceException(fi.otavanopisto.muikku.calendar.CalendarServiceException) CalendarListEntry(com.google.api.services.calendar.model.CalendarListEntry) GoogleCalendar(fi.otavanopisto.muikku.plugins.googlecalendar.model.GoogleCalendar) Calendar(com.google.api.services.calendar.Calendar) GoogleCalendar(fi.otavanopisto.muikku.plugins.googlecalendar.model.GoogleCalendar) GeneralSecurityException(java.security.GeneralSecurityException) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Aggregations

CalendarServiceException (fi.otavanopisto.muikku.calendar.CalendarServiceException)13 UserCalendar (fi.otavanopisto.muikku.plugins.calendar.model.UserCalendar)10 Calendar (fi.otavanopisto.muikku.calendar.Calendar)6 CalendarServiceProvider (fi.otavanopisto.muikku.calendar.CalendarServiceProvider)6 DefaultCalendarEvent (fi.otavanopisto.muikku.calendar.DefaultCalendarEvent)3 RESTPermitUnimplemented (fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)3 IOException (java.io.IOException)3 GeneralSecurityException (java.security.GeneralSecurityException)3 ArrayList (java.util.ArrayList)3 Path (javax.ws.rs.Path)3 Calendar (com.google.api.services.calendar.Calendar)2 DefaultCalendarEventAttendee (fi.otavanopisto.muikku.calendar.DefaultCalendarEventAttendee)2 DefaultCalendarEventReminder (fi.otavanopisto.muikku.calendar.DefaultCalendarEventReminder)2 DefaultCalendarEventTemporalField (fi.otavanopisto.muikku.calendar.DefaultCalendarEventTemporalField)2 CalendarEventAttendee (fi.otavanopisto.muikku.plugins.calendar.rest.model.CalendarEventAttendee)2 CalendarEventReminder (fi.otavanopisto.muikku.plugins.calendar.rest.model.CalendarEventReminder)2 GoogleCalendar (fi.otavanopisto.muikku.plugins.googlecalendar.model.GoogleCalendar)2 DateTime (com.google.api.client.util.DateTime)1 CalendarListEntry (com.google.api.services.calendar.model.CalendarListEntry)1 Event (com.google.api.services.calendar.model.Event)1