AddIdField with Angular 2 - Forum - Mobile - Progress Community

AddIdField with Angular 2

 Forum

AddIdField with Angular 2

This question is answered

Hello,

I am searching for an example of how to use the "AddIdField" method to generate new unique IDs when creating a new record.

I am using THIS example. I understand how 'count' method is working, but I cannot handle with AddIdField.

Thanks,

Martin

Verified Answer
  • Hi Martin.

    Have you write the code to assign the ClientNum in a CreateTrigger of your table?

    /*------------------------------------------------------------------------
    
       File        : CreateAnalistas.p
    
       Purpose     :
    
       Syntax      :
    
       Description : Trigger Create Analistas
    
       Author(s)   : William Pavei Antero
    
       Created     : Thu Mar 09 16:13:45 BRT 2017
    
       Notes       :
    
     ----------------------------------------------------------------------*/
    
    /* ***************************  Definitions  ************************** */
    
    BLOCK-LEVEL ON ERROR UNDO, THROW.
    
    /* ********************  Preprocessor Definitions  ******************** */
    
    /* ***************************  Main Block  *************************** */
    
    TRIGGER PROCEDURE FOR CREATE OF Analistas.
    
    ASSIGN
    
       Analistas.IdAnalista = REPLACE(GUID(GENERATE-UUID), "-", "").
    /*------------------------------------------------------------------------
    
      File        : Analistas
    
      Syntax      :
    
      Author(s)   : wantero
    
      Created     : Thu Feb 16 12:27:38 BRST 2017
    
      Notes       :
    
    ----------------------------------------------------------------------*/
    
    @program FILE(name="Analistas.cls", module="AppServer").
    
    @openapi.openedge.export FILE(type="REST", executionMode="singleton", useReturnValue="false", writeDataSetBeforeImage="false").
    
    @progress.service.resource FILE(name="Analistas", URI="/Analistas", schemaName="dsAnalistas", schemaFile="SGASP/src/AppServer/analistas.i").
    
    USING Progress.Lang.*.
    
    USING OpenEdge.BusinessLogic.BusinessEntity.
    
    BLOCK-LEVEL ON ERROR UNDO, THROW.
    
    CLASS Analistas INHERITS BusinessEntity:
    
    /*------------------------------------------------------------------------------
    
    Purpose:                                                                      
    
    Notes:                                                                        
    
    ------------------------------------------------------------------------------*/
    
       {"analistas.i"}
    
       DEFINE DATA-SOURCE srcAnalistas FOR sgasp.Analistas.
    
       DEFINE VARIABLE filterOpenEdge AS FilterOpenEdge NO-UNDO.
    
       DEFINE VARIABLE iSeq           AS INTEGER        NO-UNDO.
    
       /*------------------------------------------------------------------------------
    
               Purpose:                                                                      
    
               Notes:                                                                        
    
       ------------------------------------------------------------------------------*/
    
       CONSTRUCTOR PUBLIC Analistas():
    
           DEFINE VAR hDataSourceArray AS HANDLE NO-UNDO EXTENT 1.
    
           DEFINE VAR cSkipListArray   AS CHAR   NO-UNDO EXTENT 1.
    
           SUPER (DATASET dsAnalistas:HANDLE).
    
           /* Instancia a classe de filtro */
    
           filterOpenEdge = NEW FilterOpenEdge().        
    
           /* Data Source for each table in dataset. Should be in table order as defined
    
               in DataSet */    
    
           hDataSourceArray[1] =  DATA-SOURCE srcAnalistas:HANDLE.
    
           /* Skip-list entry for each table in dataset. Should be in temp-table order
    
             as defined in DataSet */
    
           /* Each skip-list entry is a comma-separated list of field names, to be
    
               ignored in create stmt */
    
           cSkipListArray[1] = "IdAnalista".
    
           THIS-OBJECT:ProDataSource = hDataSourceArray.
    
           THIS-OBJECT:SkipList = cSkipListArray.
    
       END CONSTRUCTOR.
    
       /*------------------------------------------------------------------------------
    
               Purpose:  Get one or more records, based on a filter string                                                                    
    
               Notes:                                                                        
    
       ------------------------------------------------------------------------------*/
    
       @openapi.openedge.export(type="REST", useReturnValue="false", writeDataSetBeforeImage="true").
    
       @progress.service.resourceMapping(type="REST", operation="read", URI="?filter=~{filter~}", alias="", mediaType="application/json").
    
       @openapi.openedge.method.property (name="mappingType", value="JFP").
    
       @openapi.openedge.method.property (name="capabilities", value="ablFilter,top,skip,id,orderBy").    
    
       METHOD PUBLIC VOID ReadAnalistas(
    
           INPUT filter AS CHARACTER,
    
           OUTPUT DATASET dsAnalistas):  
    
           DEFINE VARIABLE hCP AS HANDLE NO-UNDO.
    
           hCP = SESSION:CURRENT-REQUEST-INFO:GetClientPrincipal().
    
           MESSAGE "Username: " + hCP:QUALIFIED-USER-ID + " - " + hCP:DOMAIN-NAME.        
    
           /*IF NOT SET-DB-CLIENT(hCP) THEN
    
           DO:
    
               MESSAGE "User not authorized!".
    
               //QUIT.
    
           END.*/                    
    
           MESSAGE "USERID: " USERID
    
               VIEW-AS ALERT-BOX.                    
    
        IF filter BEGINS "~{" THEN
    
               filterOpenEdge:JFPFillMethod(filter,
    
                   TEMP-TABLE ttAnalistas:HANDLE:DEFAULT-BUFFER-HANDLE,
    
                   BUFFER Analistas:HANDLE,
    
                   DATA-SOURCE srcAnalistas:HANDLE,
    
                   DATASET dsAnalistas:HANDLE,
    
                   "Analistas",
    
                   iSeq).
    
           ELSE
    
           DO:
    
               BUFFER ttAnalistas:HANDLE:BATCH-SIZE = 0.
    
               BUFFER ttAnalistas:SET-CALLBACK ("AFTER-ROW-FILL", "AddIdField").
    
               SUPER:ReadData(filter).
    
           END.
    
       END METHOD.
    
       /*------------------------------------------------------------------------------
    
               Purpose: Create one or more new records                                                              
    
               Notes:                                                                        
    
       ------------------------------------------------------------------------------*/  
    
       @openapi.openedge.export(type="REST", useReturnValue="false", writeDataSetBeforeImage="true").
    
       @progress.service.resourceMapping(type="REST", operation="create", URI="", alias="", mediaType="application/json").
    
       METHOD PUBLIC VOID CreateAnalistas(INPUT-OUTPUT DATASET dsAnalistas):
    
           SUPER:CreateData(DATASET dsAnalistas BY-REFERENCE).        
    
       END METHOD.    
    
       /*------------------------------------------------------------------------------
    
               Purpose:  Update one or more records                                                                  
    
               Notes:                                                                        
    
       ------------------------------------------------------------------------------*/
    
       @openapi.openedge.export(type="REST", useReturnValue="false", writeDataSetBeforeImage="true").
    
       @progress.service.resourceMapping(type="REST", operation="update", URI="", alias="", mediaType="application/json").
    
       METHOD PUBLIC VOID UpdateAnalistas(INPUT-OUTPUT DATASET dsAnalistas):  
    
           SUPER:UpdateData(DATASET dsAnalistas BY-REFERENCE).          
    
       END METHOD.
    
       /*------------------------------------------------------------------------------
    
               Purpose:    Delete a record                                                              
    
               Notes:                                                                        
    
       ------------------------------------------------------------------------------*/
    
       @openapi.openedge.export(type="REST", useReturnValue="false", writeDataSetBeforeImage="true").
    
       @progress.service.resourceMapping(type="REST", operation="delete", URI="", alias="", mediaType="application/json").
    
       METHOD PUBLIC VOID DeleteAnalistas(INPUT-OUTPUT DATASET dsAnalistas):          
    
           SUPER:DeleteData(DATASET dsAnalistas BY-REFERENCE).
    
           IF ERROR-STATUS:ERROR THEN
    
           DO:
    
               UNDO, THROW NEW Progress.Lang.AppError(ERROR-STATUS:GET-MESSAGE(1), ERROR-STATUS:GET-NUMBER(1)).
    
           END.        
    
       END METHOD.
    
       @openapi.openedge.export(type="REST", useReturnValue="false", writeDataSetBeforeImage="false").
    
       @progress.service.resourceMapping(type="REST", operation="invoke", URI="/count?filter=~{filter~}", alias="", mediaType="application/json").
    
       METHOD PUBLIC VOID count( INPUT filter AS CHARACTER, OUTPUT numRecs AS INTEGER):
    
           filterOpenEdge:JFPCountMethod( INPUT filter,
    
               INPUT TEMP-TABLE ttAnalistas:HANDLE:DEFAULT-BUFFER-HANDLE,
    
               INPUT "Analistas",
    
               INPUT BUFFER Analistas:HANDLE,
    
               OUTPUT numRecs).
    
       END METHOD.
    
       METHOD PUBLIC VOID AddIdField (INPUT DATASET dsAnalistas):
    
           ASSIGN
    
               ttAnalistas.id    = STRING(ROWID(Analistas))
    
               iSeq              = iSeq + 1
    
               ttAnalistas.seq   = iSeq.
    
       END METHOD.
    
       DESTRUCTOR PUBLIC Analistas ( ):
    
       END DESTRUCTOR.
    
    END CLASS.

    Best Regards,

    William

All Replies
  • Hi Martin.

    The "AddIdField" is a method to add values to fields (id and seq) in temp-table when you are doing a server filtering. This method is a callback of Read method. More info: documentation.progress.com/.../index.html

    You are trying to create Id for a new record (Create method). To do this you could write you logic at the Create Method or in a Create Trigger of Table.

    Best Regards,

    William Pavei Antero

  • Hello,

    Please notice that when using a database create trigger, you may want to add the auto generated field to the skip list defined in the Business Entity.

    Example:

       cSkipListArray[1] = "CustNum".

    I hope this helps.

  • I have some problems maybe with create method. This is the way I made it working, but I am not sure how good it is. But when I use cSkipListArray[1] = "ClientNum". it stop working. The problem is: {"_retVal":"","_errors":[{"_errorMsg":"** Client already exists with ClientNum 0. (132)","_errorNum":0}]} 

     
     /*------------------------------------------------------------------------
        File        : AdvClients
        Syntax      : 
        Author(s)   : Administrator
        Created     : Wed Apr 05 15:10:05 EEST 2017
        Notes       : 
      ----------------------------------------------------------------------*/
      
    @program FILE(name="AdvClients.cls", module="AppServer").
    @openapi.openedge.export FILE(type="REST", executionMode="singleton", useReturnValue="false", writeDataSetBeforeImage="false").
    @progress.service.resource FILE(name="AdvClients", URI="/AdvClients", schemaName="dsClient", schemaFile="CtcIdea\AppServer\advclients.i").
    
    USING Progress.Lang.*.
    
    USING OpenEdge.BusinessLogic.BusinessEntity FROM PROPATH.
    USING Progress.Json.ObjectModel.*.
    
    BLOCK-LEVEL ON ERROR UNDO, THROW.
    
    CLASS AdvClients INHERITS BusinessEntity:
    	/*------------------------------------------------------------------------------
    			Purpose:                                                                      
    			Notes:                                                                        
    	------------------------------------------------------------------------------*/
    	
    	{"advclients.i"}
    	
    	DEFINE DATA-SOURCE srcClient FOR projects.Client.
    	DEFINE VARIABLE iSeq            AS INTEGER      NO-UNDO.
    	
        
    	/*------------------------------------------------------------------------------
                Purpose:                                                                      
                Notes:                                                                        
        ------------------------------------------------------------------------------*/
        CONSTRUCTOR PUBLIC AdvClients():
        	
        	DEFINE VAR hDataSourceArray AS HANDLE NO-UNDO EXTENT 1.
            DEFINE VAR cSkipListArray AS CHAR NO-UNDO EXTENT 1.
            
            SUPER (DATASET dsClient:HANDLE).
            
            /* Data Source for each table in dataset. Should be in table order as defined 
         	   in DataSet */     
         	hDataSourceArray[1] =  DATA-SOURCE srcClient:HANDLE.
         	
         	     	
         	/* Skip-list entry for each table in dataset. Should be in temp-table order 
               as defined in DataSet */
            /* Each skip-list entry is a comma-separated list of field names, to be
     	       ignored in create stmt */
         	    
         	cSkipListArray[1] = "".
         	
         	
         	THIS-OBJECT:ProDataSource = hDataSourceArray.
            THIS-OBJECT:SkipList = cSkipListArray.
         	        
        END CONSTRUCTOR.
    
    	/*------------------------------------------------------------------------------
    	 Purpose:
    	 Notes:
    	------------------------------------------------------------------------------*/
    
    	METHOD PRIVATE VOID JFPFillMethod(INPUT filter AS CHARACTER):
    
          DEFINE VARIABLE jsonParser     AS ObjectModelParser      NO-UNDO.
          DEFINE VARIABLE jsonObject     AS JsonObject             NO-UNDO.
          DEFINE VARIABLE cWhere         AS CHARACTER              NO-UNDO.
          DEFINE VARIABLE hQuery         AS HANDLE                 NO-UNDO.
          DEFINE VARIABLE lUseReposition AS LOGICAL                NO-UNDO.
          DEFINE VARIABLE iCount         AS INTEGER                NO-UNDO.
          DEFINE VARIABLE ablFilter      AS CHARACTER              NO-UNDO.
          DEFINE VARIABLE id             AS CHARACTER INITIAL ?    NO-UNDO.
          DEFINE VARIABLE iMaxRows       AS INTEGER   INITIAL ?    NO-UNDO.
          DEFINE VARIABLE iSkipRows      AS INTEGER   INITIAL ?    NO-UNDO.
          DEFINE VARIABLE cOrderBy       AS CHARACTER INITIAL ""   NO-UNDO.
    
          /* purge any existing data */
          EMPTY TEMP-TABLE ttClient.
    
          jsonParser  = NEW ObjectModelParser().
          jsonObject  = CAST(jsonParser:Parse(filter), jsonObject).
          iMaxRows    = jsonObject:GetInteger("top")  NO-ERROR.
          iSkipRows   = jsonObject:GetInteger("skip") NO-ERROR.
          ablFilter   = jsonObject:GetCharacter("ablFilter") NO-ERROR.
          id          = jsonObject:GetCharacter("id") NO-ERROR.
          cOrderBy    = jsonObject:GetCharacter("orderBy") NO-ERROR.
          cWhere      = "WHERE " + ablFilter NO-ERROR.
    
          IF cOrderBy > "" THEN DO:
            cOrderBy = REPLACE(cOrderBy, ",", " by ").
            cOrderBy = "by " + cOrderBy + " ".
            /* NOTE: id and seq fields should be removed from 
               cWhere and cOrderBy */
            cOrderBy = REPLACE(cOrderBy, "by id desc", "").
            cOrderBy = REPLACE(cOrderBy, "by id ", "").
            cOrderBy = REPLACE(cOrderBy, "by seq desc", "").
            cOrderBy = REPLACE(cOrderBy, "by seq ", "").
          END.
    
          lUseReposition = iSkipRows <> ?.
    
          IF iMaxRows <> ? AND iMaxRows > 0 THEN DO:
            BUFFER ttClient:HANDLE:BATCH-SIZE = iMaxRows.
          END.
          ELSE DO:
            IF id > "" THEN
                BUFFER ttClient:HANDLE:BATCH-SIZE = 1.
            ELSE                                 
                BUFFER ttClient:HANDLE:BATCH-SIZE = 0.
          END.                        
    
          BUFFER ttClient:ATTACH-DATA-SOURCE(DATA-SOURCE srcClient:HANDLE).
    
          IF cOrderBy = ? THEN cOrderBy = "".
          cWhere = IF cWhere > "" THEN (cWhere + " " + cOrderBy) 
                   ELSE ("WHERE " + cOrderBy).
          DATA-SOURCE srcClient:FILL-WHERE-STRING = cWhere.
    
          IF lUseReposition THEN DO:
            hQuery = DATA-SOURCE srcClient:QUERY.
            hQuery:QUERY-OPEN.
    
            IF id > "" AND id <> "?" THEN DO:
              hQuery:REPOSITION-TO-ROWID(TO-ROWID(id)).
            END.
            ELSE IF iSkipRows <> ? AND iSkipRows > 0 THEN DO:
              hQuery:REPOSITION-TO-ROW(iSkipRows).
              IF NOT AVAILABLE Client THEN
                hQuery:GET-NEXT() NO-ERROR.
            END.
    
            iCount = 0.
            REPEAT WHILE NOT hQuery:QUERY-OFF-END AND iCount < iMaxRows:
              hQuery:GET-NEXT () NO-ERROR.
              IF AVAILABLE Client THEN DO:
                CREATE ttClient.
                BUFFER-COPY Client TO ttClient.
                ASSIGN  ttClient.id  = STRING(ROWID(Client))
                        iSeq = iSeq + 1
                        ttClient.seq = iSeq.
              END.
              iCount = iCount + 1.
            END.
          END.
          ELSE DO:
            IF id > "" THEN DATA-SOURCE srcClient:RESTART-ROWID(1) 
                            = TO-ROWID ((id)).
            BUFFER ttClient:SET-CALLBACK ("AFTER-ROW-FILL", "AddIdField").
            DATASET dsClient:FILL().
          END.
    
          FINALLY:
            BUFFER ttClient:DETACH-DATA-SOURCE().
          END FINALLY. 
      
        END METHOD.
        
        METHOD PUBLIC VOID AddIdField (INPUT DATASET dsClient):
          ASSIGN  ttClient.id = STRING(ROWID(Client))
                  iSeq = iSeq + 1
                  ttClient.seq = iSeq.
        END.
    
        /*------------------------------------------------------------------------------
                Purpose:  Get one or more records, based on a filter string
                Notes:
        ------------------------------------------------------------------------------*/
        @openapi.openedge.export(type="REST", useReturnValue="false", writeDataSetBeforeImage="true").
        @progress.service.resourceMapping(type="REST", operation="read", URI="?filter=~{filter~}", alias="", mediaType="application/json").
        @openapi.openedge.method.property (name="mappingType", value="JFP").
        @openapi.openedge.method.property (name="capabilities", value="ablFilter,top,skip,id,orderBy").
        METHOD PUBLIC VOID ReadClients(
        		INPUT filter AS CHARACTER,
        		OUTPUT DATASET dsClient):
        	
        	IF filter BEGINS "~{" THEN
            THIS-OBJECT:JFPFillMethod (INPUT filter).
          ELSE DO:
            BUFFER ttClient:HANDLE:BATCH-SIZE = 0.
            BUFFER ttClient:SET-CALLBACK ("AFTER-ROW-FILL", "AddIdField").
        	
        	SUPER:ReadData(filter).
        	END.
        END METHOD.
    	  
        /*------------------------------------------------------------------------------
                Purpose: Create one or more new records                                                               
                Notes:                                                                        
        ------------------------------------------------------------------------------*/  
        @openapi.openedge.export(type="REST", useReturnValue="false", writeDataSetBeforeImage="false").
        @progress.service.resourceMapping(type="REST", operation="create", URI="", alias="", mediaType="application/json").
        METHOD PUBLIC VOID CreateClients(INPUT-OUTPUT DATASET dsClient):    		
            define buffer bClient for Client.
            define variable itemp as int no-undo.
            find last bClient use-index clientnum exclusive-lock no-error.
            if not available bclient then itemp = 1.
            else itemp = bclient.clientnum + 1.
            dataset dsClient::ttClient:FIND-FIRST ().
            if DATASET dsClient::ttClient::clientnum = 0 then DATASET dsClient::ttClient::clientnum = itemp.
            SUPER:CreateData(DATASET dsClient BY-REFERENCE).        
        END METHOD.    
    	
        /*------------------------------------------------------------------------------
                Purpose:  Update one or more records                                                                  
                Notes:                                                                        
        ------------------------------------------------------------------------------*/
        @openapi.openedge.export(type="REST", useReturnValue="false", writeDataSetBeforeImage="false").
        @progress.service.resourceMapping(type="REST", operation="update", URI="", alias="", mediaType="application/json").
        METHOD PUBLIC VOID UpdateClients(INPUT-OUTPUT DATASET dsClient): 
               		
            SUPER:UpdateData(DATASET dsClient BY-REFERENCE).        
        END METHOD.
    	
        /*------------------------------------------------------------------------------
                Purpose:    Delete a record                                                               
                Notes:                                                                        
        ------------------------------------------------------------------------------*/
        @openapi.openedge.export(type="REST", useReturnValue="false", writeDataSetBeforeImage="false").
        @progress.service.resourceMapping(type="REST", operation="delete", URI="", alias="", mediaType="application/json").
        METHOD PUBLIC VOID DeleteClients(INPUT-OUTPUT DATASET dsClient):     		       
    	
            SUPER:DeleteData(DATASET dsClient BY-REFERENCE).
        END METHOD.
        /*------------------------------------------------------------------------------
                Purpose:    Submit a record
                Notes:
        ------------------------------------------------------------------------------*/
        @openapi.openedge.export(type="REST", useReturnValue="false", writeDataSetBeforeImage="true").
        @progress.service.resourceMapping(type="REST", operation="submit", URI="/SubmitClients (IN-OUT dataset)", alias="", mediaType="application/json").
        METHOD PUBLIC VOID SubmitClients(INPUT-OUTPUT DATASET dsClient):
    
              /* Calling extending class's CUD methods instead of SUPER:Submit() in case 
               customized functionality was added.
               Do deletes first, next modifies, and finally creates */
            THIS-OBJECT:DeleteClients(DATASET dsClient).
            THIS-OBJECT:UpdateClients(DATASET dsClient).
            THIS-OBJECT:CreateClients(DATASET dsClient).
        END METHOD.
        /* ----------------------------------------- */
        @openapi.openedge.export(type="REST", useReturnValue="false", writeDataSetBeforeImage="false").
        @progress.service.resourceMapping(type="REST", operation="invoke", URI="/count?filter=~{filter~}", alias="", mediaType="application/json").
        METHOD PUBLIC VOID count( INPUT filter AS CHARACTER, OUTPUT numRecs AS INTEGER):
            DEFINE VARIABLE jsonParser   AS ObjectModelParser   NO-UNDO.
            DEFINE VARIABLE jsonObject   AS JsonObject          NO-UNDO.
            DEFINE VARIABLE ablFilter    AS CHARACTER           NO-UNDO.
            DEFINE VARIABLE cWhere       AS CHARACTER           NO-UNDO.
            DEFINE VARIABLE qh           AS HANDLE              NO-UNDO.
    
            IF filter BEGINS "WHERE " THEN
                cWhere = filter.
            ELSE IF filter BEGINS "~{" THEN
            DO:
                jsonParser  = NEW ObjectModelParser().
                jsonObject  = CAST(jsonParser:Parse(filter), jsonObject).
                ablFilter   = jsonObject:GetCharacter("ablFilter") NO-ERROR.
                cWhere      = "WHERE " + ablFilter.
            END.
            ELSE IF filter NE "" THEN
            DO:
                /* Use filter as WHERE clause */
                cWhere = "WHERE " + filter.
            END.
    
            CREATE QUERY qh.
            qh:SET-BUFFERS(BUFFER Client:HANDLE).
            qh:QUERY-PREPARE("PRESELECT EACH Client " + cWhere).
            qh:QUERY-OPEN ().
            numRecs = qh:NUM-RESULTS.
    
        END METHOD.
        
    END CLASS.
    
  • Hi Martin.

    Have you write the code to assign the ClientNum in a CreateTrigger of your table?

    /*------------------------------------------------------------------------
    
       File        : CreateAnalistas.p
    
       Purpose     :
    
       Syntax      :
    
       Description : Trigger Create Analistas
    
       Author(s)   : William Pavei Antero
    
       Created     : Thu Mar 09 16:13:45 BRT 2017
    
       Notes       :
    
     ----------------------------------------------------------------------*/
    
    /* ***************************  Definitions  ************************** */
    
    BLOCK-LEVEL ON ERROR UNDO, THROW.
    
    /* ********************  Preprocessor Definitions  ******************** */
    
    /* ***************************  Main Block  *************************** */
    
    TRIGGER PROCEDURE FOR CREATE OF Analistas.
    
    ASSIGN
    
       Analistas.IdAnalista = REPLACE(GUID(GENERATE-UUID), "-", "").
    /*------------------------------------------------------------------------
    
      File        : Analistas
    
      Syntax      :
    
      Author(s)   : wantero
    
      Created     : Thu Feb 16 12:27:38 BRST 2017
    
      Notes       :
    
    ----------------------------------------------------------------------*/
    
    @program FILE(name="Analistas.cls", module="AppServer").
    
    @openapi.openedge.export FILE(type="REST", executionMode="singleton", useReturnValue="false", writeDataSetBeforeImage="false").
    
    @progress.service.resource FILE(name="Analistas", URI="/Analistas", schemaName="dsAnalistas", schemaFile="SGASP/src/AppServer/analistas.i").
    
    USING Progress.Lang.*.
    
    USING OpenEdge.BusinessLogic.BusinessEntity.
    
    BLOCK-LEVEL ON ERROR UNDO, THROW.
    
    CLASS Analistas INHERITS BusinessEntity:
    
    /*------------------------------------------------------------------------------
    
    Purpose:                                                                      
    
    Notes:                                                                        
    
    ------------------------------------------------------------------------------*/
    
       {"analistas.i"}
    
       DEFINE DATA-SOURCE srcAnalistas FOR sgasp.Analistas.
    
       DEFINE VARIABLE filterOpenEdge AS FilterOpenEdge NO-UNDO.
    
       DEFINE VARIABLE iSeq           AS INTEGER        NO-UNDO.
    
       /*------------------------------------------------------------------------------
    
               Purpose:                                                                      
    
               Notes:                                                                        
    
       ------------------------------------------------------------------------------*/
    
       CONSTRUCTOR PUBLIC Analistas():
    
           DEFINE VAR hDataSourceArray AS HANDLE NO-UNDO EXTENT 1.
    
           DEFINE VAR cSkipListArray   AS CHAR   NO-UNDO EXTENT 1.
    
           SUPER (DATASET dsAnalistas:HANDLE).
    
           /* Instancia a classe de filtro */
    
           filterOpenEdge = NEW FilterOpenEdge().        
    
           /* Data Source for each table in dataset. Should be in table order as defined
    
               in DataSet */    
    
           hDataSourceArray[1] =  DATA-SOURCE srcAnalistas:HANDLE.
    
           /* Skip-list entry for each table in dataset. Should be in temp-table order
    
             as defined in DataSet */
    
           /* Each skip-list entry is a comma-separated list of field names, to be
    
               ignored in create stmt */
    
           cSkipListArray[1] = "IdAnalista".
    
           THIS-OBJECT:ProDataSource = hDataSourceArray.
    
           THIS-OBJECT:SkipList = cSkipListArray.
    
       END CONSTRUCTOR.
    
       /*------------------------------------------------------------------------------
    
               Purpose:  Get one or more records, based on a filter string                                                                    
    
               Notes:                                                                        
    
       ------------------------------------------------------------------------------*/
    
       @openapi.openedge.export(type="REST", useReturnValue="false", writeDataSetBeforeImage="true").
    
       @progress.service.resourceMapping(type="REST", operation="read", URI="?filter=~{filter~}", alias="", mediaType="application/json").
    
       @openapi.openedge.method.property (name="mappingType", value="JFP").
    
       @openapi.openedge.method.property (name="capabilities", value="ablFilter,top,skip,id,orderBy").    
    
       METHOD PUBLIC VOID ReadAnalistas(
    
           INPUT filter AS CHARACTER,
    
           OUTPUT DATASET dsAnalistas):  
    
           DEFINE VARIABLE hCP AS HANDLE NO-UNDO.
    
           hCP = SESSION:CURRENT-REQUEST-INFO:GetClientPrincipal().
    
           MESSAGE "Username: " + hCP:QUALIFIED-USER-ID + " - " + hCP:DOMAIN-NAME.        
    
           /*IF NOT SET-DB-CLIENT(hCP) THEN
    
           DO:
    
               MESSAGE "User not authorized!".
    
               //QUIT.
    
           END.*/                    
    
           MESSAGE "USERID: " USERID
    
               VIEW-AS ALERT-BOX.                    
    
        IF filter BEGINS "~{" THEN
    
               filterOpenEdge:JFPFillMethod(filter,
    
                   TEMP-TABLE ttAnalistas:HANDLE:DEFAULT-BUFFER-HANDLE,
    
                   BUFFER Analistas:HANDLE,
    
                   DATA-SOURCE srcAnalistas:HANDLE,
    
                   DATASET dsAnalistas:HANDLE,
    
                   "Analistas",
    
                   iSeq).
    
           ELSE
    
           DO:
    
               BUFFER ttAnalistas:HANDLE:BATCH-SIZE = 0.
    
               BUFFER ttAnalistas:SET-CALLBACK ("AFTER-ROW-FILL", "AddIdField").
    
               SUPER:ReadData(filter).
    
           END.
    
       END METHOD.
    
       /*------------------------------------------------------------------------------
    
               Purpose: Create one or more new records                                                              
    
               Notes:                                                                        
    
       ------------------------------------------------------------------------------*/  
    
       @openapi.openedge.export(type="REST", useReturnValue="false", writeDataSetBeforeImage="true").
    
       @progress.service.resourceMapping(type="REST", operation="create", URI="", alias="", mediaType="application/json").
    
       METHOD PUBLIC VOID CreateAnalistas(INPUT-OUTPUT DATASET dsAnalistas):
    
           SUPER:CreateData(DATASET dsAnalistas BY-REFERENCE).        
    
       END METHOD.    
    
       /*------------------------------------------------------------------------------
    
               Purpose:  Update one or more records                                                                  
    
               Notes:                                                                        
    
       ------------------------------------------------------------------------------*/
    
       @openapi.openedge.export(type="REST", useReturnValue="false", writeDataSetBeforeImage="true").
    
       @progress.service.resourceMapping(type="REST", operation="update", URI="", alias="", mediaType="application/json").
    
       METHOD PUBLIC VOID UpdateAnalistas(INPUT-OUTPUT DATASET dsAnalistas):  
    
           SUPER:UpdateData(DATASET dsAnalistas BY-REFERENCE).          
    
       END METHOD.
    
       /*------------------------------------------------------------------------------
    
               Purpose:    Delete a record                                                              
    
               Notes:                                                                        
    
       ------------------------------------------------------------------------------*/
    
       @openapi.openedge.export(type="REST", useReturnValue="false", writeDataSetBeforeImage="true").
    
       @progress.service.resourceMapping(type="REST", operation="delete", URI="", alias="", mediaType="application/json").
    
       METHOD PUBLIC VOID DeleteAnalistas(INPUT-OUTPUT DATASET dsAnalistas):          
    
           SUPER:DeleteData(DATASET dsAnalistas BY-REFERENCE).
    
           IF ERROR-STATUS:ERROR THEN
    
           DO:
    
               UNDO, THROW NEW Progress.Lang.AppError(ERROR-STATUS:GET-MESSAGE(1), ERROR-STATUS:GET-NUMBER(1)).
    
           END.        
    
       END METHOD.
    
       @openapi.openedge.export(type="REST", useReturnValue="false", writeDataSetBeforeImage="false").
    
       @progress.service.resourceMapping(type="REST", operation="invoke", URI="/count?filter=~{filter~}", alias="", mediaType="application/json").
    
       METHOD PUBLIC VOID count( INPUT filter AS CHARACTER, OUTPUT numRecs AS INTEGER):
    
           filterOpenEdge:JFPCountMethod( INPUT filter,
    
               INPUT TEMP-TABLE ttAnalistas:HANDLE:DEFAULT-BUFFER-HANDLE,
    
               INPUT "Analistas",
    
               INPUT BUFFER Analistas:HANDLE,
    
               OUTPUT numRecs).
    
       END METHOD.
    
       METHOD PUBLIC VOID AddIdField (INPUT DATASET dsAnalistas):
    
           ASSIGN
    
               ttAnalistas.id    = STRING(ROWID(Analistas))
    
               iSeq              = iSeq + 1
    
               ttAnalistas.seq   = iSeq.
    
       END METHOD.
    
       DESTRUCTOR PUBLIC Analistas ( ):
    
       END DESTRUCTOR.
    
    END CLASS.

    Best Regards,

    William