Methods in Business Entity - Forum - Mobile - Progress Community

Methods in Business Entity

 Forum

Methods in Business Entity

This question is not answered

Hi there

I would like to find out if one can add more parameters to the 'crud' methods in the business entity?

Also, can you add extra methods into a business entity?

Thanks,

Meyrick

All Replies
  • You can add any parameter you want.
     
    But then the JSDO won’t be able to do the calls and you’ll have to make your own REST calls. But for the REST adapter that is no problem at all.
     
     
    Von: meyrick [mailto:bounce-meyrick@community.progress.com]
    Gesendet: Donnerstag, 27. März 2014 10:53
    An: TU.Mobile@community.progress.com
    Betreff: Methods in Business Entity
     
    Thread created by meyrick

    Hi there

    I would like to find out if one can add more parameters to the 'crud' methods in the business entity?

    Also, can you add extra methods into a business entity?

    Thanks,

    Meyrick

    Stop receiving emails on this subject.

    Flag this post as spam/abuse.

    Architect of the SmartComponent Library and WinKit

    Consultingwerk Ltd.

  • Do you have an example on how to make your own REST calls?

  • As Mike said, the REST adapter can map [almost] anything in a HTTP message/response to a procedure/class method parameter list.   Some restrictions apply...    I'll supply some background information that may be useful to you before getting started.

    The process for generating a pure REST API to an AppServer is similar in nature to what happens with a Mobile project.   The Mobile tooling simply enforces a bunch of static mapping rules (like not being able to configure your own parameters) to make REST transparent and simple, just like it is suppose to do.  When you create your own REST API the PDSOE tooling cannot make any assumptions regarding any of the mapping.  You, the developer, are in 100% control of very aspect of the mapping and therefore have to manually configure it all.   Some of the penalty for any-to-any mapping ability I guess.  

    As Mike also said, you lose the value gained by using the JSDO in your clients.   Your client will then be expected to manually generate the correct HTTP requests and handle the HTTP responses.  

    In the 11.2/11.3 OpenEdge Development: Web Services you will find information about REST applications, annotating your ABL code, parameter mapping to HTTP request/response, and JSON structuring.    It is worth reviewing that before diving straight into the PDSOE project.

    You can start with your Mobile project and add REST 'service interfaces' and use PDSOE's mapping tool.   I often do this so that one web application deployment can be used for both types of clients.   You do not have to start a new project just to add REST support.   That decision is yours.

    Hope this helps.

  • Hi meyrick,

    Yes. Extra methods can be added to the Business Entity file using 'Add method' dialog and thus mobile annotations can be added to the same using 'Define Service Interface' wizard.

    Only one method pertain to each CRUD operation is allowed for a single Business Entity file ie., one Create, One Read, One Update and One Delete methods. However, there are no restrictions for the number of INVOKE (operation) methods in a single Business Entity file.

    Thanks and Regards,

    Anil Kumar.

  • Hi Meyrick,

    You can create additional methods in the Business Entity and mark them as Invoke methods. This allows you to pass any number of parameters and the JSDO will continue to do its majic.

    The only trick is that you will need to call AddRecords on the JSDO when you do a customer read invoke operation to get the records into the JSDO memory.

    For the other CUD invoke operations, you can manage them your self BUT you will lose a lot of the JSDO features that are built in like local before-image and error handling.

    -Shelley

  • Meyrick,

    Let me ask one question: Do you know how to implement Invoke Methods?  If not, maybe help on this topic will be more productive to you.

    Invoke methods are an easy way to achieve what you asking.

    If you are only doing Read, you don't  even need to call the AddRecords, otherwise (if you are planning to create, update, delete using the CRUD operations with what you Read), then you would need it.  Invoke is not the most straight forward to implement, but once you use it for the first time, it becomes very easy. I was thinking about recording a video showing how to do an Invoke implementation, just did not have time (or could put up with my on accent)  to do it.

    Something else I've done in the past is to pass multiple parameters in a READ (for example) using a pipe delimiter.  Than I would parse it in the backend and avoid INVOKE.

  • thanks for all the help. Ricardo, I have also been using the pipe delimiter. Its seems to be the most simplest way. I do not know how to implement invoke methods. All i was wanting to do is add extra read  methods to my business entity.

  • Hi Meyrick,
     
    You can add extra read methods in your business entity and annotate them with invoke annotations.
    Below is the sample Business entity code which has two read methods. One read method (ReadTempTable) is annotated with read annotations and another read method (CustomReadTempTable) with invoke annotations.
     
    @openapi.openedge.export(type="REST", useReturnValue="true", writeDataSetBeforeImage="false").
    @progress.service.resourceMapping(type="REST", operation="read", URI="?filter=~{filter~}", alias="", mediaType ="application/json").
        METHOD PUBLIC VOID ReadTempTable( INPUT filter AS CHARACTER, OUTPUT TABLE ttItem ):
           
            DEFINE VARIABLE cWhere AS CHAR NO-UNDO.
            EMPTY TEMP-TABLE ttItem.
            BUFFER ttItem:ATTACH-DATA-SOURCE(DATA-SOURCE data-srcTempTable:HANDLE).
       
            cWhere = TRIM(filter).
     
            IF cWhere NE "" AND cWhere NE ? THEN DO:       
                DATA-SOURCE data-srcTempTable:FILL-WHERE-STRING = cWhere.
            END.
     
            DATASET dsItem:FILL().
            BUFFER ttItem:DETACH-DATA-SOURCE().
       
        END METHOD.
     
        @openapi.openedge.export(type="REST", useReturnValue="true", writeDataSetBeforeImage="false").
        @progress.service.resourceMapping(type="REST", operation="invoke", URI="/CustomReadTempTable", alias="", mediaType ="application/json").
        METHOD PUBLIC VOID CustomReadTempTable( INPUT filter AS CHARACTER,
                                                INPUT qryPos AS INTEGER,
                                                OUTPUT TABLE ttItem ):
           
            DEFINE VARIABLE cWhere AS CHAR NO-UNDO.
           
            MESSAGE 'In CustomReadTempTable, filter = ' filter.
            MESSAGE 'In CustomReadTempTable, qryPos = ' qryPos.
            EMPTY TEMP-TABLE ttItem.
            BUFFER ttItem:ATTACH-DATA-SOURCE(DATA-SOURCE data-srcTempTable:HANDLE).
       
            cWhere = TRIM(filter).
     
            IF cWhere NE "" AND cWhere NE ? THEN DO:
                    IF NOT cWhere BEGINS "Where" THEN
                        cWhere = SUBSTITUTE('Where Item.ItemNum = &1', cWhere).
     
                DATA-SOURCE data-srcTempTable:FILL-WHERE-STRING = cWhere.
            END.
     
            DATASET dsItem:FILL().
            BUFFER ttItem:DETACH-DATA-SOURCE().
       
        END METHOD.
     
     
    Hope this helps,
    Sanjeev.
     
    From: meyrick [mailto:bounce-meyrick@community.progress.com]
    Sent: 28 March 2014 PM 12:31
    To: TU.Mobile@community.progress.com
    Subject: RE: Methods in Business Entity
     
    Reply by meyrick

    thanks for all the help. Ricardo, I have also been using the pipe delimiter. Its seems to be the most simplest way. I do not know how to implement invoke methods. All i was wanting to do is add extra read  methods to my business entity.

    Stop receiving emails on this subject.

    Flag this post as spam/abuse.