GithubHelp home page GithubHelp logo

Comments (13)

madanbisht avatar madanbisht commented on June 15, 2024 1

Hi David,
We have verified and its working perfectly.

We sincerely appreciate your consideration and time for developing this to us so quickly...!!!

from odata-client.

davidmoten avatar davidmoten commented on June 15, 2024

Why do you care about low-level stuff like @odata.nextLink? Just use the collections support in the API. See Collections and paging in the README.md. Can you explain your use case further?

from odata-client.

madanbisht avatar madanbisht commented on June 15, 2024

Thanks for your response and below is the use-case:

There is a service which receives request from a client and we are trying to implement paging, so that the service will send only the list of users requested by the client. As an example:

Step 1) Client send request to get the list of N users and service can get user-list as below:

     OdataClientFactory
                    .request()
                    .users().top(N)
                    .get();

After getting response client will parse N users and extract @data.nextLink from the response.

Step 2) Client sends request to get next N users providing the @data.nextLink and service can use @data.nextLink to get next N users.

After getting response client will parse the user-list and extract @data.nextLink from the response.

Step 3) Repetition of step 2.

from odata-client.

davidmoten avatar davidmoten commented on June 15, 2024

So you're sort of proxying the Graph API for the client? @odata.nextLink just uses a skip field. You could add a counter field to the returned JSON and then get the user to pass the last counter value to the service instead of @odata.nextLink and use

List<User> page = client.client.users().skip(counter).get().currentPage();

when they call the service. That way you are not coupled to odata metadata like @odata.nextLink.

I could probably provide access to the @odata.nextLink field, I just wanted to explore alternatives first.

Note also you could parse the @odata.nextLink field that the client gives you for the skip parameter and use that in the call above.

from odata-client.

madanbisht avatar madanbisht commented on June 15, 2024

We already tried skip option(as given below) but as soon as we use skip it throws an exception(java.lang.NullPointerException). It seems skip is not supported.

List<User> users = OdataClientFactory
                    .request()
                    .users().skip(1)
                    .get()
                    .currentPage();

Ideally our use case can be implemented with below code, here top works fine but as soon as we use skip it throws exception.

List<User> users = OdataClientFactory
                    .request()
                    .users().top(200).skip(100)
                    .get()
                    .currentPage();

from odata-client.

davidmoten avatar davidmoten commented on June 15, 2024

Can you supply full stack trace? An NPE sounds like something I have to fix.

from odata-client.

davidmoten avatar davidmoten commented on June 15, 2024

By the way if top is your attempt to control page size I don't think it works.

from odata-client.

davidmoten avatar davidmoten commented on June 15, 2024

I just tried client.users().top(200).skip(100).get().currentPage() and like you I got an NPE. I'll fix that. However the base cause is

10:44:32.468 [main] DEBUG com.github.davidmoten.odata.client.internal.ApacheHttpClientHttpService - response text=
{
  "error": {
    "code": "Request_BadRequest",
    "message": "'$skip' is not supported by the service.",
    "innerError": {
      "date": "2020-06-13T00:44:32",
      "request-id": "63ed6165-729f-4753-88b9-e67399a312f5"
    }
  }
}

from odata-client.

davidmoten avatar davidmoten commented on June 15, 2024

In fact, digging a bit deeper I don't even have privileges:

client.users().stream().forEach(user -> System.out.println(user.getPrincipalName()));

gives an NPE (something else to fix!) and log says:

{
  "error": {
    "code": "Authorization_RequestDenied",
    "message": "Insufficient privileges to complete the operation.",
    "innerError": {
      "date": "2020-06-13T00:48:55",
      "request-id": "31c91f39-f97b-4f8b-8f6f-c4c00c1a8fe9"
    }
  }
}

from odata-client.

davidmoten avatar davidmoten commented on June 15, 2024

Reading a bit further I think the collection returned by users().get() must use $skipToken for pagination instead of $skip. Given this I need to rethink the advice about using skip.

from odata-client.

davidmoten avatar davidmoten commented on June 15, 2024

Please review PR #17.

from odata-client.

davidmoten avatar davidmoten commented on June 15, 2024

I've addressed this issue now with #17.

You can specify the link for a collection like this:

List<User> users = client.users().urlOverride(url).get().currentPage();

I'll release shortly, let me know if any problems.

from odata-client.

davidmoten avatar davidmoten commented on June 15, 2024

0.1.16 released to Maven Central with #16, #17 that resolve this issue. You may wish to watch this repository to hear about future releases (which are pretty frequent lately).

from odata-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.