Search in sources :

Example 1 with DefaultCalendarEvent

use of fi.otavanopisto.muikku.calendar.DefaultCalendarEvent in project muikku by otavanopisto.

the class GoogleCalendarClient method toMuikkuEvent.

private CalendarEvent toMuikkuEvent(String calendarId, Event event) {
    String url = event.getHangoutLink();
    CalendarEventLocation location = new DefaultCalendarEventLocation(event.getLocation(), null, null, null);
    CalendarEventStatus status = CalendarEventStatus.valueOf(event.getStatus().toUpperCase(Locale.ROOT));
    // TODO: attendees
    List<CalendarEventAttendee> attendees = null;
    CalendarEventUser organizer = new GoogleCalendarEventUser(event.getOrganizer().getDisplayName(), event.getOrganizer().getEmail());
    CalendarEventTemporalField start = Convert.toCalendarEventTemporalField(event.getStart());
    CalendarEventTemporalField end = Convert.toCalendarEventTemporalField(event.getEnd());
    boolean allDay = event.getStart().getDate() != null;
    Map<String, String> extendedProperties = Collections.emptyMap();
    // TODO: reminders
    List<CalendarEventReminder> reminders = null;
    String recurrence = null;
    if (event.getRecurrence() != null && !event.getRecurrence().isEmpty()) {
        List<String> rrules = new ArrayList<String>();
        for (String rule : event.getRecurrence()) {
            if (StringUtils.startsWith(rule, "RRULE:")) {
                rrules.add(rule);
            } else {
                logger.warning(String.format("Ignoring unsupported recurrence rule %s from Google", rule));
            }
        }
        if (rrules.isEmpty()) {
            logger.warning("Could not parse recurring event recurrene because all rules were in unsupported formats");
        } else {
            if (rrules.size() > 1) {
                logger.warning(String.format("More than one recurrence rule defined. Ignoring %d rules", rrules.size() - 1));
            }
            recurrence = StringUtils.substring(rrules.get(0), 6);
        }
    }
    return new DefaultCalendarEvent(event.getId(), calendarId, "google", event.getSummary(), event.getDescription(), url, location, status, attendees, organizer, start, end, allDay, Convert.toDate(event.getCreated()), Convert.toDate(event.getUpdated()), extendedProperties, reminders, recurrence);
}
Also used : DefaultCalendarEventLocation(fi.otavanopisto.muikku.calendar.DefaultCalendarEventLocation) CalendarEventLocation(fi.otavanopisto.muikku.calendar.CalendarEventLocation) CalendarEventTemporalField(fi.otavanopisto.muikku.calendar.CalendarEventTemporalField) DefaultCalendarEventLocation(fi.otavanopisto.muikku.calendar.DefaultCalendarEventLocation) ArrayList(java.util.ArrayList) GoogleCalendarEventUser(fi.otavanopisto.muikku.plugins.googlecalendar.model.GoogleCalendarEventUser) CalendarEventStatus(fi.otavanopisto.muikku.calendar.CalendarEventStatus) CalendarEventUser(fi.otavanopisto.muikku.calendar.CalendarEventUser) GoogleCalendarEventUser(fi.otavanopisto.muikku.plugins.googlecalendar.model.GoogleCalendarEventUser) CalendarEventAttendee(fi.otavanopisto.muikku.calendar.CalendarEventAttendee) CalendarEventReminder(fi.otavanopisto.muikku.calendar.CalendarEventReminder) DefaultCalendarEvent(fi.otavanopisto.muikku.calendar.DefaultCalendarEvent)

Example 2 with DefaultCalendarEvent

use of fi.otavanopisto.muikku.calendar.DefaultCalendarEvent in project muikku by otavanopisto.

the class CalendarRESTService method updateEvent.

@PUT
@Path("/calendars/{CALID}/events/{EVTID}")
@RESTPermitUnimplemented
public Response updateEvent(@PathParam("CALID") Long calendarId, @PathParam("EVTID") String eventId, CalendarEvent event) {
    if (!sessionController.isLoggedIn()) {
        return Response.status(Response.Status.FORBIDDEN).build();
    }
    if (calendarId == null || StringUtils.isBlank(eventId)) {
        return Response.status(Response.Status.NOT_FOUND).build();
    }
    if (event == null) {
        return Response.status(Response.Status.BAD_REQUEST).build();
    }
    if (StringUtils.isBlank(event.getSummary())) {
        return Response.status(Response.Status.BAD_REQUEST).entity("Summary is mandatory").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 {
        fi.otavanopisto.muikku.calendar.CalendarEvent originalCalendarEvent = calendarController.findCalendarEvent(userCalendar, eventId);
        if (originalCalendarEvent == null) {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
        List<fi.otavanopisto.muikku.calendar.CalendarEventAttendee> attendees = createEventAttendeeListFromRestModel(event.getAttendees());
        List<fi.otavanopisto.muikku.calendar.CalendarEventReminder> reminders = createEventReminderListFromRestModel(event.getReminders());
        fi.otavanopisto.muikku.calendar.CalendarEventTemporalField start = new DefaultCalendarEventTemporalField(event.getStart(), event.getStartTimeZone());
        fi.otavanopisto.muikku.calendar.CalendarEventTemporalField end = new DefaultCalendarEventTemporalField(event.getEnd(), event.getEndTimeZone());
        fi.otavanopisto.muikku.calendar.CalendarEventLocation calendarEventLocation = new DefaultCalendarEventLocation(event.getLocation(), event.getVideoCallLink(), event.getLongitude(), event.getLongitude());
        fi.otavanopisto.muikku.calendar.CalendarEvent calendarEvent = new DefaultCalendarEvent(originalCalendarEvent.getId(), originalCalendarEvent.getCalendarId(), originalCalendarEvent.getServiceProvider(), event.getSummary(), event.getDescription(), event.getUrl(), calendarEventLocation, event.getStatus(), attendees, originalCalendarEvent.getOrganizer(), start, end, event.isAllDay(), null, null, event.getExtendedProperties(), reminders, event.getRecurrence());
        calendarController.updateCalendarEvent(userCalendar, calendarEvent);
        return Response.noContent().build();
    } catch (CalendarServiceException e) {
        e.printStackTrace();
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
    }
}
Also used : DefaultCalendarEventLocation(fi.otavanopisto.muikku.calendar.DefaultCalendarEventLocation) UserCalendar(fi.otavanopisto.muikku.plugins.calendar.model.UserCalendar) CalendarEventAttendee(fi.otavanopisto.muikku.plugins.calendar.rest.model.CalendarEventAttendee) DefaultCalendarEventAttendee(fi.otavanopisto.muikku.calendar.DefaultCalendarEventAttendee) CalendarServiceException(fi.otavanopisto.muikku.calendar.CalendarServiceException) DefaultCalendarEventTemporalField(fi.otavanopisto.muikku.calendar.DefaultCalendarEventTemporalField) CalendarEventReminder(fi.otavanopisto.muikku.plugins.calendar.rest.model.CalendarEventReminder) DefaultCalendarEventReminder(fi.otavanopisto.muikku.calendar.DefaultCalendarEventReminder) DefaultCalendarEvent(fi.otavanopisto.muikku.calendar.DefaultCalendarEvent) Path(javax.ws.rs.Path) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented) PUT(javax.ws.rs.PUT)

Aggregations

DefaultCalendarEvent (fi.otavanopisto.muikku.calendar.DefaultCalendarEvent)2 DefaultCalendarEventLocation (fi.otavanopisto.muikku.calendar.DefaultCalendarEventLocation)2 CalendarEventAttendee (fi.otavanopisto.muikku.calendar.CalendarEventAttendee)1 CalendarEventLocation (fi.otavanopisto.muikku.calendar.CalendarEventLocation)1 CalendarEventReminder (fi.otavanopisto.muikku.calendar.CalendarEventReminder)1 CalendarEventStatus (fi.otavanopisto.muikku.calendar.CalendarEventStatus)1 CalendarEventTemporalField (fi.otavanopisto.muikku.calendar.CalendarEventTemporalField)1 CalendarEventUser (fi.otavanopisto.muikku.calendar.CalendarEventUser)1 CalendarServiceException (fi.otavanopisto.muikku.calendar.CalendarServiceException)1 DefaultCalendarEventAttendee (fi.otavanopisto.muikku.calendar.DefaultCalendarEventAttendee)1 DefaultCalendarEventReminder (fi.otavanopisto.muikku.calendar.DefaultCalendarEventReminder)1 DefaultCalendarEventTemporalField (fi.otavanopisto.muikku.calendar.DefaultCalendarEventTemporalField)1 UserCalendar (fi.otavanopisto.muikku.plugins.calendar.model.UserCalendar)1 CalendarEventAttendee (fi.otavanopisto.muikku.plugins.calendar.rest.model.CalendarEventAttendee)1 CalendarEventReminder (fi.otavanopisto.muikku.plugins.calendar.rest.model.CalendarEventReminder)1 GoogleCalendarEventUser (fi.otavanopisto.muikku.plugins.googlecalendar.model.GoogleCalendarEventUser)1 RESTPermitUnimplemented (fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)1 ArrayList (java.util.ArrayList)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1