project QadFinancials > class BSystem > method ApiSynchroniseSyst

Description

ApiSynchroniseSyst will synchronise the class tables as the ApiSynchronise (exceptionally) synchronises the whole system instead of only the class tables


Parameters


olUpdatesDoneoutputlogicalReturns whether the method has done any updates
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


BLF
method BSystem.ApiSynchronise2


program code (program/bsystem.p)

<ANCESTOR-CODE>

/* =================================================== */
/* Set the default ReturnStatus and clear the instance */
/* =================================================== */
assign oiReturnStatus = -98.
                                                                                               
/* ================================================================================================== */
/* Set the variables holding the OpenSSL/InvoiceCertification data that needs to be set in the system */
/* This is also the place where this data needs to be changed in case another version, certificate,   */
/* public-key or private-key is supported by the QAD-applications                                     */
/* Note that the enters (line-feeds) in the public-key should reamin as they are: that's why the      */
/* layout is a bit strange with all the parts of the string starting on a new line                    */
/* ================================================================================================== */
Assign vcInvCertOpenSSLDir  = "":U /* As we do not know where the users have installed this and as this is updatable by the users */
       vcInvCertCertificate = "1352":U
       vcInvCertVersion     = "1":U
       vcInvCertPublicKey   = "-----BEGIN PUBLIC KEY-----":U + chr(10) + 
                              "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDk3WONOw4pVzYqAAp+kq1axsb/":U + chr(10) + 
                              "toQyaKdGPGzGTQZn8TkMuslX/ktud87obsE8LXoX0lBue4MJI1D9wzsxY/B2IBV7":U + chr(10) + 
                              "3BE8bigTKarru3YwcuSeAZsn1w/OLGzkAv8LVDGZroZWNQso+TYq9ldZGKSlZHlv":U + chr(10) + 
                              "9cdNqt4WYrNM3FhjywIDAQAB":U + chr(10) + 
                              "-----END PUBLIC KEY-----":U.

/* ===================================================== */
/* Check whether there is a syst record available        */
/* Check whether there is a sysproperty record available */                              
/* ===================================================== */
<Q-3 run System (all) (Read) (NoCache)
   (input '':U, (LanguageID)
    output dataset tqSystem) in BSystem>
find first tqSystem no-error.
<Q-4 run SystemPropertyByAll (all) (Read) (NoCache)  (output dataset tqSystemPropertyByAll) in BSystemProperty>
Find first tqSystemPropertyByAll no-error.

/* ======================================================================================================================================= */
/* If the Syst and SystProp record exists and the LNG and Domain are filled and the InvCert-Data is the same then we can assume it is OK   */
/* ======================================================================================================================================= */
if available tqSystem                and
   tqSystem.tcLngCode    <> '':U     and
   tqSystem.tcDomainCode <> '':U     and
   available tqSystemPropertyByAll
then do: 

    if tqSystemPropertyByAll.tcSysPropertyInvCertCertificate <> vcInvCertCertificate  or 
       tqSystemPropertyByAll.tcSysPropertyInvCertPublicKey   <> vcInvCertPublicKey    or 
       tqSystemPropertyByAll.tcSysPropertyInvCertVersion     <> vcInvCertVersion      or
       tqSystemPropertyByAll.tcCurrencyCode                   = "":U                  or 
       tqSystemPropertyByAll.tcCurrencyCode                   = ?                    
       
    then do :
     
        if viBSystemPropertyID = 0 or viBSystemPropertyID = ?
        then do :
            <I-12 {bFcStartAndOpenInstance
                 &ADD-TO-TRANSACTION   = "true"
                 &CLASS                = "BSystemProperty"}>
        end. /* if viBSystemProperty = 0 or BSystemProperty = ? */
        else do :
            <I-47 {bFcOpenInstance
                 &CLASS           = "BSystemProperty"}>
        end. /* not if viBSystemProperty = 0 or BSystemProperty = ? */
     
        <M-51 run SynchronisePropertyInvCert
           (input  vcInvCertCertificate (icSysPropertyInvCertCertificate), 
            input  vcInvCertPublicKey (icSysPropertyInvCertPublicKey), 
            input  vcInvCertVersion (icSysPropertyInvCertVersion), 
            input  tqSystemPropertyByAll.tiSysProperty_ID (iiSysProperty_ID), 
            output viFcReturnSuper (oiReturnStatus)) in BSystemProperty>
            
        <I-31 {bFcCloseInstance
             &CLASS           = "BSystemProperty"}>
        
        if viFcReturnSuper <> 0 
        then do :
            assign oiReturnStatus = viFcReturnSuper .
            if viFcReturnSuper < 0 
            then do :
                <M-35 run StopExternalInstances  (output viFcReturnSuper (oiReturnStatus)) in BSystem>
                return.
            end. /* if viFcReturnSuper < 0 */ 
            else do :
                assign olUpdatesDone  = true.
                return.
            end. /* Not if viFcReturnSuper < 0 */ 
        end. /* if viFcReturnSuper <> 0  */
        else do :
            assign olUpdatesDone  = true
                   oiReturnStatus = 0.
            return.
        end. /* Not if viFcReturnSuper <> 0 */

    end. /* if tqSystemPropertyByAll.tcSysPropertyInvCertCertificate <> vcInvCertCertificate  or */
    
    else do :
        assign olUpdatesDone  = false
               oiReturnStatus = 0.
        return.
    end. /* Not if tqSystemPropertyByAll.tcSysPropertyInvCertCertificate <> vcInvCertCertificate  or */

end. /* if available tqSystem                and */

/* ================================================================================================ */
/* In case the system domain is specified, we don't touch it                                        */
/* In case the systemn domain is not specified, we look for the domain whith domaintype = 'system'. */
/* In case this would not exist, we just take QAD                                                   */
/* ================================================================================================ */ 
if available tqSystem and 
   tqSystem.tcDomainCode <> '':U
then assign vcSystemDomainCode = tqSystem.tcDomainCode.
else do :
    <Q-5 run DomainsByDomainType (all) (Read) (NoCache)
       (input ?, (DomainID)
        input {&DOMAINSDOMAINTYPE-SYSTEM}, (DomainType)
        output dataset tqDomainsByDomainType) in BDomain >
    find first tqDomainsByDomainType no-error.
    assign vcSystemDomainCode = (if available tqDomainsByDomainType 
                                 then tqDomainsByDomainType.tcDomainCode 
                                 else 'QAD':U).
end. /* Note if available tqSystem and  */
   
/* =================================================================================================================================================================== */
/* We run the ApiSetSystemProperties method with some predefined values; This method will create Syst and SysProperty record                                           */
/* Note that we pass in the CurrencyCode surrounded by XXX as this way we know this method is called from the Synchronise process - and not via the system-maintenance */
/* =================================================================================================================================================================== */
<M-2 run ApiSetSystemPropertiesExtInvCert
   (input  'US':U (icSysLngCode), 
    input  vcSystemDomainCode (icSysDomainCode), 
    input  false (ilSysPropertyIsBudOverCh), 
    input  'XXXUSDXXX':U (icSysPropertyCurrencyCode), 
    input  false (ilSysPropertyIsWithBudget), 
    input  false (ilSysPropertyIsSpecCIApprove), 
    input  false (ilSysPropertyIsBudOLCheckGL), 
    input  false (ilSysPropertyIsBudOLCheckPrj), 
    input  false (ilSysPropertyIsBudOLCheckCC), 
    input  'XXXmfgXXX':U (icSystAdminUserLogin), 
    input  '' (icSystAdminUserPwd), 
    input  'Financials':U (icSysApplicationId), 
    input  false (ilSysPropertyIsBusRelDomRes), 
    input  vcInvCertCertificate (icSysPropertyInvCertCertificate), 
    input  vcInvCertVersion (icSysPropertyInvCertVersion), 
    input  vcInvCertPublicKey (icSysPropertyInvCertPublicKey), 
    input  vcInvCertOpenSSLDir (icSysPropertyInvCertOpenSSLDir), 
    input  100 (iiSysPropertyBankFileBatchSize), 
    input  1000 (iiSysPropertyMaxBatchSize), 
    input  1 (iiSysPropertyMinBatchSize), 
    output viFcReturnSuper (oiReturnStatus)) in BSystem>
if viFcReturnSuper <> 0 
then do:
   assign oiReturnStatus = viFcReturnSuper.
   if oiReturnStatus < 0 
   then return.
end. /* if viFcReturnSuper <> 0 - DataSave returned an error or warning */                                   
   
/* ==================================================================== */
/* If all has gone well, set the ReturnStatus to 0 (OK)                 */
/* ==================================================================== */
assign olUpdatesDone = true.
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 = "ApiSynchroniseSyst".
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.