project BLF > class BCompany > method ApiSynchronise
Description
ApiSynchronise; this method will do the synchronisation
It will make sure at least one default company with code "999 - SYSADM" is created.
Parameters
olUpdatesDone | output | logical | UpdatesDone |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
BLF
program code (program3/bcompany.p)
/* Check if Company 999 already exists with the good properties; */
/* Load/Create to make sure the users can log in */
/* The Load is done so we can set the properties correctly if it was not yet the case */
<Q-1 run CompanyByAll (all) (Read) (NoCache) (input ?, (CompanyId)
input '999 - SYSADM':U, (CompanyCode)
input ?, (CompanyIsActive)
output dataset tqCompanyByAll) in BCompany >
find first tqCompanyByAll no-lock no-error.
/* LOAD */
if available tqCompanyByAll
then do :
<M-2 run DataLoad
(input '' (icRowids),
input tqCompanyByAll.tiCompany_ID (icPkeys),
input '' (icObjectIds),
input '' (icFreeform),
input false (ilKeepPrevious),
output viFcReturnSuper (oiReturnStatus)) in BCompany>
find tCompany where
tCompany.Company_ID = tqCompanyByAll.tiCompany_ID
no-error.
if not available tCompany
then do :
assign vcMessage = trim(substitute(#T-3'Internal error: unable to load the entity based on its ID (&1).':100(6598)T-3#,string(tqCompanyByAll.tiCompany_ID))).
<M-4 run SetMessage (input vcMessage (icMessage),
input '' (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'BLF-46':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCompany>
assign oiReturnStatus = -1.
Return.
end. /* if not available tCompany */
end. /* if available tqCompanyByAll */
/* CREATE */
else do :
<M-7 run DataNew (output viFcReturnSuper (oiReturnStatus)) in BCompany>
find first tCompany no-error.
if not available tCompany
then do :
assign vcMessage = trim(#T-8'Internal error: unable to find the newly created entity.':100(6600)T-8#).
<M-9 run SetMessage (input vcMessage (icMessage),
input '' (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'BLF-47':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCompany>
assign oiReturnStatus = -1.
Return.
end. /* if not available tCompany */
assign tCompany.CompanyCode = '999 - SYSADM':U
tCompany.CompanyDescription = 'SYSTEM':U.
end. /* if not available tqCompanyByAll */
/* State all requiered properties */
if tCompany.CompanyIsActive = false
then do :
assign tCompany.CompanyIsActive = true.
if tCompany.tc_Status = "":U
then assign tCompany.tc_Status = "C":U.
end. /* if tCompany.CompanyIsActive = false */
/* Check the Domain */
if (tCompany.Domain_ID = 0 or tCompany.Domain_ID = ?) and
(tCompany.tcDomainCode = '':U)
then do :
<Q-16 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:
assign tCompany.Domain_ID = tqDomainsPrim.tiDomain_ID
tCompany.tcDomainCode = tqDomainsPrim.tcDomainCode.
if tCompany.tc_Status = "":U
then assign tCompany.tc_Status = "C":U.
end.
end.
for each tCompany where
tCompany.tc_Status <> "D":U,
each tCompanySharedSet where
tCompanySharedSet.tc_ParentRowid = tCompany.tc_Rowid and
tCompanySharedSet.tc_Status <> "D":U and
tCompanySharedSet.tcSharedSetTypeCode <> "":U and
tCompanySharedSet.tcSharedSetTypeCode <> ? and
(tCompanySharedSet.tcSharedSetCode = "":U or
tCompanySharedSet.tcSharedSetCode = ?) on error undo, throw:
<Q-10 run SharedSetByType (all) (Read) (NoCache)
(input TRUE, (SharedSetIsActive)
input tCompanySharedSet.tcSharedSetTypeCode, (SharedSetTypeCode)
output dataset tqSharedSetByType) in BSharedSet >
find first tqSharedSetByType no-lock no-error.
if available tqSharedSetByType
then do :
assign tCompanySharedSet.tcSharedSetCode = tqSharedSetByType.tcSharedSetCode.
if tCompanySharedSet.tc_Status = "":U
then assign tCompanySharedSet.tc_Status = "C":U.
end. /* if available tqSharedSetByType */
end. /* for each */
/* Perform extra synchronise code. */
<M-14 run ApiSynchroniseCustom (output vlUpdatesDone (olUpdatesDone),
output viFcReturnSuper (oiReturnStatus)) in BCompany>
if vifcreturnsuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then return.
/* Set output indication */
if can-find (first tCompany where tCompany.tc_Status <> "":U) or
vlUpdatesDone
then assign olUpdatesDone = true.
/* Validate, AdditionalUpdates and Save */
<M-11 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BCompany>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then return.
<M-12 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BCompany>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then return.
<M-13 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BCompany>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then return.
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 = "BCompany".
create ttContext.
assign ttContext.propertyName = "methodName"
ttContext.propertyValue = "ApiSynchronise".
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.