Package com.google.gdata.client.calendar

Examples of com.google.gdata.client.calendar.CalendarService


  private CalendarService oCalSrv;
  private CalendarEntry oCalendar;
  private HashMap<String,Integer> oWrkA;
 
  public GCalendarSynchronizer() {
    oCalSrv = new CalendarService("knowgate-hipergate-6");
    oWrkA = new HashMap<String,Integer>();
  }
View Full Code Here


public class SmsUtil {
    public static void send(String title, String username, String password)
            throws SmsSendException {
        CalendarEventEntry entry = new CalendarEventEntry();
        CalendarService service = new CalendarService("GrayGoose-1.0");

        try {
            service.setUserCredentials(username, password);
        } catch (AuthenticationException e) {
            throw new SmsSendException("Illegal credentials.", e);
        }

        entry.setService(service);
        entry.setTitle(TextConstruct.plainText(title));
        entry.setContent(TextConstruct.plainText(""));

        setupWhen(entry);
        try {
            CalendarEventEntry insertedEntry = service.insert(
                    new URL("http://www.google.com/calendar/feeds/default/private/full"),
                    entry
            );
            setupReminder(insertedEntry);
            insertedEntry.update();
View Full Code Here

  public GDataCalendarProxy(String calendarFeedUrl, long gdataThreadSleep, long gdataConnectTimeout) {

  }

  public GDataCalendarProxy(String calendarFeedUrl, String login, String password, long gdataThreadSleep, long gdataConnectTimeout) {
    this.service = new CalendarService("Avicena-v1");
    this.gdataThreadSleep = gdataThreadSleep;
    this.gdataConnectTimeout = gdataConnectTimeout;
    try {
      if (isDevMod()) {
        // Ignore the servlet parameter
View Full Code Here

            + (contact.hasBirthday() ? "\t" + contact.getBirthday().getValue() : ""));
      }
*/
     
      // Create CalendarService and authenticate using ClientLogin
      CalendarService calService = new CalendarService(APP_NAME);
      calService.setProtocolVersion(CalendarService.Versions.V2_1);
      calService.setUserCredentials(userName, userPassword);

      // The URL for the own calendars feed of the specified user
      URL calUrl = new URL ( CALENDAR_FEED_URL );

      // Get Number of calendars 
      Query calQuery = new Query(calUrl);
      calQuery.setMaxResults(1);    
      CalendarFeed calFeed = calService.query(calQuery, CalendarFeed.class);
      if (calFeed.getTotalResults() == 0) {
        System.out.println("No Calendars");
      } else {
        // Set Number of calendars for query
        calQuery.setMaxResults(calFeed.getTotalResults());
        calFeed = calService.query(calQuery, CalendarFeed.class)
      }
     
      // Search calendar
      System.out.println("Calendar to use for birthdays");
      for (CalendarEntry entry : calFeed.getEntries()) {
        if ( entry.getTitle().getPlainText().equals( CALENDAR_NAME ) ) {
          calEntry = entry;
        }
      }
      if (calEntry == null) {
        // No calendar found - Add a birthday calendar
        calEntry = new CalendarEntry();
        calEntry.setTitle(new PlainTextConstruct( CALENDAR_NAME ));
        calEntry.setSummary(new PlainTextConstruct( CALENDAR_SUMMARY ));
        calEntry.setTimeZone(calFeed.getEntries().get(0).getTimeZone());
        calEntry.setHidden(HiddenProperty.FALSE);
        calEntry.setColor(new ColorProperty( CALENDAR_COLOR ));
        calEntry.setSelected(SelectedProperty.TRUE);
        //calEntry.addLocation(new Where("", "", "Oakland"));
        //calEntry.addLocation(calFeed.getEntries().get(0).getLocations().);

          // Insert the calendar
        calService.insert(calUrl, calEntry);
        System.out.println("\tCreated: " + calEntry.getTitle().getPlainText());
        //Thread.sleep(5000);
        calQuery.setMaxResults(calFeed.getTotalResults()+1);
        calFeed = calService.query(calQuery, CalendarFeed.class)
        for (CalendarEntry entry : calFeed.getEntries()) {
          if ( entry.getTitle().getPlainText().equals( CALENDAR_NAME ) ) {
            calEntry = entry;
          }
        }
      }
      else {
        System.out.println("\tFound: " + ( (calEntry != null) ? calEntry.getTitle().getPlainText() : "null") );
      }

     
      // Get all events
      URL eventUrl = new URL ( calEntry.getLink(Link.Rel.ALTERNATE, Link.Type.ATOM).getHref() );
     
      // Get Number of events 
      Query eventQuery = new Query(eventUrl);
      eventQuery.setMaxResults(1);    
      CalendarEventFeed eventFeed = calService.query(eventQuery, CalendarEventFeed.class)
      if (eventFeed.getTotalResults() == 0) {
        System.out.println("No Events");
      } else {
        // Set Number of events for query
        eventQuery.setMaxResults(eventFeed.getTotalResults());
        eventFeed = calService.query(eventQuery, CalendarEventFeed.class);       
      }

      Boolean exists = false;
      Boolean update = false;
      Integer batchid = 0;

        Method methodType = Method.ALERT; //Method.EMAIL;
        Reminder reminder = new Reminder();
        reminder.setDays( REMINDER_DAYS );
        reminder.setMethod(methodType);
      CalendarEventFeed batchRequest = new CalendarEventFeed();

      // Copy contacts with title and birthday and check if event exists
      for (ContactEntry contact : conFeed.getEntries()) {

        if ( (contact.hasName()) && (contact.hasBirthday()) ) {
         
          exists = false;
          update = false;
         
          CalendarEventEntry entry = new CalendarEventEntry();
         
          SimpleDateFormat sdf = new SimpleDateFormat( DATE_FORMAT_GCON_PARSE_YMD );
          Date date;
          String datePattern;
          try {
            sdf.applyPattern( DATE_FORMAT_GCON_PARSE_YMD );
            date = sdf.parse(contact.getBirthday().getWhen());
            datePattern = DATE_FORMAT_GCAL_TEXT_DMY;
          } catch (ParseException e) {
            sdf.applyPattern( DATE_FORMAT_GCON_PARSE_MD );
            date = sdf.parse(contact.getBirthday().getWhen());
            datePattern = DATE_FORMAT_GCAL_TEXT_DM;
          }         
         
          for ( CalendarEventEntry event : eventFeed.getEntries() ) {

            if ( event.getTitle().getPlainText().contains( contact.getName().getFullName().getValue() ) ) {
              // found event for given contact
              // check date
              sdf.applyPattern( DATE_FORMAT_GCAL_SET_EVENT );
              if ( event.getRecurrence().getValue().contains( sdf.format(date) )) {
              //if ( event.getRecurrence().getValue().contains( recurData.substring(0, 25) )) {
                // same date - nothing todo
                //DEBUG: System.out.println("\tcontact and event have same date: " + contact.getName().getFullName().getValue() + " " + event.getTitle().getPlainText() );
                System.out.println("\tcontact and event have same date: " + contact.getName().getFullName().getValue() + " " + event.getTitle().getPlainText() );
                exists = true;
              }
              else {
                // date not correct - update date
                //DEBUG: System.out.println("\tcontact and event have not the same date: " + contact.getName().getFullName().getValue() + " " + contact.getBirthday().getWhen() + " " + event.getTitle().getPlainText() /* + " " + event.getRecurrence().getValue() */ );
                System.out.println("\tcontact and event have not the same date: " + contact.getName().getFullName().getValue() + " " + contact.getBirthday().getWhen() );
                update = true;
                entry = event;
              }
            }
          }
          if ( exists == false ) {
            // no event for given contact - add event
            sdf.applyPattern( datePattern );
            entry.setTitle( new PlainTextConstruct( contact.getName().getFullName().getValue() + " " + sdf.format(date) ) );
            entry.setContent( new PlainTextConstruct( "Birthday Celebration " + contact.getName().getFullName().getValue() + " (" + sdf.format(date) + ")") );
              sdf.applyPattern( DATE_FORMAT_GCAL_SET_EVENT );
            String recurData = "DTSTART;VALUE=DATE:" + sdf.format(date) + "\n"
                       + "DTEND;VALUE=DATE:" + sdf.format(date) + "\n"
                       + "RRULE:FREQ=YEARLY";
              Recurrence recur = new Recurrence();
              recur.setValue(recurData);
              entry.setRecurrence(recur);

              entry.getReminder().add(reminder);

            batchid++;
            BatchUtils.setBatchId(entry, batchid.toString());
            if ( update == true ) {
              System.out.println("\tUpd contact: " + contact.getName().getFullName().getValue());
              BatchUtils.setBatchOperationType(entry, BatchOperationType.UPDATE);
            } else {
              System.out.println("\tAdd contact: " + contact.getName().getFullName().getValue());
              BatchUtils.setBatchOperationType(entry, BatchOperationType.INSERT)
            }
            batchRequest.getEntries().add(entry);
          }
        }
      }

     
      // Get the batch link URL and send the batch request there.
      if ( batchRequest.getEntries().isEmpty() ) {
        System.out.println("No Batch Request");
      }else {
            System.out.println("Send Calendar Batch Request");
        Link batchLink = eventFeed.getLink(Link.Rel.FEED_BATCH, Link.Type.ATOM);
        //CalendarEventFeed batchResponse =
          calService.batch(new URL(batchLink.getHref()), batchRequest);
      }
     
/* //DEBUG:     
      // Print all events 
      // Get Number of calendar entries 
View Full Code Here

        GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
        oauthParameters.setOAuthConsumerKey(consumerKey);
        oauthParameters.setOAuthConsumerSecret(consumerSecret);
        System.out.println(consumerKey + " " + consumerSecret);
        oauthParameters.setOAuthType(OAuthParameters.OAuthType.TWO_LEGGED_OAUTH);
        calendarService = new CalendarService("marketplace-hello");
        try {
            calendarService.setOAuthCredentials(oauthParameters, new OAuthHmacSha1Signer());
        } catch (OAuthException e) {
            throw new ServletException("Unable to initialize calendar service", e);
        }
View Full Code Here

        GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
        oauthParameters.setOAuthConsumerKey(consumerKey);
        oauthParameters.setOAuthConsumerSecret(consumerSecret);

        calendarService = new CalendarService("marketplace-hello");
        try {
            calendarService.setOAuthCredentials(oauthParameters, new OAuthHmacSha1Signer());
        } catch (OAuthException e) {
            throw new ServletException("Unable to initialize calendar service", e);
        }
View Full Code Here

   * @throws EPAuthenticationException
   */
  private CalendarService getCalService()
      throws EPAuthenticationException {
    if (this.calService == null) {
      CalendarService calService = new CalendarService(APP_IDENTITY);
      try {
        calService.setUserCredentials(calUsername, calPassword);
      } catch (com.google.gdata.util.AuthenticationException authEx) {
        throw new EPAuthenticationException("Bad calendar credentials");
      }
      this.calService = calService;
      return calService;
View Full Code Here

   * @throws IOException
   * @throws ServiceException
   */
  private void publishEventToCalendar(Event event)
  throws EPAuthenticationException, IOException, ServiceException {
    CalendarService calService = getCalService();
    CalendarEventEntry entry = null;
    if (event.getCalendarUrl() != null) {
      // updating event
      entry = calService.getEntry(event.getCalendarUrl(),
          CalendarEventEntry.class);
    } else {
      // publishing new event
      entry = new CalendarEventEntry();  
    }

    // set data on event
    entry.setTitle(new PlainTextConstruct(event.getTitle()));
    entry.setContent(new PlainTextConstruct(event.getDescription()));
    When when = new When();
    DateTime startDateTime = new DateTime(event.getStartDate());
    startDateTime.setDateOnly(true);

    // we must add 1 day to the event as the end-date is exclusive
    Calendar endDateCal = new GregorianCalendar();
    endDateCal.setTime(event.getEndDate());
    endDateCal.add(Calendar.DATE, 1);
    DateTime endDateTime = new DateTime(endDateCal.getTime());
    endDateTime.setDateOnly(true);

    when.setStartTime(startDateTime);
    when.setEndTime(endDateTime);
    entry.getTimes().add(when);
    if (event.getCalendarUrl() != null) {
      // updating event
      entry.update()
    } else {
      // insert event
      CalendarEventEntry resultEntry = calService.insert(calUrl, entry);
      updateSsEventEditUrl(event.getSsEditUrl(),
          resultEntry.getEditLink().getHref(),
          null);
    }
  }
View Full Code Here

      return;
    } else if (args.length == 3) {
      userToShareWith = args[2];
    }

    CalendarService myService = new CalendarService("demo-AclFeedDemo-1");
    String userName = args[0];
    String userPassword = args[1];

    // Create necessary URL objects
    try {
      metafeedUrl = new URL(METAFEED_URL_BASE + userName);
      aclFeedUrl = new URL(METAFEED_URL_BASE + userName + ACL_FEED_URL_SUFFIX);
    } catch (MalformedURLException e) {
        // Bad URL
        System.err.println("Uh oh - you've got an invalid URL.");
        e.printStackTrace();
        return;
    }
   
    try {
      myService.setUserCredentials(userName, userPassword);

      // Demonstrate retrieving access control list feeds.
      printAclList(myService);

      if (userToShareWith != null) {
View Full Code Here

    }

    String uname = args[0];
    String upassword = args[1];

    CalendarService myService = new CalendarService(
        "gdata-CalendarPartialDemo");
    myService.setUserCredentials(uname, upassword);

    EventFeedPartialDemo demo = new EventFeedPartialDemo(myService);

    while (true) {
      try {
View Full Code Here

TOP

Related Classes of com.google.gdata.client.calendar.CalendarService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.