Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#9047 closed enhancement (fixed)

dojox.data.JsonRestStore support custom service for nested items

Reported by: Jarrod Carlson Owned by: Kris Zyp
Priority: high Milestone: 1.4
Component: DojoX Data Version: 1.3.0
Keywords: dojox rpc jsonrest jsonreststore Cc:
Blocked By: Blocking:

Description

I have a REST service that provides for nested resources, e.g.:

/foos/123
/foos/123/bar

Because dojox.rpc.Rest insists on appending a trailing slash to the target path (#8980), I have provided my JsonRestStore? a custom service object.

However, after setting values on the nested "bar" item of /foos/123 and calling store.save(), there is a problem. dojox.rpc.JsonRest#getServiceAndId? attempts to locate a service for the id of the dirty object. Normally, it isn't a problem, but in this case, the "path" of the bar item being saved is "/foos/123/" with an id of "bar". In this case, JsonRest? determines that a service object is unavailable and proceeds to create one.

The problem is that JsonRest? is hard-coded to create an instance of dojox.rpc.Rest, and not the custom service object I had provided, which is perfectly capable of handling the PUT.

In order to solve this, I've modified the JsonRestStore? and JsonRest? classes to work with a "generator" class, which defaults to dojox.rpc.Rest. This way, when a JsonRestStore? is created, it can be provided a service generator instead of a service, and any subsequently created service objects will also be created by the same generator.

This probably isn't the "ideal" solution, but it does work. Please see the attached patches.

Alternatively, the getServiceAndId method could be modified to support nested matches. For example, if I already have a service for "/foos/" and I request the service for "/foos/123/bar", then the existing "/foos" service should be returned, rather than creating a new service.

Attachments (3)

dojox.rpc.JsonRest.js.diff (3.2 KB) - added by Jarrod Carlson 10 years ago.
dojox.rpc.JsonRest?
dojox.data.JsonRestStore.js.diff (6.1 KB) - added by Jarrod Carlson 10 years ago.
dojox.data.JsonRestStore?
9047.diff (1.9 KB) - added by Jarrod Carlson 10 years ago.
Alternative solution (much less invasive)

Download all attachments as: .zip

Change History (7)

Changed 10 years ago by Jarrod Carlson

Attachment: dojox.rpc.JsonRest.js.diff added

dojox.rpc.JsonRest?

Changed 10 years ago by Jarrod Carlson

dojox.data.JsonRestStore?

comment:1 Changed 10 years ago by Jarrod Carlson

The attached "alternative solitution" in 9047.diff is considerably less invasive of a change. In this alternate version, we configure the JsonRest? class with a default constructor for a service object, which can be overridden by user code. It also changes the getServiceAndId method to allow partial matches on a service path, thus allowing nested resources to be handled by the parent service.

Finally, in JsonRestStore?, the _getStoreForItem method is modified to try finding an existing service and use the attached store and creating a new store only as a last resort.

Changed 10 years ago by Jarrod Carlson

Attachment: 9047.diff added

Alternative solution (much less invasive)

comment:2 Changed 10 years ago by Jared Jurkiewicz

Owner: changed from Jared Jurkiewicz to Kris Zyp

comment:3 Changed 10 years ago by Kris Zyp

Resolution: fixed
Status: newclosed

comment:4 Changed 10 years ago by Adam Peller

Milestone: tbd1.4
Note: See TracTickets for help on using tickets.