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

The following examples show how to use com.google.api.services.calendar.model.Event#setSummary() . 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: GoogleCalendarResource.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Path("/update/event")
@PATCH
public Response updateCalendarEvent(@QueryParam("calendarId") String calendarId, @QueryParam("eventId") String eventId) {
    Map<String, Object> headers = new HashMap<>();
    headers.put("CamelGoogleCalendar.calendarId", calendarId);
    headers.put("CamelGoogleCalendar.eventId", eventId);
    try {
        Event response = producerTemplate.requestBodyAndHeaders("google-calendar://events/get", null, headers,
                Event.class);
        if (response == null) {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
        response.setSummary(response.getSummary() + " Updated");

        headers = new HashMap<>();
        headers.put("CamelGoogleCalendar.calendarId", calendarId);
        headers.put("CamelGoogleCalendar.eventId", eventId);
        headers.put("CamelGoogleCalendar.content", response);
        producerTemplate.requestBodyAndHeaders("google-calendar://events/update", null, headers);
        return Response.ok().build();
    } catch (CamelExecutionException e) {
        Exception exchangeException = e.getExchange().getException();
        if (exchangeException != null && exchangeException.getCause() instanceof GoogleJsonResponseException) {
            GoogleJsonResponseException originalException = (GoogleJsonResponseException) exchangeException.getCause();
            return Response.status(originalException.getStatusCode()).build();
        }
        throw e;
    }
}
 
Example 4
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 5
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 6
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 7
Source File: ConditionalModificationSample.java    From java-samples with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a test event, pauses while the user modifies the event in the Calendar UI, and then
 * updates the event with a new location, ensure that the user's changes aren't overwritten.
 */
private static void run() throws IOException {
  // Create a test event.
  Event event = Utils.createTestEvent(client, "Test Event");
  System.out.println(String.format("Event created: %s", event.getHtmlLink()));

  // Pause while the user modifies the event in the Calendar UI.
  System.out.println("Modify the event's description and hit enter to continue.");
  System.in.read();

  // Modify the local copy of the event.
  event.setSummary("Updated Test Event");

  // Update the event, making sure that we don't overwrite other changes.
  int numAttempts = 0;
  boolean isUpdated = false;
  do {
    Calendar.Events.Update request = client.events().update("primary", event.getId(), event);
    request.setRequestHeaders(new HttpHeaders().setIfMatch(event.getEtag()));
    try {
      event = request.execute();
      isUpdated = true;
    } catch (GoogleJsonResponseException e) {
      if (e.getStatusCode() == 412) {
        // A 412 status code, "Precondition failed", indicates that the etag values didn't
        // match, and the event was updated on the server since we last retrieved it. Use
        // {@link Calendar.Events.Get} to retrieve the latest version.
        Event latestEvent = client.events().get("primary", event.getId()).execute();

        // You may want to have more complex logic here to resolve conflicts. In this sample we're
        // simply overwriting the summary.
        latestEvent.setSummary(event.getSummary());
        event = latestEvent;
      } else {
        throw e;
      }
    }
    numAttempts++;
  } while (!isUpdated && numAttempts <= MAX_UPDATE_ATTEMPTS);

  if (isUpdated) {
    System.out.println("Event updated.");
  } else {
    System.out.println(String.format("Failed to update event after %d attempts.", numAttempts));
  }
}