project BLF > class BResource > method AdditionalUpdates

Description

This method is part of the SetPublicTables flow.
When executed, data in the input class tables (prefix t_s) is validated and found correct, and copied into the class tables (prefix t_o).
This method can be extended to do updates that do not require a validation or that involve running business methods of other business classes. These classes should be started with ADD-TO-TRANSACTION = 'true'. Also make sure to add these classes in method StopExternalInstances.


Parameters


oiReturnStatusoutputinteger


Internal usage


BLF
method BResource.ApiLinkResource
method BResource.ApiSetResourceCategories
method BResource.ApiSynchronize
method BResource.CreateResource


program code (program/bresource.p)

<ANCESTOR-CODE>

<M-8 run StartCacher
   (output vhFcComponent (ohCacher), 
    output viFcReturnSuper (oiReturnStatus)) in BResource>
<M-9 run GetLogicalValueFromSession
   (input  viSessionID (iiSessionId), 
    input  'SynchronizeIsRunning':U (icDataItemName), 
    output vlSyncRunning (olValue), 
    output viFcReturnSuper (oiReturnStatus)) in Cacher>

if vlSyncRunning = true
then do:
    /* ================================== */
    /* Create a link to the 'General'role */
    /* ================================== */
    <Q-1 assign vlFcQueryRecordsAvailable = RolePrim (NoCache)
          (input ?, (RoleID)
           input 'SUPERUSER':U, (RoleName)) in BRole >
    if vlFcQueryRecordsAvailable <> false
    then do :
        assign vpResourceIds = '':U.
        for each tResources where
                 tResources.tc_Status = 'N':U
                 on error undo, throw:
            if vpResourceIds = ""
            then vpResourceIds = string(tResources.Resource_ID).
            else vpResourceIds = vpResourceIds + ',':U + string(tResources.Resource_ID).
        end.
        
        if vpResourceIds <> '':U
        then do:
            /* ======================================== */
            /* Start And Open Role (add to transaction) */
            /* ======================================== */
            <I-11 {bFcAddToTransaction
                 &CLASS           = "BRole"}>
            
            /* =================================================================== */
            /* Run method in BRole to create the link between Role and BusActivity */
            /* =================================================================== */
            <M-4 run CreateRolResource
               (input  vpResourceIds (ipResourceIds), 
                output viFcReturnSuper (oiReturnStatus)) in BRole>
            if viFcReturnSuper <> 0
            then oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0
            then return.
        end.
    end. /* if vlFcQueryRecordsAvailable <> false */
end. /*if vlSyncRunning = true*/

/* ================================================================= */
/* When changing SOD category on a resource, update violations.      */
/* ================================================================= */
viCategoryIDForSODCheck = -1.

<Q-32 assign vlFcQueryRecordsAvailable = SystSODActive (NoCache)  () in BSystem >
if vlFcQueryRecordsAvailable
then do:
    for each t_oResources where
             t_oResources.tc_Status = "D" and
             t_oResources.SODcategory_ID <> 0
             on error undo, throw:
    
        if viBSODViolationRule19ID = 0
        then do:
            <I-15 {bFcAddToTransaction
                 &CLASS           = "BSODViolationRule1"}>
        end.
        <M-16 run DeleteByRoleResource
           (input  0 (iiRoleID), 
            input  t_oResources.Resource_ID (iiResourceID), 
            output viFcReturnSuper (oiReturnStatus)) in BSODViolationRule1>
        if viFcReturnSuper = -4
        then viFcReturnSuper = 0.
        else vlDeletes1Done = yes.
        if viFcReturnSuper <> 0
        then oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0
        then return.
    
        if viBSODViolationRule27ID = 0
        then do:
            <I-22 {bFcAddToTransaction
                 &CLASS           = "BSODViolationRule2"}>
        end.
        <M-23 run DeleteByRoleResource
           (input  0 (iiRoleID), 
            input  t_oResources.Resource_ID (iiResourceID), 
            output viFcReturnSuper (oiReturnStatus)) in BSODViolationRule2>
        if viFcReturnSuper = -4
        then viFcReturnSuper = 0.
        else vlDeletes2Done = yes.
        if viFcReturnSuper <> 0
        then oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0
        then return.
    end.
        
    for each t_oResources where
             t_oResources.tc_Status = "C",
        each t_iResources where
             t_iResources.tc_Rowid = t_oResources.tc_Rowid and
             t_iResources.SODcategory_ID <> t_oResources.SODcategory_ID
             on error undo, throw:
    
        /* delete violations on previous category */
        if t_iResources.SODcategory_ID <> 0
        then do:
            if viBSODViolationRule19ID = 0
            then do:
                <I-12 {bFcAddToTransaction
                     &CLASS           = "BSODViolationRule1"}>
            end.
            <M-13 run DeleteByRoleResource
               (input  0 (iiRoleID), 
                input  t_iResources.Resource_ID (iiResourceID), 
                output viFcReturnSuper (oiReturnStatus)) in BSODViolationRule1>
            if viFcReturnSuper = -4
            then viFcReturnSuper = 0.
            else vlDeletes1Done = yes.
            if viFcReturnSuper <> 0
            then oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0
            then return.
            
            if viBSODViolationRule27ID = 0
            then do:
                <I-25 {bFcAddToTransaction
                     &CLASS           = "BSODViolationRule2"}>
            end.
            <M-26 run DeleteByRoleResource
               (input  0 (iiRoleID), 
                input  t_iResources.Resource_ID (iiResourceID), 
                output viFcReturnSuper (oiReturnStatus)) in BSODViolationRule2>
            if viFcReturnSuper = -4
            then viFcReturnSuper = 0.
            else vlDeletes2Done = yes.
            if viFcReturnSuper <> 0
            then oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0
            then return.
        end.
        
        /* Creating violations must be done outside of this transaction,
           when the new category is available in the database. */
        if not (vlSODBlock or t_oResources.SODcategory_ID = 0)
        then if viCategoryIDForSODCheck = -1
             then viCategoryIDForSODCheck = t_oResources.SODcategory_ID.
             else if viCategoryIDForSODCheck <> t_oResources.SODcategory_ID
                  then viCategoryIDForSODCheck = 0.
    end.
        
    if viBSODViolationRule19ID <> 0
    then if vlDeletes1Done
    then do:
        <M-18 run DeleteFinish  (output viFcReturnSuper (oiReturnStatus)) in BSODViolationRule1>
        if viFcReturnSuper <> 0
        then oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0
        then return.
    end.
    else do:
        <I-21 {bFcCloseAndStopInstance
             &CLASS           = "BSODViolationRule1"}>
    end.
    
    if viBSODViolationRule27ID <> 0
    then if vlDeletes2Done
    then do:
        <M-29 run DeleteFinish  (output viFcReturnSuper (oiReturnStatus)) in BSODViolationRule2>
        if viFcReturnSuper <> 0
        then oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0
        then return.
    end.
    else do:
        <I-28 {bFcCloseAndStopInstance
             &CLASS           = "BSODViolationRule2"}>
    end.
    
    if not vlSODBlock
    then for each t_oResources where
                  t_oResources.tc_Status = "N" and
                  t_oResources.SODcategory_ID <> 0
                  on error undo, throw:
        if viCategoryIDForSODCheck = -1
        then viCategoryIDForSODCheck = t_oResources.SODcategory_ID.
        else if viCategoryIDForSODCheck <> t_oResources.SODcategory_ID
             then viCategoryIDForSODCheck = 0.
    end.
end.

finally:
    if oiReturnStatus < 0
    then do:
        <M-91 run StopExternalInstances  (output viFcReturnSuper (oiReturnStatus)) in BResource>
    end.
end finally.