Re: ERXRest response

Giles Palmer <[email protected]> Tue, 14 May 2013 05:12:25 +0100
Newsgroups gmane.comp.web.webobjects.wonder-disc
Message-ID <[email protected]>
Hi 

Thanks Johann but Matt is correct and that getUnitPriceForSale takes an argument so I can't simply use a filter with ERXKey etc.

Matt I will look at your nodeWillWrite(..) and ERXRestFormat.Delegate but I managed to come up with my own solution as follows so comments welcomed if you think it is the wrong approach.


I ended up creating a POJO wrapper (WebPageStockItem) around a StockItem that takes a PriceList object and can return the getUnitPriceForSale method.  I then created a WebPageStockItemRestDelegate extending ERXAbstractRestDelegate.

In my controller method I create the webPageNode and then create a second node with an array of WebPageStockItems before adding the second node as a child of the webPageNode.

This is basically the code:

ERXRestRequestNode webPageNode = ERXRestRequestNode.requestNodeWithObjectAndFilter(webPage, webPageFilter, restContext());

ERXRestRequestNode webPageStockItemsNode = ERXRestRequestNode.requestNodeWithObjectAndFilter(ERXRestClassDescriptionFactory.classDescriptionForEntityName("WebPageStockItem"), stockItems, webPageStockItemFilter, restContext());
webPageNode.addChild(stockItemsNode);
return response(format(), webPageNode);


This nicely does what I was looking for so I hope I haven't violated any rules here.

Thanks for your help.


Giles




> I think Giles needs to process a value contextually using a business object (PriceList) rather than a simple attribute that can be extended by creating an ERXKey<BigDecimal>. His method getUnitPriceForSale takes an argument.
> 
> If that is the case, and you don't mind getting a bit sticky, you can create your own implementation of ERXRestFormat.Delegate (or overriding the default one perhaps) and set up the PriceList object in that delegate, or some reference to it. 
> 
> You can then use nodeWillWrite(..) in your delegate to override setting the value on that node (find the correct node by node.name()) based on whatever calculation you need to perform with the PriceList object (node.setValue(..)).
> 
> So in this case you will still need to add an ERXKey to your filter, but it should reference a method in your EO/Rest Object which takes no arguments.
> 
> -- 
> Matt.
> 
> http://logicsquad.net/
> 
> 
> 
> On 14/05/2013, at 7:17 AM, Johann Werner wrote:
> 
>> Hi Giles,
>> 
>> just add the name of your method "getUnitPriceForSale" to your filter. It should then add its value to the Rest response though it will take the method name as key name. I am not sure if it is easily possible to make it use "salePrice" as label instead.
>> 
>> jw
>> 
>> 
>> Am 13.05.2013 um 13:17 schrieb Giles Palmer <[email protected]>:
>> 
>>> Hi All
>>> 
>>> I have a webPage entity that  has a to-many relationship to stockItems.  I am using my controller class and ERXKeyFilters to create the webPage response along with the related stockItems and this all works well.
>>> 
>>> However I also want to add a "salePrice" value to the response for each of the stock items and this sale price is calculated by a stockItem using a priceList object.  
>>> 
>>> In my StockItem.java it is just a method:  public BigDecimal getUnitPriceForSale(PriceList priceList).  How would I include/add this "salePrice" to the stockItem when it is not a simple attribute of a stockItem? 
>>> 
>>> Many thanks
>>> 
>>> 
>>> Giles
>> 
>> 
>> ------------------------------------------------------------------------------
>> AlienVault Unified Security Management (USM) platform delivers complete
>> security visibility with the essential security capabilities. Easily and
>> efficiently configure, manage, and operate all of your security controls
>> from a single console and one unified framework. Download a free trial.
>> http://p.sf.net/sfu/alienvault_d2d
>> _______________________________________________
>> Wonder-disc mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/wonder-disc
> 
> 


------------------------------------------------------------------------------
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d