project BLF > class BSystem > method ApiDumpDefaultSecurity


Parameters


icRoleRowidsinputcharacter
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program3/bsystem.p)

if oiReturnStatus = 0
then assign oiReturnStatus = -98.

if icRoleRowids = ?
then assign icRoleRowids = "".

/* ======================================= */
/* Get the location of the server.xml file */
/* ======================================= */
<M-68 run Main  (input  viSessionID (iiSessionId)) in TApplication>
<M-7 run GetDefaultsFolder  (output vcLocation (ocFolder)) in TApplication>
run gipr_DeleteProcedure in vhFcComponent.
delete procedure vhFcComponent.

/* ============================ */
/* Export SOD Category Defaults */
/* ============================ */

/* Create the dataset */
create dataset vhDataSet in widget-pool "non-persistent".
assign vhDataSet:name = "SODCategoryDefaults".

/* Create and fill SODCategory table */
create temp-table vhTable in widget-pool "non-persistent".
vhTable:add-new-field("SODCategoryCode", "character").
vhTable:add-new-field("SODCategoryDescription", "character").
vhTable:temp-table-prepare("SODCategory").
assign vhBuf = vhTable:default-buffer-handle.

<Q-31 run SODCategoryForLoad (all) (Read) (NoCache)  (output dataset tqSODCategoryForLoad) in BSODCategory >

for each tqSODCategoryForLoad:
    vhBuf:buffer-create().

    assign vhBuf::SODCategoryCode        = tqSODCategoryForLoad.tcSODCategoryCode
           vhBuf::SODCategoryDescription = tqSODCategoryForLoad.tcSODCategoryDescription.
end.

vhDataSet:add-buffer(vhBuf).

/* Create and fill Resource table */
create temp-table vhTable in widget-pool "non-persistent".
vhTable:add-new-field("SODCategoryCode", "character").
vhTable:add-new-field("URI", "character").
vhTable:temp-table-prepare("Resource").
assign vhBuf = vhTable:default-buffer-handle.

<Q-85 run ResourceBySODCategory (all) (Read) (NoCache)
   (input ?, (SODCategoryID)
    input ?, (SODCategoryCode)
    input ?, (ResourceID)
    output dataset tqResourceBySODCategory) in BResource >

for each tqResourceBySODCategory:
    vhBuf:buffer-create().

    assign vhBuf::SODCategoryCode = tqResourceBySODCategory.tcSODCategoryCode
           vhBuf::URI             = tqResourceBySODCategory.tcResourceURI.
end.

vhDataSet:add-buffer(vhBuf).

/* Write the SODCategoryDefaults.xml file */
vhDataSet:write-xml("file", vcLocation + "SODCategoryDefaults.xml", true).

/* Clean up */
delete object vhDataSet.
assign vhDataSet = ?.
empty temp-table tqSODCategoryForLoad.
empty temp-table tqResourceBySODCategory.

/* ================= */
/* Export SOD Matrix */
/* ================= */

/* Create the dataset */
create dataset vhDataSet in widget-pool "non-persistent".
assign vhDataSet:name = "SODMatrix".

/* Create and fill SODCategory table */
create temp-table vhTable in widget-pool "non-persistent".
vhTable:add-new-field("SODCategory1", "character").
vhTable:add-new-field("CannotBeCombinedWith", "logical").
vhTable:add-new-field("SODCategory2", "character").
vhTable:add-new-field("ExclusionLevel", "character").
vhTable:add-new-field("Comments", "character").
vhTable:temp-table-prepare("SODMatrix").
assign vhBuf = vhTable:default-buffer-handle.

<I-28 {bFcStartAndOpenInstance
     &CLASS                = "BSODCategoryExclusion"}>

<M-48 run ApiGetMatrixData
   (input  '' (icCategoryFilter1), 
    input  '' (icCategoryFilter2), 
    output tGetSODCategory1Syst (tGetSODCategory1), 
    output tGetSODCategory2Syst (tGetSODCategory2), 
    output tGetSODMatrixSyst (tGetSODMatrix), 
    output viFcReturnSuper (oiReturnStatus)) in BSODCategoryExclusion>

<I-32 {bFcCloseAndStopInstance
     &CLASS           = "BSODCategoryExclusion"}>

if viFcReturnSuper < 0 or
   viFcReturnSuper > 0 and
   oiReturnStatus  = -98
then assign oiReturnStatus = viFcReturnSuper.

if viFcReturnSuper < 0
then return.

for each tGetSODCategory1Syst:
    for each tGetSODCategory2Syst where
             tGetSODCategory2Syst.tcSODCategoryCode <> tGetSODCategory1Syst.tcSODCategoryCode:
        find tGetSODMatrixSyst where
             tGetSODMatrixSyst.tcSODCategory1Code = tGetSODCategory1Syst.tcSODCategoryCode and
             tGetSODMatrixSyst.tcSODCategory2Code = tGetSODCategory2Syst.tcSODCategoryCode
             no-error.

        vhBuf:buffer-create().

        assign vhBuf::SODCategory1         = tGetSODCategory1Syst.tcSODCategoryCode
               vhBuf::CannotBeCombinedWith = available tGetSODMatrixSyst
               vhBuf::SODCategory2         = tGetSODCategory2Syst.tcSODCategoryCode
               vhBuf::Comments             = if available tGetSODMatrixSyst
                                             then tGetSODMatrixSyst.tcExclusionDescription
                                             else ""
               vhBuf::ExclusionLevel       = if available tGetSODMatrixSyst
                                             then tGetSODMatrixSyst.tcExclusionLevel
                                             else "".
    end.
end.

vhDataSet:add-buffer(vhBuf).

/* Write the SODMatrix.xml file */
vhDataSet:write-xml("file", vcLocation + "SODMatrix.xml", true).

/* Clean up */
delete object vhDataSet.
assign vhDataSet = ?.
empty temp-table tGetSODCategory1Syst.
empty temp-table tGetSODCategory2Syst.
empty temp-table tGetSODMatrixSyst.

/* ==================== */
/* Export Role Defaults */
/* ==================== */

/* 1. Switch to entity 999 - SYSADM. This will result in tContextInfo.tcCompanyCode being set to that in stead of the current entity. */
/* If we keep the current entity, it will not be possible to load this exported default data in a system that doesn't contain an      */
/* entity with that name.                                                                                                             */
assign vcOldCompanyCode = vcCompanyCode.

<I-91 {bFcOpenInstance
     &CLASS           = "Session"}>
     
<M-30 run SwitchCompany
   (input  '999 - SYSADM' (icCompanyCode), 
    input  ? (iiCompanyId), 
    output viLocalReturn (oiReturnStatus)) in Session>
    
<I-64 {bFcCloseInstance
     &CLASS           = "Session"}>
     
if viLocalReturn  < 0 or
   viLocalReturn  > 0 and
   oiReturnStatus = -98
then assign oiReturnStatus = viLocalReturn.

if viLocalReturn < 0
then return.

/* 2. Dump the roles */
<I-57 {bFcStartAndOpenInstance
     &CLASS                = "BRole"}>

if icRoleRowids = ""
then do:
    <M-61 run DumpXmlRepresentation
       (input  vcLocation + 'RoleDefaults.xml' (icFile), 
        input  false (ilHeaderOnly), 
        input  false (ilSuppressEmptyFields), 
        input  0 (iiPriority), 
        input  false (ilWriteXMLSchema), 
        input  '' (icObjectRowId), 
        input  true (ilExportForInput), 
        output viFcReturnSuper (oiReturnStatus)) in BRole>
end.
else do:
    <M-11 run ApiDumpXmlRepresentation
       (input  icRoleRowids (icRowids), 
        input  vcLocation + 'RoleDefaults.xml' (icFile), 
        input  false (ilHeaderOnly), 
        input  false (ilSuppressEmptyFields), 
        input  0 (iiPriority), 
        input  false (ilWriteXMLSchema), 
        input  '' (icObjectRowId), 
        input  true (ilExportForInput), 
        output viFcReturnSuper (oiReturnStatus)) in BRole>
end.

<I-42 {bFcCloseAndStopInstance
     &CLASS           = "BRole"}>
     
if viFcReturnSuper < 0 or
   viFcReturnSuper > 0 and
   oiReturnStatus  = -98
then assign oiReturnStatus = viFcReturnSuper.

if viFcReturnSuper < 0
then return.

/* 3. Switch back to the original entity */
<I-78 {bFcOpenInstance
     &CLASS           = "Session"}>
     
<M-87 run SwitchCompany
   (input  vcOldCompanyCode (icCompanyCode), 
    input  ? (iiCompanyId), 
    output viLocalReturn (oiReturnStatus)) in Session>
    
<I-33 {bFcCloseInstance
     &CLASS           = "Session"}>
     
if viLocalReturn  < 0 or
   viLocalReturn  > 0 and
   oiReturnStatus = -98
then assign oiReturnStatus = viLocalReturn.

if viLocalReturn < 0
then return.

if oiReturnStatus = -98
then assign oiReturnStatus = 0.


Sample code: how to call this method through RPCRequestService (QXtend Inbound)

define temp-table ttContext no-undo
    field propertyQualifier as character
    field propertyName as character
    field propertyValue as character
    index entityContext is primary unique
        propertyQualifier
        propertyName
    index propertyQualifier
        propertyQualifier.

define dataset dsContext for ttContext.

define variable vhContextDS as handle no-undo.
define variable vhExceptionDS as handle no-undo.
define variable vhServer as handle no-undo.
define variable vhInputDS as handle no-undo.
define variable vhInputOutputDS as handle no-undo.
define variable vhOutputDS as handle no-undo.
define variable vhParameter as handle no-undo.

/* Create context */
create ttContext.
assign ttContext.propertyName = "programName"
       ttContext.propertyValue = "BSystem".
create ttContext.
assign ttContext.propertyName = "methodName"
       ttContext.propertyValue = "ApiDumpDefaultSecurity".
create ttContext.
assign ttContext.propertyName = "applicationId"
       ttContext.propertyValue = "fin".
create ttContext.
assign ttContext.propertyName = "entity"
       ttContext.propertyValue = "1000".
create ttContext.
assign ttContext.propertyName = "userName"
       ttContext.propertyValue = "mfg".
create ttContext.
assign ttContext.propertyName = "password"
       ttContext.propertyValue = "".

/* Create input dataset */
create dataset vhInputDS.
vhInputDS:read-xmlschema("file", "xml/bsystem.apidumpdefaultsecurity.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icRoleRowids = <parameter value>.

/* Connect the AppServer */
create server vhServer.
vhServer:connect("-URL <appserver-url>").

if not vhServer:connected()
then do:
    message "Could not connect AppServer" view-as alert-box error title "Error".
    return.
end.

/* Run */
assign vhContextDS = dataset dsContext:handle.

run program/rpcrequestservice.p on vhServer
    (input-output dataset-handle vhContextDS by-reference,
           output dataset-handle vhExceptionDS,
     input        dataset-handle vhInputDS by-reference,
     input-output dataset-handle vhInputOutputDS by-reference,
           output dataset-handle vhOutputDS).

/* Handle output however you want, in this example, we dump it to xml */
if valid-handle(vhExceptionDS)
then vhExceptionDS:write-xml("file", "Exceptions.xml", true).

if valid-handle(vhOutputDS)
then vhOutputDS:write-xml("file", "Output.xml", true).

/* Cleanup */
vhServer:disconnect().
assign vhServer = ?.

if valid-handle(vhInputDS)
then delete object vhInputDS.

if valid-handle(vhOutputDS)
then delete object vhOutputDS.

if valid-handle(vhExceptionDS)
then delete object vhExceptionDS.