Search in sources :

Example 1 with Events

use of com.google.api.services.calendar.model.Events in project openhab1-addons by openhab.

the class GCalEventDownloader method execute.

/**
     * @{inheritDoc}
     */
@Override
protected void execute() {
    Events myFeed = downloadEventFeed();
    if (myFeed != null) {
        List<Event> entries = myFeed.getItems();
        if (entries.size() > 0) {
            logger.debug("found {} calendar events to process", entries.size());
            try {
                if (scheduler.isShutdown()) {
                    logger.warn("Scheduler has been shut down - probably due to exceptions?");
                }
                cleanJobs();
                processEntries(entries);
            } catch (SchedulerException se) {
                logger.error("scheduling jobs throws exception", se);
            }
        } else {
            logger.debug("gcal feed contains no events ...");
        }
    }
}
Also used : SchedulerException(org.quartz.SchedulerException) Events(com.google.api.services.calendar.model.Events) Event(com.google.api.services.calendar.model.Event)

Example 2 with Events

use of com.google.api.services.calendar.model.Events in project openhab1-addons by openhab.

the class GCalEventDownloader method downloadEventFeed.

/**
     * Connects to Google-Calendar Service and returns the specified Events
     *
     * @return the corresponding Events or <code>null</code> if an error
     *         occurs. <i>Note:</i> We do only return events if their startTime lies between
     *         <code>now</code> and <code>now + 2 * refreshInterval</code> to reduce
     *         the amount of events to process.
     */
private static Events downloadEventFeed() {
    if (StringUtils.isBlank(calendar_name)) {
        logger.warn("Login aborted no calendar name defined");
        return null;
    }
    // authorization
    CalendarListEntry calendarID = GCalGoogleOAuth.getCalendarId(calendar_name);
    if (calendarID == null) {
        return null;
    }
    DateTime start = new DateTime(new Date(), TimeZone.getTimeZone(calendarID.getTimeZone()));
    DateTime end = new DateTime(new Date(start.getValue() + (2 * refreshInterval)), TimeZone.getTimeZone(calendarID.getTimeZone()));
    logger.debug("Downloading calendar feed for time interval: {} to  {} ", start, end);
    Events feed = null;
    try {
        Credential credential = GCalGoogleOAuth.getCredential(false);
        // set up global Calendar instance
        Calendar client = new Calendar.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName("openHAB").build();
        Calendar.Events.List l = client.events().list(calendarID.getId()).setSingleEvents(true).setTimeMin(start).setTimeMax(end);
        // add the fulltext filter if it has been configured
        if (StringUtils.isNotBlank(filter)) {
            l = l.setQ(filter);
        }
        feed = l.execute();
    } catch (IOException e1) {
        logger.error("Event fetch failed: {}", e1.getMessage());
    }
    try {
        if (feed != null) {
            checkIfFullCalendarFeed(feed.getItems());
        }
        return feed;
    } catch (Exception e) {
        logger.error("downloading CalendarEventFeed throws exception: {}", e.getMessage());
    }
    return null;
}
Also used : CalendarListEntry(com.google.api.services.calendar.model.CalendarListEntry) Credential(com.google.api.client.auth.oauth2.Credential) Events(com.google.api.services.calendar.model.Events) Calendar(com.google.api.services.calendar.Calendar) TimeRangeCalendar(org.openhab.io.gcal.internal.util.TimeRangeCalendar) IOException(java.io.IOException) DateTime(com.google.api.client.util.DateTime) EventDateTime(com.google.api.services.calendar.model.EventDateTime) Date(java.util.Date) ConfigurationException(org.osgi.service.cm.ConfigurationException) SchedulerException(org.quartz.SchedulerException) IOException(java.io.IOException)

Aggregations

Events (com.google.api.services.calendar.model.Events)2 SchedulerException (org.quartz.SchedulerException)2 Credential (com.google.api.client.auth.oauth2.Credential)1 DateTime (com.google.api.client.util.DateTime)1 Calendar (com.google.api.services.calendar.Calendar)1 CalendarListEntry (com.google.api.services.calendar.model.CalendarListEntry)1 Event (com.google.api.services.calendar.model.Event)1 EventDateTime (com.google.api.services.calendar.model.EventDateTime)1 IOException (java.io.IOException)1 Date (java.util.Date)1 TimeRangeCalendar (org.openhab.io.gcal.internal.util.TimeRangeCalendar)1 ConfigurationException (org.osgi.service.cm.ConfigurationException)1