/*------------------------------------------------------------------------
   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 PROGRESS.lang.*                               FROM PROPATH.

USING src.ch.adprime.gemis.WebHandlerUtilities      FROM PROPATH.
USING utilities.selectboxHandler                    FROM PROPATH.
USING utilities.utilitiesHandler                    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 oJsonActiveSelectBox AS JsonObject           NO-UNDO.    
    
    DEFINE VARIABLE hError               AS HANDLE               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 cMaxHeight           AS CHARACTER            NO-UNDO.
    DEFINE VARIABLE iItemsPage           AS INTEGER              NO-UNDO.
    DEFINE VARIABLE cLogFile             AS CHARACTER            NO-UNDO.
    DEFINE VARIABLE hBuffer              AS HANDLE               NO-UNDO.
    DEFINE VARIABLE hField               AS HANDLE               NO-UNDO.
    
    DEFINE VARIABLE cMethode             AS CHARACTER            NO-UNDO.
    DEFINE VARIABLE cClass               AS CHARACTER            NO-UNDO.
    DEFINE VARIABLE rClass               AS Progress.Lang.Class.
    DEFINE VARIABLE oHandler             AS Progress.Lang.Object 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 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.
        cLogFile = SUBSTITUTE('C:\TEMP\handleDELETE_&1.json', REPLACE(STRING(TIME,'HH:MM:SS'), ':', '')).
        oJsonData:WriteFile(cLogFile, TRUE).

        hError            = ERROR-STATUS:HANDLE.
        outilitiesHandler = NEW utilitiesHandler().
        cQueryString      = STRING(poRequest:GetContextValue("QUERY_STRING"))    NO-ERROR.
        
        outilitiesHandler:getHeaderData(
            INPUT  poRequest    ,
            INPUT  cQueryString ,
            OUTPUT ccompany     ,
            OUTPUT cuser_name   ,
            OUTPUT cAnzeigeName ,
            OUTPUT ilanguage_id ,
            OUTPUT cSessionToken,
            OUTPUT cFunction    ,
            OUTPUT oJsonIdent   
            ).

        // oJsonIdent:WriteFile('C:\TEMP\dynamicform_DELETE_ident.json', TRUE).
                
        cForm_Id   = oJsonIdent:GetCharacter('formId').
        cClassName = ENTRY(1, cForm_Id, '_').
        cFileName  = ENTRY(1, cForm_Id, '_').
        //
        //  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.
      
        cProgram = outilitiesHandler:getProgramName (
            INPUT  oJsonIdent,
            INPUT  cUsers
            ).
            
        REPEAT TRANSACTION WHILE cFunction = 'delete' ON ERROR UNDO, LEAVE:
            CASE cClassName:
                WHEN 'users' THEN 
                    cClass = 'admin.adminprogsHandler'.
                WHEN 'messages' THEN 
                    cClass = 'admin.adminprogsHandler'.
                WHEN 'labeltexte' THEN 
                    cClass = 'admin.adminprogsHandler'.
            END CASE.

            rClass   = Progress.Lang.Class:GetClass(cClass) NO-ERROR.
            cMethode = 'deleteData'.
            oHandler = rClass:NEW().
            lRetVal  = DYNAMIC-INVOKE ( oHandler, cMethode,
                INPUT  oJsonIdent ,
                INPUT  oJsonData  ,
                OUTPUT oJsonResult
                ) NO-ERROR.
            outilitiesHandler:evaluateErrorStatus(hError).
            IF NOT lRetVal THEN LEAVE.
            
            oJsonResult:WRITE(lcJsonString, FALSE).
            oJsonResult:WriteFile('C:\TEMP\DYNAMIC_DELETE_Respons.json', TRUE).
            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 DELETE').
            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 oHandler     NO-ERROR.
            DELETE OBJECT oJsonMessage NO-ERROR.
            DELETE OBJECT oResponse    NO-ERROR.
            DELETE OBJECT oWriter      NO-ERROR.
        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 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 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 cFormUser        AS CHARACTER  NO-UNDO.
        
        DEFINE VARIABLE oJsonResult      AS JsonObject NO-UNDO.
        DEFINE VARIABLE httBuffer        AS HANDLE     NO-UNDO.
        
        hError            = ERROR-STATUS:HANDLE.
        outilitiesHandler = NEW utilitiesHandler().
        cQueryString      = STRING(poRequest:GetContextValue("QUERY_STRING"))    NO-ERROR.
        
        outilitiesHandler:getHeaderData(
            INPUT  poRequest    ,
            INPUT  cQueryString ,
            OUTPUT ccompany     ,
            OUTPUT cuser_name   ,
            OUTPUT cAnzeigeName ,
            OUTPUT ilanguage_id ,
            OUTPUT cSessionToken,
            OUTPUT cFunction    ,
            OUTPUT oJsonIdent   
            ).
        //
        //  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.
        
        cLogFile = SUBSTITUTE('C:\TEMP\handleGET_&1.json', REPLACE(STRING(TIME,'HH:MM:SS'), ':', '')).
        oJsonIdent:WriteFile(cLogFile, TRUE) NO-ERROR.
        outilitiesHandler:evaluateErrorStatus(INPUT hError).
        
        lRetVal = FALSE.

        MASTERLOOP:
        DO WHILE TRUE:
            //
            //  Programmname aus den möglichen Benutzern ermitteln
            //
            cMaxHeight = '250px'.
            iItemsPage = 50.
            cProgram = outilitiesHandler:getProgramName (
                INPUT        oJsonIdent,
                INPUT        cUsers    ,
                OUTPUT       cFormUser ,
                INPUT-OUTPUT iItemsPage,
                INPUT-OUTPUT cMaxHeight
                ).
            IF cProgram = '' THEN 
            DO:
                outilitiesHandler:getErrorMessage(
                    INPUT  '2001',
                    INPUT  iLanguage_id,
                    INPUT  oJsonIdent:GetCharacter('frameId'),  /* Parameters */
                    OUTPUT lcMessage
                    ).
                LEAVE.
            END.            
            oJsonIdent:ADD('program'       , cProgram  ).
            oJsonIdent:ADD('itemsPerPage'  , iItemsPage).
            oJsonIdent:ADD('tableMaxHeight', cMaxHeight).
            oJsonIdent:ADD('formUser'      , cFormUser ).

            cErrorNo   = ''.
            cForm_Id   = oJsonIdent:GetCharacter("formId"    ) NO-ERROR.
            cFileName  = oJsonIdent:GetCharacter("file_name" ) NO-ERROR.
            cClassName = oJsonIdent:GetCharacter("class_name") NO-ERROR.
            
            //            
            //  active-Feld-Filter ermitten
            //
            outilitiesHandler:getActiveSelection(
                INPUT  oJsonIdent      ,
                INPUT  cFileName       ,
                OUTPUT cActiveSelection
                ).
            IF cActiveSelection <> '' THEN 
            DO:
                IF NOT oJsonIdent:HAS('activeFilter') THEN oJsonIdent:ADD('activeFilter', cActiveSelection ).
            END.

            DO WHILE cFunction = 'saveActiveFilter' AND cProgram <> '':
                outilitiesHandler:setActiveSelection(
                    INPUT  oJsonIdent,
                    INPUT  cFileName,
                    INPUT  oJsonIdent:GetCharacter('activeFilter')
                    ).
                lRetVal = TRUE.
                LEAVE.
            END.

            DO WHILE cFunction = 'init' AND cProgram <> '':
                //
                //  wenn die Tabelle(File) das Feld active enthält, soll der activeFilter activiert werden
                //
                CREATE BUFFER hBuffer FOR TABLE cFilename NO-ERROR.
                hField = hBuffer:BUFFER-FIELD('active') NO-ERROR.
                IF  NOT ERROR-STATUS:ERROR AND 
                    VALID-HANDLE(hField)   THEN lActive = TRUE.
                DELETE OBJECT hBuffer.
                //
                //  Alle Felder, welche als Selectboxen definiert sind, füllen
                //                
                oselectboxHandler = NEW selectboxHandler().
                oJsonSelectBoxes  = NEW JsonObject().
                FOR EACH selectboxfields NO-LOCK
                    WHERE selectboxfields.company   = ccompany
                    AND   selectboxfields.program   = cform_id
                    AND   selectboxfields.user_name = cFormUser:

                    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) NO-ERROR.
                            httBuffer:WRITE-JSON ('JsonArray', oJsonBox) NO-ERROR.
                            oJsonSelectBoxes:ADD(cFieldName, oJsonBox) NO-ERROR.
                            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.
                
                oJsonResponse = NEW JsonObject().
                oJsonResponse:ADD('selectOptionsFix', oJsonSelectBoxes).
                oJsonResponse:ADD("tableMaxHeight"  , cMaxHeight      ).
                oJsonResponse:ADD("itemsPerPage"    , iItemsPage      ).
                //
                //  Wenn die Tabelle das Feld active hat, wird die SelectBox für den activ-Filter gefüllt
                //
                IF lActive THEN 
                DO:
                    oJsonResponse:ADD("activeFilter"    , cActiveSelection).
                    oJsonResponse:ADD("hasActiveField"  , lActive         ).
                    
                    oJsonActiveSelectBox = NEW JsonObject().
                    FOR EACH labeltexte NO-LOCK 
                        WHERE labeltexte.company     = ccompany
                        AND   labeltexte.user_name   = cuser_name
                        AND   labeltexte.program     = 'Labels'
                        AND   labeltexte.table_name  = 'table'
                        AND   labeltexte.field_name BEGINS 'LBL_FILTER'
                        AND   labeltexte.language_id = ilanguage_id :
                        oJsonActiveSelectBox:ADD(CAPS(labeltexte.field_name), labeltexte.headlabel).
                    END.
                END.
                oJsonResponse:ADD('activeFilterLabels', oJsonActiveSelectBox).
                
                lRetVal = TRUE.                
                LEAVE. 
            END.
            
            DO WHILE cFunction = 'loaddata' AND cProgram <> '':
                CASE cClassName:
                    WHEN 'users' THEN 
                        cClass = 'admin.adminprogsHandler'.
                    WHEN 'messages' THEN 
                        cClass = 'admin.adminprogsHandler'.
                    WHEN 'labeltexte' THEN 
                        cClass = 'admin.adminprogsHandler'.
                END CASE.

                rClass   = Progress.Lang.Class:GetClass(cClass) NO-ERROR.
                cMethode = 'getData'.
                oHandler = rClass:NEW().
                lRetVal  = DYNAMIC-INVOKE ( oHandler, cMethode,
                    INPUT  oJsonIdent  ,
                    OUTPUT oJsonResult
                    ) NO-ERROR.
                outilitiesHandler:evaluateErrorStatus(hError).
                IF NOT lRetVal THEN LEAVE.
 
                oJsonResponse = NEW JsonObject().
                oJsonResponse:ADD('selectOptionsFix', oJsonSelectBoxes).
            
                oJsonResponse = oJsonResult.

                lRetVal = TRUE.
                LEAVE.
            END.
        
            DO WHILE cFunction = 'change' AND cProgram <> '':
                CASE cClassName:
                    WHEN 'users' THEN 
                        cClass = 'adminprogsHandler'.
                    WHEN 'messages' THEN 
                        cClass = 'adminprogsHandler'.
                    WHEN 'labeltexte' THEN 
                        cClass = 'adminprogsHandler'.
                END CASE.
            
                ASSIGN
                    rClass = Progress.Lang.Class:GetClass(cClass).
                
                cMethode = 'change'.

                oHandler = rClass:NEW().
                lRetVal = DYNAMIC-INVOKE ( oHandler, cMethode,
                    INPUT  oJsonIdent  ,
                    INPUT  oJsonData   ,
                    OUTPUT oJsonResult
                    ).
                IF NOT lRetVal THEN LEAVE.
                
                oJsonResponse = NEW JsonObject().
                oJsonResponse:ADD('selectOptionsFix', oJsonSelectBoxes).
            
                oJsonResponse = oJsonResult.

                lRetVal = TRUE.
                LEAVE.
            END.
        
            DO WHILE cFunction = 'rebuild':
                CASE cClassName:
                    WHEN 'users' THEN 
                        cClass = 'adminprogsHandler'.
                    WHEN 'messages' THEN 
                        cClass = 'adminprogsHandler'.
                    WHEN 'labeltexte' THEN 
                        cClass = 'adminprogsHandler'.
                END CASE.
            
                ASSIGN
                    rClass = Progress.Lang.Class:GetClass(cClass).
                
                cMethode = 'rebuildData'.

                oHandler = rClass:NEW().
                lRetVal = DYNAMIC-INVOKE ( oHandler, cMethode,
                    INPUT  oJsonIdent  ,
                    INPUT  oJsonData   ,
                    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'.
// MESSAGE 'Get-Respond ' STRING(lcJsonString).
        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:
            DELETE OBJECT oHandler          NO-ERROR.
            DELETE OBJECT oSelectBoxHandler NO-ERROR.
            DELETE OBJECT oResponse         NO-ERROR.
            DELETE OBJECT oWriter           NO-ERROR.
            DELETE OBJECT oJsonSelectBoxes  NO-ERROR.
            DELETE OBJECT oJsonBox          NO-ERROR.
            DELETE OBJECT oParser           NO-ERROR.
            DELETE OBJECT oJsonData         NO-ERROR.
            DELETE OBJECT oJsonResponse     NO-ERROR.
        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.

        cLogFile = SUBSTITUTE('C:\TEMP\handlePOST_&1.json', REPLACE(STRING(TIME,'HH:MM:SS'), ':', '')).
        oJsonData:WriteFile(cLogFile, TRUE).

        outilitiesHandler = NEW utilitiesHandler().
        hError            = ERROR-STATUS:HANDLE.        
        cQueryString      = STRING(poRequest:GetContextValue("QUERY_STRING")) NO-ERROR.
        
        outilitiesHandler:getHeaderData(
            INPUT  poRequest    ,
            INPUT  cQueryString ,
            OUTPUT ccompany     ,
            OUTPUT cuser_name   ,
            OUTPUT cAnzeigeName ,
            OUTPUT ilanguage_id ,
            OUTPUT cSessionToken,
            OUTPUT cFunction    ,
            OUTPUT oJsonIdent   
            ).

        oJsonIdent:WriteFile('C:\TEMP\dynamicform_POST.json', TRUE).
        //
        //  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.
        
        cForm_Id   = poRequest:URI:GetQueryValue("formId") NO-ERROR.
        cClassName = ENTRY(1, cForm_Id, '_').
        cFileName  = ENTRY(1, cForm_Id, '_').
        //
        //  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.
        
        cProgram = outilitiesHandler:getProgramName (
            INPUT  oJsonIdent,
            INPUT  cUsers
            ).
            
        cForm_Id   = oJsonIdent:GetCharacter('formId').
        cClassName = ENTRY(1, cForm_Id, '_').
        cFileName  = ENTRY(1, cForm_Id, '_').

        REPEAT TRANSACTION WHILE cFunction = 'create' ON ERROR UNDO, LEAVE:
            CASE cClassName:
                WHEN 'users' THEN 
                    cClass = 'admin.adminprogsHandler'.
                WHEN 'messages' THEN 
                    cClass = 'admin.adminprogsHandler'.
                WHEN 'labeltexte' THEN 
                    cClass = 'admin.adminprogsHandler'.
            END CASE.

            rClass   = Progress.Lang.Class:GetClass(cClass) NO-ERROR.
            cMethode = 'createData'.
            oHandler = rClass:NEW().
            lRetVal  = DYNAMIC-INVOKE (oHandler, cMethode,
                INPUT  oJsonIdent ,
                INPUT  oJsonData  ,
                OUTPUT oJsonResult
                ) NO-ERROR.
            outilitiesHandler:evaluateErrorStatus(hError).
            IF NOT lRetVal THEN LEAVE.
            
            oJsonResult:WRITE(lcJsonString, FALSE).
            oJsonResult:WriteFile('C:\TEMP\DYNAMIC_CREATE_Respons.json', TRUE).
            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 oJsonMessage  NO-ERROR.
            DELETE OBJECT oResponse     NO-ERROR.
            DELETE OBJECT oWriter       NO-ERROR.
            DELETE OBJECT oJsonResult   NO-ERROR.
        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 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.
        
        cLogFile = SUBSTITUTE('C:\TEMP\handlePATCH_&1.json', REPLACE(STRING(TIME,'HH:MM:SS'), ':', '')).
        oJsonData:WriteFile(cLogFile, TRUE).
        
        outilitiesHandler = NEW utilitiesHandler().
        hError            = ERROR-STATUS:HANDLE.        
        cQueryString      = STRING(poRequest:GetContextValue("QUERY_STRING")) NO-ERROR.
        
        outilitiesHandler:getHeaderData(
            INPUT  poRequest    ,
            INPUT  cQueryString ,
            OUTPUT ccompany     ,
            OUTPUT cuser_name   ,
            OUTPUT cAnzeigeName ,
            OUTPUT ilanguage_id ,
            OUTPUT cSessionToken,
            OUTPUT cFunction    ,
            OUTPUT oJsonIdent   
            ).

        cForm_Id   = poRequest:URI:GetQueryValue("formId") NO-ERROR.
        cClassName = ENTRY(1, cForm_Id, '_').
        cFileName  = ENTRY(1, cForm_Id, '_').
        //
        //  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.
        
        cProgram = outilitiesHandler:getProgramName (
            INPUT  oJsonIdent,
            INPUT  cUsers
            ).
            
        REPEAT TRANSACTION WHILE cFunction = 'update' ON ERROR UNDO, LEAVE:
            CASE cClassName:
                WHEN 'users' THEN 
                    cClass = 'admin.adminprogsHandler'.
                WHEN 'messages' THEN 
                    cClass = 'admin.adminprogsHandler'.
                WHEN 'labeltexte' THEN 
                    cClass = 'admin.adminprogsHandler'.
            END CASE.

            rClass   = Progress.Lang.Class:GetClass(cClass) NO-ERROR.
            cMethode = 'updateData'.
            oHandler = rClass:NEW().
            lRetVal  = DYNAMIC-INVOKE ( oHandler, cMethode,
                INPUT  oJsonIdent ,
                INPUT  oJsonData  ,
                OUTPUT oJsonResult
                ) NO-ERROR.
            outilitiesHandler:evaluateErrorStatus(hError).
            IF NOT lRetVal THEN LEAVE.
            
            oJsonResult:WRITE(LcJsonString, FALSE).
            // oJsonResult:WriteFile('C:\TEMP\DYNAMIC_UPDATE_Respons.json', TRUE).
            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 'Rueckmeldung ' STRING(lcJsonString).
                            
        oWriter:Open().
        oWriter:Write(lcJsonString).
        oWriter:Close().
    
        RETURN 0.
    
        CATCH e AS Progress.Lang.Error:
                
        END CATCH.
                
        FINALLY:
            DELETE OBJECT oJsonMessage  NO-ERROR.
            DELETE OBJECT oWriter       NO-ERROR.
            DELETE OBJECT oResponse     NO-ERROR.
            DELETE OBJECT oHandler      NO-ERROR.
        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.