Java Code Examples for com.google.api.services.calendar.model.Event#setStart()

The following examples show how to use com.google.api.services.calendar.model.Event#setStart() . 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: 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 2
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 3
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 4
Source File: GoogleCalendarEventModel.java    From syndesis with Apache License 2.0 5 votes vote down vote up
Event asEvent() {
    final Event event = new Event();
    event.setSummary(title);
    event.setDescription(description);
    event.setAttendees(GoogleCalendarUtils.parseAtendees(attendees));
    event.setStart(getStart());
    event.setEnd(getEnd());
    event.setLocation(location);
    event.setId(eventId);

    return event;
}
 
Example 5
Source File: GoogleCalendarEventModelTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Test
public void createsConnectorModelFromGoogleModel() {
    final Event googleModel = new Event();
    googleModel.setSummary("summary");
    googleModel.setDescription("description");
    googleModel.setAttendees(Arrays.asList(attendee("[email protected]"), attendee("[email protected]")));
    googleModel.setStart(dateTime("2018-05-18T15:30:00+02:00"));
    googleModel.setEnd(dateTime("2018-05-18T16:30:00+02:00"));
    googleModel.setLocation("location");
    googleModel.setId("eventId");

    final GoogleCalendarEventModel eventModel = GoogleCalendarEventModel.newFrom(googleModel);

    final GoogleCalendarEventModel expected = new GoogleCalendarEventModel();
    expected.setTitle("summary");
    expected.setDescription("description");
    expected.setAttendees("[email protected],[email protected]");
    expected.setStartDate("2018-05-18");
    expected.setStartTime("15:30:00");
    expected.setEndDate("2018-05-18");
    expected.setEndTime("16:30:00");
    expected.setLocation("location");
    expected.setEventId("eventId");

    assertThat(eventModel).isEqualToComparingFieldByField(expected);
    googleModel.setStart(dateTime("2018-05-18T15:30:00.000Z"));
    googleModel.setEnd(dateTime("2018-05-18T16:30:00.000Z"));
    assertThat(eventModel.asEvent()).isEqualTo(googleModel);
}
 
Example 6
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;
        }