Dhruti90 / google-gdata1111

Automatically exported from code.google.com/p/google-gdata
0 stars 0 forks source link

RetrieveAllUsers Method only returns the first 200 users. #298

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Call the RetrieveAllUsers Method from the AppService Class

What is the expected output? What do you see instead?

A feed of all the users in my domain

What version of the product are you using? On what operating system?

r958  Windows 7

Please provide any additional information below.

An application I wrote using a version of gdata from Feb. 2009 still 
returns all users, but when I use a more current version of gdata, I only 
get 200 user in my domain. The issue appears in r952 also.

The code below will output "200" to the console:
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  Dim appsService As New Google.GData.Apps.AppsService("example.org", 
"user@example.org", "Password")
        Dim users As Google.GData.Apps.UserFeed
        Dim count As Integer = 0
        users = appsService.RetrieveAllUsers

        For Each u As Google.GData.Apps.UserEntry In users.Entries
            count += 1

        Next
        Console.WriteLine(count.ToString)
        Console.ReadLine()
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Original issue reported on code.google.com by edwin.la...@gmail.com on 2 Dec 2009 at 12:45

GoogleCodeExporter commented 9 years ago
I found out why it's only returning 200 entries.  In the userservice.cs file, 
in the 
Query method, a call to feed.Parse leaves the original "next" AtomLink in the 
feed 
and appends the new "next" AtomLink to the feed.  When a call to 
feed.Links.FindService("next", null) is made, it returns the first "next" 
AtomLink it 
finds, when it should return the AtomLink from the last call.  I made a change 
in my 
copy of the code as a temporary fix, but I'd imagine that you guys would want 
to 
change the behavior of wherever the feed.Parse call goes.  To get it to work 
for me I 
got a list of all the "next" AtomLinks, and used the last in the list for my 
new Uri.  
Sorry I didn't go further with it, but I'm a VB guy.  Semicolons and squiggly 
brackets make me agitated. :) 

I changed the code to:

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
public UserFeed Query(UserQuery feedQuery)
        {
            try
            {
                Stream feedStream = Query(feedQuery.Uri);
                UserFeed feed = new UserFeed(feedQuery.Uri, this);

                feed.Parse(feedStream, AlternativeFormat.Atom);
                feedStream.Close();

                if (feedQuery.RetrieveAllUsers)
                {

                    AtomLink next, prev = null;
                    List<AtomLink> nexts;

                    prev = new AtomLink();
                    next = feed.Links.FindService("next", null);

                    while ((next != null) && (next.HRef != prev.HRef))
                    {
                        prev = next;
                        feedStream = Query(new Uri(next.HRef.ToString()));
                        feed.Parse(feedStream,AlternativeFormat.Atom);
                        feedStream.Close();
                        nexts = feed.Links.FindServiceList("next", null);
                        next = nexts[nexts.Count - 1];                     
                     }

                }

                return feed;
            }
            catch (GDataRequestException e)
            {
                AppsException a = AppsException.ParseAppsException(e);
                throw (a == null ? e : a);
            }
        }
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

From:

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
public UserFeed Query(UserQuery feedQuery)
        {
            try
            {
                Stream feedStream = Query(feedQuery.Uri);
                UserFeed feed = new UserFeed(feedQuery.Uri, this);
                feed.Parse(feedStream, AlternativeFormat.Atom);
                feedStream.Close();

                if (feedQuery.RetrieveAllUsers)
                {
                    AtomLink next, prev = null;
                    while ((next = feed.Links.FindService("next", null)) != null && 
next != prev)
                    {
                        feedStream = Query(new Uri(next.HRef.ToString()));
                        feed.Parse(feedStream, AlternativeFormat.Atom);
                        feedStream.Close();

                        prev = next;
                    }
                }

                return feed;
            }
            catch (GDataRequestException e)
            {
                AppsException a = AppsException.ParseAppsException(e);
                throw (a == null ? e : a);
            }
        }
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Original comment by edwin.la...@gmail.com on 2 Dec 2009 at 11:00

GoogleCodeExporter commented 9 years ago
Thanks for the detailed bug report. This helped a lot. The bug is that 
feed.Parse()
did not take into account that it might be called several times on the same 
object.

I modified the .Parse() implementation to reset it's collections before 
parsing. If
you would be so kind to download new DLLs from the subversion repository and 
try out
if that fixes your issue.

Frank Mantek
Google

Original comment by fman...@gmail.com on 8 Dec 2009 at 1:36

GoogleCodeExporter commented 9 years ago
Thanks Frank,

It works now!

Original comment by edwin.la...@gmail.com on 8 Dec 2009 at 6:14

GoogleCodeExporter commented 9 years ago
Then i declare it FIXED :)

Original comment by fman...@gmail.com on 9 Dec 2009 at 8:40