ibmmaximorestjsonapis / maximorestclient

The Maximo REST client library provides a set of driver API's which can be consumed by an JAVA based web component that would like to interface with a Maximo instance.
Apache License 2.0
42 stars 43 forks source link

ResourceSet methods fetchMember and create do not set Resource to isLoaded #7

Closed bloodgain closed 7 years ago

bloodgain commented 7 years ago

The ResourceSet methods fetchMember and create return a Resource object created from JSON obtained from the server within the same function call. However, they do not set the isLoaded flag in the returned Resource object to true. An examination of the code reveals the same issue with other methods, including sync and mergeSync (possibly others).

Subsequent method calls on the Resource object (notably toJSON) initiate a load call on the Resource object before returning a value. This creates an extraneous call to the web service and discards properties arguments passed to the original loading method. As a result, the user is unable to get a reduced-scope JSON object from Resource objects when using these methods, while also generating unexpected calls to the server.

Possible solutions:

  1. Expose the isLoaded variable in Resource through package-private methods or constructors, allowing partner classes to create "pre-loaded" Resource objects.
  2. Set isLoaded to true by default in the Resource constructors that take JsonObject parameters. Make the constructors package-private.

Neither solution exposes the isLoaded variable to the public interface, but Solution 2 seems superior. It is simpler to implement and requires no extra work within ResourceSet or other partner classes. The current library design offers no obvious reason for users to construct Resource objects directly. If that need arises, static factory methods could be added to enable controlled construction.

ibmmaximorestjsonapis commented 7 years ago

Thank you for your feedback, we are currently reviewing the issues. Will update the issue as soon as we have the explanation or fix ready to post.

ibmmaximorestjsonapis commented 7 years ago

Here is the code example for preload:

    //Functionality Test for pre-load
    int index=0;
    Resource preLoadResource = setHasTerms.member(index);
    while(preLoadResource != null)
    {
        if(index%2 != 0) {
            preLoadResource.setLoaded(true);
        }
        Util.jsonPrettyPrinter(preLoadResource.toJSON());
        preLoadResource = setHasTerms.member(++index);
    }       
    Util.jsonPrettyPrinter(setHasTerms.count());

It is available in Git and Maven.