project BLF > class BResource > method ApiSynchronize

Description

This method will make sure that the resources are synchronized. If you want to extend the logic in an inherited class then you should use ApiSynchronizeCustom.


Parameters


olUpdatesDoneoutputlogical
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


BLF
method BSystem.ApiSynchronise2


program code (program3/bresource.p)

/*get old flag on session that indicated the synchronize is running*/
<M-5 run StartCacher
   (output vhFcComponent (ohCacher), 
    output viFcReturnSuper (oiReturnStatus)) in BResource>
<M-6 run GetLogicalValueFromSession
   (input  viSessionID (iiSessionId), 
    input  'SynchronizeIsRunning':U (icDataItemName), 
    output vlSyncIsRunningOld (olValue), 
    output viFcReturnSuper (oiReturnStatus)) in Cacher>

/*set flag on session that synchronize is running*/
<I-7 {bFcOpenInstance
     &CLASS           = "Session"}>

<M-8 run SetLogicalValue
   (input  'SynchronizeIsRunning':U (icName), 
    input  true (ilValue), 
    output viFcReturnSuper (oiReturnStatus)) in Session>

<I-9 {bFcCloseInstance
     &CLASS           = "Session"}>

    
/* Perform extra synchronise code. */    
<M-1 run ApiSynchronizeCustom
   (output vlUpdatesDone (olUpdatesDone), 
    output viFcReturnSuper (oiReturnStatus)) in BResource>
if vifcreturnsuper <> 0 
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 
then return.

/* Set output indication */    
if can-find (first tResources where tResources.tc_Status <> "":U) or
   vlUpdatesDone
then assign olUpdatesDone = true.

/* Validate, AdditionalUpdates and Save */    
<M-2 run ValidateBC
   (output viFcReturnSuper (oiReturnStatus)) in BResource>
if viFcReturnSuper <> 0 
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 
then return.

<M-3 run AdditionalUpdates
   (output viFcReturnSuper (oiReturnStatus)) in BResource>
if viFcReturnSuper <> 0 
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 
then return.

<M-4 run DataSave
   (output viFcReturnSuper (oiReturnStatus)) in BResource>
if viFcReturnSuper <> 0 
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 
then return.

/*set old flag on session that synchronize is running back*/
<I-10 {bFcOpenInstance
     &CLASS           = "Session"}>

<M-11 run SetLogicalValue
   (input  'SynchronizeIsRunning':U (icName), 
    input  vlSyncIsRunningOld (ilValue), 
    output viFcReturnSuper (oiReturnStatus)) in Session>

<I-12 {bFcCloseInstance
     &CLASS           = "Session"}>


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 = "BResource".
create ttContext.
assign ttContext.propertyName = "methodName"
       ttContext.propertyValue = "ApiSynchronize".
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 = "".

/* 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.