static Event convertToGoogleCalendarEvent(CalendarEventModel eventModel) { Event event = new Event() .setLocation(eventModel.getLocation()) .setDescription(eventModel.getTitle()) .setSummary(eventModel.getNotes()) .setStart(getEventDateTime(eventModel.getStartTime())) .setEnd(getEventDateTime(eventModel.getEndTime())); if (eventModel.getAttendees() != null) { event.setAttendees(eventModel.getAttendees().stream() .map(GoogleCalendarImporter::transformToEventAttendee) .collect(Collectors.toList())); } return event; }
private static CalendarEventModel convertToCalendarEventModel(String id, Event eventData) { List<EventAttendee> attendees = eventData.getAttendees(); List<String> recurrenceRulesStrings = eventData.getRecurrence(); return new CalendarEventModel( id, eventData.getDescription(), eventData.getSummary(), attendees == null ? null : attendees .stream() .map(GoogleCalendarExporter::transformToModelAttendee) .collect(Collectors.toList()), eventData.getLocation(), getEventTime(eventData.getStart()), getEventTime(eventData.getEnd()), recurrenceRulesStrings == null ? null : getRecurrenceRule(recurrenceRulesStrings)); }
com.google.api.services.calendar.model.Calendar cal = service.calendars().get(calendarData.getCalendarId()).execute(); Event event = new Event(); event.setId(KeyGenerator.generateEventId()); event.setVisibility("public"); event.setSummary(body.getString("summary")); event.setDescription(body.getString("description")); event.setStart(start.setTimeZone(cal.getTimeZone())); event.setEnd(end.setTimeZone(cal.getTimeZone())); event.setColorId(EventColor.fromNameOrHexOrID(body.getString("color")).getId() + ""); event.setLocation(body.getString("location")); event.setRecurrence(Arrays.asList(rr)); ed.setEventId(event.getId()); ed.setEventEnd(event.getEnd().getDateTime().getValue()); respondBody.put("id", confirmed.getId());
public PreEvent(long _guildId, Event e) { guildId = _guildId; eventId = e.getId(); color = EventColor.fromNameOrHexOrID(e.getColorId()); if (e.getRecurrence() != null && e.getRecurrence().size() > 0) { recur = true; recurrence.fromRRule(e.getRecurrence().get(0)); if (e.getSummary() != null) summary = e.getSummary(); if (e.getDescription() != null) description = e.getDescription(); if (e.getLocation() != null) location = e.getLocation(); startDateTime = e.getStart(); endDateTime = e.getEnd(); if (e.getStart().getDateTime() != null) { viewableStartDate = new EventDateTime().setDateTime(new DateTime(TimeUtils.applyTimeZoneOffset(e.getStart().getDateTime().getValue(), cal.getTimeZone()))); viewableEndDate = new EventDateTime().setDateTime(new DateTime(TimeUtils.applyTimeZoneOffset(e.getEnd().getDateTime().getValue(), cal.getTimeZone()))); } else { viewableStartDate = new EventDateTime().setDate(new DateTime(TimeUtils.applyTimeZoneOffset(e.getStart().getDate().getValue(), cal.getTimeZone()))); viewableEndDate = new EventDateTime().setDate(new DateTime(TimeUtils.applyTimeZoneOffset(e.getEnd().getDate().getValue(), cal.getTimeZone())));
if (ObjectHelper.isNotEmpty(event.getSummary())) { model.setTitle(event.getSummary()); if (ObjectHelper.isNotEmpty(event.getDescription())) { model.setDescription(event.getDescription()); if (ObjectHelper.isNotEmpty(event.getAttendees())) { model.setAttendees(getAttendeesString(event.getAttendees())); if (ObjectHelper.isNotEmpty(event.getStart())) { if (event.getStart().getDateTime() != null) { model.setStartDate(dateFormat.format(new Date(event.getStart().getDateTime().getValue()))); model.setStartTime(timeFormat.format(new Date(event.getStart().getDateTime().getValue()))); } else { model.setStartDate(dateFormat.format(new Date(event.getStart().getDate().getValue()))); if (ObjectHelper.isNotEmpty(event.getEnd())) { if (event.getEnd().getDateTime() != null) { model.setEndDate(dateFormat.format(new Date(event.getEnd().getDateTime().getValue()))); model.setEndTime(timeFormat.format(new Date(event.getEnd().getDateTime().getValue()))); } else { model.setEndDate(dateFormat.format(new Date(event.getEnd().getDate().getValue()))); if (ObjectHelper.isNotEmpty(event.getLocation())) { model.setLocation(event.getLocation()); if (ObjectHelper.isNotEmpty(event.getId())) { model.setEventId(event.getId());
private AppointmentDto convertToAppointmentDto(final Event event) { final GoogleAppointmentDto result = new GoogleAppointmentDto(); result.setGoogleId(event.getId()); if (event.getExtendedProperties() != null && event.getExtendedProperties().getPrivate() != null) { result.setExchangeId(event.getExtendedProperties().getPrivate().get(EXT_PROPERTY_EXCHANGE_ID)); result.setLastModified(convertToJodaDateTime(event.getUpdated())); result.setSummary(event.getSummary()); result.setDescription(event.getDescription()); result.setStart(convertToJodaDateTime(event.getStart())); result.setEnd(convertToJodaDateTime(event.getEnd())); if (event.getEnd().getDateTime() != null) { result.setAllDay(event.getEnd().getDateTime().isDateOnly()); result.setLocation(event.getLocation()); if (event.getOrganizer() != null) { final PersonDto person = new PersonDto(); person.setName(event.getOrganizer().getDisplayName()); person.setEmail(event.getOrganizer().getEmail()); result.setOrganizer(person); if (event.getAttendees() != null) { final Set<PersonDto> attendees = new HashSet<PersonDto>(); for (final EventAttendee eventAttendee : event.getAttendees()) { final PersonDto person = new PersonDto(); person.setName(eventAttendee.getDisplayName()); if (event.getReminders() != null && event.getReminders().getOverrides() != null) { final EventReminder reminder = event.getReminders().getOverrides().iterator().next(); result.setReminderMinutesBeforeStart(reminder.getMinutes());
private void populateEventFromAppointmentDto(final AppointmentDto appointmentDto, final Event event) { event.setSummary(appointmentDto.getSummary()); event.setDescription(appointmentDto.getDescription()); event.setStart(convertToEventDateTime(appointmentDto.getStart(), appointmentDto.isAllDay(), calendarTimeZone)); event.setEnd(convertToEventDateTime(appointmentDto.getEnd(), appointmentDto.isAllDay(), calendarTimeZone)); event.setLocation(appointmentDto.getLocation()); if (syncOrganizerAndAttendees) { if (appointmentDto.getOrganizer() != null && appointmentDto.getOrganizer().getEmail() != null) { organizer.setDisplayName(appointmentDto.getOrganizer().getName()); organizer.setEmail(obfuscateEmail(appointmentDto.getOrganizer().getEmail())); event.setOrganizer(organizer); event.setAttendees(attendees); reminders.setUseDefault(false); reminders.setOverrides(Collections.singletonList(reminder)); event.setReminders(reminders); event.setRecurrence(Collections.singletonList(recurrencePattern));
private static Event newEvent() { Event event = new Event(); event.setSummary("New Event"); Date startDate = new Date(); Date endDate = new Date(startDate.getTime() + 3600000); DateTime start = new DateTime(startDate, TimeZone.getTimeZone("UTC")); event.setStart(new EventDateTime().setDateTime(start)); DateTime end = new DateTime(endDate, TimeZone.getTimeZone("UTC")); event.setEnd(new EventDateTime().setDateTime(end)); return event; }
public static PreEvent copyEvent(long guildId, Event event) { PreEvent pe = new PreEvent(guildId); pe.setSummary(event.getSummary()); pe.setDescription(event.getDescription()); pe.setLocation(event.getLocation()); if (event.getColorId() != null) pe.setColor(EventColor.fromNameOrHexOrID(event.getColorId())); else pe.setColor(EventColor.RED); pe.setEventData(DatabaseManager.getManager().getEventData(guildId, event.getId())); return pe; } }
private static void fillEvent(Absence absence, Event event) { event.setSummary(absence.getEventSubject()); EventAttendee eventAttendee = new EventAttendee(); eventAttendee.setEmail(absence.getPerson().getEmail()); eventAttendee.setDisplayName(absence.getPerson().getNiceName()); event.setAttendees(Collections.singletonList(eventAttendee)); EventDateTime startEventDateTime; EventDateTime endEventDateTime; if (absence.isAllDay()) { // To create an all-day event, you must use setDate() having created DateTime objects using a String DateFormat dateFormat = new SimpleDateFormat(DATE_PATTERN_YYYY_MM_DD); String startDateStr = dateFormat.format(absence.getStartDate()); String endDateStr = dateFormat.format(absence.getEndDate()); DateTime startDateTime = new DateTime(startDateStr); DateTime endDateTime = new DateTime(endDateStr); startEventDateTime = new EventDateTime().setDate(startDateTime); endEventDateTime = new EventDateTime().setDate(endDateTime); } else { DateTime dateTimeStart = new DateTime(absence.getStartDate()); DateTime dateTimeEnd = new DateTime(absence.getEndDate()); startEventDateTime = new EventDateTime().setDateTime(dateTimeStart); endEventDateTime = new EventDateTime().setDateTime(dateTimeEnd); } event.setStart(startEventDateTime); event.setEnd(endEventDateTime); }
@Override public Optional<String> add(Absence absence, CalendarSettings calendarSettings) { googleCalendarClient = getOrCreateGoogleCalendarClient(); if (googleCalendarClient != null) { GoogleCalendarSettings googleCalendarSettings = settingsService.getSettings().getCalendarSettings().getGoogleCalendarSettings(); String calendarId = googleCalendarSettings.getCalendarId(); try { Event eventToCommit = new Event(); fillEvent(absence, eventToCommit); Event eventInCalendar = googleCalendarClient.events().insert(calendarId, eventToCommit).execute(); LOG.info(String.format("Event %s for '%s' added to calendar '%s'.", eventInCalendar.getId(), absence.getPerson().getNiceName(), eventInCalendar.getSummary())); return Optional.of(eventInCalendar.getId()); } catch (IOException ex) { LOG.warn(String.format("An error occurred while trying to add appointment to calendar %s", calendarId), ex); mailService.sendCalendarSyncErrorNotification(calendarId, absence, ex.toString()); } } return Optional.empty(); }
public static void main(String... args) throws IOException, GeneralSecurityException { // Build a new authorized API client service. final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport(); Calendar service = new Calendar.Builder(HTTP_TRANSPORT, JSON_FACTORY, getCredentials(HTTP_TRANSPORT)) .setApplicationName(APPLICATION_NAME) .build(); // List the next 10 events from the primary calendar. DateTime now = new DateTime(System.currentTimeMillis()); Events events = service.events().list("primary") .setMaxResults(10) .setTimeMin(now) .setOrderBy("startTime") .setSingleEvents(true) .execute(); List<Event> items = events.getItems(); if (items.isEmpty()) { System.out.println("No upcoming events found."); } else { System.out.println("Upcoming events"); for (Event event : items) { DateTime start = event.getStart().getDateTime(); if (start == null) { start = event.getStart().getDate(); } System.out.printf("%s (%s)\n", event.getSummary(), start); } } } }
new CalendarEventModel(modelCalendarId, null, null, null, null, null, null, null); Event eventToInsert = GoogleCalendarImporter.convertToGoogleCalendarEvent(eventModel); Event responseEvent = new Event();
public Exchange createExchange(ExchangePattern pattern, Event event) { Exchange exchange = super.createExchange(pattern); Message message = exchange.getIn(); message.setBody(event); message.setHeader(GoogleCalendarStreamConstants.EVENT_ID, event.getId()); return exchange; } }
@Override public void addAppointment(final AppointmentDto appointment) throws IOException { final Event event = new Event(); final Map<String, String> privateProperties = new HashMap<String, String>(); privateProperties.put(EXT_PROPERTY_EXCHANGE_ID, appointment.getExchangeId()); final ExtendedProperties extProperties = new ExtendedProperties(); extProperties.setPrivate(privateProperties); event.setExtendedProperties(extProperties); populateEventFromAppointmentDto(appointment, event); client.events().insert(calendarId, event).execute(); LOG.info("Added Google appointment " + appointment.getSummary()); }
com.google.api.services.calendar.model.Calendar cal = service.calendars().get(calendarData.getCalendarId()).execute(); Event event = new Event(); event.setId(KeyGenerator.generateEventId()); event.setVisibility("public"); event.setSummary(body.getString("summary")); event.setDescription(body.getString("description")); event.setStart(start.setTimeZone(cal.getTimeZone())); event.setEnd(end.setTimeZone(cal.getTimeZone())); event.setColorId(EventColor.fromNameOrHexOrID(body.getString("color")).getId() + ""); event.setLocation(body.getString("location")); event.setRecurrence(Arrays.asList(rr)); ed.setEventId(event.getId()); ed.setEventEnd(event.getEnd().getDateTime().getValue()); respondBody.put("id", confirmed.getId());
for (Event e : items) { JSONObject jo = new JSONObject(); jo.put("id", e.getId()); jo.put("epochStart", e.getStart().getDateTime().getValue()); jo.put("epochEnd", e.getEnd().getDateTime().getValue()); jo.put("timezone", tz); jo.put("summary", e.getSummary()); jo.put("description", e.getDescription()); if (e.getLocked() != null) jo.put("location", e.getLocation()); else jo.put("location", "N/a"); jo.put("color", EventColor.fromNameOrHexOrID(e.getColorId()).name()); jo.put("isParent", !(e.getId().contains("_"))); if (e.getRecurrence() != null && e.getRecurrence().size() > 0) { jo.put("recur", true); Recurrence r = new Recurrence().fromRRule(e.getRecurrence().get(0)); EventData ed = DatabaseManager.getManager().getEventData(settings.getGuildID(), e.getId());