use of fi.otavanopisto.muikku.calendar.DefaultCalendarEventLocation 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);
}
use of fi.otavanopisto.muikku.calendar.DefaultCalendarEventLocation 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();
}
}
Aggregations