Hi Ola,

Thanks for providing all the info for this query.

The reason that Isis wants an href for the "basketItem" parameter is
because RO only supports the idea of passing a reference to an existing
persistent object; it isn't possible to pass an arbitrary blob of JSON
(which is what you are doing here) and have it be magically transformed
server-side into an object.

I was about to say that the suggestion you dismissed - to extend the
signature of the action to include parameters for the values of the basket
item - would be reasonable; but then it occurred to me that probably you
want the basket item to be polymorphic (ie any Object), and so changing the
action signature would prevent this.

So, instead, what you'll need to do is to do two interactions; the first to
create and persist the BasketItem as a server-side object (which will give
you its href) and then secondly to call the action with the href of said
BasketItem.

Another possibility, I suppose, is that you define the last parameter as a
simple string, and then do the parsing of the JSON server-side within your
action.  That seems rather ugly to me, though.   (Perhaps the framework/RO
spec needs better support here to allow pluggable serialization of
parameters; something for me to think about).

Hope that helps, at least a little.

Dan


On 27 March 2014 19:51, Tomoloju, Ola <[email protected]> wrote:

> Hello Dan,
>
> Could you assist with this problem please:
>
> I am having problems persisting an object as a type.
>
> I could pass the properties of the object from the client, then compose
> the object in the method getBasket(...)
>
> But, we need to do things the right way!
>
> Below is the error in my chrome debugger:
>
>
>
> "invalidReason":"Expected a link (because this object's type is not a
> value) but found no 'href'"},"x-ro-invalidReason":"Basket Item is
> mandatory"}
>
>
>
> The operation RO Json:
>
>
> {
>     "rel" : "urn:org.restfulobjects:rels/invoke",
>     "href" : "
> http://localhost:8080/xxx-webapp-1.0-SNAPSHOT/restful/services/ShoppingBaskets/actions/getBasket/invoke
> ",
>     "method" : "POST",
>     "type" :
> "application/json;profile=\"urn:org.restfulobjects:repr-types/action-result\"",
>     "arguments" : {
>       "enterVanNumber" : {
>         "value" : null
>       },
>       "sessionId" : {
>         "value" : null
>       },
>       "customerId" : {
>         "value" : null
>       },
>       "email" : {
>         "value" : null
>       },
>       "basketItem" : {
>         "value" : null
>       }
>     }
>
> Method signature is below:
>
>   @Bookmarkable
>     @MemberOrder(sequence = "1")
>     @Named("View Basket - rich client")
>     @PublishedAction
>     public final ShoppingBasket getBasket(@Named("Enter Van Number") final
> String vanNumber,
>             @Named("Session ID") final String sessionID,
>             @Named("Customer ID") final String customerID,
>             @Named("Email") final String email,
>             @Named("Basket Item") final Object obj) {
> }
> NB- Object obj is the argument giving me headache!
>
> The implementation of this method casts the obj parameter to a specific
> type for the Basket Item.
>
> In my AngularJS Controller, I am obtaining all the required params to
> compose the Basket Item, but Isis does not like the JSON I am sending to
> the server for the entity.
> Below is the sample JSON sent to the RO server:
>
>                  var basketItem=
>                  {
>                                    vanNumber : {
>                                             id : "vanNumber",
>                                             memberType: "property",
>                                             value : '12344456'
>                                    },
>                                    startJourney : {
>                                             id : "startJourney",
>                                             memberType : "property",
>                                             value : 'Watford'
>                                    },
>                                    endJourney : {
>                                             id : "endJourney",
>                                             memberType: "property",
>                                             value : 'Coventry'
>                                    }
>                  };
>
>
>
>                  var basketItemToPersist=
>                  {
>                                    enterVanNumber : {
>                                             id : "enterVanNumber",
>                                             memberType: "property",
>                                             value : $scope.vanNumber
>                                    },
>                                    sessionId : {
>                                             id : "sessionId",
>                                             memberType : "property",
>                                             value : '343234543636hghghgh'
>                                    },
>                                    customerId : {
>                                             id : "customerId",
>                                             memberType: "property",
>                                             value : '123456'
>                                    },
>                                    email : {
>                                             id : "email",
>                                             memberType : "property",
>                                             value : "[email protected]"
>                                    },
>                                    basketItem : {
> //href:"http://localhost:8080/xxx-1.0-SNAPSHOT/restful/objects/VanItem";,
> ????? I am not sure why Isis expects a href and how to determine the href
> for a non-existing entity
>                                                    id : "basketItem",
>                                                     memberType :
> "property",
>                                                     value : basketItem
>                                    }
>                  };
>
>
>
>                  ShoppingBasketFactory.create(basketItemToPersist,
>                                    function(data) {
>                                             //Success Handler
>                                             $scope.success =true;
>                                             },
>                                             function(error) {
>                                             //Error Handler
>                                             $scope.success =false;
>                                             }
>                  );
>
> Thanks.
>
> OLA TOMOLOJU
>
>
>

Reply via email to