project BLF > class BSystem > method ApiSaveSODData
Description
method for excel integration
Parameters
ilValidateOnly | input | logical | |
ilCheckRule2Violations | input | logical | |
dSODDS | input | dataset | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
BLF
program code (program3/bsystem.p)
define buffer Resources1 for Resources.
define buffer Resources2 for Resources.
define buffer RoleResource1 for RoleResource.
define buffer RoleResource2 for RoleResource.
define buffer Role1 for Role.
define buffer Role2 for Role.
define buffer UsrRoleCompany1 for UsrRoleCompany.
define buffer UsrRoleCompany2 for UsrRoleCompany.
define buffer bqSelectResource for tqSelectResource.
if ilValidateOnly
then do:
/* ========================================= */
/* When only validating, do validations here */
/* ========================================= */
<Q-16 run SelectResource (all) (Read) (NoCache) (output dataset tqSelectResource) in BResource >
for each tResources on error undo, throw:
find first tqSelectResource where tqSelectResource.tcResourceURI = tResources.tcResourceURI no-error.
if available tqSelectResource
then tqSelectResource.tcSODCategoryCode = tResources.tcCategoryCode.
else do:
assign viErrorsReported = viErrorsReported + 1
oiReturnStatus = -1.
<M-67 run SetMessage
(input trim(#T-13'Cannot find resource with URI $1.':255(8864)T-13#) (icMessage),
input tResources.tcResourceURI (icArguments),
input 'tResources.tcResourceURI' (icFieldName),
input tResources.tcResourceURI (icFieldValue),
input 'E' (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'blf-537895':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BSystem>
if viErrorsReported = 100
then return.
end.
end.
for each tSODMatrix where
tSODMatrix.tcSODCategory2Code = tSODMatrix.tcSODCategory1Code and
tSODMatrix.tlSODCategoriesConflict
on error undo, throw:
assign viErrorsReported = viErrorsReported + 1
oiReturnStatus = -1.
<M-94 run SetMessage
(input trim(#T-94'A SOD category cannot be conflicting to itself.':255(73475939)T-94# + ' (' + tSODMatrix.tcSODCategory2Code + ')') (icMessage),
input '' (icArguments),
input 'tSODMatrix.tcSODCategory2Code' (icFieldName),
input tSODMatrix.tcSODCategory2Code (icFieldValue),
input 'E' (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'blf-917495':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BSystem>
if viErrorsReported = 100
then return.
end.
for each tSODMatrix where
tSODMatrix.tcSODCategory2Code > tSODMatrix.tcSODCategory1Code
on error undo, throw:
if can-find (first bSODMatrix where
bSODMatrix.tcSODCategory1Code = tSODMatrix.tcSODCategory2Code and
bSODMatrix.tcSODCategory2Code = tSODMatrix.tcSODCategory1Code and
bSODMatrix.tlSODCategoriesConflict <> tSODMatrix.tlSODCategoriesConflict)
then do:
assign viErrorsReported = viErrorsReported + 1
oiReturnStatus = -1.
<M-62 run SetMessage
(input trim(#T-41'Conflicting input for category $1 and category $2.':255(413968481)T-41#) (icMessage),
input tSODMatrix.tcSODCategory1Code + chr(2) + tSODMatrix.tcSODCategory2Code (icArguments),
input 'tSODMatrix.tcSODCategory2Code' (icFieldName),
input tSODMatrix.tcSODCategory2Code (icFieldValue),
input 'E' (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'blf-646748':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BSystem>
if viErrorsReported = 100
then return.
end.
end.
for each tSODMatrix on error undo, throw:
if not can-find (first bSODMatrix where
bSODMatrix.tcSODCategory1Code = tSODMatrix.tcSODCategory2Code and
bSODMatrix.tcSODCategory2Code = tSODMatrix.tcSODCategory1Code)
then do:
create bSODMatrix.
assign bSODMatrix.tcSODCategory1Code = tSODMatrix.tcSODCategory2Code
bSODMatrix.tcSODCategory2Code = tSODMatrix.tcSODCategory1Code
bSODMatrix.tlSODCategoriesConflict = tSODMatrix.tlSODCategoriesConflict
bSODMatrix.tcExclusionDescription = tSODMatrix.tcExclusionDescription.
release bSODMatrix.
end.
end.
for each tqSelectResource where
tqSelectResource.tcResourceURI > ""
on error undo, throw:
if tqSelectResource.tcSODCategoryCode = "" or
tqSelectResource.tcSODCategoryCode = ? or
not can-find (first tSODMatrix where
tSODMatrix.tcSODCategory1Code = tqSelectResource.tcSODCategoryCode and
tSODMatrix.tlSODCategoriesConflict)
then next.
for each RoleResource1 fields (Resource_ID Role_ID) no-lock where
RoleResource1.Resource_ID = tqSelectResource.tiResource_ID,
each Role fields (Role_ID RoleName RoleSODException) no-lock where
Role.Role_ID = RoleResource1.Role_ID and
Role.RoleSODException = no on error undo, throw:
if can-find (first tRule1SODValidation where
tRule1SODValidation.tiRole_ID = Role.Role_ID)
then next.
/* Dummy record */
create tRule1SODValidation.
assign tRule1SODValidation.tiRole_ID = Role.Role_ID
tRule1SODValidation.tcResourceURI = "".
release tRule1SODValidation.
/* Real records */
for each RoleResource2 fields (Resource_ID Role_ID) no-lock where
RoleResource2.Role_ID = Role.Role_ID,
each Resources fields (Resource_ID ResourceURI) no-lock where
Resources.Resource_ID = RoleResource2.Resource_ID on error undo, throw:
create tRule1SODValidation.
assign tRule1SODValidation.tiRole_ID = Role.Role_ID
tRule1SODValidation.tcRoleName = Role.RoleName
tRule1SODValidation.tcResourceURI = Resources.ResourceURI.
release tRule1SODValidation.
end.
end.
if ilCheckRule2Violations
then for each RoleResource1 fields (Resource_ID Role_ID) no-lock where
RoleResource1.Resource_ID = tqSelectResource.tiResource_ID,
each Role1 fields (Role_ID RoleName RoleSODException) no-lock where
Role1.Role_ID = RoleResource1.Role_ID and
Role1.RoleSODException = no,
each UsrRoleCompany1 fields (Usr_ID Role_ID Company_ID) no-lock where
UsrRoleCompany1.Role_ID = Role1.Role_ID on error undo, throw:
if can-find (first tRule2SODValidation where
tRule2SODValidation.tiUsr_ID = UsrRoleCompany1.Usr_ID and
tRule2SODValidation.tiCompany_ID = UsrRoleCompany1.Company_ID)
then next.
/* Dummy record */
create tRule2SODValidation.
assign tRule2SODValidation.tiUsr_ID = UsrRoleCompany1.Usr_ID
tRule2SODValidation.tiCompany_ID = UsrRoleCompany1.Company_ID
tRule2SODValidation.tcResourceURI = "".
release tRule2SODValidation.
/* Real records */
for each UsrRoleCompany2 fields (Usr_ID Role_ID Company_ID) no-lock where
UsrRoleCompany2.Usr_ID = UsrRoleCompany1.Usr_ID and
UsrRoleCompany2.Company_ID = UsrRoleCompany1.Company_ID,
each Role2 fields (Role_ID RoleName RoleSODException) no-lock where
Role2.Role_ID = UsrRoleCompany.Role_ID and
Role2.RoleSODException = no,
each Usr fields (Usr_ID UsrName) no-lock where
Usr.Usr_ID = UsrRoleCompany2.Usr_ID,
each RoleResource2 fields (Resource_ID Role_ID) no-lock where
RoleResource2.Role_ID = Role2.Role_ID,
each Resources fields (Resource_ID ResourceURI SODcategory_ID) no-lock where
Resources.Resource_ID = RoleResource2.Resource_ID and
Resources.SODcategory_ID <> 0 on error undo, throw:
create tRule2SODValidation.
assign tRule2SODValidation.tiUsr_ID = Usr.Usr_ID
tRule2SODValidation.tcUsrName = Usr.UsrName
tRule2SODValidation.tiCompany_ID = UsrRoleCompany2.Company_ID
tRule2SODValidation.tiRole_ID = Role2.Role_ID
tRule2SODValidation.tcRoleName = Role2.RoleName
tRule2SODValidation.tcResourceURI = Resources.ResourceURI.
release tRule2SODValidation.
end.
end.
end.
for each tRule1SODValidation where
tRule1SODValidation.tcResourceURI > "",
each tqSelectResource where
tqSelectResource.tcResourceURI = tRule1SODValidation.tcResourceURI,
each tSODMatrix where
tSODMatrix.tcSODCategory1Code = tqSelectResource.tcSODCategoryCode and
tSODMatrix.tcSODCategory2Code > tSODMatrix.tcSODCategory1Code and
tSODMatrix.tlSODCategoriesConflict,
each bqSelectResource where
bqSelectResource.tcSODCategoryCode = tSODMatrix.tcSODCategory2Code and
bqSelectResource.tcResourceURI > "",
each bRule1SODValidation where
bRule1SODValidation.tcResourceURI = bqSelectResource.tcResourceURI and
bRule1SODValidation.tiRole_ID = tRule1SODValidation.tiRole_ID
on error undo, throw:
assign viErrorsReported = viErrorsReported + 1
oiReturnStatus = -1.
<M-84 run SetMessage
(input trim(#T-57'Cannot set SOD category on resource: conflict found with resource $1 in role $2.':255(860106386)T-57#) (icMessage),
input bqSelectResource.tcResourceURI + chr(2) + trule1SODValidation.tcRoleName (icArguments),
input 'tResources.tcResourceURI' (icFieldName),
input tqSelectResource.tcResourceURI (icFieldValue),
input 'E' (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'blf-256367':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BSystem>
if viErrorsReported = 100
then return.
end.
for each tRule2SODValidation where
tRule2SODValidation.tcResourceURI > "",
each tqSelectResource where
tqSelectResource.tcResourceURI = tRule2SODValidation.tcResourceURI,
each tSODMatrix where
tSODMatrix.tcSODCategory1Code = tqSelectResource.tcSODCategoryCode and
tSODMatrix.tcSODCategory2Code > tSODMatrix.tcSODCategory1Code and
tSODMatrix.tlSODCategoriesConflict,
each bqSelectResource where
bqSelectResource.tcSODCategoryCode = tSODMatrix.tcSODCategory2Code and
bqSelectResource.tcResourceURI > "",
each bRule2SODValidation where
bRule2SODValidation.tcResourceURI = bqSelectResource.tcResourceURI and
bRule2SODValidation.tiUsr_ID = tRule2SODValidation.tiUsr_ID and
bRule2SODValidation.tiCompany_ID = tRule2SODValidation.tiCompany_ID and
bRule2SODValidation.tiRole_ID <> tRule2SODValidation.tiRole_ID
on error undo, throw:
assign viErrorsReported = viErrorsReported + 1
oiReturnStatus = -1.
vcSODCompanyCode = "".
for first Company fields (Company_ID CompanyCode) no-lock where
Company.Company_ID = UsrRoleCompany1.Company_ID:
vcSODCompanyCode = Company.CompanyCode.
end.
assign vcContext = trim(#T-95'User Name':17(7033)T-95#) + " = " + tRule2SODValidation.tcUsrName + chr(10) +
trim(#T-22'Entity Code':24(8770)T-22#) + " = " + vcSODCompanyCode + chr(10) +
trim(#T-46'Role 1 Name':20(733738256)T-46#) + " = " + tRule2SODValidation.tcRoleName + chr(10) +
trim(#T-71'Resource 1 URI':20(998717657)T-71#) + " = " + tqSelectResource.tcResourceURI + chr(10) +
trim(#T-50'SOD category 1 code':20(583998413)T-50#) + " = " + tqSelectResource.tcSODCategoryCode + chr(10) +
trim(#T-64'Role 2 Name':20(73458301)T-64#) + " = " + bRule2SODValidation.tcRoleName + chr(10) +
trim(#T-27'Resource 2 URI':20(117798426)T-27#) + " = " + bqSelectResource.tcResourceURI + chr(10) +
trim(#T-2'SOD category 2 code':20(52834825)T-2#) + " = " + bqSelectResource.tcSODCategoryCode.
<M-73 run SetMessage
(input trim(#T-8'Cannot set SOD category on resource: conflict found for user $1.':255(140233697)T-8#) (icMessage),
input tRule2SODValidation.tcUsrName (icArguments),
input 'tResources.tcResourceURI' (icFieldName),
input tqSelectResource.tcResourceURI (icFieldValue),
input 'E' (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'blf-634319':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input vcContext (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BSystem>
if viErrorsReported = 100
then return.
end.
end.
else do:
/* ========================================================== */
/* When also updating, validations will be done by the other */
/* business components, so validations are not repeated here. */
/* Update in three distinct transactions. */
/* ========================================================== */
if can-find(first tCategory)
then do:
<I-11 {bFcStartAndOpenInstance
&CLASS = "BSODCategory"}>
<M-65 run ApiCreateCategories
(input tCategory (tCategoryForCreate),
output viFcReturnSuper (oiReturnStatus)) in BSODCategory>
<I-54 {bFcCloseAndStopInstance
&CLASS = "BSODCategory"}>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
end.
if can-find(first tSODMatrix)
then do:
<I-23 {bFcStartAndOpenInstance
&CLASS = "BSODCategoryExclusion"}>
<M-14 run ApiSetMatrixData
(input tSODMatrix (tSetSODMatrix),
output viFcReturnSuper (oiReturnStatus)) in BSODCategoryExclusion>
<I-88 {bFcCloseAndStopInstance
&CLASS = "BSODCategoryExclusion"}>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
end.
if can-find(first tResources)
then do:
empty temp-table tLinkResource.
for each tResources:
if can-find (first tLinkResource where tLinkResource.tcResourceURI = tResources.tcResourceURI)
then do:
oiReturnStatus = -3.
<M-74 run SetMessage
(input #T-77'Duplicate entry in input ($1).':255(332074471)T-77# (icMessage),
input tResources.tcResourceURI (icArguments),
input 'tResources.ResourceURI' (icFieldName),
input tResources.tcResourceURI (icFieldValue),
input 'E' (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'BLF-218503':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BSystem>
end.
else do:
create tLinkResource.
assign tLinkResource.tcResourceURI = tResources.tcResourceURI
tLinkResource.tcResourceCategory = tResources.tcCategoryCode
tLinkResource.tcRequiredStatus = "C".
release tLinkResource.
end.
end.
if oiReturnStatus < 0
then return.
<I-83 {bFcStartAndOpenInstance
&CLASS = "BResource"}>
<M-33 run ApiLinkResource
(input tLinkResource (tInputResource),
output viFcReturnSuper (oiReturnStatus)) in BResource>
<I-36 {bFcCloseAndStopInstance
&CLASS = "BResource"}>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
end.
end.
finally:
if viErrorsReported >= 100
then do:
<M-34 run SetMessage
(input #T-90'Validation is aborted after 100 errors were reported.':255(415735840)T-90# (icMessage),
input '' (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'W' (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'blf-474331':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BSystem>
end.
end finally.
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 = "BSystem".
create ttContext.
assign ttContext.propertyName = "methodName"
ttContext.propertyValue = "ApiSaveSODData".
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/bsystem.apisavesoddata.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::ilValidateOnly = <parameter value>
vhParameter::ilCheckRule2Violations = <parameter value>.
vhParameter = vhInputDS:get-buffer-handle("tSODMatrix").
vhParameter:buffer-create().
assign vhParameter::<field-name-1> = <field-value-1>
vhParameter::<field-name-2> = <field-value-2>
...
vhParameter = vhInputDS:get-buffer-handle("tCategory").
vhParameter:buffer-create().
assign vhParameter::<field-name-1> = <field-value-1>
vhParameter::<field-name-2> = <field-value-2>
...
vhParameter = vhInputDS:get-buffer-handle("tResources").
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.