use of com.google.api.services.calendar.model.CalendarListEntry in project drbookings by DrBookings.
the class GoogleCalendarSync method addCheckOutEvent.
private static void addCheckOutEvent(final BookingBean b) throws IOException {
final CalendarListEntry flats = getCalendar();
String note = "Checkout: ";
if (b.getCheckOutNote() != null) {
note += b.getCheckOutNote();
}
final Event event = new EventFactory().newEvent(getCheckOutSummary(b), b.getCheckOut(), b.getGuest().getName() + ": " + note);
b.addCalendarId(addEvent(flats.getId(), event));
}
use of com.google.api.services.calendar.model.CalendarListEntry in project drbookings by DrBookings.
the class RunnableImportGoogleCalendar method process.
@Override
protected List<Booking> process(final IProgressMonitor monitor) throws Exception {
try {
if (logger.isInfoEnabled()) {
logger.info("Adding from " + url);
}
// initialize the transport
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
// initialize the data store factory
dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);
// authorization
final Credential credential = authorize();
// set up global Calendar instance
final Calendar client = new com.google.api.services.calendar.Calendar.Builder(httpTransport, JSON_FACTORY, credential).setApplicationName("drbookings").build();
final CalendarList list = client.calendarList().list().execute();
String id = null;
for (final CalendarListEntry item : list.getItems()) {
if (item.getSummary().contains("airbnb")) {
id = item.getId();
}
}
final Events feed = client.events().list(id).execute();
final List<Booking> result = new ArrayList<>();
for (final Event item : feed.getItems()) {
System.out.println(item);
result.add(new BookingBean(item.getSummary(), LocalDate.parse(item.getStart().getDate().toString()), LocalDate.parse(item.getEnd().getDate().toString())));
}
return result;
} finally {
monitor.done();
}
}
use of com.google.api.services.calendar.model.CalendarListEntry in project jbpm-work-items by kiegroup.
the class GetEventsWorkitemHandler method getCalendarIdBySummary.
public String getCalendarIdBySummary(com.google.api.services.calendar.Calendar client, String summary) {
String resultId = null;
try {
CalendarList calendarList = getAllCalendars(client);
List<CalendarListEntry> entryList = calendarList.getItems();
for (CalendarListEntry entry : entryList) {
if (entry.getSummary().equalsIgnoreCase(summary)) {
resultId = entry.getId();
}
}
} catch (Exception e) {
logger.error(MessageFormat.format("Error retrieveing calendars: {0}", e.getMessage()));
}
return resultId;
}
use of com.google.api.services.calendar.model.CalendarListEntry 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;
}
use of com.google.api.services.calendar.model.CalendarListEntry in project camel by apache.
the class CalendarCalendarListIntegrationTest method isCalendarInList.
protected boolean isCalendarInList(Calendar calendar) {
CalendarList calendarList = requestBody("direct://LIST", null);
java.util.List<CalendarListEntry> items = calendarList.getItems();
boolean found = false;
for (CalendarListEntry calendarListEntry : items) {
if (calendar.getSummary().equals(calendarListEntry.getSummary())) {
found = true;
}
}
return found;
}
Aggregations