/*------------------------------------------------------------------------
   File        : dynamicformImplImpl
   Purpose     : 
   Syntax      : 
   Description : 
   Author(s)   : walter.riechsteiner
   Created     : Wed Nov 19 13:23:38 CET 2025
   Notes       : 
 ----------------------------------------------------------------------*/


BLOCK-LEVEL ON ERROR UNDO, THROW.

USING OpenEdge.Core.String                          FROM PROPATH.
USING OpenEdge.Net.HTTP.IHttpResponse               FROM PROPATH.
USING OpenEdge.Net.HTTP.StatusCodeEnum              FROM PROPATH.
USING OpenEdge.Web.IWebRequest                      FROM PROPATH.
USING OpenEdge.Web.WebResponseWriter                FROM PROPATH.
USING OpenEdge.Web.WebHandler                       FROM PROPATH.

USING Progress.Json.ObjectModel.ObjectModelParser   FROM PROPATH.
USING Progress.Json.ObjectModel.JsonObject          FROM PROPATH.
USING Progress.Json.ObjectModel.JsonArray           FROM PROPATH.

USING src.ch.adprime.gemis.WebHandlerUtilities      FROM PROPATH.
USING utilities.selectboxHandler                    FROM PROPATH.
USING utilities.utilitiesHandler                    FROM PROPATH.
USING admin.usersHandler                            FROM PROPATH.
USING admin.adminprogsHandler                       FROM PROPATH.

CLASS admin.dynamicformImpl INHERITS WebHandler: 

    DEFINE VARIABLE oResponse         AS IHttpResponse        NO-UNDO.         
    DEFINE VARIABLE oWriter           AS WebResponseWriter    NO-UNDO.
    DEFINE VARIABLE oBody             AS String               NO-UNDO.
    DEFINE VARIABLE cDefautlCharSet   AS CHARACTER            NO-UNDO INIT 'UTF-8'.
    DEFINE VARIABLE oParser           AS ObjectModelParser    NO-UNDO.           
    DEFINE VARIABLE cCorralationID    AS CHARACTER            NO-UNDO.
    DEFINE VARIABLE cContent-Type     AS CHARACTER            NO-UNDO.
    DEFINE VARIABLE lcJsonString      AS LONGCHAR             NO-UNDO.
    
    DEFINE VARIABLE oHandler          AS Progress.Lang.Object NO-UNDO.
    DEFINE VARIABLE cMethode          AS CHARACTER            NO-UNDO.
    
    DEFINE VARIABLE ccompany          AS CHARACTER            NO-UNDO.
    DEFINE VARIABLE cuser_name        AS CHARACTER            NO-UNDO.
    DEFINE VARIABLE cAnzeigeName      AS CHARACTER            NO-UNDO.
    DEFINE VARIABLE ilanguage_id      AS INTEGER              NO-UNDO.
    DEFINE VARIABLE cSessionToken     AS CHARACTER            NO-UNDO.
    DEFINE VARIABLE cFunction         AS CHARACTER            NO-UNDO.
    DEFINE VARIABLE cForm_Id          AS CHARACTER            NO-UNDO.
    DEFINE VARIABLE cProgram          AS CHARACTER            NO-UNDO.
    DEFINE VARIABLE cProgramUser      AS CHARACTER            NO-UNDO.
    DEFINE VARIABLE cUsers            AS CHARACTER            NO-UNDO INIT 'user,admin'.
    DEFINE VARIABLE lcMessage         AS LONGCHAR             NO-UNDO.
    DEFINE VARIABLE cErrorNo          AS CHARACTER            NO-UNDO.
    
    DEFINE VARIABLE lCompany          AS LOGICAL              NO-UNDO.
    DEFINE VARIABLE lActive           AS LOGICAL              NO-UNDO.
    DEFINE VARIABLE lWordindex        AS LOGICAL              NO-UNDO.
    
    DEFINE VARIABLE outilitiesHandler AS utilitiesHandler     NO-UNDO.
    DEFINE VARIABLE oselectboxHandler AS selectboxHandler     NO-UNDO.


    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD OVERRIDE PROTECTED INTEGER HandleDelete(INPUT poRequest AS IWebRequest):
        
        DEFINE VARIABLE oJsonResponse AS JsonObject NO-UNDO.
        DEFINE VARIABLE oJsonIdent    AS JsonObject NO-UNDO.
        DEFINE VARIABLE oJsonBox      AS JsonArray  NO-UNDO.
        DEFINE VARIABLE oJsonData     AS JsonObject NO-UNDO.
        
        DEFINE VARIABLE lRetVal       AS LOGICAL    NO-UNDO.
        DEFINE VARIABLE ii            AS INTEGER    NO-UNDO.
        DEFINE VARIABLE i1            AS INTEGER    NO-UNDO.
        DEFINE VARIABLE cQueryString  AS CHARACTER  NO-UNDO.
        DEFINE VARIABLE cQueryPairs   AS CHARACTER  NO-UNDO.
        DEFINE VARIABLE cQueryKey     AS CHARACTER  NO-UNDO.
        DEFINE VARIABLE cQueryValue   AS CHARACTER  NO-UNDO.
        DEFINE VARIABLE cFileName     AS CHARACTER  NO-UNDO.
        DEFINE VARIABLE cFieldName    AS CHARACTER  NO-UNDO.
        DEFINE VARIABLE cClassName    AS CHARACTER  NO-UNDO.
        
        DEFINE VARIABLE oJsonResult   AS JsonObject NO-UNDO.
        DEFINE VARIABLE oJsonMessage  AS JsonObject NO-UNDO.
        DEFINE VARIABLE httBuffer     AS HANDLE     NO-UNDO.

        lRetVal = WebHandlerUtilities:getJsonFromRequest(INPUT poRequest, OUTPUT oJsonData) NO-ERROR.

        outilitiesHandler = NEW utilitiesHandler().
        
        outilitiesHandler:getHeaderData(
            INPUT  poRequest    ,
            OUTPUT ccompany     ,
            OUTPUT cuser_name   ,
            OUTPUT cAnzeigeName ,
            OUTPUT ilanguage_id ,
            OUTPUT cSessionToken
            ).

        oJsonIdent = NEW JsonObject().
        oJsonIdent:ADD('company'     , ccompany     )   NO-ERROR.
        oJsonIdent:ADD('user_name'   , cuser_name   )   NO-ERROR.
        oJsonIdent:ADD('language_id' , iLanguage_id )   NO-ERROR.
        oJsonIdent:ADD('sessionToken', cSessionToken)   NO-ERROR.
        
        cQueryString = STRING(poRequest:GetContextValue("QUERY_STRING"))    NO-ERROR.
        DO ii = 1 TO NUM-ENTRIES(cQueryString, '&'):
            cQueryPairs = ENTRY(ii, cQueryString, '&').
            cQueryKey   = ENTRY(1 , cQueryPairs , '=').
            cQueryValue = ENTRY(2 , cQueryPairs , '=').
            IF oJsonIdent:Has(cQueryKey) THEN oJsonIdent:SET(cQueryKey, cQueryValue) NO-ERROR.
            ELSE                              oJsonIdent:ADD(cQueryKey, cQueryValue) NO-ERROR.
        END.
        MESSAGE 'dynamic DELETE' STRING(oJsonIdent:GetJsonText()).        
        cClassName = ENTRY(1, cForm_Id, '_').
        
        lRetVal  = FALSE.
        
        cuser_name = oJsonIdent:GetCharacter('H_user_name') NO-ERROR.
        IF LOOKUP(cuser_name, cUsers, ',') = 0 THEN cUsers = cuser_name + ',' + cUsers.
        cuser_name = oJsonIdent:GetCharacter('user_name') NO-ERROR.
        IF LOOKUP(cuser_name, cUsers, ',') = 0 THEN cUsers = cuser_name + ',' + cUsers.
        cProgram = outilitiesHandler:getProgramName (
            INPUT  oJsonIdent,
            INPUT  cUsers
            ).
            
        cFunction = oJsonIdent:GetCharacter('function').

        REPEAT TRANSACTION WHILE cFunction = 'delete' ON ERROR UNDO, LEAVE:
            
            DEFINE VARIABLE cClass     AS CHARACTER                   NO-UNDO.
            DEFINE VARIABLE rClass     AS Progress.Lang.Class.
            DEFINE VARIABLE rParamList AS Progress.Lang.ParameterList.
            
            CASE cClassName:
                WHEN 'users'    THEN 
                    cClass = 'admin.usersHandler'. 
                WHEN 'messages' THEN 
                    cClass = 'admin.adminprogsHandler'. 
                WHEN 'labeltexte' THEN 
                    cClass = 'admin.adminprogsHandler'. 
            END CASE.
            
            ASSIGN
                rClass = Progress.Lang.Class:GetClass(cClass).
            oHandler = rClass:NEW().
            /*            CASE cClassName:                           */
            /*                WHEN 'users' THEN                      */
            /*                    oHandler = NEW usersHandler().     */
            /*                WHEN 'messages' THEN                   */
            /*                    oHandler = NEW adminprogsHandler().*/
            /*            END CASE.                                  */

            cMethode = 'deleteData'.

            oHandler = rClass:NEW().
            lRetVal = DYNAMIC-INVOKE ( oHandler, cMethode,
                INPUT  oJsonIdent  ,
                INPUT  oJsonData   ,
                OUTPUT oJsonResult
                ).
            IF NOT lRetVal THEN LEAVE.
            
            oJsonResult:WRITE(lcJsonString, FALSE).
            LEAVE.
        END.
                    
        oResponse             = NEW OpenEdge.Web.WebResponse().
        oResponse:StatusCode  = INTEGER(StatusCodeEnum:OK).
        oResponse:ContentType = "application/json;charset=utf-8".
        oWriter               = NEW WebResponseWriter(oResponse).
                        
        IF NOT lRetVal THEN 
        DO:
            oJsonMessage = NEW JsonObject().
            oJsonMessage:ADD('success', FALSE).
            oJsonMessage:ADD('message', 'Fehler beim create/POST des Users').
            oJsonMessage:WRITE(lcJsonString, FALSE).
        END.
                            
        oWriter:Open().
        oWriter:Write(lcJsonString).
        oWriter:Close().
    
        RETURN 0.
    
        CATCH e AS Progress.Lang.Error:
                
        END CATCH.
                
        FINALLY:
        /*            DELETE OBJECT oJsonConfig. */
        /*            DELETE OBJECT oJsonMessage.*/
        END FINALLY.

    END METHOD.
    
    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD OVERRIDE PROTECTED INTEGER HandleGet (INPUT poRequest AS IWebRequest ):
        
        DEFINE VARIABLE oJsonResponse    AS JsonObject NO-UNDO.
        DEFINE VARIABLE oJsonIdent       AS JsonObject NO-UNDO.
        DEFINE VARIABLE oJsonSelectBoxes AS JsonObject NO-UNDO.
        DEFINE VARIABLE oJsonBox         AS JsonArray  NO-UNDO.
        
        DEFINE VARIABLE lRetVal          AS LOGICAL    NO-UNDO.
        DEFINE VARIABLE ii               AS INTEGER    NO-UNDO.
        DEFINE VARIABLE i1               AS INTEGER    NO-UNDO.
        DEFINE VARIABLE cQueryString     AS CHARACTER  NO-UNDO.
        DEFINE VARIABLE cQueryPairs      AS CHARACTER  NO-UNDO.
        DEFINE VARIABLE cQueryKey        AS CHARACTER  NO-UNDO.
        DEFINE VARIABLE cQueryValue      AS CHARACTER  NO-UNDO.
        DEFINE VARIABLE cFileName        AS CHARACTER  NO-UNDO.
        DEFINE VARIABLE cFieldName       AS CHARACTER  NO-UNDO.
        DEFINE VARIABLE cClassName       AS CHARACTER  NO-UNDO.
        DEFINE VARIABLE cActiveSelection AS CHARACTER  NO-UNDO.
        
        DEFINE VARIABLE oJsonResult      AS JsonObject NO-UNDO.
        DEFINE VARIABLE httBuffer        AS HANDLE     NO-UNDO.
        
        outilitiesHandler = NEW utilitiesHandler().
        
        outilitiesHandler:getHeaderData(
            INPUT  poRequest    ,
            OUTPUT ccompany     ,
            OUTPUT cuser_name   ,
            OUTPUT cAnzeigeName ,
            OUTPUT ilanguage_id ,
            OUTPUT cSessionToken
            ).
        
        oJsonIdent = NEW JsonObject().
        oJsonIdent:ADD('H_company'     , ccompany     )   NO-ERROR.
        oJsonIdent:ADD('H_user_name'   , cuser_name   )   NO-ERROR.
        oJsonIdent:ADD('H_display_name', cAnzeigeName )   NO-ERROR.
        oJsonIdent:ADD('H_language_id' , iLanguage_id )   NO-ERROR.
        oJsonIdent:ADD('H_sessionToken', cSessionToken)   NO-ERROR.
        //
        //  Alle Parameter aus dem Query-String lesen und im Object oJsonIdent ergänzenz
        //
        cQueryString = STRING(poRequest:GetContextValue("QUERY_STRING"))    NO-ERROR.
        DO ii = 1 TO NUM-ENTRIES(cQueryString, '&'):
            cQueryPairs = ENTRY(ii, cQueryString, '&').
            cQueryKey   = ENTRY(1 , cQueryPairs , '=').
            cQueryValue = ENTRY(2 , cQueryPairs , '=').
            IF oJsonIdent:Has(cQueryKey) THEN oJsonIdent:SET(cQueryKey, cQueryValue) NO-ERROR.
            ELSE                              oJsonIdent:ADD(cQueryKey, cQueryValue) NO-ERROR.
        END.
        //
        //  mögliche Benutzer für das durchsuchen von HTML-DOkumenten und Labeltexten ...
        //
        cuser_name = oJsonIdent:GetCharacter('H_user_name') NO-ERROR.
        IF NOT ERROR-STATUS:ERROR AND LOOKUP(cuser_name, cUsers, ',') = 0 THEN cUsers = cuser_name + ',' + cUsers.
        cuser_name = oJsonIdent:GetCharacter('user_name') NO-ERROR.
        IF NOT ERROR-STATUS:ERROR AND LOOKUP(cuser_name, cUsers, ',') = 0 THEN cUsers = cuser_name + ',' + cUsers.
        
        lRetVal = FALSE.

        MASTERLOOP:
        DO WHILE TRUE:
            //
            //  Programmname aus den möglichen Benutzern ermitteln
            //
            cProgram = outilitiesHandler:getProgramName (
                INPUT  oJsonIdent,
                INPUT  cUsers
                ).
MESSAGE 'getProgramName ' cProgram.
            IF cProgram = '' THEN 
            DO:
                outilitiesHandler:getErrorMessage(
                    INPUT  '1000',
                    INPUT  oJsonIdent:GetInteger('language_id'),
                    INPUT  '',  /* Parameters */
                    OUTPUT lcMessage
                    ).
                LEAVE.
            END.            
            oJsonIdent:ADD('program', cProgram).
            
            cErrorNo = ''.
            cForm_Id = oJsonIdent:GetCharacter("formId") NO-ERROR.
            IF NOT ERROR-STATUS:ERROR THEN 
            DO:
                cClassName = ENTRY(1, cForm_Id, '_').
                cFileName  = ENTRY(1, cForm_Id, '_').
            END.
            IF  cClassName = '' THEN
                cErrorNo = cErrorNo 
                    + (IF cErrorNo = '' THEN '' ELSE ',')
                    + '1001'.
            IF cFileName = '' THEN
                cErrorNo = cErrorNo 
                    + (IF cErrorNo = '' THEN '' ELSE ',')
                    + '1002'.
            IF cErrorNo <> '' THEN 
            DO:
                outilitiesHandler:getErrorMessage(
                    INPUT  cErrorNo,
                    INPUT  oJsonIdent:GetInteger('language_id'),
                    INPUT  '',  /* Parameters */
                    OUTPUT lcMessage
                    ).
                LEAVE.
            END.
            oJsonIdent:ADD('class_name', cClassName).
            oJsonIdent:ADD('file_name' , cFileName ).
            
            IF NOT oJsonIdent:HAS('company'    ) THEN oJsonIdent:ADD('company'    , oJsonIdent:GetCharacter('H_company'    )).
            IF NOT oJsonIdent:HAS('user_name'  ) THEN oJsonIdent:ADD('user_name'  , oJsonIdent:GetCharacter('H_user_name'  )).
            IF NOT oJsonIdent:HAS('language_id') THEN oJsonIdent:ADD('language_id', oJsonIdent:GetInteger  ('H_language_id')).
        
            oJsonIdent:WriteFile('C:\TEMP\dynamicform_GET.json', TRUE).
        
            cFunction = oJsonIdent:GetCharacter('function').
            cCompany  = oJsonIdent:GetCharacter('company').
     
            DO WHILE cFunction = 'init' AND cProgram <> '':
            
                FIND FIRST selectboxfields NO-LOCK
                    WHERE selectboxfields.company = ccompany
                    AND   selectboxfields.program = cform_id NO-ERROR.
                IF NOT AVAILABLE selectboxfields THEN LEAVE.

                oselectboxHandler = NEW selectboxHandler().
                oJsonSelectBoxes  = NEW JsonObject().
                FOR EACH selectboxfields NO-LOCK
                    WHERE selectboxfields.company = ccompany
                    AND   selectboxfields.program = cform_id:

                    DO ii = 1 TO NUM-ENTRIES(selectboxfields.boxfields, ';'):
                        cFieldName = ENTRY(ii, selectboxfields.boxfields, ';').
                        cFileName  = ENTRY(1, cFieldName, '_').

                        IF cFieldName MATCHES('*company*') THEN 
                        DO:
                            oJsonBox  = NEW JsonArray().
                            httBuffer = oSelectboxHandler:getSelboxCompany(INPUT cFileName).
                            httBuffer:WRITE-JSON ('JsonArray', oJsonBox).
                            oJsonSelectBoxes:ADD(cFieldName, oJsonBox).
                            NEXT.
                        END.
            
                        IF cFieldName MATCHES('*language_id*') THEN 
                        DO:
                            oJsonBox  = NEW JsonArray().
                            httBuffer = oSelectboxHandler:getSelboxLanguage(INPUT cFileName).
                            httBuffer:WRITE-JSON ('JsonArray', oJsonBox).
                            oJsonSelectBoxes:ADD(cFieldName, oJsonBox).
                            NEXT.
                        END.
                    
                        IF cFieldName MATCHES('*user_name*') THEN 
                        DO:
                            oJsonBox  = NEW JsonArray().
                            httBuffer = oSelectboxHandler:getSelboxUsers(INPUT cFileName).
                            httBuffer:WRITE-JSON ('JsonArray', oJsonBox).
                            oJsonSelectBoxes:ADD(cFieldName, oJsonBox).
                            NEXT.
                        END.
                    
                        IF cFieldName MATCHES('*table_name*') THEN 
                        DO:
                            oJsonBox  = NEW JsonArray().
                            httBuffer = oSelectboxHandler:getSelboxTables(INPUT cFileName).
                            httBuffer:WRITE-JSON ('JsonArray', oJsonBox).
                            oJsonSelectBoxes:ADD(cFieldName, oJsonBox).
                            NEXT.
                        END.
                    
                    END.
                END.
            
                outilitiesHandler:evaluateFile(
                    INPUT  oJsonIdent   ,
                    OUTPUT cFileName    ,
                    OUTPUT lCompany     ,
                    OUTPUT lActive      ,
                    OUTPUT lWordindex
                    ).
            
                outilitiesHandler:getActiveSelection(
                    INPUT  oJsonIdent      ,
                    INPUT  cFileName       ,
                    OUTPUT cActiveSelection
                    ).
            
                oJsonResponse = NEW JsonObject().
                oJsonResponse:ADD('selectOptionsFix', oJsonSelectBoxes).
                oJsonResponse:ADD("activeFilter"    , cActiveSelection).
                oJsonResponse:ADD("hasActiveField"  , lActive         ).
                oJsonResponse:ADD("tableMaxHeight"  , '400px'         ).
                oJsonResponse:ADD("itemsPerPage"    , 25              ).
                oJsonResponse:WriteFile('C:\Temp\Dynamic_Init_response.json', TRUE).
                lRetVal = TRUE.                
                LEAVE. 
            END.
            
            DO WHILE cFunction = 'loaddata' AND cProgram <> '':
                CASE cClassName:
                    WHEN 'users' THEN 
                        oHandler = NEW usersHandler().
                    WHEN 'messages' THEN 
                        oHandler = NEW adminprogsHandler().
                    WHEN 'labeltexte' THEN 
                        oHandler = NEW adminprogsHandler().
                END CASE.

                cMethode = 'getData'.

                lRetVal = DYNAMIC-INVOKE ( oHandler, cMethode,
                    INPUT  oJsonIdent    ,
                    OUTPUT oJsonResult
                    ).
            // oJsonResult:WriteFile('C:\TEMP\loaddate_result.json', TRUE).
 
                oJsonResponse = NEW JsonObject().
                oJsonResponse:ADD('selectOptionsFix', oJsonSelectBoxes).
            
                oJsonResponse = oJsonResult.

                lRetVal = TRUE.
                LEAVE.
            END.
        
            DO WHILE cFunction = 'change' AND cProgram <> '':

                CASE cClassName:
                    WHEN 'users' THEN 
                        oHandler = NEW usersHandler().
                    WHEN 'messages' THEN 
                        oHandler = NEW adminprogsHandler().
                    WHEN 'labeltexte' THEN 
                        oHandler = NEW adminprogsHandler().
                END CASE.

                cMethode = 'getChanges'.

                lRetVal = DYNAMIC-INVOKE ( oHandler, cMethode,
                    INPUT  oJsonIdent    ,
                    OUTPUT oJsonResult
                    ).
            
                oJsonResponse = NEW JsonObject().
                oJsonResponse:ADD('selectOptionsFix', oJsonSelectBoxes).
            
                oJsonResponse = oJsonResult.

                lRetVal = TRUE.
                LEAVE.
            END.
        
            DO WHILE cFunction = 'rebuild':
            
                CASE cClassName:
                    WHEN 'users' THEN 
                        oHandler = NEW usersHandler().
                    WHEN 'messages' THEN 
                        oHandler = NEW adminprogsHandler().
                    WHEN 'labeltexte' THEN 
                        oHandler = NEW adminprogsHandler().
                END CASE.

                cMethode = 'rebuildData'.

                lRetVal = DYNAMIC-INVOKE ( oHandler, cMethode,
                    INPUT  oJsonIdent    ,
                    OUTPUT oJsonResult
                    ).
                IF NOT lRetVal THEN 
                DO:
                    outilitiesHandler:getErrorMessage(
                        INPUT  '900'        ,
                        INPUT  ilanguage_id ,
                        INPUT   '',
                        OUTPUT lcMessage).                    
                    oJsonResponse = NEW JsonObject().
                    oJsonResponse:ADD('success', FALSE).
                    oJsonResponse:ADD('message', lcMessage).
                    oJsonResponse:WRITE(lcJsonString, FALSE).
                END.
            
                oJsonResponse = NEW JsonObject().
                oJsonResponse:ADD('selectOptionsFix', oJsonSelectBoxes).
            
                oJsonResponse = oJsonResult.

                lRetVal = TRUE.
                LEAVE.
            END.
        
            DO WHILE cFunction = 'saveActiveFilter':
                cActiveSelection = oJsonIdent:GetCharacter('activeFilter').
                outilitiesHandler:setActiveSelection(
                    INPUT  oJsonIdent      ,
                    INPUT  cFileName       ,
                    INPUT  cActiveSelection
                    ).
            
                oJsonResponse = NEW JsonObject().
                oJsonResponse:ADD('success', TRUE).
                oJsonResponse:WRITE(lcJsonString, FALSE).
            
                lRetVal = TRUE.
                LEAVE.
            END.
        
        // oJsonResponse:WriteFile('C:\Temp\dynamicform_response.json').
            oJsonResponse:WRITE(lcJsonString, FALSE).
        
            LEAVE.
        END.

        IF NOT lRetVal THEN 
        DO:
            oJsonResponse = NEW JsonObject().
            oJsonResponse:ADD('success', FALSE).
            oJsonResponse:WRITE(lcJsonString, FALSE).
        END.
                
        cContent-Type   = "application/json".
        cDefautlCharSet = 'utf-8'.

        oBody = NEW STRING(lcJsonString).
        WebHandlerUtilities:createHttpResponse(INPUT INTEGER(StatusCodeEnum:OK), INPUT oBody, INPUT cContent-Type, INPUT cDefautlCharSet, INPUT cCorralationID, OUTPUT oResponse).
//        oResponse:SetHeader(HttpHeaderBuilder:Build(cHeaderCorralationID):Value(cCorralationID):Header).

        
        oWriter = NEW WebResponseWriter(oResponse).
        oWriter:Open(). 
        oWriter:Close(). 

        RETURN 0.
        
        CATCH e AS Progress.Lang.Error:

        END CATCH.

        FINALLY:

        END FINALLY.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD OVERRIDE PROTECTED INTEGER HandlePost(INPUT poRequest AS IWebRequest):
        
        DEFINE VARIABLE oJsonResponse AS JsonObject NO-UNDO.
        DEFINE VARIABLE oJsonIdent    AS JsonObject NO-UNDO.
        DEFINE VARIABLE oJsonBox      AS JsonArray  NO-UNDO.
        DEFINE VARIABLE oJsonData     AS JsonObject NO-UNDO.
        
        DEFINE VARIABLE lRetVal       AS LOGICAL    NO-UNDO.
        DEFINE VARIABLE ii            AS INTEGER    NO-UNDO.
        DEFINE VARIABLE i1            AS INTEGER    NO-UNDO.
        DEFINE VARIABLE cQueryString  AS CHARACTER  NO-UNDO.
        DEFINE VARIABLE cQueryPairs   AS CHARACTER  NO-UNDO.
        DEFINE VARIABLE cQueryKey     AS CHARACTER  NO-UNDO.
        DEFINE VARIABLE cQueryValue   AS CHARACTER  NO-UNDO.
        DEFINE VARIABLE cFileName     AS CHARACTER  NO-UNDO.
        DEFINE VARIABLE cFieldName    AS CHARACTER  NO-UNDO.
        DEFINE VARIABLE cClassName    AS CHARACTER  NO-UNDO.
        
        DEFINE VARIABLE oJsonResult   AS JsonObject NO-UNDO.
        DEFINE VARIABLE oJsonMessage  AS JsonObject NO-UNDO.
        DEFINE VARIABLE httBuffer     AS HANDLE     NO-UNDO.
        
        lRetVal = WebHandlerUtilities:getJsonFromRequest(INPUT poRequest, OUTPUT oJsonData) NO-ERROR.

        outilitiesHandler = NEW utilitiesHandler().
        
        outilitiesHandler:getHeaderData(
            INPUT  poRequest    ,
            OUTPUT ccompany     ,
            OUTPUT cuser_name   ,
            OUTPUT cAnzeigeName ,
            OUTPUT ilanguage_id ,
            OUTPUT cSessionToken
            ).

        oJsonIdent = NEW JsonObject().
        oJsonIdent:ADD('H_company'     , ccompany     )   NO-ERROR.
        oJsonIdent:ADD('H_user_name'   , cuser_name   )   NO-ERROR.
        oJsonIdent:ADD('H_display_name', cAnzeigeName )   NO-ERROR.
        oJsonIdent:ADD('H_language_id' , iLanguage_id )   NO-ERROR.
        oJsonIdent:ADD('H_sessionToken', cSessionToken)   NO-ERROR.
        //
        //  Alle Parameter aus dem Query-String lesen und im Object oJsonIdent ergänzenz
        //
        cQueryString = STRING(poRequest:GetContextValue("QUERY_STRING"))    NO-ERROR.
        DO ii = 1 TO NUM-ENTRIES(cQueryString, '&'):
            cQueryPairs = ENTRY(ii, cQueryString, '&').
            cQueryKey   = ENTRY(1 , cQueryPairs , '=').
            cQueryValue = ENTRY(2 , cQueryPairs , '=').
            IF oJsonIdent:Has(cQueryKey) THEN oJsonIdent:SET(cQueryKey, cQueryValue) NO-ERROR.
            ELSE                              oJsonIdent:ADD(cQueryKey, cQueryValue) NO-ERROR.
        END.
        
        lRetVal  = FALSE.
        cProgram = outilitiesHandler:getProgramName (
            INPUT  oJsonIdent,
            INPUT  cUsers
            ).
            
        cFunction = oJsonIdent:GetCharacter('function').

        REPEAT TRANSACTION WHILE cFunction = 'create' ON ERROR UNDO, LEAVE:
            
            CASE cClassName:
                WHEN 'users' THEN 
                    oHandler = NEW usersHandler().
                WHEN 'messages' THEN 
                    oHandler = NEW adminprogsHandler().
                WHEN 'labeltexte' THEN 
                    oHandler = NEW adminprogsHandler().
            END CASE.

            cMethode = 'createData'.

            lRetVal = DYNAMIC-INVOKE ( oHandler, cMethode,
                INPUT  oJsonIdent  ,
                INPUT  oJsonData   ,
                OUTPUT oJsonResult
                ).
            IF NOT lRetVal THEN LEAVE.
            
            oJsonResult:WRITE(lcJsonString, FALSE).
            LEAVE.
        END.
                    
        oResponse             = NEW OpenEdge.Web.WebResponse().
        oResponse:StatusCode  = INTEGER(StatusCodeEnum:OK).
        oResponse:ContentType = "application/json;charset=utf-8".
        oWriter               = NEW WebResponseWriter(oResponse).
                        
        IF NOT lRetVal THEN 
        DO:
            oJsonMessage = NEW JsonObject().
            oJsonMessage:ADD('success', FALSE).
            oJsonMessage:ADD('message', oJsonResult:GetLongchar('message')).
            oJsonMessage:WRITE(lcJsonString, FALSE).
        END.
        MESSAGE 'Rueckmeldung beim POST (CREATE) ' STRING(lcJsonString).
                            
        oWriter:Open().
        oWriter:Write(lcJsonString).
        oWriter:Close().
    
        RETURN 0.
    
        CATCH e AS Progress.Lang.Error:
                
        END CATCH.
                
        FINALLY:
        /*            DELETE OBJECT oJsonConfig. */
        /*            DELETE OBJECT oJsonMessage.*/
        END FINALLY.

    END METHOD.
    
    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD OVERRIDE PROTECTED INTEGER HandlePatch(INPUT poRequest AS IWebRequest):
        
        DEFINE VARIABLE oJsonResponse AS JsonObject NO-UNDO.
        DEFINE VARIABLE oJsonIdent    AS JsonObject NO-UNDO.
        DEFINE VARIABLE oJsonBox      AS JsonArray  NO-UNDO.
        DEFINE VARIABLE oJsonData     AS JsonObject NO-UNDO.
        
        DEFINE VARIABLE lRetVal       AS LOGICAL    NO-UNDO.
        DEFINE VARIABLE ii            AS INTEGER    NO-UNDO.
        DEFINE VARIABLE i1            AS INTEGER    NO-UNDO.
        DEFINE VARIABLE cQueryString  AS CHARACTER  NO-UNDO.
        DEFINE VARIABLE cQueryPairs   AS CHARACTER  NO-UNDO.
        DEFINE VARIABLE cQueryKey     AS CHARACTER  NO-UNDO.
        DEFINE VARIABLE cQueryValue   AS CHARACTER  NO-UNDO.
        DEFINE VARIABLE cFileName     AS CHARACTER  NO-UNDO.
        DEFINE VARIABLE cFieldName    AS CHARACTER  NO-UNDO.
        DEFINE VARIABLE cClassName    AS CHARACTER  NO-UNDO.
        
        DEFINE VARIABLE oJsonResult   AS JsonObject NO-UNDO.
        DEFINE VARIABLE oJsonMessage  AS JsonObject NO-UNDO.
        DEFINE VARIABLE httBuffer     AS HANDLE     NO-UNDO.
        
        lRetVal = WebHandlerUtilities:getJsonFromRequest(INPUT poRequest, OUTPUT oJsonData) NO-ERROR.
        
        outilitiesHandler = NEW utilitiesHandler().
        
        outilitiesHandler:getHeaderData(
            INPUT  poRequest    ,
            OUTPUT ccompany     ,
            OUTPUT cuser_name   ,
            OUTPUT cAnzeigeName ,
            OUTPUT ilanguage_id ,
            OUTPUT cSessionToken
            ).

        oJsonIdent = NEW JsonObject().
        oJsonIdent:ADD('company'     , ccompany     )   NO-ERROR.
        oJsonIdent:ADD('user_name'   , cuser_name   )   NO-ERROR.
        oJsonIdent:ADD('language_id' , iLanguage_id )   NO-ERROR.
        oJsonIdent:ADD('sessionToken', cSessionToken)   NO-ERROR.
        
        cQueryString = STRING(poRequest:GetContextValue("QUERY_STRING"))    NO-ERROR.
        DO ii = 1 TO NUM-ENTRIES(cQueryString, '&'):
            cQueryPairs = ENTRY(ii, cQueryString, '&').
            cQueryKey   = ENTRY(1 , cQueryPairs , '=').
            cQueryValue = ENTRY(2 , cQueryPairs , '=').
            IF oJsonIdent:Has(cQueryKey) THEN oJsonIdent:SET(cQueryKey, cQueryValue) NO-ERROR.
            ELSE                              oJsonIdent:ADD(cQueryKey, cQueryValue) NO-ERROR.
        END.
        MESSAGE 'dynamic PATCH' STRING(oJsonIdent:GetJsonText()).
        cForm_Id   = poRequest:URI:GetQueryValue("formId") NO-ERROR.
        cClassName = ENTRY(1, cForm_Id, '_').
        
        lRetVal  = FALSE.
        cProgram = outilitiesHandler:getProgramName (
            INPUT  oJsonIdent,
            INPUT  cUsers
            ).
            
        cFunction = oJsonIdent:GetCharacter('function').
        
        REPEAT TRANSACTION WHILE cFunction = 'update' ON ERROR UNDO, LEAVE:
            
            CASE cClassName:
                WHEN 'users' THEN 
                    oHandler = NEW usersHandler().
                WHEN 'messages' THEN 
                    oHandler = NEW adminprogsHandler().
                WHEN 'labeltexte' THEN 
                    oHandler = NEW adminprogsHandler().
            END CASE.

            cMethode = 'updateData'.

            lRetVal = DYNAMIC-INVOKE ( oHandler, cMethode,
                INPUT  oJsonIdent  ,
                INPUT  oJsonData   ,
                OUTPUT oJsonResult
                ).
            
            oJsonResult:WRITE(LcJsonString, FALSE).
            LEAVE.
        END.
                    
        oResponse             = NEW OpenEdge.Web.WebResponse().
        oResponse:StatusCode  = INTEGER(StatusCodeEnum:OK).
        oResponse:ContentType = "application/json;charset=utf-8".
        oWriter               = NEW WebResponseWriter(oResponse).
                        
        IF NOT lRetVal THEN 
        DO:
            oJsonMessage = NEW JsonObject().
            oJsonMessage:ADD('success', FALSE).
            oJsonMessage:ADD('message', 'Fehler beim Update/PATCH des Users').
            oJsonMessage:WRITE(lcJsonString, FALSE).
        END.
        // MESSAGE 'R�ckmeldung ' STRING(lcJsonString).
                            
        oWriter:Open().
        oWriter:Write(lcJsonString).
        oWriter:Close().
    
        RETURN 0.
    
        CATCH e AS Progress.Lang.Error:
                
        END CATCH.
                
        FINALLY:
        /*            DELETE OBJECT oJsonConfig. */
        /*            DELETE OBJECT oJsonMessage.*/
        END FINALLY.

    END METHOD.
    
    
    METHOD OVERRIDE PROTECTED INTEGER HandleNotAllowedMethod(INPUT poRequest AS IWebRequest):
        DEFINE VARIABLE result AS INTEGER NO-UNDO.
        MESSAGE "HandleNotAllowedMethod called" VIEW-AS ALERT-BOX.
        RETURN result.
    END METHOD.

    METHOD OVERRIDE PROTECTED INTEGER HandleNotImplemented(INPUT poRequest AS IWebRequest):
        DEFINE VARIABLE result AS INTEGER NO-UNDO.
        MESSAGE "HandleNotImplemented called" VIEW-AS ALERT-BOX.
        RETURN result.
    END METHOD.

    DESTRUCTOR PUBLIC dynamicformImpl ( ):

    END DESTRUCTOR.

END CLASS.