Search in sources :

Example 1 with DefaultCalendarEventTemporalField

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

Example 2 with DefaultCalendarEventTemporalField

use of fi.otavanopisto.muikku.calendar.DefaultCalendarEventTemporalField 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

CalendarServiceException (fi.otavanopisto.muikku.calendar.CalendarServiceException)2 DefaultCalendarEventTemporalField (fi.otavanopisto.muikku.calendar.DefaultCalendarEventTemporalField)2 UserCalendar (fi.otavanopisto.muikku.plugins.calendar.model.UserCalendar)2 Calendar (fi.otavanopisto.muikku.calendar.Calendar)1 CalendarServiceProvider (fi.otavanopisto.muikku.calendar.CalendarServiceProvider)1 DefaultCalendarEvent (fi.otavanopisto.muikku.calendar.DefaultCalendarEvent)1 DefaultCalendarEventAttendee (fi.otavanopisto.muikku.calendar.DefaultCalendarEventAttendee)1 DefaultCalendarEventLocation (fi.otavanopisto.muikku.calendar.DefaultCalendarEventLocation)1 DefaultCalendarEventReminder (fi.otavanopisto.muikku.calendar.DefaultCalendarEventReminder)1 CalendarEventAttendee (fi.otavanopisto.muikku.plugins.calendar.rest.model.CalendarEventAttendee)1 CalendarEventReminder (fi.otavanopisto.muikku.plugins.calendar.rest.model.CalendarEventReminder)1 RESTPermitUnimplemented (fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1