project BLF > class BUser > method ValidateComponent
Description
Write here all tests on database update (new / modify / delete) that cannot be coded with a validation mask.
The type of update can be found in tc_status (N/C/D).
If you find incorrect data, you must write an entry in tFcMessages (using SetMessage) and set the return status of this method to either +1 or -1.
Return status +1 = data will still be accepted.
Return status -1 = data will not be accepted.
This method is run from SetPublicTables, before transferring the received data into the class temp-tables.
Parameters
oiReturnStatus | output | integer | |
Internal usage
unused
program code (program/buser.p)
<ANCESTOR-CODE>
For Each t_sUsr:
for each t_sUsrCompany where
t_sUsrCompany.tc_ParentRowid = t_sUsr.tc_Rowid:
<Q-15 run CompanyByCompanyCodeDomainCode (all) (Read) (NoCache)
(input t_sUsrCompany.Company_ID, (CompanyId)
input ?, (CompanyCode)
input ?, (DomainCode)
input ?, (DomainId)
input ?, (CompanyIsActive)
output dataset tqCompanyByCompanyCodeDomainCode) in BCompany>
find first tqCompanyByCompanyCodeDomainCode no-error.
if available tqCompanyByCompanyCodeDomainCode
then assign t_sUsrCompany.Domain_ID = tqCompanyByCompanyCodeDomainCode.tiDomain_ID.
end.
/*if the user has 1 or more usrdomains check that there is 1 default domain*/
if can-find(first t_sUsrDomain where
t_sUsrDomain.tc_ParentRowid = t_sUsr.tc_Rowid and
t_sUsrDomain.tc_Status <> 'D':U) and
not can-find(first t_sUsrDomain where
t_sUsrDomain.tc_ParentRowid = t_sUsr.tc_Rowid and
t_sUsrDomain.UsrDomainIsDefault = true and
t_sUsrDomain.tc_Status <> 'D':U)
then do:
Assign vcMessage = Trim(#T-13'A user must have one default domain specified.':255(8853)T-13#)
oiReturnStatus = -1.
<M-12 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 't_sUsr.UsrLogin':U (icFieldName),
input t_sUsr.UsrLogin (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sUsr.tc_Rowid (icRowid),
input 'BLF-421':U:U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BUser>
end.
/*check if the user has more than one default domain*/
videfault = 0.
for each t_sUsrDomain Where
t_sUsrDomain.tc_ParentRowid = t_sUsr.tc_Rowid And
t_sUsrDomain.UsrDomainIsDefault = True And
t_sUsrDomain.tc_Status <> 'D':U:
videfault = videfault + 1.
if videfault > 1
Then Do:
Assign vcMessage = Trim(#T-1'A user cannot have more than one default domain specified.':255(6817)T-1#)
oiReturnStatus = -1.
<M-2 run SetMessage (input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sUsr.tc_Rowid (icRowid),
input 'BLF-238':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BUser>
leave.
End.
end.
/*if a usrcompany or usr gets deleted, the corresponding record should not exist in usrrolecompany*/
for each t_sUsrCompany where
t_sUsrCompany.tc_ParentRowid = t_sUsr.tc_Rowid and
(t_sUsrCompany.tc_Status = 'D':U or
t_sUsr.tc_Status = 'D':U):
<Q-18 run UsrRoleCompanyByUsrRoleCompDom (all) (Read) (NoCache)
(input t_sUsrCompany.Company_ID, (CompanyId)
input ?, (UsrLogin)
input ?, (RoleName)
input ?, (CompanyCode)
input ?, (DomainCode)
input t_sUsrCompany.Usr_ID, (UserId)
input ?, (RoleId)
input ?, (DomainId)
output dataset tqUsrRoleCompanyByUsrRoleCompDom) in BUserRole >
if can-find(first tqUsrRoleCompanyByUsrRoleCompDom)
then do:
Assign vcMessage = Trim(#T-20'Can not delete user entity combination, a corresponding combination still exists in role membership. ($1 / $2)':255(825521580)T-20#)
oiReturnStatus = -1.
<M-19 run SetMessage
(input vcMessage (icMessage),
input t_sUsr.UsrLogin + chr(2) + t_sUsrCompany.tcCompanyCode (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input t_sUsr.tc_Rowid (icRowid),
input 'BLF-422':U:U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BUser>
end.
end.
End.