icRoleModuleURI | input | character | The RoleModuleURI that drives which roles need to be loaded, updated, created and deleted. Mandatory. |
tRoleForLoad | input | temp-table | Temp-table defined like the class-table. All existing Roles that belong to the RoleModuleURI that is stated in the first parameter, will be loaded into the instance. Records that exist in the instance but not in this input-table will be deleted, records that exist in this input-table but not in the the instance will be created and for the records that exist in this input-table and in the instance, the content of the instance will be be updated with the content of this input-table. Note that property RoleModuleURI for all records mentioned above, the value will be set equal to the RoleModuleURI (first parameter of the method) and not to the value in the input-table. |
tRoleResourceForLoad | input | temp-table | Temp-table defined like the class-table. Note that in the initial version of this method, the content of this input temp-table is just ignored. |
icActivityCode | input | character | Activity for the API on this class. If the caller provides an activity-code and the activity on this class is still empty then this parameter will be set as the activity in this class. Note that this API is secured: you will only be able to execute this method when the current activity in this class is "MaintainRolesForModuleURI" and you have access to this activity. |
oiReturnStatus | output | integer | Return status of the method. |
/* ============================================================================================================================ */ /* ApiMaintainRolesForModuleURI: */ /* Api-method with the class-tables as input and another input param string holding the RoleModuleURI. */ /* All Roles with this RoleModuleURI will be loaded and that data will be synchronised with that data in the input temp-tables. */ /* So: Roles with that RoleModuleURI that are in the db but not in the input temp-table will be deleted, Roles with that */ /* RoleModuleURI that are in the db and that are in the input temp-table will be updated and Roles with that RoleModuleURI that */ /* are in the input temp-table but not in the db will be created */ /* ============================================================================================================================ */ /* NOTE: In the initial version of this method, the content of input temp-table tRoleResourceForLoad is just ignored. If in a */ /* later version the code is adapted to handle the content of input temp-table tRoleResourceForLoad as well then ensure also */ /* the descrption of the parameter is adapted */ /* ============================================================================================================================ */ /* ================================================================ */ /* If the caller provided an activity-code and the activity on the */ /* class is still empty then use that as the activity in this class */ /* ================================================================ */ if icActivityCode <> "":U and icActivityCode <> ? and (vcActivityCode = "":U or vcActivityCode = ?) then assign vcActivityCode = icActivityCode. /* ============================================================================================ */ /* This method should only be executed with the correct Activity and the ModuleURI is mandatory */ /* ============================================================================================ */ if vcActivityCode <> "MaintainRolesForModuleURI":U then do : assign vcMessage = trim(substitute(#T-23'This method can only be executed in activity &1':200(746517231)T-23#,"MaintainRolesForModuleURI":U)) + chr(10) + trim(substitute(#T-70'Currenct avtivity: &1':200(968918753)T-70#,vcActivityCode)) + chr(10) + trim(substitute(#T-52'Program-method: &1':200(168372048)T-52#,program-name(1))). oiReturnStatus = -1. <M-91 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-771632':U (icFcMsgNumber), input '' (icFcExplanation), input '' (icFcIdentification), input '' (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BRole> Return. end. /* if vcActivityCode <> "MaintainRolesForModuleURI":U */ if icRoleModuleURI = "":U or icRoleModuleURI = ? then do : assign vcMessage = trim(substitute(#T-71'Parameter &1 is mandatory as input for this method':200(169247559)T-71#,"icRoleModuleUR":U)) + chr(10) + trim(substitute(#T-95'Program-method: &1':200(168372048)T-95#,program-name(1))). oiReturnStatus = -1. <M-41 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-886779':U (icFcMsgNumber), input '' (icFcExplanation), input '' (icFcIdentification), input '' (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BRole> Return. end. /* if icRoleModuleURI = "":U or */ /* ==================================================================== */ /* Start from a clean instance and Load all Roles with that ModuleURI */ /* Ignore error -4 from DataLoad as that means no data was read from db */ /* ==================================================================== */ assign vcFreeFormQuery = "for each Role where Role.RoleModuleURI = ":U + <M-5 EnQuote (input icRoleModuleURI (icToQuote)) in BRole>. <M-20 run DataLoad (input '' (icRowids), input '' (icPkeys), input '' (icObjectIds), input vcFreeFormQuery (icFreeform), input false (ilKeepPrevious), output viFcReturnSuper (oiReturnStatus)) in BRole> if viFcReturnSuper <> 0 and viFcReturnSuper <> -4 then assign oiReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 and viFcReturnSuper <> -4 then return. /* ==================================================================== */ /* Cycle through the input: this will result in new and modified tRoles */ /* ==================================================================== */ for each tRoleForLoad on error undo, throw : /* ================================================================== */ /* Find the role in the instance or create a new role in the instance */ /* ================================================================== */ find tRole where tRole.RoleName = tRoleForLoad.RoleName no-lock no-error. if available tRole then assign tRole.tc_status = "C":U. else do : <M-44 run AddDetailLine (input 'Role':U (icTable), input '':U (icParentRowid), output viFcReturnSuper (oiReturnStatus)) in BRole> if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 then return. end. /* Not if available tRole */ /* ================================================================== */ /* Update the content in the instance with the input data */ /* ================================================================== */ Buffer-copy tRoleForLoad except Role_ID RoleModuleURI tc_Status tc_Rowid tc_ParentRowid to tRole assign tRole.RoleModuleURI = icRoleModuleURI. end. /* for each tRoleForLoad : */ /* ============================================================================= */ /* Cycle through the instance-data and delete the ones that are not in the input */ /* ============================================================================= */ for each tRole where tRole.tc_status <> "D":U on error undo, throw : if not can-find (tRoleForLoad where tRoleForLoad.RoleName = tRole.RoleName) then assign tRole.tc_Status = "D":U. end. /* for each tRole on error undo, throw : */ /* ========================================== */ /* ValidateBC, AdditionalUpdates, DataSave */ /* ========================================== */ <M-19 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BRole> if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 then return. <M-96 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BRole> if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 then return. <M-74 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BRole> if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 then return.
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 = "BRole". create ttContext. assign ttContext.propertyName = "methodName" ttContext.propertyValue = "ApiMaintainRolesForModuleURI". 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/brole.apimaintainrolesformoduleuri.i.xsd", ?). vhParameter = vhInputDS:get-buffer-handle("tParameterI"). vhParameter:buffer-create(). assign vhParameter::icRoleModuleURI = <parameter value> vhParameter::icActivityCode = <parameter value>. vhParameter = vhInputDS:get-buffer-handle("tRoleResourceForLoad"). vhParameter:buffer-create(). assign vhParameter::<field-name-1> = <field-value-1> vhParameter::<field-name-2> = <field-value-2> ... vhParameter = vhInputDS:get-buffer-handle("tRoleForLoad"). 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.