use of fi.otavanopisto.muikku.plugins.calendar.rest.model.CalendarEvent 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.plugins.calendar.rest.model.CalendarEvent in project muikku by otavanopisto.
the class CalendarRESTService method createEventRestModel.
private CalendarEvent createEventRestModel(UserCalendar userCalendar, fi.otavanopisto.muikku.calendar.CalendarEvent calendarEvent) {
List<CalendarEventAttendee> attendees = new ArrayList<>();
List<CalendarEventReminder> reminders = new ArrayList<>();
if (calendarEvent.getAttendees() != null) {
for (fi.otavanopisto.muikku.calendar.CalendarEventAttendee calendarEventAttendee : calendarEvent.getAttendees()) {
attendees.add(new CalendarEventAttendee(calendarEventAttendee.getEmail(), calendarEventAttendee.getDisplayName(), calendarEventAttendee.getStatus(), calendarEventAttendee.getComment()));
}
}
if (calendarEvent.getEventReminders() != null) {
for (fi.otavanopisto.muikku.calendar.CalendarEventReminder calendarEventReminder : calendarEvent.getEventReminders()) {
reminders.add(new CalendarEventReminder(calendarEventReminder.getType(), calendarEventReminder.getMinutesBefore()));
}
}
String recurrence = calendarEvent.getRecurrence();
String location = calendarEvent.getLocation() != null ? calendarEvent.getLocation().getLocation() : null;
String videoCallLink = calendarEvent.getLocation() != null ? calendarEvent.getLocation().getVideoCallLink() : null;
BigDecimal longitude = calendarEvent.getLocation() != null ? calendarEvent.getLocation().getLongitude() : null;
BigDecimal latitude = calendarEvent.getLocation() != null ? calendarEvent.getLocation().getLatitude() : null;
return new CalendarEvent(userCalendar.getId(), calendarEvent.getId(), calendarEvent.getSummary(), calendarEvent.getDescription(), calendarEvent.getUrl(), location, videoCallLink, longitude, latitude, calendarEvent.getStatus(), calendarEvent.getStart().getDateTime(), calendarEvent.getStart().getTimeZone(), calendarEvent.getEnd().getDateTime(), calendarEvent.getEnd().getTimeZone(), calendarEvent.isAllDay(), calendarEvent.getCreated(), calendarEvent.getUpdated(), calendarEvent.getExtendedProperties(), attendees, reminders, recurrence);
}
Aggregations