project BLF > class BRole > method ApiImportRoles

Description

This method is used to import roles from a certain XML file.


Parameters


icFileNameinputcharacterName of the XML file used to import roles.
ocFullPathNameoutputcharacterGives the full pathname of the dumped file.
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program3/brole.p)

if oiReturnStatus = 0
then oiReturnStatus = -98.

/* Check if the file realy exists as a file */       
assign FILE-INFO:FILE-NAME = icFileName no-error.
if error-status:error      or
   FILE-INFO:FILE-NAME = ? or
   FILE-INFO:FILE-TYPE = ? or
   INDEX(FILE-INFO:FILE-TYPE,"F":U) = 0
then do :
    assign vlSuccess      = false
           vcMessage      = trim(#T-4'No proper XML file was found by the default roles.':255(8890)T-4#) + chr(10) + 
                            trim(substitute(#T-5'File name: &1.':255(428)T-5#,FILE-INFO:FILE-NAME)) + chr(10) + 
                            trim(substitute(#T-6'File type: &1.':255(429)T-6#,FILE-INFO:FILE-type)) + chr(10) + 
                            trim(substitute(#T-7'Internal error number: &1.':255(433)T-7#,(if error-status:error then #T-8'Yes':4(431)T-8# else #T-9'No':4(432)T-9#))) + chr(10) + 
                            (if error-status:error = true
                             then trim(substitute(#T-10'Internal error number: &1.':255(433)T-10#,string(ERROR-STATUS:GET-NUMBER(1)))) + chr(10)
                             else "":U) 
           oiReturnStatus = -1.
    <M-1 run SetMessage
       (input  vcMessage (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'BLF-174':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BRole>
    return.
end. /* if error-status:error or */

assign ocFullPathName = file-info:full-pathname.

/* Import the roles from the XML-file */
<M-2 run apiMaintainByXml
   (input  ? (imDocument), 
    input  icFileName (icFileName), 
    output vlSuccess (olSuccess), 
    output tXmlObjects (tXmlObjects), 
    output viFcReturnSuper (oiReturnStatus)) in BRole>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.

/* olsuccess = no does not mean 'no updates required'                */
/* create an error messages                                          */
if not vlSuccess
then do:
    assign vcMessage = trim(#T-11'Import of Default Roles Failed.':255(8995)T-11#).
    <M-3 run SetMessage
       (input  vcMessage (icMessage), 
        input  '' (icArguments), 
        input  '' (icFieldName), 
        input  '' (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  '' (icRowid), 
        input  'BLF-175':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BRole>
    assign oiReturnStatus = -1.
    return.
end.

if oiReturnStatus = -98
then 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 = "BRole".
create ttContext.
assign ttContext.propertyName = "methodName"
       ttContext.propertyValue = "ApiImportRoles".
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/brole.apiimportroles.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icFileName = <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.