com.google.api.services.calendar.model.EventDateTime Java Examples

The following examples show how to use com.google.api.services.calendar.model.EventDateTime. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GoogleCalendarImporter.java    From data-transfer-project with Apache License 2.0 6 votes vote down vote up
private static EventDateTime getEventDateTime(CalendarEventModel.CalendarEventTime dateTime) {
  if (dateTime == null) {
    return null;
  }

  EventDateTime eventDateTime = new EventDateTime();

  // google's APIs want millisecond from epoch, and the timezone offset in minutes.
  if (dateTime.isDateOnly()) {
    eventDateTime.setDate(new DateTime(true,
        dateTime.getDateTime().toEpochSecond() * 1000,
        dateTime.getDateTime().getOffset().getTotalSeconds() / 60));
  } else {
    eventDateTime.setDateTime(new DateTime(
        dateTime.getDateTime().toEpochSecond() * 1000,
        dateTime.getDateTime().getOffset().getTotalSeconds() / 60));
  }

  return eventDateTime;
}
 
Example #2
Source File: GoogleCalendarExporter.java    From data-transfer-project with Apache License 2.0 6 votes vote down vote up
private static CalendarEventModel.CalendarEventTime getEventTime(EventDateTime dateTime) {
  if (dateTime == null) {
    return null;
  }

  OffsetDateTime offsetDateTime;

  if (dateTime.getDate() == null) {
    offsetDateTime = OffsetDateTime.parse(dateTime.getDateTime().toString());
  } else {
    offsetDateTime =
        OffsetDateTime.from(
            LocalDate.parse(dateTime.getDate().toString()).atStartOfDay(ZoneId.of("UTC")));
  }

  return new CalendarEventModel.CalendarEventTime(offsetDateTime, dateTime.getDate() != null);
}
 
Example #3
Source File: GCalPersistenceService.java    From openhab1-addons with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Creates a new Google Calendar Entry for each <code>item</code> and adds
 * it to the processing queue. The entries' title will either be the items
 * name or <code>alias</code> if it is <code>!= null</code>.
 *
 * The new Calendar Entry will contain a single command to be executed e.g.<br>
 * <p>
 * <code>send &lt;item.name&gt; &lt;item.state&gt;</code>
 * </p>
 *
 * @param item the item which state should be persisted.
 * @param alias the alias under which the item should be persisted.
 */
@Override
public void store(final Item item, final String alias) {
    if (initialized) {
        String newAlias = alias != null ? alias : item.getName();

        Event event = new Event();
        event.setSummary("[PresenceSimulation] " + newAlias);
        event.setDescription(String.format(executeScript, item.getName(), item.getState().toString()));
        Date now = new Date();
        Date startDate = new Date(now.getTime() + 3600000L * 24 * offset);
        Date endDate = startDate;
        DateTime start = new DateTime(startDate);
        event.setStart(new EventDateTime().setDateTime(start));
        DateTime end = new DateTime(endDate);
        event.setEnd(new EventDateTime().setDateTime(end));

        entries.offer(event);

        logger.trace("added new entry '{}' for item '{}' to upload queue", event.getSummary(), item.getName());
    } else {
        logger.debug(
                "GCal PresenceSimulation Service isn't initialized properly! No entries will be uploaded to your Google Calendar");
    }
}
 
Example #4
Source File: GoogleCalendar.java    From garoon-google with MIT License 6 votes vote down vote up
public String addSchedule(Date start, Date end, String title, String description, String location, String color, ArrayList<String> recurrence, TimeZone timezone) throws Exception {
	String id = null;

	Event googleSchedule = new Event();
	googleSchedule.setStart(new EventDateTime().setTimeZone(timezone.getID()).setDateTime(new DateTime(start)));
	googleSchedule.setEnd(new EventDateTime().setTimeZone(timezone.getID()).setDateTime(new DateTime(end)));
	googleSchedule.setRecurrence(null);
	googleSchedule.setSummary(title.trim());
	googleSchedule.setDescription(description.trim());
	googleSchedule.setLocation(location.trim());
	googleSchedule.setColorId(color);

	googleSchedule.setRecurrence(recurrence);

	Event createdEvent = this.CALENDAR.events().insert(this.CALENDAR_NAME, googleSchedule).execute();
	id = createdEvent.getId();

	return id;
}
 
Example #5
Source File: AddEventWorkitemHandler.java    From jbpm-work-items with Apache License 2.0 5 votes vote down vote up
private static Event createNewEvent(String paramEventSummary,
                                    String paramEventStart,
                                    String paramEventEnd,
                                    String paramEventAttendees,
                                    String paramEventCreator) throws Exception {
    Event event = new Event();
    event.setSummary(paramEventSummary);

    DateFormat format = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z",
                                             Locale.ENGLISH);

    if (paramEventStart != null) {
        DateTime startDateTime = new DateTime(format.parse(paramEventStart));
        event.setStart(new EventDateTime().setDateTime(startDateTime));
    }

    if (paramEventEnd != null) {
        DateTime endDateTime = new DateTime(format.parse(paramEventEnd));
        event.setEnd(new EventDateTime().setDateTime(endDateTime));
    }

    if (paramEventAttendees != null) {
        List<String> attendees = Arrays.asList(paramEventAttendees.split(","));
        List<EventAttendee> attendiesList = new ArrayList<>();
        for (String attendee : attendees) {
            EventAttendee newAttendee = new EventAttendee();
            newAttendee.setEmail(attendee);
            attendiesList.add(newAttendee);
        }
        event.setAttendees(attendiesList);
    }

    if (paramEventCreator != null) {
        Creator creator = new Creator();
        creator.setEmail(paramEventCreator);
        event.setCreator(creator);
    }

    return event;
}
 
Example #6
Source File: GoogleCalendarEventModel.java    From syndesis with Apache License 2.0 5 votes vote down vote up
private EventDateTime getStart() {
    final EventDateTime start = new EventDateTime();

    if (startTime == null) {
        start.setDate(DateTime.parseRfc3339(startDate));
    } else {
        start.setDateTime(DateTime.parseRfc3339(startDate + "T" + startTime));
    }

    return start;
}
 
Example #7
Source File: GoogleCalendarEventModel.java    From syndesis with Apache License 2.0 5 votes vote down vote up
private EventDateTime getEnd() {
    final EventDateTime end = new EventDateTime();

    if (endTime == null) {
        end.setDate(DateTime.parseRfc3339(endDate));
    } else {
        end.setDateTime(DateTime.parseRfc3339(endDate + "T" + endTime));
    }

    return end;
}
 
Example #8
Source File: Utils.java    From java-samples with Apache License 2.0 5 votes vote down vote up
/** Creates a test event. */
public static Event createTestEvent(Calendar client, String summary) throws IOException {
  Date oneHourFromNow = Utils.getRelativeDate(java.util.Calendar.HOUR, 1);
  Date twoHoursFromNow = Utils.getRelativeDate(java.util.Calendar.HOUR, 2);
  DateTime start = new DateTime(oneHourFromNow, TimeZone.getTimeZone("UTC"));
  DateTime end = new DateTime(twoHoursFromNow, TimeZone.getTimeZone("UTC"));

  Event event = new Event().setSummary(summary)
      .setReminders(new Reminders().setUseDefault(false))
      .setStart(new EventDateTime().setDateTime(start))
      .setEnd(new EventDateTime().setDateTime(end));
  return client.events().insert("primary", event).execute();
}
 
Example #9
Source File: GCalEventDownloader.java    From openhab1-addons with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Creates a set quartz-triggers for <code>job</code>. For each {@link When}
 * object of <code>event</code> a new trigger is created. That is the case
 * in recurring events where gcal creates one event (with one unique IcalUID)
 * and a set of {@link When}-object for each occurrence.
 *
 * @param job the {@link Job} to create triggers for
 * @param event the {@link CalendarEventEntry} to read the {@link When}-objects
 *            from
 * @param modifiedByEvent defines the name of an event which modifies the
 *            schedule of the new Trigger
 * @param isStartEvent indicator to identify whether this trigger will be
 *            triggering a start or an end command.
 *
 * @throws SchedulerException if there is an internal Scheduler error.
 */
protected boolean createTriggerAndSchedule(JobDetail job, Event event, String modifiedByEvent,
        boolean isStartEvent) {
    boolean triggersCreated = false;

    if (job == null) {
        logger.debug("job is null -> no triggers are created");
        return false;
    }

    String jobIdentity = event.getICalUID() + (isStartEvent ? "_start" : "_end");

    EventDateTime date = isStartEvent ? event.getStart() : event.getEnd();
    long dateValue = date.getDateTime().getValue();

    /*
     * TODO: TEE: do only create a new trigger when the start/endtime
     * lies in the future. This exclusion is necessary because the SimpleTrigger
     * triggers a job even if the startTime lies in the past. If somebody
     * knows the way to let quartz ignore such triggers this exclusion
     * can be omitted.
     */
    if (dateValue >= (new Date()).getTime()) {

        Trigger trigger;

        if (StringUtils.isBlank(modifiedByEvent)) {
            trigger = newTrigger().forJob(job)
                    .withIdentity(jobIdentity + "_" + dateValue + "_trigger", GCAL_SCHEDULER_GROUP)
                    .startAt(new Date(dateValue)).build();
        } else {
            trigger = newTrigger().forJob(job)
                    .withIdentity(jobIdentity + "_" + dateValue + "_trigger", GCAL_SCHEDULER_GROUP)
                    .startAt(new Date(dateValue)).modifiedByCalendar(modifiedByEvent).build();
        }

        try {
            scheduler.scheduleJob(job, trigger);
            triggersCreated = true;
        } catch (SchedulerException se) {
            logger.warn("scheduling Trigger '{}' throws an exception: {}", trigger, se);
        }
    }
    // }
    return triggersCreated;
}
 
Example #10
Source File: PreEvent.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 4 votes vote down vote up
public PreEvent(Snowflake _guildId, Event e) {
	guildId = _guildId;
	eventId = e.getId();

	color = EventColor.fromNameOrHexOrID(e.getColorId());

	recurrence = new Recurrence();

	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();

	//Here is where I need to fix the display times
	GuildSettings settings = DatabaseManager.getManager().getSettings(guildId);
	//TODO: Support multiple calendars
	CalendarData data = DatabaseManager.getManager().getMainCalendar(guildId);

	Calendar cal = null;
	try {
		cal = CalendarAuth.getCalendarService(settings).calendars().get(data.getCalendarAddress()).execute();
	} catch (Exception ex) {
		Logger.getLogger().exception(null, "Failed to get proper date time for event!", ex, true, this.getClass());
	}

	if (cal != null) {

		//Check if either DateTime or just Date...
		if (e.getStart().getDateTime() != null) {
			//DateTime
			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 {
			//Just Date
			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())));
		}
	} else {
		//Almost definitely not correct, but we need something displayed here.
		viewableStartDate = e.getStart();
		viewableEndDate = e.getEnd();
	}

	eventData = DatabaseManager.getManager().getEventData(guildId, e.getId());

	editing = false;
	lastEdit = System.currentTimeMillis();
}
 
Example #11
Source File: EventCommand.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void moduleEndDate(String[] args, MessageCreateEvent event, GuildSettings settings) {
	if (args.length == 2) {
		if (EventCreator.getCreator().hasPreEvent(settings.getGuildID())) {
			String dateRaw = args[1].trim();
			if (dateRaw.length() > 10) {
				try {
					//Do a lot of date shuffling to get to proper formats and shit like that.
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss");
					TimeZone tz = TimeZone.getTimeZone(EventCreator.getCreator().getPreEvent(settings.getGuildID()).getTimeZone());
					sdf.setTimeZone(tz);
					Date dateObj = sdf.parse(dateRaw);
					DateTime dateTime = new DateTime(dateObj);
					EventDateTime eventDateTime = new EventDateTime();
					eventDateTime.setDateTime(dateTime);

					//Wait! Lets check now if its in the future and not the past!
					if (!TimeUtils.inPast(dateRaw, tz) && !TimeUtils.endBeforeStart(dateRaw, tz, EventCreator.getCreator().getPreEvent(settings.getGuildID()))) {
						//Date shuffling done, now actually apply all that damn stuff here.
						EventCreator.getCreator().getPreEvent(settings.getGuildID()).setEndDateTime(eventDateTime);

						//Apply viewable date/times...
						SimpleDateFormat sdfV = new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss");
						Date dateObjV = sdfV.parse(dateRaw);
						DateTime dateTimeV = new DateTime(dateObjV);
						EventDateTime eventDateTimeV = new EventDateTime();
						eventDateTimeV.setDateTime(dateTimeV);
						EventCreator.getCreator().getPreEvent(settings.getGuildID()).setViewableEndDate(eventDateTimeV);

						if (EventCreator.getCreator().hasCreatorMessage(settings.getGuildID())) {
							MessageManager.deleteMessage(event);
							MessageManager.deleteMessage(EventCreator.getCreator().getCreatorMessage(settings.getGuildID()));
							EventCreator.getCreator().setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Event.End.Success.New", settings), EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(settings.getGuildID()), settings), event));
						} else {
							String msg = MessageManager.getMessage("Creator.Event.End.Success", settings);
							msg = msg.replaceAll("%date%", EventMessageFormatter.getHumanReadableDate(eventDateTimeV, settings, true)).replaceAll("%time%", EventMessageFormatter.getHumanReadableTime(eventDateTimeV, settings, true));
							MessageManager.sendMessageAsync(msg, event);
						}
					} else {
						//Oops! Time is in the past or before the starting time...
						if (EventCreator.getCreator().hasCreatorMessage(settings.getGuildID())) {
							MessageManager.deleteMessage(event);
							MessageManager.deleteMessage(EventCreator.getCreator().getCreatorMessage(settings.getGuildID()));
							EventCreator.getCreator().setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Event.End.Failure.Illegal", settings), EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(settings.getGuildID()), settings), event));
						} else {
							MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.End.Failure.Illegal", settings), event);
						}
					}
				} catch (ParseException e) {
					if (EventCreator.getCreator().hasCreatorMessage(settings.getGuildID())) {
						MessageManager.deleteMessage(event);
						MessageManager.deleteMessage(EventCreator.getCreator().getCreatorMessage(settings.getGuildID()));
						EventCreator.getCreator().setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Event.Time.Invalid", settings), EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(settings.getGuildID()), settings), event));
					} else {
						MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.Time.Invalid", settings), event);
					}
				}
			} else {
				if (EventCreator.getCreator().hasCreatorMessage(settings.getGuildID())) {
					MessageManager.deleteMessage(event);
					MessageManager.deleteMessage(EventCreator.getCreator().getCreatorMessage(settings.getGuildID()));
					EventCreator.getCreator().setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Event.Time.InvalidFormat", settings), EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(settings.getGuildID()), settings), event));
				} else {
					MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.Time.InvalidFormat", settings), event);
				}
			}
		} else {
			MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.NotInit", settings), event);
		}
	} else {
		if (EventCreator.getCreator().hasCreatorMessage(settings.getGuildID())) {
			MessageManager.deleteMessage(event);
			MessageManager.deleteMessage(EventCreator.getCreator().getCreatorMessage(settings.getGuildID()));
			EventCreator.getCreator().setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Event.End.Specify", settings), EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(settings.getGuildID()), settings), event));
		} else {
			MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.End.Specify", settings), event);
		}
	}
}
 
Example #12
Source File: EventCommand.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void moduleStartDate(String[] args, MessageCreateEvent event, GuildSettings settings) {
	if (args.length == 2) {
		if (EventCreator.getCreator().hasPreEvent(settings.getGuildID())) {
			String dateRaw = args[1].trim();
			if (dateRaw.length() > 10) {
				try {
					//Do a lot of date shuffling to get to proper formats and shit like that.
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss");
					TimeZone tz = TimeZone.getTimeZone(EventCreator.getCreator().getPreEvent(settings.getGuildID()).getTimeZone());
					sdf.setTimeZone(tz);
					Date dateObj = sdf.parse(dateRaw);
					DateTime dateTime = new DateTime(dateObj);
					EventDateTime eventDateTime = new EventDateTime();
					eventDateTime.setDateTime(dateTime);

					//Wait! Lets check now if its in the future and not the past!
					if (!TimeUtils.inPast(dateRaw, tz) && !TimeUtils.startAfterEnd(dateRaw, tz, EventCreator.getCreator().getPreEvent(settings.getGuildID()))) {
						//Date shuffling done, now actually apply all that damn stuff here.
						EventCreator.getCreator().getPreEvent(settings.getGuildID()).setStartDateTime(eventDateTime);

						//Apply viewable date/times...
						SimpleDateFormat sdfV = new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss");
						Date dateObjV = sdfV.parse(dateRaw);
						DateTime dateTimeV = new DateTime(dateObjV);
						EventDateTime eventDateTimeV = new EventDateTime();
						eventDateTimeV.setDateTime(dateTimeV);
						EventCreator.getCreator().getPreEvent(settings.getGuildID()).setViewableStartDate(eventDateTimeV);


						//To streamline, check if event end is null, if so, apply 2 hour duration!
						if (EventCreator.getCreator().getPreEvent(settings.getGuildID()).getEndDateTime() == null) {
							EventDateTime end = EventCreator.getCreator().getPreEvent(settings.getGuildID()).getStartDateTime().clone();
							long endLong = end.getDateTime().getValue() + 3600000; //Add an hour

							end.setDateTime(new DateTime(endLong));

							EventCreator.getCreator().getPreEvent(settings.getGuildID()).setEndDateTime(end);


							//Viewable date
							EventDateTime endV = EventCreator.getCreator().getPreEvent(settings.getGuildID()).getViewableStartDate().clone();
							long endVLong = endV.getDateTime().getValue() + 3600000; //Add an hour

							endV.setDateTime(new DateTime(endVLong));

							EventCreator.getCreator().getPreEvent(settings.getGuildID()).setViewableEndDate(endV);
						}

						if (EventCreator.getCreator().hasCreatorMessage(settings.getGuildID())) {
							MessageManager.deleteMessage(event);
							MessageManager.deleteMessage(EventCreator.getCreator().getCreatorMessage(settings.getGuildID()));
							EventCreator.getCreator().setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Event.Start.Success.New", settings), EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(settings.getGuildID()), settings), event));
						} else {
							String msg = MessageManager.getMessage("Creator.Event.Start.Success", settings);
							msg = msg.replaceAll("%date%", EventMessageFormatter.getHumanReadableDate(eventDateTimeV, settings, true)).replaceAll("%time%", EventMessageFormatter.getHumanReadableTime(eventDateTimeV, settings, true));
							MessageManager.sendMessageAsync(msg, event);
						}
					} else {
						//Oops! Time is in the past or after end...
						if (EventCreator.getCreator().hasCreatorMessage(settings.getGuildID())) {
							MessageManager.deleteMessage(event);
							MessageManager.deleteMessage(EventCreator.getCreator().getCreatorMessage(settings.getGuildID()));
							EventCreator.getCreator().setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Event.Start.Failure.Illegal", settings), EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(settings.getGuildID()), settings), event));
						} else {
							MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.Start.Failure.Illegal", settings), event);
						}
					}
				} catch (ParseException e) {
					if (EventCreator.getCreator().hasCreatorMessage(settings.getGuildID())) {
						MessageManager.deleteMessage(event);
						MessageManager.deleteMessage(EventCreator.getCreator().getCreatorMessage(settings.getGuildID()));
						EventCreator.getCreator().setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Event.Time.Invalid", settings), EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(settings.getGuildID()), settings), event));
					} else {
						MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.Time.Invalid", settings), event);
					}
				}
			} else {
				if (EventCreator.getCreator().hasCreatorMessage(settings.getGuildID())) {
					MessageManager.deleteMessage(event);
					MessageManager.deleteMessage(EventCreator.getCreator().getCreatorMessage(settings.getGuildID()));
					EventCreator.getCreator().setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Event.Time.InvalidFormat", settings), EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(settings.getGuildID()), settings), event));
				} else {
					MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.Time.InvalidFormat", settings), event);
				}
			}
		} else {
			MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.NotInit", settings), event);
		}
	} else {
		if (EventCreator.getCreator().hasCreatorMessage(settings.getGuildID())) {
			MessageManager.deleteMessage(event);
			MessageManager.deleteMessage(EventCreator.getCreator().getCreatorMessage(settings.getGuildID()));
			EventCreator.getCreator().setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Event.Start.Specify", settings), EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(settings.getGuildID()), settings), event));
		} else {
			MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.Start.Specify", settings), event);
		}
	}
}
 
Example #13
Source File: TestHelper.java    From syndesis with Apache License 2.0 4 votes vote down vote up
static EventDateTime date(String asString) {
    final EventDateTime dateTime = new EventDateTime();
    dateTime.setDate(DateTime.parseRfc3339(asString));

    return dateTime;
}
 
Example #14
Source File: CheckupReminders.java    From Crimson with Apache License 2.0 4 votes vote down vote up
private List<String> createEvent() throws IOException {
            // Refer to the Java quickstart on how to setup the environment:
// https://developers.google.com/google-apps/calendar/quickstart/java
// Change the scope to CalendarScopes.CALENDAR and delete any stored
// credentials.

            Event event = new Event()
                    .setSummary("Appointment with Dr. A.K. Awasthi")
                    .setLocation("Sujanpura,Lucknow,226005")
                    .setDescription("Yearly eye check-up.");

            DateTime startDateTime = new DateTime("2016-10-01T14:30:00Z");
            EventDateTime start = new EventDateTime()
                    .setDateTime(startDateTime)
                    .setTimeZone(TimeZone.getDefault().getID());
            event.setStart(start);

            DateTime endDateTime = new DateTime("2016-10-01T15:30:00Z");
            EventDateTime end = new EventDateTime()
                    .setDateTime(endDateTime)
                    .setTimeZone(TimeZone.getDefault().getID());
            event.setEnd(end);

            /*String[] recurrence = new String[] {"RRULE:FREQ=DAILY;COUNT=2"};
            event.setRecurrence(Arrays.asList(recurrence));*/

           /* EventAttendee[] attendees = new EventAttendee[] {
                    new EventAttendee().setEmail("[email protected]"),
                    new EventAttendee().setEmail("[email protected]"),
            };*/
            //event.setAttendees(Arrays.asList(attendees));

            EventReminder[] reminderOverrides = new EventReminder[]{
                    new EventReminder().setMethod("email").setMinutes(24 * 60),
                    new EventReminder().setMethod("popup").setMinutes(10),
            };
            Event.Reminders reminders = new Event.Reminders()
                    .setUseDefault(false)
                    .setOverrides(Arrays.asList(reminderOverrides));
            event.setReminders(reminders);

            String calendarId = "primary";
            event = mService.events().insert(calendarId, event).execute();
            System.out.printf("Event created: %s\n", event.getHtmlLink());
            ArrayList<String> arrayList = new ArrayList<>();
            arrayList.add(0, "Success");

            return arrayList;
        }
 
Example #15
Source File: EventCommand.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void moduleStartDate(String[] args, MessageCreateEvent event, GuildSettings settings) {
	if (args.length == 2) {
		if (EventCreator.getCreator().hasPreEvent(settings.getGuildID())) {
			String dateRaw = args[1].trim();
			if (dateRaw.length() > 10) {
				try {
					//Do a lot of date shuffling to get to proper formats and shit like that.
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss");
					TimeZone tz = TimeZone.getTimeZone(EventCreator.getCreator().getPreEvent(settings.getGuildID()).getTimeZone());
					sdf.setTimeZone(tz);
					Date dateObj = sdf.parse(dateRaw);
					DateTime dateTime = new DateTime(dateObj);
					EventDateTime eventDateTime = new EventDateTime();
					eventDateTime.setDateTime(dateTime);

					//Wait! Lets check now if its in the future and not the past!
					if (!TimeUtils.inPast(dateRaw, tz) && !TimeUtils.startAfterEnd(dateRaw, tz, EventCreator.getCreator().getPreEvent(settings.getGuildID()))) {
						//Date shuffling done, now actually apply all that damn stuff here.
						EventCreator.getCreator().getPreEvent(settings.getGuildID()).setStartDateTime(eventDateTime);

						//Apply viewable date/times...
						SimpleDateFormat sdfV = new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss");
						Date dateObjV = sdfV.parse(dateRaw);
						DateTime dateTimeV = new DateTime(dateObjV);
						EventDateTime eventDateTimeV = new EventDateTime();
						eventDateTimeV.setDateTime(dateTimeV);
						EventCreator.getCreator().getPreEvent(settings.getGuildID()).setViewableStartDate(eventDateTimeV);


						//To streamline, check if event end is null, if so, apply 2 hour duration!
						if (EventCreator.getCreator().getPreEvent(settings.getGuildID()).getEndDateTime() == null) {
							EventDateTime end = EventCreator.getCreator().getPreEvent(settings.getGuildID()).getStartDateTime().clone();
							long endLong = end.getDateTime().getValue() + 3600000; //Add an hour

							end.setDateTime(new DateTime(endLong));

							EventCreator.getCreator().getPreEvent(settings.getGuildID()).setEndDateTime(end);


							//Viewable date
							EventDateTime endV = EventCreator.getCreator().getPreEvent(settings.getGuildID()).getViewableStartDate().clone();
							long endVLong = endV.getDateTime().getValue() + 3600000; //Add an hour

							endV.setDateTime(new DateTime(endVLong));

							EventCreator.getCreator().getPreEvent(settings.getGuildID()).setViewableEndDate(endV);
						}

						if (EventCreator.getCreator().hasCreatorMessage(settings.getGuildID())) {
							MessageManager.deleteMessage(event);
							MessageManager.deleteMessage(EventCreator.getCreator().getCreatorMessage(settings.getGuildID()));
							EventCreator.getCreator().setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Event.Start.Success.New", settings), EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(settings.getGuildID()), settings), event));
						} else {
							String msg = MessageManager.getMessage("Creator.Event.Start.Success", settings);
							msg = msg.replaceAll("%date%", EventMessageFormatter.getHumanReadableDate(eventDateTimeV, settings, true)).replaceAll("%time%", EventMessageFormatter.getHumanReadableTime(eventDateTimeV, settings, true));
							MessageManager.sendMessageAsync(msg, event);
						}
					} else {
						//Oops! Time is in the past or after end...
						if (EventCreator.getCreator().hasCreatorMessage(settings.getGuildID())) {
							MessageManager.deleteMessage(event);
							MessageManager.deleteMessage(EventCreator.getCreator().getCreatorMessage(settings.getGuildID()));
							EventCreator.getCreator().setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Event.Start.Failure.Illegal", settings), EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(settings.getGuildID()), settings), event));
						} else {
							MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.Start.Failure.Illegal", settings), event);
						}
					}
				} catch (ParseException e) {
					if (EventCreator.getCreator().hasCreatorMessage(settings.getGuildID())) {
						MessageManager.deleteMessage(event);
						MessageManager.deleteMessage(EventCreator.getCreator().getCreatorMessage(settings.getGuildID()));
						EventCreator.getCreator().setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Event.Time.Invalid", settings), EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(settings.getGuildID()), settings), event));
					} else {
						MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.Time.Invalid", settings), event);
					}
				}
			} else {
				if (EventCreator.getCreator().hasCreatorMessage(settings.getGuildID())) {
					MessageManager.deleteMessage(event);
					MessageManager.deleteMessage(EventCreator.getCreator().getCreatorMessage(settings.getGuildID()));
					EventCreator.getCreator().setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Event.Time.InvalidFormat", settings), EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(settings.getGuildID()), settings), event));
				} else {
					MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.Time.InvalidFormat", settings), event);
				}
			}
		} else {
			MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.NotInit", settings), event);
		}
	} else {
		if (EventCreator.getCreator().hasCreatorMessage(settings.getGuildID())) {
			MessageManager.deleteMessage(event);
			MessageManager.deleteMessage(EventCreator.getCreator().getCreatorMessage(settings.getGuildID()));
			EventCreator.getCreator().setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Event.Start.Specify", settings), EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(settings.getGuildID()), settings), event));
		} else {
			MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.Start.Specify", settings), event);
		}
	}
}
 
Example #16
Source File: PreEvent.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 4 votes vote down vote up
public PreEvent(Snowflake _guildId, Event e) {
	guildId = _guildId;
	eventId = e.getId();

	color = EventColor.fromNameOrHexOrID(e.getColorId());

	recurrence = new Recurrence();

	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();

	//Here is where I need to fix the display times
	GuildSettings settings = DatabaseManager.getManager().getSettings(guildId);
	//TODO: Support multiple calendars
	CalendarData data = DatabaseManager.getManager().getMainCalendar(guildId);

	Calendar cal = null;
	try {
		cal = CalendarAuth.getCalendarService(settings).calendars().get(data.getCalendarAddress()).execute();
	} catch (Exception ex) {
		Logger.getLogger().exception(null, "Failed to get proper date time for event!", ex, true, this.getClass());
	}

	if (cal != null) {

		//Check if either DateTime or just Date...
		if (e.getStart().getDateTime() != null) {
			//DateTime
			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 {
			//Just Date
			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())));
		}
	} else {
		//Almost definitely not correct, but we need something displayed here.
		viewableStartDate = e.getStart();
		viewableEndDate = e.getEnd();
	}

	eventData = DatabaseManager.getManager().getEventData(guildId, e.getId());

	editing = false;
	lastEdit = System.currentTimeMillis();
}
 
Example #17
Source File: EventCommand.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void moduleEndDate(String[] args, MessageCreateEvent event, GuildSettings settings) {
	if (args.length == 2) {
		if (EventCreator.getCreator().hasPreEvent(settings.getGuildID())) {
			String dateRaw = args[1].trim();
			if (dateRaw.length() > 10) {
				try {
					//Do a lot of date shuffling to get to proper formats and shit like that.
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss");
					TimeZone tz = TimeZone.getTimeZone(EventCreator.getCreator().getPreEvent(settings.getGuildID()).getTimeZone());
					sdf.setTimeZone(tz);
					Date dateObj = sdf.parse(dateRaw);
					DateTime dateTime = new DateTime(dateObj);
					EventDateTime eventDateTime = new EventDateTime();
					eventDateTime.setDateTime(dateTime);

					//Wait! Lets check now if its in the future and not the past!
					if (!TimeUtils.inPast(dateRaw, tz) && !TimeUtils.endBeforeStart(dateRaw, tz, EventCreator.getCreator().getPreEvent(settings.getGuildID()))) {
						//Date shuffling done, now actually apply all that damn stuff here.
						EventCreator.getCreator().getPreEvent(settings.getGuildID()).setEndDateTime(eventDateTime);

						//Apply viewable date/times...
						SimpleDateFormat sdfV = new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss");
						Date dateObjV = sdfV.parse(dateRaw);
						DateTime dateTimeV = new DateTime(dateObjV);
						EventDateTime eventDateTimeV = new EventDateTime();
						eventDateTimeV.setDateTime(dateTimeV);
						EventCreator.getCreator().getPreEvent(settings.getGuildID()).setViewableEndDate(eventDateTimeV);

						if (EventCreator.getCreator().hasCreatorMessage(settings.getGuildID())) {
							MessageManager.deleteMessage(event);
							MessageManager.deleteMessage(EventCreator.getCreator().getCreatorMessage(settings.getGuildID()));
							EventCreator.getCreator().setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Event.End.Success.New", settings), EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(settings.getGuildID()), settings), event));
						} else {
							String msg = MessageManager.getMessage("Creator.Event.End.Success", settings);
							msg = msg.replaceAll("%date%", EventMessageFormatter.getHumanReadableDate(eventDateTimeV, settings, true)).replaceAll("%time%", EventMessageFormatter.getHumanReadableTime(eventDateTimeV, settings, true));
							MessageManager.sendMessageAsync(msg, event);
						}
					} else {
						//Oops! Time is in the past or before the starting time...
						if (EventCreator.getCreator().hasCreatorMessage(settings.getGuildID())) {
							MessageManager.deleteMessage(event);
							MessageManager.deleteMessage(EventCreator.getCreator().getCreatorMessage(settings.getGuildID()));
							EventCreator.getCreator().setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Event.End.Failure.Illegal", settings), EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(settings.getGuildID()), settings), event));
						} else {
							MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.End.Failure.Illegal", settings), event);
						}
					}
				} catch (ParseException e) {
					if (EventCreator.getCreator().hasCreatorMessage(settings.getGuildID())) {
						MessageManager.deleteMessage(event);
						MessageManager.deleteMessage(EventCreator.getCreator().getCreatorMessage(settings.getGuildID()));
						EventCreator.getCreator().setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Event.Time.Invalid", settings), EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(settings.getGuildID()), settings), event));
					} else {
						MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.Time.Invalid", settings), event);
					}
				}
			} else {
				if (EventCreator.getCreator().hasCreatorMessage(settings.getGuildID())) {
					MessageManager.deleteMessage(event);
					MessageManager.deleteMessage(EventCreator.getCreator().getCreatorMessage(settings.getGuildID()));
					EventCreator.getCreator().setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Event.Time.InvalidFormat", settings), EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(settings.getGuildID()), settings), event));
				} else {
					MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.Time.InvalidFormat", settings), event);
				}
			}
		} else {
			MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.NotInit", settings), event);
		}
	} else {
		if (EventCreator.getCreator().hasCreatorMessage(settings.getGuildID())) {
			MessageManager.deleteMessage(event);
			MessageManager.deleteMessage(EventCreator.getCreator().getCreatorMessage(settings.getGuildID()));
			EventCreator.getCreator().setCreatorMessage(MessageManager.sendMessageSync(MessageManager.getMessage("Creator.Event.End.Specify", settings), EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(settings.getGuildID()), settings), event));
		} else {
			MessageManager.sendMessageAsync(MessageManager.getMessage("Creator.Event.End.Specify", settings), event);
		}
	}
}
 
Example #18
Source File: PreEvent.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Gets the start date and time.
 *
 * @return The start date and time.
 */
public EventDateTime getStartDateTime() {
	return startDateTime;
}
 
Example #19
Source File: PreEvent.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Sets the viewable end date and time of the event.
 *
 * @param _viewableEnd The viewable end date and time of the event.
 */
public void setViewableEndDate(EventDateTime _viewableEnd) {
	viewableEndDate = _viewableEnd;
}
 
Example #20
Source File: PreEvent.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Sets the viewable start date and time of the event.
 *
 * @param _viewableStart The viewable start date and time of the event.
 */
public void setViewableStartDate(EventDateTime _viewableStart) {
	viewableStartDate = _viewableStart;
}
 
Example #21
Source File: PreEvent.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Sets the end date and time of the event.
 *
 * @param _endDateTime The end date and time of the event.
 */
public void setEndDateTime(EventDateTime _endDateTime) {
	endDateTime = _endDateTime;
}
 
Example #22
Source File: PreEvent.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Sets the start date and time of the event.
 *
 * @param _startDateTime The start date and time of the event.
 */
public void setStartDateTime(EventDateTime _startDateTime) {
	startDateTime = _startDateTime;
}
 
Example #23
Source File: PreEvent.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Gets the viewable end date and time.
 *
 * @return The viewable end date and time.
 */
public EventDateTime getViewableEndDate() {
	return viewableEndDate;
}
 
Example #24
Source File: PreEvent.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Gets the viewable start date and time.
 *
 * @return The viewable start date and time.
 */
public EventDateTime getViewableStartDate() {
	return viewableStartDate;
}
 
Example #25
Source File: PreEvent.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Gets the end date and time.
 *
 * @return The end date and time.
 */
public EventDateTime getEndDateTime() {
	return endDateTime;
}
 
Example #26
Source File: PreEvent.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Gets the viewable start date and time.
 *
 * @return The viewable start date and time.
 */
public EventDateTime getViewableStartDate() {
	return viewableStartDate;
}
 
Example #27
Source File: PreEvent.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Gets the start date and time.
 *
 * @return The start date and time.
 */
public EventDateTime getStartDateTime() {
	return startDateTime;
}
 
Example #28
Source File: PreEvent.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Gets the end date and time.
 *
 * @return The end date and time.
 */
public EventDateTime getEndDateTime() {
	return endDateTime;
}
 
Example #29
Source File: PreEvent.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Sets the viewable end date and time of the event.
 *
 * @param _viewableEnd The viewable end date and time of the event.
 */
public void setViewableEndDate(EventDateTime _viewableEnd) {
	viewableEndDate = _viewableEnd;
}
 
Example #30
Source File: PreEvent.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Sets the viewable start date and time of the event.
 *
 * @param _viewableStart The viewable start date and time of the event.
 */
public void setViewableStartDate(EventDateTime _viewableStart) {
	viewableStartDate = _viewableStart;
}