project QadFinancials > class BMultiCyProcessor > method ProcessRequest

Description

Runs a single business function over all entities in a single entity group. Each call will use the same parameter set.


Parameters


icBusinessClassShortNameinputcharacterName of the business component containing the business function to run.
icMethodNameinputcharacterName of the business function to run.
When not specified, default 'LoadAndUpdateInstanceData' will be used.
icCompanyGroupCodeinputcharactername of the entity group
icActivityCodeinputcharacterParameter values for the business function. The business function itself defines the implementation of this parameter.
izInstanceDatainputdataset-handleParameter values for the business function. The business function itself defines the implementation of this parameter.
icUnmanagedDatainputcharacterParameter values for the business function. The business function itself defines the implementation of this parameter.
ocUnmanagedDataoutputcharacterParameter values for the business function. The business function itself defines the implementation of this parameter.
oiCurrentCompanyReturnStatusoutputintegerReturn status of the execution of the activity in the Entity, user is logged in.
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFitnesse
method BMultiCyProcessor.ApiProcessRequest


program code (program1/bmulticyprocessor.p)

assign viSessionSavedID   = viSessionID
       viSessionSavedOC   = viSessionOC
       vhSessionSavedInst = vhSessionInst
       viCurrentCompanyId = viCompanyId
       viSessionID        = 0
       viSessionOC        = 0
       vhSessionInst      = ?.

empty temp-table tProcessErrors.

/* ================================================================= */
/* Validate input data.                                              */
/* ================================================================= */

if icBusinessClassShortName = ""
or icBusinessClassShortName = ?
or icCompanyGroupCode = ""
or icCompanyGroupCode = ?
then do:
    if icBusinessClassShortName = ""
    or icBusinessClassShortName = ?
    then do:
        <M-55 run SetMessage
           (input  #T-73'Input parameters do not contain valid values':255(999890914)T-73# (icMessage), 
            input  '' (icArguments), 
            input  '' (icFieldName), 
            input  '' (icFieldValue), 
            input  'E' (icType), 
            input  3 (iiSeverity), 
            input  '' (icRowid), 
            input  'qadfin-656675':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  'parameter icBusinessClassShortName' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BMultiCyProcessor>
    end. /* icBusinessClassShortName = "" or icBusinessClassShortName = ? */
    else do:
        <M-15 run SetMessage
           (input  #T-41'Input parameters do not contain valid values':255(999890914)T-41# (icMessage), 
            input  '' (icArguments), 
            input  '' (icFieldName), 
            input  '' (icFieldValue), 
            input  'E' (icType), 
            input  3 (iiSeverity), 
            input  '' (icRowid), 
            input  'qadfin-715230':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  'parameter icCompanyGroupCode' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BMultiCyProcessor>
    end. /* icCompanyGroupCode = "" or icCompanyGroupCode = ? */
    oiReturnStatus = -98.
    return.
end. /* icBusinessClassShortName = "" or icBusinessClassShortName = ? or icCompanyGroupCode = "" or icCompanyGroupCode = ? */

if not can-find (CYGroup where CYGroup.CYGroupCode = icCompanyGroupCode)
then do:
    <M-82 run SetMessage
       (input  #T-5'Unknown entity group $1.':255(452513062)T-5# (icMessage), 
        input  icCompanyGroupCode (icArguments), 
        input  '' (icFieldName), 
        input  '' (icFieldValue), 
        input  'D' (icType), 
        input  3 (iiSeverity), 
        input  '' (icRowid), 
        input  'qadfin-394871':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BMultiCyProcessor>
    oiReturnStatus = -3.
    return.
end. /* not vlFcOk */

if icMethodName = ""
or icMethodName = ?
then icMethodName = "LoadAndUpdateInstanceData".

/* ================================================================= */
/* Lookup the members of the selected entity group.                  */
/* ================================================================= */

<Q-21 run CyGroupCompanyByGrpCy (all) (Read) (NoCache)
   (input 0, (CompanyId)
    input 0, (GroupID)
    input icCompanyGroupCode, (GroupCode)
    output dataset tqCyGroupCompanyByGrpCy) in BCompanyGroup>

/* Current entity must be member of the selected entity group */
if not can-find (first tqCyGroupCompanyByGrpCy where tqCyGroupCompanyByGrpCy.tcCompanyCode = vcCompanyCode)
then do:
    assign vcMessage = #T-43'The current entity (&1) should belong to the specified entity-group (&2).':255(490312612)T-43#
           vcMessage = substitute(vcMessage, vcCompanycode, icCompanyGroupCode).
    <M-87 run SetMessage
       (input  vcMessage (icMessage), 
        input  '' (icArguments), 
        input  '' (icFieldName), 
        input  '' (icFieldValue), 
        input  'E' (icType), 
        input  3 (iiSeverity), 
        input  '' (icRowid), 
        input  'qadfin-416841':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BMultiCyProcessor>
    oiReturnStatus = -3.
    return.
end. /* not can-find (first tqCyGroupCompanyByGrpCy where tqCyGroupCompanyByGrpCy.tcCompanyCode = vcCompanyCode) */

for each tqCyGroupCompanyByGrpCy by tqCyGroupCompanyByGrpCy.tcCompanyCode on error undo, throw:

    viCYReturnStatus = 0.
    empty temp-table tFcMessages.
    
    CYBLOCK: do on error undo, throw:
    
        /* ================================================================= */
        /* Start a new session that can be switched to the needed company.   */
        /* This session will be deleted when this method ends.               */
        /* ================================================================= */
        
        if viSessionID = 0
        then do:
            <I-57 {bFcStartAndOpenInstance
                 &CLASS                = "Session"}>
            <M-48 run ApplicationLogin
               (input  vcGlobalSessionId (icGlobalSessionId), 
                input  tqCyGroupCompanyByGrpCy.tcCompanyCode (icCompanyCode), 
                input  '':U (icExtra), 
                input  false (ilReturnTimeStamps), 
                output vcDummy1 (ocReportTimeStamp), 
                output vcDummy2 (ocSystCacheDateTime), 
                output vcDummy3 (ocSystDateTime), 
                output viFcReturnSuper (oiReturnStatus)) in Session>
            if viFcReturnSuper <> 0
            then oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0
            then return. /* error on starting session is fatal */
        end. /* viSessionID = 0 */
        else do:
            <M-74 run SwitchCompany
               (input  tqCyGroupCompanyByGrpCy.tcCompanyCode (icCompanyCode), 
                input  0 (iiCompanyId), 
                output viFcReturnSuper (oiReturnStatus)) in Session>
            if viFcReturnSuper <> 0
            then viCYReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0
            then leave CYBLOCK. /* error on switching session current company is not fatal, just log and go to next company */
        end. /* viSessionID <> 0 */
        
        /* ================================================================= */
        /* Run the requested business component and then run the business    */
        /* method itself (with a fixed parameter set).                       */
        /* ================================================================= */
        
        <M-88 run BusinessClassActions
           (input  icBusinessClassShortName (icClassShortname), 
            input  'START+OPEN' (icAction), 
            input  no (ilSubtransaction), 
            input-output viBCompOC (biClassOpenCount), 
            input-output vhBCompInst (bhClassInstanceHandle), 
            input-output viBCompID (biClassInstanceId), 
            input  '' (icDraftReference), 
            input  '' (icUserDefinedContext), 
            output viFcReturnSuper (oiReturnStatus)) in BMultiCyProcessor>
        if viFcReturnSuper <> 0
        then viCYReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0
        then leave CYBLOCK.
        
        run value (icMethodName) in vhBCompInst
           (input icActivityCode,
            input dataset-handle izInstanceData,
            input icUnmanagedData,
            output ocUnmanagedData,
            output viFcReturnSuper) no-error.
        if error-status:num-messages > 0
        then do:
            vcDummy1 = "".
            do viFcCount1 = 1 to error-status:num-messages:
                vcDummy1 = vcDummy1 + error-status:get-message(viFcCount1) + chr(10).
            end.
            if error-status:num-messages = 1
            and error-status:get-number(1) = 6456
            then vcDummy2 = trim(#T-18'Internal error: Business component &1 does not contain a definition for &2.':255(104852940)T-18#).
            else if error-status:num-messages = 1
                 and error-status:get-number(1) = 3230
                 then vcDummy2 = trim(#T-45'Internal error: &1.&2 is not implemented correctly.':255(578680440)T-45#).
                 else vcDummy2 = trim(#T-6'Internal error: Failed to run &1.&2.':255(252068056)T-6#).
            viFcReturnSuper = -3.
            <M-91 run SetMessage
               (input  vcDummy2 (icMessage), 
                input  icBusinessClassShortName + chr(2) + icmethodName (icArguments), 
                input  '' (icFieldName), 
                input  '' (icFieldValue), 
                input  'E' (icType), 
                input  3 (iiSeverity), 
                input  '' (icRowid), 
                input  'qadfin-458419':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  vcDummy1 (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BMultiCyProcessor>
        end. /* error-status:num-messages > 0 */
        if viFcReturnSuper <> 0
        then viCYReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0
        then leave CYBLOCK.
        
        finally:
            <M-69 run BusinessClassActions
               (input  icBusinessClassShortName (icClassShortname), 
                input  'CLOSE+STOP' (icAction), 
                input  no (ilSubtransaction), 
                input-output viBCompOC (biClassOpenCount), 
                input-output vhBCompInst (bhClassInstanceHandle), 
                input-output viBCompID (biClassInstanceId), 
                input  '' (icDraftReference), 
                input  '' (icUserDefinedContext), 
                output viFcReturnSuper (oiReturnStatus)) in BMultiCyProcessor>
        end finally.
    end.    /* CYBLOCK */
    
    /* ===================================================================== */
    /* Remember return status from the execution in the entity, user is      */
    /* logged in                                                             */
    /* ===================================================================== */
    if tqCyGroupCompanyByGrpCy.tiCompany_ID = viCurrentCompanyId
    then assign oiCurrentCompanyReturnStatus = viCYReturnStatus.
    
    
    /* ===================================================================== */
    /* Collect all warnings and errors from the business method execution.   */
    /* ===================================================================== */
    if viCYReturnStatus <> 0
    then do:
        /* Create Error/Warning message by entity */
        assign vcMessage = if viCYReturnStatus < 0
                           then #T-78'Operation failed for entity &1.':255(660100836)T-78#
                           else #T-24'Operation completed with warnings for entity &1.':255(575820651)T-24#
               vcMessage = substitute(vcMessage, tqCyGroupCompanyByGrpCy.tcCompanyCode)
               vcContext = "":U.
               
        for each tFcMessages:
            assign vcContext = substitute("&1&2&3=&4":U, 
                                          vcContext, 
                                          if vcContext = "":U then "":U else chr(2),
                                          tFcMessages.tcFcMsgNumber,
                                          tFcMessages.tcFcMessage).
        end.        
        
        <M-59 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  if viCYReturnStatus < 0 then 'E':U else 'W':U (icType), 
            input  3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'qadfin-299094':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  vcContext (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BMultiCyProcessor>
        
        /* Store all error messages to backup temp table - because of order, we have to take first the message created above */
        for each tFcMessages where
                 tFcMessages.tcFcMsgNumber = "qadfin-299094":U:
            create tProcessErrors.
            buffer-copy tFcMessages to tProcessErrors.
            delete tFcMessages.
        end.
        
        for each tFcMessages:
            create tProcessErrors.
            buffer-copy tFcMessages to tProcessErrors
                        assign tProcessErrors.tcFcMessage = substitute(" &1 &2 - &3":U, #T-13'Entity':20(210)T-13#, tqCyGroupCompanyByGrpCy.tcCompanyCode, tFcMessages.tcFcMessage).
            delete tFcMessages.
        end.
    end. /* if viCYReturnStatus <> 0 */
end. /* for each tqCyGroupCompanyByGrpCy */

finally:

    if viSessionID <> 0
    then do:
        <I-32 {bFcCloseAndStopInstance
             &CLASS           = "Session"}>
    end. /* viSessionID <> 0 */
    
    assign viSessionID   = viSessionSavedID
           viSessionOC   = viSessionSavedOC
           vhSessionInst = vhSessionSavedInst.

    /* ================================================================= */
    /* Provide the error handling for the ProcessRequest method itself.  */
    /* ================================================================= */
    for each tProcessErrors:
        create tFcMessages.
        buffer-copy tProcessErrors to tFcMessages.
        
        if tFcMessages.tcFcType = "W":U
        then do:
            if oiReturnStatus = 0 then assign oiReturnStatus = 1.
        end.
        else assign oiReturnStatus = -1.
    end. 
    empty temp-table tProcessErrors.
end finally.