project BLF > class BUserRole > method ApiGetUserMembership
Description
Method that returns all membership possibilities for the given parameters.
Parameters
icUserLogin | input | character | |
icRoleName | input | character | |
icDomainCode | input | character | |
icCompanyCode | input | character | |
tUserMembership | output | temp-table | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
unused
program code (program3/buserrole.p)
if oiReturnStatus = 0
then assign oiReturnStatus = -98.
empty temp-table tUserMembership.
/*
read users depending on icUsrLogin
if icUsrLogin filled, then only 1 user is returned,
if icUsrLogin is empty, then all users are returned,
if a non-existing userlogin is given, then no user is returned
*/
assign viUserIdT = 0.
if icUserLogin <> "" and
icUserLogin <> ?
then do:
<Q-1 run UserByUsrLogin (all) (Read) (NoCache)
(input icUserLogin, (UsrLogin)
output dataset tqUserByUsrLogin) in BUser >
find first tqUserByUsrLogin where
tqUserByUsrLogin.tcUsrLogin = icUserLogin
no-error.
assign viUserIdT = if available tqUserByUsrLogin
then tqUserByUsrLogin.tiUsr_ID
else -9999.
end.
/* read roles */
assign viRoleIdT = 0.
<Q-6 run RolePrim (all) (Read) (NoCache)
(input ?, (RoleID)
input icRoleName, (RoleName)
output dataset tqRolePrim) in BRole >
if icRoleName <> "" and
icRoleName <> ?
then do:
find first tqRolePrim where
tqRolePrim.tcRoleName = icRoleName
no-error.
assign viRoleIdT = if available tqRolePrim
then tqRolePrim.tiRole_ID
else -9999.
end.
/* assign viCompanyIdT */
assign viCompanyIdT = 0.
if icCompanyCode <> "" and
icCompanyCode <> ?
then do:
<Q-8 run CompanyPrim (all) (Read) (NoCache)
(input ?, (LookupCompanyId)
input icCompanyCode, (CompanyCode)
output dataset tqCompanyPrim) in BCompany >
find first tqCompanyPrim where
tqCompanyPrim.tcCompanyCode = icCompanyCode
no-error.
assign viCompanyIdT = if available tqCompanyPrim
then tqCompanyPrim.tiCompany_ID
else -9999.
end.
/* read Domain */
assign viDomainIdT = 0.
if icDomainCode <> "" and
icDomainCode <> ?
then do:
<Q-9 run DomainsPrim (all) (Read) (NoCache)
(input ?, (DomainID)
input icDomainCode, (DomainCode)
output dataset tqDomainsPrim) in BDomain >
find first tqDomainsPrim where
tqDomainsPrim.tcDomainCode = icDomainCode
no-error.
assign viDomainIdT = if available tqDomainsPrim
then tqDomainsPrim.tiDomain_ID
else -9999.
end.
/* return if one of the parameters in invalid */
if viUserIdT = -9999 or
viCompanyIdT = -9999 or
viDomainIdT = -9999 or
viRoleIdT = -9999
then do:
assign oiReturnStatus = 0.
return.
end.
/* read existing user-company combinations */
<Q-10 run UsrCompanyByLoginCompDomain (all) (Read) (NoCache)
(input viCompanyIdT, (CompanyId)
input icUserLogin, (UserLogin)
input icCompanyCode, (CompanyCode)
input icDomainCode, (DomainCode)
input viDomainIdT, (DomainId)
input viUserIdT, (UserId)
output dataset tqUsrCompanyByLoginCompDomain) in BUser >
/* read existing user role company combinations */
<Q-7 run UsrRoleCompanyByUsrRoleCompDom (all) (Read) (NoCache)
(input viCompanyIdT, (CompanyId)
input icUserLogin, (UsrLogin)
input icRoleName, (RoleName)
input icCompanyCode, (CompanyCode)
input icDomainCode, (DomainCode)
input viUserIdT, (UserId)
input viRoleIdT, (RoleId)
input viDomainIdT, (DomainId)
output dataset tqUsrRoleCompanyByUsrRoleCompDom) in BUserRole >
/* create all possible user role company combination */
for each tqUsrCompanyByLoginCompDomain:
/* create all possible user role company combination */
for each tqRolePrim:
create tUserMembership.
assign tUserMembership.tcDomainName = ""
tUserMembership.tcDomainCode = tqUsrCompanyByLoginCompDomain.tcDomainCode
tUserMembership.tiDomain_ID = tqUsrCompanyByLoginCompDomain.tiDomain_ID
tUserMembership.tcCompanyCode = tqUsrCompanyByLoginCompDomain.tcCompanyCode
tUserMembership.tcCompanyDescription = tqUsrCompanyByLoginCompDomain.tcCompanyDescriptio
tUserMembership.tiCompany_ID = tqUsrCompanyByLoginCompDomain.tiCompany_ID
tUserMembership.tcUsrLogin = tqUsrCompanyByLoginCompDomain.tcUsrLogin
tUserMembership.tcUsrName = tqUsrCompanyByLoginCompDomain.tcUsrNam
tUserMembership.tiUsr_ID = tqUsrCompanyByLoginCompDomain.tiUsr_ID
tUserMembership.tcRoleName = tqRolePrim.tcRoleName
tUserMembership.tiRole_ID = tqRolePrim.tiRole_ID
tUserMembership.tlLink = can-find(first tqUsrRoleCompanyByUsrRoleCompDom where
tqUsrRoleCompanyByUsrRoleCompDom.tcCompanyCode = tqUsrCompanyByLoginCompDomain.tcCompanyCode and
tqUsrRoleCompanyByUsrRoleCompDom.tcUsrLogin = tqUsrCompanyByLoginCompDomain.tcUsrLogin and
tqUsrRoleCompanyByUsrRoleCompDom.tcRoleName = tqRolePrim.tcRoleName)
tUserMembership.tlChanged = false
tUserMembership.tlUsrRoleIsDefaultRole = can-find(first tqUsrRoleCompanyByUsrRoleCompDom where
tqUsrRoleCompanyByUsrRoleCompDom.tcCompanyCode = tqUsrCompanyByLoginCompDomain.tcCompanyCode and
tqUsrRoleCompanyByUsrRoleCompDom.tcUsrLogin = tqUsrCompanyByLoginCompDomain.tcUsrLogin and
tqUsrRoleCompanyByUsrRoleCompDom.tcRoleName = tqRolePrim.tcRoleName and
tqUsrRoleCompanyByUsrRoleCompDom.tlUsrRoleIsDefaultRole = true).
end.
end.
if oiReturnStatus = -98
then assign oiReturnStatus = 0.
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 = "BUserRole".
create ttContext.
assign ttContext.propertyName = "methodName"
ttContext.propertyValue = "ApiGetUserMembership".
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/buserrole.apigetusermembership.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icUserLogin = <parameter value>
vhParameter::icRoleName = <parameter value>
vhParameter::icDomainCode = <parameter value>
vhParameter::icCompanyCode = <parameter value>.
/* 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.