project BLF > class BTranslation > method ApiSetTranslation
Description
Saves the translations for a single application object based on an input temp-table.
Parameters
| tTrans | input | temp-table | Temp-table containing all information about the translations of a single native string. |
| oiReturnStatus | output | integer | Return status of the method. |
Internal usage
unused
program code (program9/btranslation.p)
define variable v1 as character case-sensitive.
define variable v2 as character case-sensitive.
/* ================================================================== */
/* Validate input parameters; */
/* The parentID should be the same for all records and cannot be zero */
/* The LanguageCode should be valid */
/* ================================================================== */
find first tTrans no-lock no-error.
if not available tTrans
then do :
assign oiReturnStatus = -3
vcMessage = trim(#T-14'No information about the translations was passed. No translation can be saved.':255(451)T-14#).
<M-5 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'BLF-227':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BTranslation>
Return.
end. /* if not available tTrans */
assign viFirstParentObjectID = tTrans.tiParentObjectID.
find first tTrans where
tTrans.tiParentObjectID <> viFirstParentObjectID
no-lock no-error.
if available tTrans
then do :
assign oiReturnStatus = -3
vcMessage = trim(#T-15'The input table should only contain information about one single native string, but different parent IDs were found.':255(452)T-15#) + chr(10) +
trim(substitute(#T-16'First parent ID: &1.':255(453)T-16#,string(viFirstParentObjectID))) + chr(10) +
trim(substitute(#T-17'Second parent ID: &1.':255(454)T-17#,string(tTrans.tiParentObjectID))).
<M-6 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'BLF-228':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BTranslation>
Return.
end. /* if available tTrans */
/* ================== */
/* Clear the instance */
/* ================== */
<M-7 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BTranslation>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then return.
/* ============================= */
/* Retrieve existing information */
/* ============================= */
<Q-2 run LanguagePrim (all) (Read) (NoCache)
(input ?, (LngCode)
input ?, (LngID)
output dataset tqLanguagePrim) in BLanguage >
<Q-3 run TranslationByIDLngParent (all) (Read) (NoCache)
(input ?, (LngID)
input viFirstParentObjectID, (ParentID)
input ?, (TranslationID)
output dataset tqTranslationByIDLngParent) in BTranslation >
/* ==================================================================================== */
/* Go through the input temp-table, check the language and try to find the original one */
/* Perform a DataLoad or AddDetailline depending on the previous checks */
/* ==================================================================================== */
for each tTrans no-lock :
find tqTranslationByIDLngParent where
tqTranslationByIDLngParent.tcLngCode = tTrans.tcLngCode and
tqTranslationByIDLngParent.tiParentObject_ID = tTrans.tiParentObjectID
no-lock no-error.
if not available tqTranslationByIDLngParent
then do :
<M-8 run AddDetailLine (input 'TranslationString':U (icTable),
input '':U (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BTranslation>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then return.
assign tTranslationString.Lng_ID = tTrans.tiLngID
tTranslationString.tcLngCode = tTrans.tcLngCode
tTranslationString.TranslationStringText = tTrans.tcTranslationStringText
tTranslationString.ParentObject_ID = tTrans.tiParentObjectID.
end. /* if not available tqTranslationByIDLngParent */
else Do:
Assign v1 = tTrans.tcTranslationStringText
v2 = tqTranslationByIDLngParent.tcTranslationStringText.
if v1 <> v2
then do :
assign vcTranslationStringRowid = (if num-entries(tqTranslationByIDLngParent.tc_rowid) > 1
then entry(1,tqTranslationByIDLngParent.tc_rowid)
else tqTranslationByIDLngParent.tc_rowid).
<M-9 run DataLoad
(input vcTranslationStringRowid (icRowids),
input '':U (icPkeys),
input '':U (icObjectIds),
input '' (icFreeform),
input true (ilKeepPrevious),
output viFcReturnSuper (oiReturnStatus)) in BTranslation>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then return.
find tTranslationString where
tTranslationString.tc_Rowid = vcTranslationStringRowid
no-error.
if not available tTranslationString
then do :
assign oiReturnStatus = -3
vcMessage = trim(substitute(#T-18'The translation was found but cannot be loaded based on the row ID (&1).':255(455)T-18#,string(vcTranslationStringRowid))).
<M-10 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'BLF-229':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BTranslation>
Return.
end. /* if not available tTranslationString */
else assign tTranslationString.TranslationStringText = tTrans.tcTranslationStringText
tTranslationString.tc_Status = "C":U.
end. /* if not available tqTranslationByIDLngParent and Text has changed */
end.
end. /* for each tTrans */
/* =================================== */
/* Validate, AddtionalUpdates and Save */
/* =================================== */
<M-11 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BTranslation>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then return.
<M-12 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BTranslation>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0 then return.
<M-13 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BTranslation>
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 = "BTranslation".
create ttContext.
assign ttContext.propertyName = "methodName"
ttContext.propertyValue = "ApiSetTranslation".
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 = "".
/* Create input dataset */
create dataset vhInputDS.
vhInputDS:read-xmlschema("file", "xml/btranslation.apisettranslation.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tTrans").
vhParameter:buffer-create().
assign vhParameter::<field-name-1> = <field-value-1>
vhParameter::<field-name-2> = <field-value-2>
...
/* 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.