Commit 90b3ae07 authored by Kaustubh Murumkar's avatar Kaustubh Murumkar
Browse files

Handle txn while calling service

parent 00f777af
Branches
Tags
2 merge requests!252staging branch is merged into devbranch.,!246Transaction handle support added for call service.
Showing with 52 additions and 0 deletions
......@@ -205,3 +205,55 @@ func CallServiceWithBranch(name, branch string, rs *gjson.Result, isRestricted b
}
return res, nil
}
// CallServiceTXN - calls service with provided configuration, returns result and error from executed service
func CallServiceTXN(name string, rs *gjson.Result, isRestricted bool, isRoleBased bool, p servicebuildermdl.Principal) (interface{}, *servicebuildermdl.AbstractBusinessLogicHolder, error) {
return CallServiceWithBranchHandleTXN(name, constantmdl.Branch_Main, rs, isRestricted, isRoleBased, p)
}
// CallServiceWithBranchHandleTXN - calls service of given branch with provided configuration, returns result and error from executed service and handles transaction
func CallServiceWithBranchHandleTXN(name, branch string, rs *gjson.Result, isRestricted bool, isRoleBased bool, p servicebuildermdl.Principal) (interface{}, *servicebuildermdl.AbstractBusinessLogicHolder, error) {
var found bool
var service interface{}
if strings.TrimSpace(branch) == "" {
loggermdl.LogError("Branch is empty")
return nil, nil, errormdl.Wrap("Branch is empty")
}
activityName := ConcatenateEntityWithBranch(name, branch)
// if isRestricted {
// if isRoleBased {
// service, found = roleBasedServices.Get(activityName)
// } else {
// service, found = restrictedServices.Get(activityName)
// }
// } else {
// service, found = openServices.Get(activityName)
// }
switch {
case isRestricted == true && isRoleBased == true:
service, found = roleBasedServices.Get(activityName)
case isRestricted == true && isRoleBased == false:
service, found = restrictedServices.Get(activityName)
case isRestricted == false:
service, found = openServices.Get(activityName)
}
if !found {
loggermdl.LogError("Service Not Found: " + name)
return nil, nil, errormdl.Wrap("Service Not Found: " + name)
}
tmpSvcCache, ok := service.(ServiceCache)
if !ok {
loggermdl.LogError("Unable to cast service object for ", name)
return nil, nil, errormdl.Wrap("Service execution failed for " + name)
}
serviceCache := tmpSvcCache
res, ab, err := serviceCache.Service(rs, p)
if err != nil {
loggermdl.LogError("Service execution failed for ", name, " : ", err)
return nil, nil, err
}
return res, ab, nil
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment