project BLF > class BSystem > method ApiSynchronise2

Description

Subprocedure of ApiSynchronise


Parameters


iiLngSynchroniseErrorinputinteger
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


BLF
method BSystem.ApiSynchronise


program code (program9/bsystem.p)

/* ======================== */
/* Start MASTERSYNCHROBLOCK */
/* ======================== */
MASTERSYNCHROBLOCK2 : DO :

    /* ==================== */
    /* WHEN DEFAULT COMPANY */
    /* ==================== */
    find tTopic where 
         tTopic.tiTopicNumber = 11 and /* Default Company */
         tTopic.tlSelected    = true
         no-error.
    if available tTopic and
      (vcSynchronizeType = {&SYNCHRONIZETYPE-FULL} or
       tTopic.tcSynchronizeType = vcSynchronizeType)
    then do :
        <I-29 {bFcStartAndOpenInstance
             &CLASS                = "BCompany"}>
        
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BCompany.ApiSynchronise Start":U skip.
        output close.
        
        <M-31 run ApiSynchronise (output vlUpdatesDone (olUpdatesDone), 
                         output viSynchroniseError (oiReturnStatus)) in BCompany>

        <I-32 {bFcCloseAndStopInstance
             &CLASS           = "BCompany"}>
                        
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BCompany.ApiSynchronise End : ":U string (viSynchroniseError) string (vlUpdatesDone) skip.
        output close.
                                
        if viSynchroniseError >= 0
        then do:
        <Q-71 run DomainsPrim (all) (Read) (NoCache)
           (input ?, (DomainID)
            input 'QAD':U, (DomainCode)
            output dataset tqDomainsPrim) in BDomain >        
                               
        find tqDomainsPrim where
             tqDomainsPrim.tcDomainCode = 'QAD':U no-error.
        if available tqDomainsPrim
        then do:
            /*update domain primarycompany*/
            <I-55 {bFcStartAndOpenInstance
                 &CLASS                = "BDomain"}>
            <M-57 run SetPrimaryCompany
               (input  tqDomainsPrim.tiDomain_ID (iiDomainId), 
                input  '999 - SYSADM':U (icCompanyCode), 
                output viSynchroniseError (oiReturnStatus)) in BDomain>
            <I-58 {bFcCloseAndStopInstance
                 &CLASS           = "BDomain"}>   
        end. /*if available tqDomainsPrim*/
        end.
        
        if viSynchroniseError < 0
        or (oiReturnStatus = 0 and viSynchroniseError > 0)
        then assign oiReturnStatus = viSynchroniseError.

        if viSynchroniseError < 0
        then assign tTopic.tcUpdateInformation = #T-635'Update Failed':30(829486138)T-635#.
        else
        if vlUpdatesDone
        then assign tTopic.tcUpdateInformation = trim(#T-33'Updates Done':30(449)T-33#).
        else assign tTopic.tcUpdateInformation = trim(#T-34'No updates required':30(450)T-34#).
    end. /* if available tTopic (Default Company) */

    /* =================== */
    /* WHEN USERS  (needs company and domain)        */
    /* =================== */
    find tTopic where 
         tTopic.tiTopicNumber = 10 and /* Users */
         tTopic.tlSelected    = true
         no-error.
    if available tTopic and
      (vcSynchronizeType = {&SYNCHRONIZETYPE-FULL} or
       tTopic.tcSynchronizeType = vcSynchronizeType)
    then do :
        <I-1 {bFcStartAndOpenInstance
             &CLASS                = "BUser"}>
        
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BUser.ApiSynchronise Start":U skip.
        output close.
        
        <M-3 run ApiSynchronise (output vlUpdatesDone (olUpdatesDone), 
                         output viSynchroniseError (oiReturnStatus)) in BUser>
        
        <I-4 {bFcCloseAndStopInstance
             &CLASS           = "BUser"}>
                       
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BUser.ApiSynchronise End : ":U string (viSynchroniseError) string (vlUpdatesDone) skip.
        output close.
                       
        if viSynchroniseError < 0
        or (oiReturnStatus = 0 and viSynchroniseError > 0)
        then assign oiReturnStatus = viSynchroniseError.

        if viSynchroniseError < 0
        then assign tTopic.tcUpdateInformation = #T-552'Update Failed':30(829486138)T-552#.
        else
        if vlUpdatesDone
        then assign tTopic.tcUpdateInformation = trim(#T-5'Updates Done':30(449)T-5#).
        else assign tTopic.tcUpdateInformation = trim(#T-6'No updates required':30(450)T-6#).
    end. /* if available tTopic -1 (USERS) */
                
    /* ==================== */
    /* WHEN UserRole (needs user and role and company and domain)       */
    /* ==================== */
    find tTopic where 
         tTopic.tiTopicNumber = 6 and /* UserRole */
         tTopic.tlSelected    = true
         no-error.
    if available tTopic and
      (vcSynchronizeType = {&SYNCHRONIZETYPE-FULL} or
       tTopic.tcSynchronizeType = vcSynchronizeType)
    then do :        
        /*for UserRoles*/
        <I-17 {bFcStartAndOpenInstance
             &CLASS                = "BUserRole"}>
        
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BUserRole.ApiSynchronise Start":U skip.
        output close.
        
        <M-19 run ApiSynchronise (output vlUpdatesDone (olUpdatesDone), 
                          output viSynchroniseError (oiReturnStatus)) in BUserRole>

        <I-20 {bFcCloseAndStopInstance
             &CLASS           = "BUserRole"}>
                         
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BUserRole.ApiSynchronise End : ":U string (viSynchroniseError) string (vlUpdatesDone) skip.
        output close.    
                             
        if viSynchroniseError < 0
        or (oiReturnStatus = 0 and viSynchroniseError > 0)
        then assign oiReturnStatus = viSynchroniseError.

        if viSynchroniseError < 0
        then assign tTopic.tcUpdateInformation = #T-48'Update Failed':30(829486138)T-48#.
        else
        if vlUpdatesDone
        then assign tTopic.tcUpdateInformation = trim(#T-21'Updates Done':30(449)T-21#).
        else assign tTopic.tcUpdateInformation = trim(#T-22'No Updates Required':30(450)T-22#).
    end. /* if available tTopic 6 */
        
    /* ======================== */
    /* WHEN Syst/SysProperty    */
    /* ======================== */
    find tTopic where 
         tTopic.tiTopicNumber = 14 and 
         tTopic.tlSelected    = true
         no-error.
    if available tTopic and
      (vcSynchronizeType = {&SYNCHRONIZETYPE-FULL} or
       tTopic.tcSynchronizeType = vcSynchronizeType)
    then do :
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U

            "BSystem.ApiSynchroniseSyst Start":U skip.
        output close.
        
        <M-53 run ApiSynchroniseSyst
           (output vlUpdatesDone (olUpdatesDone), 
            output viSynchroniseError (oiReturnStatus)) in BSystem>
                                                            
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BSystem.ApiSynchroniseSyst End : ":U string (viSynchroniseError) ' ':U string (vlUpdatesDone) skip.
        output close.
                                                                    
        if viSynchroniseError < 0
        or (oiReturnStatus = 0 and viSynchroniseError > 0)
        then assign oiReturnStatus = viSynchroniseError.

        if viSynchroniseError < 0
        then assign tTopic.tcUpdateInformation = #T-90'Update Failed':30(829486138)T-90#.
        else
        if vlUpdatesDone 
        then assign tTopic.tcUpdateInformation = trim(#T-51'Updates Done':30(449)T-51#).
        else assign tTopic.tcUpdateInformation = trim(#T-52'No updates required':30(450)T-52#).
       
    end. 
        
    /* =================== */
    /* WHEN BusCompActArea (needs Role) */
    /* =================== */
    find tTopic where 
         tTopic.tiTopicNumber = 2 and /* Area/Component/Activity */
         tTopic.tlSelected    = true
         no-error.
    if available tTopic and
      (vcSynchronizeType = {&SYNCHRONIZETYPE-FULL} or
       tTopic.tcSynchronizeType = vcSynchronizeType)
    then do :
        
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BSystem.SynchroniseNavig Start":U skip.
        output close.
    
        <M-35 run SynchroniseNavig
           (output vlUpdatesDone (olUpdatesDone), 
            output viClassSynchroniseError (oiReturnStatus)) in BSystem>
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BSystem.SynchroniseNavig End : ":U string (viClassSynchroniseError) ' ':U string (vlUpdatesDone) skip.
        output close.
                                    
        if viClassSynchroniseError < 0
        or (oiReturnStatus = 0 and viClassSynchroniseError > 0)
        then assign oiReturnStatus = viClassSynchroniseError.

        if viClassSynchroniseError < 0
        then assign tTopic.tcUpdateInformation = #T-875'Update Failed':30(829486138)T-875#.
        else
        if vlUpdatesDone 
        then assign tTopic.tcUpdateInformation = trim(#T-36'Updates Done':30(449)T-36#).
        else if tTopic.tcUpdateInformation = "":U
             then assign tTopic.tcUpdateInformation = trim(#T-37'No Updates Required':30(450)T-37#).
    end. /* if available tTopic 2 */        
        
    /* ==================== */
    /* WHEN DefaultActivity (needs BusCompActArea) */
    /* ==================== */
    find tTopic where 
         tTopic.tiTopicNumber = 3 and /* DefaultActivity */
         tTopic.tlSelected    = true
         no-error.
    if available tTopic and
      (vcSynchronizeType = {&SYNCHRONIZETYPE-FULL} or
       tTopic.tcSynchronizeType = vcSynchronizeType)
    then if viClassSynchroniseError < 0
    then assign tTopic.tcUpdateInformation = #T-93'Skipped':30(781314445)T-93#.
    else do:
        <I-38 {bFcStartAndOpenInstance
             &CLASS                = "BBusinessComponent"}>
        
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BBusinessComponent.ApiSynchroniseDefaultActivities Start":U skip.
        output close.
        
        <M-40 run ApiSynchroniseDefaultActivities (output vlUpdatesDone (olUpdatesDone), 
                                           output viSynchroniseError (oiReturnStatus)) in BBusinessComponent>

        <I-41 {bFcCloseAndStopInstance
             &CLASS           = "BBusinessComponent"}>
               
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BBusinessComponent.ApiSynchroniseDefaultActivities End : ":U string (viSynchroniseError) ' ':U string (vlUpdatesDone) skip.
        output close.
               
        if viSynchroniseError < 0
        or (oiReturnStatus = 0 and viSynchroniseError > 0)
        then assign oiReturnStatus = viSynchroniseError.

        if viSynchroniseError < 0
        then assign tTopic.tcUpdateInformation = #T-86'Update Failed':30(829486138)T-86#.
        else
        if vlUpdatesDone
        then assign tTopic.tcUpdateInformation = trim(#T-42'Updates Done':30(449)T-42#).
        else assign tTopic.tcUpdateInformation = trim(#T-43'No Updates Required':30(450)T-43#).
    end. /* if available tTopic 3 */  
    
    /* ==================== */
    /* WHEN Resources (needs BusCompActArea) */
    /* ==================== */
    find tTopic where 
         tTopic.tiTopicNumber = 15 and 
         tTopic.tlSelected    = true
         no-error.
    if available tTopic and
      (vcSynchronizeType = {&SYNCHRONIZETYPE-FULL} or
       tTopic.tcSynchronizeType = vcSynchronizeType)
    then if viClassSynchroniseError < 0
    then assign tTopic.tcUpdateInformation = #T-88'Skipped':30(781314445)T-88#.
    else do:
        <I-59 {bFcStartAndOpenInstance
             &CLASS                = "BResource"}>
        
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BResource.ApiSynchronize Start":U skip.
        output close.
        
        <M-65 run ApiSynchronize
           (output vlUpdatesDone (olUpdatesDone), 
            output viSynchroniseError (oiReturnStatus)) in BResource>

        <I-62 {bFcCloseAndStopInstance
             &CLASS           = "BResource"}>        
       
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BResource.ApiSynchronize End : ":U string (viSynchroniseError) ' ':U string (vlUpdatesDone) skip.
        output close.
               
        if viSynchroniseError < 0
        or (oiReturnStatus = 0 and viSynchroniseError > 0)
        then assign oiReturnStatus = viSynchroniseError.

        if viSynchroniseError < 0
        then assign tTopic.tcUpdateInformation = #T-147'Update Failed':30(829486138)T-147#.
        else
        if vlUpdatesDone
        then assign tTopic.tcUpdateInformation = trim(#T-63'Updates Done':30(449)T-63#).
        else assign tTopic.tcUpdateInformation = trim(#T-64'No updates required':30(450)T-64#).
    End. /* if available tTopic 15 */
        
    /* ======================================= */
    /* WHEN StoredSearch  (Company must exist) */
    /* ======================================= */
    find tTopic where 
         tTopic.tiTopicNumber = 5 and /* StoredSearch */
         tTopic.tlSelected    = true
         no-error.
    if available tTopic and
      (vcSynchronizeType = {&SYNCHRONIZETYPE-FULL} or
       tTopic.tcSynchronizeType = vcSynchronizeType)
    then do :
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BStoredSearch.ApiSynchronise Start":U skip.
        output close.
        
        <I-23 {bFcStartAndOpenInstance
             &ADD-TO-TRANSACTION = "false"
             &CLASS              = "BStoredSearch"}>
        <M-25 run ApiSynchronise
           (output vlUpdatesDone (olUpdatesDone), 
            output viSynchroniseError (oiReturnStatus)) in BStoredSearch>
        <I-73 {bFcCloseAndStopInstance
             &CLASS           = "BStoredSearch"}>

        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BStoredSearch.ApiSynchronise End : ":U string (viSynchroniseError) ' ':U string (vlUpdatesDone) skip.
        output close.

        if viSynchroniseError >= 0
        then do:
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BReportVariant.ApiSynchronise Start":U skip.
        output close.
        
        <I-72 {bFcStartAndOpenInstance
             &CLASS              = "BReportVariant"}>
        <M-74 run apiSynchronise
           (output vlFcOk (olUpdatesDone), 
            output viSynchroniseError (oiReturnStatus)) in BReportVariant>
        if vlFcOk then vlUpdatesDone = yes.
        <I-75 {bFcCloseAndStopInstance
             &CLASS           = "BReportVariant"}>

        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BReportVariant.ApiSynchronise End : ":U string (viSynchroniseError) ' ':U string (vlUpdatesDone) skip.
        output close.
        end.

        if viSynchroniseError >= 0
        then do:
        <M-47 run Main  (input  viSessionID (iiSessionId)) in TApplication>
        <M-54 run GetDefaultsFolder  (output vcFactoryDefaultsPath (ocFolder)) in TApplication>
        run gipr_DeleteProcedure in vhFcComponent.
        delete procedure vhFcComponent.
        
        vcFactoryDefaultsPath = vcFactoryDefaultsPath + "gridfactorydefaults.xml".
        
        if search(vcFactoryDefaultsPath) <> ?
        then do:
            output to value (vcSynchroniseLogFile) append.
            put unformatted string (now) '> ':U
                "BControlProperty.ApiSynchronise Start":U skip.
            output close.
        
            <I-68 {bFcStartAndOpenInstance
                 &CLASS                = "BControlProperty"}>
            <M-846 run ApiImportCustomization
               (input  vcFactoryDefaultsPath (icImportFile), 
                output viSynchroniseError (oiReturnStatus)) in BControlProperty>
            <I-46 {bFcCloseAndStopInstance
                 &CLASS           = "BControlProperty"}>
        
            output to value (vcSynchroniseLogFile) append.
            put unformatted string (now) '> ':U
                "BControlProperty.ApiSynchronise End : ":U string (viSynchroniseError) ' ':U string (vlUpdatesDone) skip.
            output close.
        end.
        end.
        
        if viSynchroniseError < 0
        or (oiReturnStatus = 0 and viSynchroniseError > 0)
        then assign oiReturnStatus = viSynchroniseError.

        if viSynchroniseError < 0
        then assign tTopic.tcUpdateInformation = #T-87'Update Failed':30(829486138)T-87#.
        else
        if vlUpdatesDone
        then assign tTopic.tcUpdateInformation = trim(#T-27'Updates Done':30(449)T-27#).
        else assign tTopic.tcUpdateInformation = trim(#T-28'No Updates Required':30(450)T-28#).
        
    end. /* if available tTopic 5 */

    /* ==================== */
    /* 6. WHEN Default Roles (needs resources and roles)*/
    /* ==================== */
    find tTopic where 
         tTopic.tiTopicNumber = 6 and /* Default Roles */
         tTopic.tlSelected    = true
         no-error.
    if available tTopic and
      (vcSynchronizeType = {&SYNCHRONIZETYPE-FULL} or
       tTopic.tcSynchronizeType = vcSynchronizeType)
    then do :
        <I-66 {bFcStartAndOpenInstance
             &CLASS                = "BRole"}>
        
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BRole.ApiSynchronizeDefaultRoles Start":U skip.
        output close.
        
        <M-70 run ApiSynchronizeDefaultRoles
           (output vlUpdatesDone (olUpdatesDone), 
            output viSynchroniseError (oiReturnStatus)) in BRole>       

        <I-69 {bFcCloseAndStopInstance
             &CLASS           = "BRole"}>
        
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BRole.ApiSynchronizeDefaultRoles End : ":U string (viSynchroniseError) ' ':U string (vlUpdatesDone) skip.
        output close.
        
        if viSynchroniseError < 0
        or (oiReturnStatus = 0 and viSynchroniseError > 0)
        then assign oiReturnStatus = viSynchroniseError.

        if viSynchroniseError < 0
        then assign tTopic.tcUpdateInformation = #T-78'Update Failed':30(829486138)T-78#.
        else
        if vlUpdatesDone
        then assign tTopic.tcUpdateInformation = trim(#T-44'Updates Done':30(449)T-44#).
        else assign tTopic.tcUpdateInformation = trim(#T-126'No Updates Required':30(64147886)T-126#).
        
    end. /* if available tTopic 16 */
    
    /* ===================== */
    /* 3. WHEN Report String */
    /* ===================== */
    find tTopic where 
         tTopic.tiTopicNumber = 7 and
         tTopic.tlSelected    = true
         no-error.
    if available tTopic and
      (vcSynchronizeType = {&SYNCHRONIZETYPE-FULL} or
       tTopic.tcSynchronizeType = vcSynchronizeType)
    then if iiLngSynchroniseError < 0
    then assign tTopic.tcUpdateInformation = #T-817'Skipped':30(781314445)T-817#.
    else do:
        <I-92 {bFcStartAndOpenInstance
             &CLASS                = "BReportTranslation"}>
        
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BReportTranslation.ApiSynchronise Start":U skip.
        output close.

        <M-24 run apiSynchronise
           (output vlUpdatesDone (olUpdatesDone), 
            output viSynchroniseError (oiReturnStatus)) in BReportTranslation>

        <I-16 {bFcCloseAndStopInstance
             &CLASS           = "BReportTranslation"}>
        
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BReportTranslation.ApiSynchronise End : ":U string (viSynchroniseError) ' ':U string (vlUpdatesDone) skip.
        output close.
                                
        if viSynchroniseError < 0
        or (oiReturnStatus = 0 and viSynchroniseError > 0)
        then assign oiReturnStatus = viSynchroniseError.

        if viSynchroniseError < 0
        then assign tTopic.tcUpdateInformation = #T-863'Update Failed':30(829486138)T-863#.
        else
        if vlUpdatesDone
        then assign tTopic.tcUpdateInformation = trim(#T-61'Updates Done':30(449)T-61#).
        else assign tTopic.tcUpdateInformation = trim(#T-441'No updates required':30(450)T-441#).
    end. /* if available tTopic 7 */
               
end.