Package com.google.gdata.data.contacts

Examples of com.google.gdata.data.contacts.ContactFeed


    public List<GoogleContactsEntry> searchContact(
            GoogleContactsConnection cnx, GoogleQuery gQuery, int count,
            GoogleEntryCallback callback)
    {
        URL url = null;
        ContactFeed contactFeed = null;
        ContactQuery query = null;
        List<GoogleContactsEntry> ret = new ArrayList<GoogleContactsEntry>();
        boolean endOfContacts = false;
        int matchedContacts = 0;
        int index = 1;
        GoogleContactsConnectionImpl cnxImpl =
            (GoogleContactsConnectionImpl)cnx;

        if(count <= 0)
        {
            count = MAX_RESULT;
        }

        try
        {
            url = new URL(feedURL);
        }
        catch(MalformedURLException e)
        {
            logger.info("Malformed URL", e);
            return ret;
        }

        if(gQuery.isCancelled())
        {
            return ret;
        }

        while(matchedContacts < count || endOfContacts)
        {
            query = new ContactQuery(url);
            query.setStartIndex(index);
            query.setMaxResults(MAX_NUMBER);
            query.setSortOrder(ContactQuery.SortOrder.DESCENDING);

            if(gQuery.isCancelled())
            {
                return ret;
            }

            try
            {
                contactFeed = cnxImpl.getGoogleService().query(
                        query, ContactFeed.class);
            }
            catch(Exception e)
            {
                logger.info(
                        "Problem occurred during Google Contacts retrievment",
                        e);
                return ret;
            }

            if(contactFeed.getEntries().size() == 0)
            {
                endOfContacts = true;
                break;
            }

            for (int i = 0; i < contactFeed.getEntries().size(); i++)
            {
                if(gQuery.isCancelled())
                {
                    return ret;
                }

                ContactEntry entry = contactFeed.getEntries().get(i);

                if(filter(entry, gQuery.getQueryPattern()))
                {
                    GoogleContactsEntry gcEntry = null;

                    gcEntry = getGoogleContactsEntry(entry);
                    matchedContacts++;
                    ret.add(gcEntry);

                    if(callback != null)
                    {
                        callback.callback(gcEntry);
                    }

                    if(matchedContacts >= count)
                    {
                        break;
                    }
                }
            }

            index += contactFeed.getEntries().size();
        }
        return ret;
    }
View Full Code Here


        }
        try {
            URL feedUrl = new URL("http://www.google.com/m8/feeds/contacts/" + email + "/full");
            Query query = new Query(feedUrl);
            query.setMaxResults(Integer.MAX_VALUE);
            ContactFeed resultFeed = service.query(query, ContactFeed.class);
            List<Contact> contacts = new ArrayList<Contact>();
            for (ContactEntry entry : resultFeed.getEntries()) {
                for (Email email : entry.getEmailAddresses()) {
                    String address = email.getAddress();
                    String name = null;
                    if (entry.hasName()) {
                        name = entry.getName().getFullName().getValue();
View Full Code Here

    public List<GoogleContactsEntry> searchContact(
            GoogleContactsConnection cnx, GoogleQuery gQuery, int count,
            GoogleEntryCallback callback)
    {
        URL url = null;
        ContactFeed contactFeed = null;
        ContactQuery query = null;
        List<GoogleContactsEntry> ret = new ArrayList<GoogleContactsEntry>();
        boolean endOfContacts = false;
        int matchedContacts = 0;
        int index = 1;
        GoogleContactsConnectionImpl cnxImpl =
            (GoogleContactsConnectionImpl)cnx;

        if(count <= 0)
        {
            count = MAX_RESULT;
        }

        try
        {
            url = new URL(feedURL);
        }
        catch(MalformedURLException e)
        {
            logger.info("Malformed URL", e);
            return ret;
        }

        if(gQuery.isCancelled())
        {
            return ret;
        }

        while(matchedContacts < count || endOfContacts)
        {
            query = new ContactQuery(url);
            query.setStartIndex(index);
            query.setMaxResults(MAX_NUMBER);
            query.setSortOrder(ContactQuery.SortOrder.DESCENDING);

            if(gQuery.isCancelled())
            {
                return ret;
            }

            try
            {
                contactFeed = cnxImpl.getGoogleService().query(
                        query, ContactFeed.class);
            }
            catch(Exception e)
            {
                logger.info(
                        "Problem occurred during Google Contacts retrievment",
                        e);
                return ret;
            }

            if(contactFeed.getEntries().size() == 0)
            {
                endOfContacts = true;
                break;
            }

            for (int i = 0; i < contactFeed.getEntries().size(); i++)
            {
                if(gQuery.isCancelled())
                {
                    return ret;
                }

                ContactEntry entry = contactFeed.getEntries().get(i);

                if(filter(entry, gQuery.getQueryPattern()))
                {
                    GoogleContactsEntry gcEntry = null;

                    gcEntry = getGoogleContactsEntry(entry);
                    matchedContacts++;
                    ret.add(gcEntry);

                    if(callback != null)
                    {
                        callback.callback(gcEntry);
                    }

                    if(matchedContacts >= count)
                    {
                        break;
                    }
                }
            }

            index += contactFeed.getEntries().size();
        }
        return ret;
    }
View Full Code Here

    public List<GoogleContactsEntry> searchContact(
            GoogleContactsConnection cnx, GoogleQuery gQuery, int count,
            GoogleEntryCallback callback)
    {
        URL url = null;
        ContactFeed contactFeed = null;
        ContactQuery query = null;
        List<GoogleContactsEntry> ret = new ArrayList<GoogleContactsEntry>();
        boolean endOfContacts = false;
        int matchedContacts = 0;
        int index = 1;
        GoogleContactsConnectionImpl cnxImpl =
            (GoogleContactsConnectionImpl)cnx;

        if(count <= 0)
        {
            count = MAX_RESULT;
        }

        try
        {
            url = new URL(feedURL);
        }
        catch(MalformedURLException e)
        {
            logger.info("Malformed URL", e);
            return ret;
        }

        if(gQuery.isCancelled())
        {
            return ret;
        }

        while(matchedContacts < count || endOfContacts)
        {
            query = new ContactQuery(url);
            query.setStartIndex(index);
            query.setMaxResults(MAX_NUMBER);
            query.setSortOrder(ContactQuery.SortOrder.DESCENDING);

            if(gQuery.isCancelled())
            {
                return ret;
            }

            try
            {
                contactFeed = cnxImpl.getGoogleService().query(
                        query, ContactFeed.class);
            }
            catch(Exception e)
            {
                logger.info(
                        "Problem occurred during Google Contacts retrievment",
                        e);
                return ret;
            }

            if(contactFeed.getEntries().size() == 0)
            {
                endOfContacts = true;
                break;
            }

            for (int i = 0; i < contactFeed.getEntries().size(); i++)
            {
                if(gQuery.isCancelled())
                {
                    return ret;
                }

                ContactEntry entry = contactFeed.getEntries().get(i);

                if(filter(entry, gQuery.getQueryPattern()))
                {
                    GoogleContactsEntry gcEntry = null;

                    gcEntry = getGoogleContactsEntry(entry);
                    matchedContacts++;
                    ret.add(gcEntry);

                    if(callback != null)
                    {
                        callback.callback(gcEntry);
                    }

                    if(matchedContacts >= count)
                    {
                        break;
                    }
                }
            }

            index += contactFeed.getEntries().size();
        }
        return ret;
    }
View Full Code Here

      OAuthSigner signer = new OAuthHmacSha1Signer();

      service.setOAuthCredentials(params, signer);

      ContactFeed resultFeed;
      try {
        resultFeed = service.getFeed(feedUrl, ContactFeed.class);
      } catch (NullPointerException e) {
        request.setAttribute("contacts", null);
        return;
View Full Code Here

      URL conUrl = new URL( CONTACTS_FEED_URL );

      // Get Number of contacts 
      Query conQuery = new Query(conUrl);
      conQuery.setMaxResults(1);    
      ContactFeed conFeed = myService.query(conQuery, ContactFeed.class);
      if (conFeed.getTotalResults() == 0) {
        System.out.println("No Contacts");
        return;
      } else {
        // Set Number of contacts for query
        conQuery.setMaxResults(conFeed.getTotalResults());
        conFeed = myService.query(conQuery, ContactFeed.class);
     
     
/* //DEBUG:   
          System.out.println("All contacts:");
      for (ContactEntry contact : conFeed.getEntries()) {
        System.out.println("\tContact: "
            + (contact.hasName() ? contact.getName().getFullName().getValue() : "null")
            + (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;
View Full Code Here

          printGroup(entry);
        }
        System.err.println("Total: " + groupFeed.getEntries().size()
            + " entries found");
      } else {
        ContactFeed resultFeed = service.query(myQuery, ContactFeed.class);
        for (ContactEntry entry : resultFeed.getEntries()) {
          printContact(entry);
        }
        System.err.println("Total: " + resultFeed.getEntries().size()
            + " entries found");
      }
    } catch (NoLongerAvailableException ex) {
      System.err.println(
          "Not all placehorders of deleted entries are available");
View Full Code Here

        printGroup(entry);
      }
      System.err.println("Total: " + groupFeed.getEntries().size() +
          " groups found");
    } else {
      ContactFeed resultFeed = service.getFeed(feedUrl, ContactFeed.class);
      // Print the results
      System.err.println(resultFeed.getTitle().getPlainText());
      for (ContactEntry entry : resultFeed.getEntries()) {
        printContact(entry);
        // Since 2.0, the photo link is always there, the presence of an actual
        // photo is indicated by the presence of an ETag.
        Link photoLink = entry.getLink(
            "http://schemas.google.com/contacts/2008/rel#photo", "image/*");
        if (photoLink.getEtag() != null) {
          Service.GDataRequest request =
              service.createLinkQueryRequest(photoLink);
          request.execute();
          InputStream in = request.getResponseStream();
          ByteArrayOutputStream out = new ByteArrayOutputStream();
          RandomAccessFile file = new RandomAccessFile(
              "/tmp/" + entry.getSelfLink().getHref().substring(
              entry.getSelfLink().getHref().lastIndexOf('/') + 1), "rw");
          byte[] buffer = new byte[4096];
          for (int read = 0; (read = in.read(buffer)) != -1;
              out.write(buffer, 0, read)) {}
          file.write(out.toByteArray());
          file.close();
          in.close();
          request.end();
        }
      }
      System.err.println("Total: " + resultFeed.getEntries().size()
          + " entries found");
    }
  }
View Full Code Here

      URL feedUrl =
          new URL("https://www.google.com/m8/feeds/profiles/domain/" + this.domain
              + "/full?xoauth_requestor_id=" + this.adminEmail);
      while (feedUrl != null) {
        ContactFeed resultFeed = this.myService.getFeed(feedUrl, ContactFeed.class);

        profiles.addAll(resultFeed.getEntries());

        if (resultFeed.getNextLink() != null && resultFeed.getNextLink().getHref() != null
            && resultFeed.getNextLink().getHref().length() > 0) {
          feedUrl = new URL(resultFeed.getNextLink().getHref());
        } else {
          feedUrl = null;
        }
      }
      this.profiles = profiles;
View Full Code Here

      Status status = new Status();
      int index = 0;

      status.setIndexed(false);
      while (index < this.profiles.size()) {
        ContactFeed requestFeed = new ContactFeed();

        for (int i = 0; i < this.batchSize && index < this.profiles.size(); ++i, ++index) {
          ContactEntry entry = this.profiles.get(index);

          entry.setStatus(status);
          BatchUtils.setBatchOperationType(entry, BatchOperationType.UPDATE);
          requestFeed.getEntries().add(entry);
        }

        ContactFeed responseFeed =
            myService.batch(new URL("https://www.google.com/m8/feeds/profiles/domain/"
                + this.domain + "/full/batch?xoauth_requestor_id=" + this.adminEmail), requestFeed);

        // Check the status of each operation.
        for (ContactEntry entry : responseFeed.getEntries()) {
          BatchStatus batchStatus = BatchUtils.getBatchStatus(entry);

          if (batchStatus.getCode() == 200) {
            result.setSuccess(result.getSuccess() + 1);
          } else {
View Full Code Here

TOP

Related Classes of com.google.gdata.data.contacts.ContactFeed

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.