Search in sources :

Example 6 with CalendarListEntry

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));
}
Also used : CalendarListEntry(com.google.api.services.calendar.model.CalendarListEntry) Event(com.google.api.services.calendar.model.Event)

Example 7 with CalendarListEntry

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();
    }
}
Also used : Credential(com.google.api.client.auth.oauth2.Credential) Calendar(com.google.api.services.calendar.Calendar) ArrayList(java.util.ArrayList) Booking(com.github.drbookings.core.datamodel.api.Booking) BookingBean(com.github.drbookings.core.datamodel.impl.BookingBean) FileDataStoreFactory(com.google.api.client.util.store.FileDataStoreFactory) CalendarListEntry(com.google.api.services.calendar.model.CalendarListEntry) Events(com.google.api.services.calendar.model.Events) Event(com.google.api.services.calendar.model.Event) CalendarList(com.google.api.services.calendar.model.CalendarList)

Example 8 with CalendarListEntry

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;
}
Also used : CalendarListEntry(com.google.api.services.calendar.model.CalendarListEntry) CalendarList(com.google.api.services.calendar.model.CalendarList) IOException(java.io.IOException)

Example 9 with CalendarListEntry

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;
}
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)

Example 10 with CalendarListEntry

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;
}
Also used : CalendarListEntry(com.google.api.services.calendar.model.CalendarListEntry) CalendarList(com.google.api.services.calendar.model.CalendarList)

Aggregations

CalendarListEntry (com.google.api.services.calendar.model.CalendarListEntry)16 Calendar (com.google.api.services.calendar.Calendar)6 CalendarList (com.google.api.services.calendar.model.CalendarList)6 IOException (java.io.IOException)6 Event (com.google.api.services.calendar.model.Event)5 ArrayList (java.util.ArrayList)4 Events (com.google.api.services.calendar.model.Events)3 Credential (com.google.api.client.auth.oauth2.Credential)2 DateTime (com.google.api.client.util.DateTime)2 AESEncryption (com.cloudcraftgaming.discal.api.crypto.AESEncryption)1 GuildSettings (com.cloudcraftgaming.discal.api.object.GuildSettings)1 CalendarData (com.cloudcraftgaming.discal.api.object.calendar.CalendarData)1 AuthPollResponseError (com.cloudcraftgaming.discal.api.object.json.google.AuthPollResponseError)1 AuthPollResponseGrant (com.cloudcraftgaming.discal.api.object.json.google.AuthPollResponseGrant)1 Booking (com.github.drbookings.core.datamodel.api.Booking)1 BookingBean (com.github.drbookings.core.datamodel.impl.BookingBean)1 FileDataStoreFactory (com.google.api.client.util.store.FileDataStoreFactory)1 Calendar (com.google.api.services.calendar.model.Calendar)1 EventDateTime (com.google.api.services.calendar.model.EventDateTime)1 Gson (com.google.gson.Gson)1