예제 #1
1
  private String getOrCreateCalendar() throws IOException {
    LOG.debug("Searching for calendar {}.", CalendarConstants.CALENDAR_ID_ACHIEVO);
    Calendars calendars = googleCalendarService.calendars();
    String calendarId = findAchievoCalendarId();

    if (calendarId == null) {

      Calendar calendar = new Calendar();
      calendar.setSummary(CalendarConstants.CALENDAR_ID_ACHIEVO);

      LOG.debug(
          "Calendar {} not found creating new: {}",
          CalendarConstants.CALENDAR_ID_ACHIEVO,
          calendar);
      Calendar result = calendars.insert(calendar).execute();
      calendarId = result.getId();
      LOG.trace("Request:\n{}", calendar);
      LOG.trace("Response:\n{}", result);
    }
    return calendarId;
  }
예제 #2
0
  @RequestMapping("list")
  public @ResponseBody List<String> list() throws IOException {
    List<String> ret = Lists.newArrayList();

    String pageToken = null;
    do {
      com.google.api.services.calendar.model.CalendarList calendarList =
          googleCalendarService.calendarList().list().setPageToken(pageToken).execute();
      List<CalendarListEntry> items = calendarList.getItems();

      for (CalendarListEntry calendarListEntry : items) {
        ret.add(calendarListEntry.getSummary());
      }
      pageToken = calendarList.getNextPageToken();
    } while (pageToken != null);
    return ret;
  }
예제 #3
0
  private void updateReports(String calendarId) throws IOException {
    Date to = new Date();
    Date from = DateUtils.addDays(to, -10);
    DateTime fromDateTime = new DateTime(from);
    DateTime toDateTime = new DateTime(to);

    List<WorkReport> reports = achievoConnector.getHours(from, to);
    Events events =
        googleCalendarService
            .events()
            .list(calendarId)
            .setTimeMin(fromDateTime)
            .setTimeMax(toDateTime)
            .execute();

    new ReportMerger(googleCalendarService, calendarId).merge(reports, events);
  }
예제 #4
0
  private String findAchievoCalendarId() throws IOException {
    String pageToken = null;
    do {
      com.google.api.services.calendar.model.CalendarList calendarList =
          googleCalendarService.calendarList().list().setPageToken(pageToken).execute();
      List<CalendarListEntry> items = calendarList.getItems();

      for (CalendarListEntry calendarListEntry : items) {

        if (CalendarConstants.CALENDAR_ID_ACHIEVO.equals(calendarListEntry.getSummary())) {
          return calendarListEntry.getId();
        }
      }
      pageToken = calendarList.getNextPageToken();
    } while (pageToken != null);
    return null;
  }