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 ...");
}
}
}
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;
}
Aggregations