project BLF > class BSystem > method ApiSynchronise

Description

This method will do the synchronisation (=upload of some fixed data) and the upload of the classes, areas and activities.


Parameters


icSynchronizeTypeinputcharacterCan be
SYNCHRONIZEFULL (synchronize all topics)
SYNCHRONIZELIMITED (synchronize limited topics, see output of ApiGetSynchronizationTopics)
SYNCHRONIZETOPIC + nr (synchronize one topic)
tTopicinput-outputtemp-tableInput-output temp-table with the Topics that need to be synchronised
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


BLF
method TApplication.Synchronize


program code (program9/bsystem.p)

assign vcSynchronizeType = icSynchronizeType.

/* ================================================================================ */
/* Log the Synchronisation in vcSynchroniseLogFile                                  */
/* ================================================================================ */
assign vcFile = search ("server.xml":U)
       vhFcComponent = ?.
<M-3 run MainBlock  () in XML>

<M-28 run ReadXMLNodeValue
   (input  vcFile (icXMLFile), 
    input  'logging':U (icStartTag), 
    input  'LoggingDirectory':U (icNodeTag), 
    output vcSynchroniseLogFile (ocNodeValue), 
    output viFcReturnSuper (oiReturnStatus)) in XML>

if index(vcSynchroniseLogFile,"$ENVROOT") > 0
then do:
    <M-1 run ReadXMLNodeValue
       (input  vcFile (icXMLFile), 
        input  'serverConfiguration' (icStartTag), 
        input  'ENVROOT' (icNodeTag), 
        output vcFile (ocNodeValue), 
        output viFcReturnSuper (oiReturnStatus)) in XML>
    vcSynchroniseLogFile = replace(vcSynchroniseLogFile,"$ENVROOT",vcFile).
end.

run gipr_DeleteProcedure in vhFcComponent.
delete procedure vhFcComponent.

if vcSynchroniseLogFile <> ""
then do:
    file-info:file-name = vcSynchroniseLogFile.
    if file-info:file-type = ?
    or index(file-info:file-type,"D":U) = 0
    or index(file-info:file-type,"R":U) = 0
    then 
        vcSynchroniseLogFile = "".    /* not a valid directory with write permissions */
    else
        vcSynchroniseLogFile = file-info:full-pathname.
end.

if vcSynchroniseLogFile = ""
THEN ASSIGN vcSynchroniseLogFile = REPLACE (search ("server.xml":U),"server.xml":U,"BSystem.ApiSynchronise.out":U).
Else ASSIGN vcSynchroniseLogFile = vcSynchroniseLogFile + "/BSystem.ApiSynchronise.out":U.

output to value (vcSynchroniseLogFile) append.
put '':U  skip.
put unformatted string (now) '> ':U
    'Following data will be synchronized: ':U vcSynchronizeType skip.
put unformatted string (now) '> ':U
    '!! Remark that the order is not the order of execution. To get the order of execution, look at the Program Flow.' skip.

for each tTopic where
         tTopic.tlSelected
         by tTopic.tlSelected by tTopic.tiTopicNumber :
    
    if vcSynchronizeType = {&SYNCHRONIZETYPE-FULL} or
       tTopic.tcSynchronizeType = vcSynchronizeType  or
       vcSynchronizeType = {&SYNCHRONIZETYPE-TOPIC} + string (tTopic.tiTopicNumber)
    then  put unformatted string (now) '> ':U '   '
                     tTopic.tlSelected ' ' 
                     tTopic.tcTopicName ' (' tTopic.tiTopicNumber ') ' 
                     tTopic.tcSynchronizeType 
                     skip.                
end.
put '':U skip.
output close.


output to value (vcSynchroniseLogFile) append.
put unformatted string (now) '> ':U
    "Program Flow:":U skip.
put unformatted string (now) '> ':U
    "BSystem.ApiSynchronise Start":U skip.
output close.

/* ============================================== */
/* Return if no actions are required              */
/* Fill the output-param default with all zero's  */
/* ============================================== */
if not can-find (first tTopic where tTopic.tlSelected = true)
then return.

for each tTopic :
    assign tTopic.tcUpdateInformation = "":U.
end. /* for each tTopic */

/* =============================================== */
/* Make sure all external components are 'cleared' */
/* =============================================== */
<M-186 run StopExternalInstances
   (output viFcReturnSuper (oiReturnStatus)) in BSystem>
if viFcReturnSuper < 0
then return.

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

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

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

/* ======================== */
/* Start MASTERSYNCHROBLOCK */
/* ======================== */
MASTERSYNCHROBLOCK : DO :
    
    /* =================== */
    /* 1. WHEN Language    */
    /* =================== */
    find tTopic where 
         tTopic.tiTopicNumber = 1 and /* Language */
         tTopic.tlSelected    = true
         no-error.
    if available tTopic and
      (vcSynchronizeType = {&SYNCHRONIZETYPE-FULL} or
       tTopic.tcSynchronizeType = vcSynchronizeType)
    then do :
        <I-84 {bFcStartAndOpenInstance
             &CLASS                = "BLanguage"}>
        
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BLanguage.ApiSynchronise Start":U skip.
        output close.
        
        <M-86 run ApiSynchronise
           (output vlUpdatesDone (olUpdatesDone), 
            output viLngSynchroniseError (oiReturnStatus)) in BLanguage>

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

        if viLngSynchroniseError < 0
        then assign tTopic.tcUpdateInformation = #T-20'Update Failed':30(829486138)T-20#.
        else
        if vlUpdatesDone
        then assign tTopic.tcUpdateInformation = trim(#T-97'Updates Done':30(449)t-97#).
        else assign tTopic.tcUpdateInformation = trim(#T-98'No Updates Required':30(450)t-98#).
    end. /* if available tTopic 1 */                
        
    /* ====================== */
    /* 2. WHEN Translations   */
    /* ====================== */
    find tTopic where 
         tTopic.tiTopicNumber = 12 and /* Translations */
         tTopic.tlSelected    = true
         no-error.
    if available tTopic and
      (vcSynchronizeType = {&SYNCHRONIZETYPE-FULL} or
       tTopic.tcSynchronizeType = vcSynchronizeType)
    then if viLngSynchroniseError < 0
    then assign tTopic.tcUpdateInformation = #T-518'Skipped':30(781314445)T-518#.
    else do:
        <I-159 {bFcStartAndOpenInstance
             &CLASS                = "BFcTranslation"}>

        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BFcTranslation.ApiSynchronise Start":U skip.
        output close.
        
        <M-161 run APISynchronise (output vlUpdatesDone (olUpdatesDone), 
                           output viSynchroniseError (oiReturnStatus)) in BFcTranslation>

        <I-162 {bFcCloseAndStopInstance
             &CLASS           = "BFcTranslation"}>

        output to value (vcSynchroniseLogFile) append.
        for each tFcMessages where tFcMessages.tcFcType = "F":
            put unformatted string (now) '> ':U tFcMessages.tcFcMessage skip.
            delete tFcMessages.
        end.
        put unformatted string (now) '> ':U
            "BFcTranslation.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-17'Update Failed':30(829486138)T-17#.
        else
        if vlUpdatesDone
        then assign tTopic.tcUpdateInformation = trim(#T-163'Updates Done':30(449)T-163#).
        else assign tTopic.tcUpdateInformation = trim(#T-164'No Updates Required':30(450)T-164#).
    end. /* if available tTopic -10 */

    /* ================================================================= */
    /* 4. WHEN settings configuration                                    */
    /* ================================================================= */
    find tTopic where 
         tTopic.tiTopicNumber = 9 and
         tTopic.tlSelected    = true
         no-error.
    if available tTopic and
      (vcSynchronizeType = {&SYNCHRONIZETYPE-FULL} or
       tTopic.tcSynchronizeType = vcSynchronizeType)
    then do:
        <I-165 {bFcStartAndOpenInstance
             &CLASS                = "BSettingConfiguration"}>
        
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BSettingConfiguration.ApiSynchronise Start":U skip.
        output close.
        
        <M-167 run apiSynchronise (output vlUpdatesDone (olUpdatesDone), 
                           output viSynchroniseError (oiReturnStatus)) in BSettingConfiguration>

        <I-168 {bFcCloseAndStopInstance
             &CLASS           = "BSettingConfiguration"}>

        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BSettingConfiguration.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-53'Update Failed':30(829486138)T-53#.
        else
        if vlUpdatesDone
        then assign tTopic.tcUpdateInformation = trim(#T-169'Updates Done':30(449)T-169#).
        else assign tTopic.tcUpdateInformation = trim(#T-170'No Updates Required':30(450)T-170#).
    end. /* if available tTopic 9 */
    
    /* ===================== */
    /* 5.WHEN SharedSetType  */
    /* ===================== */
    find tTopic where 
         tTopic.tiTopicNumber = 4 and /* SharedSetType */
         tTopic.tlSelected    = true
         no-error.
    if available tTopic and
      (vcSynchronizeType = {&SYNCHRONIZETYPE-FULL} or
       tTopic.tcSynchronizeType = vcSynchronizeType)
    then do :
        <I-42 {bFcStartAndOpenInstance
             &CLASS                = "BSharedSetType"}>
        
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BSharedSetType.ApiSynchronise Start":U ' ':U skip.
        output close.
        
        <M-46 run ApiSynchronise (output vlUpdatesDone (olUpdatesDone), 
                          output viSynchroniseError (oiReturnStatus)) in BSharedSetType>

        <I-45 {bFcCloseAndStopInstance
             &CLASS           = "BSharedSetType"}>                        
           
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BSharedSetType.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-19'Update Failed':30(829486138)T-19#.
        else
        if vlUpdatesDone
        then assign tTopic.tcUpdateInformation = trim(#T-103'Updates Done':30(449)t-103#).
        else assign tTopic.tcUpdateInformation = trim(#T-104'No Updates Required':30(450)t-104#).
    end. /* if available tTopic 4 */
           
    /* ==================== */
    /* 6. WHEN default roles*/
    /* ==================== */
    find tTopic where 
         tTopic.tiTopicNumber = 6 and /* Role */
         tTopic.tlSelected    = true
         no-error.
    if available tTopic and
      (vcSynchronizeType = {&SYNCHRONIZETYPE-FULL} or
       tTopic.tcSynchronizeType = vcSynchronizeType)
    then do :
        <I-61 {bFcStartAndOpenInstance
             &CLASS                = "BRole"}>
        
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BRole.ApiSynchronise Start":U skip.
        output close.
        
        <M-65 run ApiSynchronise (output vlUpdatesDone (olUpdatesDone), 
                          output viSynchroniseError (oiReturnStatus)) in BRole>

        <I-64 {bFcCloseAndStopInstance
             &CLASS           = "BRole"}>
        
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BRole.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-33'Update Failed':30(829486138)T-33#.
        else
        if vlUpdatesDone
        then assign tTopic.tcUpdateInformation = trim(#T-21'Updates Done':30(449)T-21#).
        else assign tTopic.tcUpdateInformation = trim(#T-9'No Updates Required':30(64147886)T-9#).
        
    end. /* if available tTopic 6 */
           
    /* ==================== */
    /* 7. WHEN Daemons      */
    /* ==================== */
    find tTopic where 

         tTopic.tiTopicNumber = 8 and
         tTopic.tlSelected    = true
         no-error.
    if available tTopic and
      (vcSynchronizeType = {&SYNCHRONIZETYPE-FULL} or
       tTopic.tcSynchronizeType = vcSynchronizeType)
    then do:
        assign vlDaemonsUpdated = no.
        
        /* Process the XMLDaemon */
        <I-70 {bFcStartAndOpenInstance
             &CLASS                = "BXmlDaemon"}>
        
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BXmlDaemon.ApiSynchronise Start":U skip.
        output close.
        
        <M-72 run ApiSynchronise (output vlUpdatesDone (olUpdatesDone), 
                          output viSynchroniseError (oiReturnStatus)) in BXmlDaemon>

        <I-73 {bFcCloseAndStopInstance
             &CLASS           = "BXmlDaemon"}>
        
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BXmlDaemon.ApiSynchronise End : ":U string (viSynchroniseError) ' ':U string (vlUpdatesDone) skip.
        output close.
                                
        if viSynchroniseError < 0
        or (oiReturnStatus = 0 and viSynchroniseError > 0)
        then assign oiReturnStatus = viSynchroniseError
                    vlDaemonsUpdated = ?.
        else
        if vlUpdatesDone = yes and vlDaemonsUpdated = no then assign vlDaemonsUpdated = true.

        /* Process the EventDaemon */
        <I-79 {bFcStartAndOpenInstance
             &CLASS                = "BEventDaemon"}>
        
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BEventDaemon.ApiSynchronise Start":U skip.
        output close.
        
        <M-83 run ApiSynchronise (output vlUpdatesDone (olUpdatesDone), 
                          output viSynchroniseError (oiReturnStatus)) in BEventDaemon>

        <I-82 {bFcCloseAndStopInstance
             &CLASS           = "BEventDaemon"}>
        
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BEventDaemon.ApiSynchronise End : ":U string (viSynchroniseError) ' ':U string (vlUpdatesDone) skip.
        output close.
                                
        if viSynchroniseError < 0
        or (oiReturnStatus = 0 and viSynchroniseError > 0)
        then assign oiReturnStatus = viSynchroniseError
                    vlDaemonsUpdated = ?.
        else
        if vlUpdatesDone = yes and vlDaemonsUpdated = no then assign vlDaemonsUpdated = true.
        
        /* Process the ScanDaemon */
        <I-89 {bFcStartAndOpenInstance
             &CLASS                = "BScanDaemon"}>
        
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BScanDaemon.ApiSynchronise Start":U skip.
        output close.
        
        <M-96 run ApiSynchronise (output vlUpdatesDone (olUpdatesDone), 
                          output viFcReturnSuper (oiReturnStatus)) in BScanDaemon>

        <I-92 {bFcCloseAndStopInstance
             &CLASS           = "BScanDaemon"}>
                        
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BScanDaemon.ApiSynchronise End : ":U string (viSynchroniseError) ' ':U string (vlUpdatesDone) skip.
        output close.
                                
        if viSynchroniseError < 0
        or (oiReturnStatus = 0 and viSynchroniseError > 0)
        then assign oiReturnStatus = viSynchroniseError
                    vlDaemonsUpdated = ?.
        else
        if vlUpdatesDone = yes and vlDaemonsUpdated = no then assign vlDaemonsUpdated = true.
        
        /* Process the ReportDaemon */
        <I-188 {bFcStartAndOpenInstance
             &CLASS                = "BReportDaemon"}>
        
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BReportDaemon.ApiSynchronise Start":U skip.
        output close.
        
        <M-190 run ApiSynchronise
           (output vlUpdatesDone (olUpdatesDone), 
            output viFcReturnSuper (oiReturnStatus)) in BReportDaemon>

        <I-191 {bFcCloseAndStopInstance
             &CLASS           = "BReportDaemon"}>
                        
        output to value (vcSynchroniseLogFile) append.
        put unformatted string (now) '> ':U
            "BReportDaemon.ApiSynchronise End : ":U string (viSynchroniseError) ' ':U string (vlUpdatesDone) skip.
        output close.
                                
        if viSynchroniseError < 0
        or (oiReturnStatus = 0 and viSynchroniseError > 0)
        then assign oiReturnStatus = viSynchroniseError
                    vlDaemonsUpdated = ?.
        else
        if vlUpdatesDone = yes and vlDaemonsUpdated = no then assign vlDaemonsUpdated = true.
        
        /* State result */
        if vlDaemonsUpdated = ?
        then assign tTopic.tcUpdateInformation = #T-88'Update Failed':30(829486138)T-88#.
        else if vlDaemonsUpdated = yes
        then assign tTopic.tcUpdateInformation = trim(#T-111'Updates Done':30(449)t-111#).
        else assign tTopic.tcUpdateInformation = trim(#T-112'No Updates Required':30(450)t-112#).
    end. /* if available tTopic 8 */

            
    /* ======================================================================== */
    /* Call method ApiSynchroniseScba that will handle the pure Scba-components */
    /* ======================================================================== */
    output to value (vcSynchroniseLogFile) append.
    put unformatted string (now) '> ':U
        "BSystem.ApiSynchroniseCustom Start":U skip.
    output close.
    
    <M-141 run ApiSynchroniseCustom  (output viSynchroniseError (oiReturnStatus)) in BSystem>
                                 
    output to value (vcSynchroniseLogFile) append.
    put unformatted string (now) '> ':U
        "BSystem.ApiSynchroniseCustom End : ":U string (viSynchroniseError) skip.
    output close.
                                     
    if viSynchroniseError < 0
    or (oiReturnStatus = 0 and viSynchroniseError > 0)
    then assign oiReturnStatus = viSynchroniseError.

    output to value (vcSynchroniseLogFile) append.
    put unformatted string (now) '> ':U
        "BSystem.ApiSynchronise2 Start":U skip.
    output close.
        
     <M-152 run ApiSynchronise2
        (input  viLngSynchroniseError (iiLngSynchroniseError), 
         output viSynchroniseError (oiReturnStatus)) in BSystem>

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

    if viSynchroniseError < 0
    or (oiReturnStatus = 0 and viSynchroniseError > 0)
    then assign oiReturnStatus = viSynchroniseError.
    
END. /* MASTERSYNCHROBLOCK */

/* ======================================================== */
/* Check for errors; stop all accesed components and return */
/* ======================================================== */
if can-find (first tFcMessages)
then do :

    output to value (vcSynchroniseLogFile) append.
    put '':U skip.
            
    for each tFcMessages :     
        put unformatted
            (if tFcMessages.tcFcType = 'W' then  'Warning'  else if tFcMessages.tcFcType = 'E' then 'Error' else tFcMessages.tcFcType) '=<':U 
            tFcMessages.tcFcMsgNumber ',':U 
            tFcMessages.tcFcMessage ',':U 
            tFcMessages.tcFcFieldName ',':U 
            tFcMessages.tcFcFieldValue '>':U 
            skip.
    end.
    put '':U skip.
    output close.
    
    <M-187 run StopExternalInstances
       (output viFcReturnSuper (oiReturnStatus)) in BSystem>
    
end. /* if oiReturnStatus < 0 */

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

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

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

output to value (vcSynchroniseLogFile) append.
if oiReturnStatus = 0
then  put unformatted string (now) '> ':U
         "BSystem.ApiSynchronise Ended successfully (oiReturnStatus=":U string (oiReturnStatus) ")" skip.
else
if oiReturnStatus > 0
then  put unformatted string (now) '> ':U
         "BSystem.ApiSynchronise Ended successfully, warnings were found (oiReturnStatus=":U string (oiReturnStatus) ")" skip.
else put unformatted string (now) '> ':U
         "BSystem.ApiSynchronise Ended with errors (oiReturnStatus=":U string (oiReturnStatus) ")" skip.
output close.