mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Moved aliasing for CDRs into CdrServer to have it centralized for other methods pushing CDRs
This commit is contained in:
@@ -166,8 +166,20 @@ func (self *CdrServer) processCdr(storedCdr *StoredCdr) (err error) {
|
||||
if storedCdr.Subject == "" { // Use account information as rating subject if missing
|
||||
storedCdr.Subject = storedCdr.Account
|
||||
}
|
||||
|
||||
if err := LoadUserProfile(storedCdr, "ExtraFields"); err != nil {
|
||||
// replace aliases
|
||||
if err := LoadAlias(&AttrMatchingAlias{
|
||||
Destination: storedCdr.Destination,
|
||||
Direction: storedCdr.Direction,
|
||||
Tenant: storedCdr.Tenant,
|
||||
Category: storedCdr.Category,
|
||||
Account: storedCdr.Account,
|
||||
Subject: storedCdr.Subject,
|
||||
Context: utils.ALIAS_CONTEXT_RATING,
|
||||
}, storedCdr, utils.EXTRA_FIELDS); err != nil && err != utils.ErrNotFound {
|
||||
return err
|
||||
}
|
||||
// replace user profile fields
|
||||
if err := LoadUserProfile(storedCdr, utils.EXTRA_FIELDS); err != nil {
|
||||
return err
|
||||
}
|
||||
if storedCdr.ReqType == utils.META_NONE {
|
||||
|
||||
@@ -82,7 +82,7 @@ func (rs *Responder) GetCost(arg *CallDescriptor, reply *CallCost) (err error) {
|
||||
arg.Subject = arg.Account
|
||||
}
|
||||
// replace aliases
|
||||
LoadAlias(
|
||||
if err := LoadAlias(
|
||||
&AttrMatchingAlias{
|
||||
Destination: arg.Destination,
|
||||
Direction: arg.Direction,
|
||||
@@ -91,7 +91,9 @@ func (rs *Responder) GetCost(arg *CallDescriptor, reply *CallCost) (err error) {
|
||||
Account: arg.Account,
|
||||
Subject: arg.Subject,
|
||||
Context: utils.ALIAS_CONTEXT_RATING,
|
||||
}, arg, utils.EXTRA_FIELDS)
|
||||
}, arg, utils.EXTRA_FIELDS); err != nil && err != utils.ErrNotFound {
|
||||
return err
|
||||
}
|
||||
// replace user profile fields
|
||||
if err := LoadUserProfile(arg, utils.EXTRA_FIELDS); err != nil {
|
||||
return err
|
||||
@@ -117,7 +119,7 @@ func (rs *Responder) Debit(arg *CallDescriptor, reply *CallCost) (err error) {
|
||||
arg.Subject = arg.Account
|
||||
}
|
||||
// replace aliases
|
||||
LoadAlias(
|
||||
if err := LoadAlias(
|
||||
&AttrMatchingAlias{
|
||||
Destination: arg.Destination,
|
||||
Direction: arg.Direction,
|
||||
@@ -126,7 +128,9 @@ func (rs *Responder) Debit(arg *CallDescriptor, reply *CallCost) (err error) {
|
||||
Account: arg.Account,
|
||||
Subject: arg.Subject,
|
||||
Context: utils.ALIAS_CONTEXT_RATING,
|
||||
}, arg, utils.EXTRA_FIELDS)
|
||||
}, arg, utils.EXTRA_FIELDS); err != nil && err != utils.ErrNotFound {
|
||||
return err
|
||||
}
|
||||
// replace user profile fields
|
||||
if err := LoadUserProfile(arg, utils.EXTRA_FIELDS); err != nil {
|
||||
return err
|
||||
@@ -154,7 +158,7 @@ func (rs *Responder) MaxDebit(arg *CallDescriptor, reply *CallCost) (err error)
|
||||
arg.Subject = arg.Account
|
||||
}
|
||||
// replace aliases
|
||||
LoadAlias(
|
||||
if err := LoadAlias(
|
||||
&AttrMatchingAlias{
|
||||
Destination: arg.Destination,
|
||||
Direction: arg.Direction,
|
||||
@@ -163,7 +167,9 @@ func (rs *Responder) MaxDebit(arg *CallDescriptor, reply *CallCost) (err error)
|
||||
Account: arg.Account,
|
||||
Subject: arg.Subject,
|
||||
Context: utils.ALIAS_CONTEXT_RATING,
|
||||
}, arg, utils.EXTRA_FIELDS)
|
||||
}, arg, utils.EXTRA_FIELDS); err != nil && err != utils.ErrNotFound {
|
||||
return err
|
||||
}
|
||||
// replace user profile fields
|
||||
if err := LoadUserProfile(arg, utils.EXTRA_FIELDS); err != nil {
|
||||
return err
|
||||
@@ -198,7 +204,7 @@ func (rs *Responder) RefundIncrements(arg *CallDescriptor, reply *float64) (err
|
||||
arg.Subject = arg.Account
|
||||
}
|
||||
// replace aliases
|
||||
LoadAlias(
|
||||
if err := LoadAlias(
|
||||
&AttrMatchingAlias{
|
||||
Destination: arg.Destination,
|
||||
Direction: arg.Direction,
|
||||
@@ -207,7 +213,9 @@ func (rs *Responder) RefundIncrements(arg *CallDescriptor, reply *float64) (err
|
||||
Account: arg.Account,
|
||||
Subject: arg.Subject,
|
||||
Context: utils.ALIAS_CONTEXT_RATING,
|
||||
}, arg, utils.EXTRA_FIELDS)
|
||||
}, arg, utils.EXTRA_FIELDS); err != nil && err != utils.ErrNotFound {
|
||||
return err
|
||||
}
|
||||
// replace user profile fields
|
||||
if err := LoadUserProfile(arg, utils.EXTRA_FIELDS); err != nil {
|
||||
return err
|
||||
@@ -232,7 +240,7 @@ func (rs *Responder) GetMaxSessionTime(arg *CallDescriptor, reply *float64) (err
|
||||
arg.Subject = arg.Account
|
||||
}
|
||||
// replace aliases
|
||||
LoadAlias(
|
||||
if err := LoadAlias(
|
||||
&AttrMatchingAlias{
|
||||
Destination: arg.Destination,
|
||||
Direction: arg.Direction,
|
||||
@@ -241,7 +249,9 @@ func (rs *Responder) GetMaxSessionTime(arg *CallDescriptor, reply *float64) (err
|
||||
Account: arg.Account,
|
||||
Subject: arg.Subject,
|
||||
Context: utils.ALIAS_CONTEXT_RATING,
|
||||
}, arg, utils.EXTRA_FIELDS)
|
||||
}, arg, utils.EXTRA_FIELDS); err != nil && err != utils.ErrNotFound {
|
||||
return err
|
||||
}
|
||||
// replace user profile fields
|
||||
if err := LoadUserProfile(arg, utils.EXTRA_FIELDS); err != nil {
|
||||
return err
|
||||
@@ -264,7 +274,7 @@ func (rs *Responder) GetDerivedMaxSessionTime(ev *StoredCdr, reply *float64) err
|
||||
ev.Subject = ev.Account
|
||||
}
|
||||
// replace aliases
|
||||
LoadAlias(
|
||||
if err := LoadAlias(
|
||||
&AttrMatchingAlias{
|
||||
Destination: ev.Destination,
|
||||
Direction: ev.Direction,
|
||||
@@ -273,7 +283,9 @@ func (rs *Responder) GetDerivedMaxSessionTime(ev *StoredCdr, reply *float64) err
|
||||
Account: ev.Account,
|
||||
Subject: ev.Subject,
|
||||
Context: utils.ALIAS_CONTEXT_RATING,
|
||||
}, ev, utils.EXTRA_FIELDS)
|
||||
}, ev, utils.EXTRA_FIELDS); err != nil && err != utils.ErrNotFound {
|
||||
return err
|
||||
}
|
||||
|
||||
// replace user profile fields
|
||||
if err := LoadUserProfile(ev, utils.EXTRA_FIELDS); err != nil {
|
||||
@@ -352,7 +364,7 @@ func (rs *Responder) GetSessionRuns(ev *StoredCdr, sRuns *[]*SessionRun) error {
|
||||
ev.Subject = ev.Account
|
||||
}
|
||||
// replace aliases
|
||||
LoadAlias(
|
||||
if err := LoadAlias(
|
||||
&AttrMatchingAlias{
|
||||
Destination: ev.Destination,
|
||||
Direction: ev.Direction,
|
||||
@@ -361,7 +373,9 @@ func (rs *Responder) GetSessionRuns(ev *StoredCdr, sRuns *[]*SessionRun) error {
|
||||
Account: ev.Account,
|
||||
Subject: ev.Subject,
|
||||
Context: utils.ALIAS_CONTEXT_RATING,
|
||||
}, ev, utils.EXTRA_FIELDS)
|
||||
}, ev, utils.EXTRA_FIELDS); err != nil && err != utils.ErrNotFound {
|
||||
return err
|
||||
}
|
||||
// replace user profile fields
|
||||
if err := LoadUserProfile(ev, utils.EXTRA_FIELDS); err != nil {
|
||||
return err
|
||||
@@ -421,21 +435,6 @@ func (rs *Responder) ProcessCdr(cdr *StoredCdr, reply *string) error {
|
||||
if rs.CdrSrv == nil {
|
||||
return errors.New("CDR_SERVER_NOT_RUNNING")
|
||||
}
|
||||
// replace aliases
|
||||
LoadAlias(
|
||||
&AttrMatchingAlias{
|
||||
Destination: cdr.Destination,
|
||||
Direction: cdr.Direction,
|
||||
Tenant: cdr.Tenant,
|
||||
Category: cdr.Category,
|
||||
Account: cdr.Account,
|
||||
Subject: cdr.Subject,
|
||||
Context: utils.ALIAS_CONTEXT_RATING,
|
||||
}, cdr, utils.EXTRA_FIELDS)
|
||||
// replace user profile fields
|
||||
if err := LoadUserProfile(cdr, utils.EXTRA_FIELDS); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := rs.CdrSrv.ProcessCdr(cdr); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -474,7 +473,7 @@ func (rs *Responder) GetLCR(attrs *AttrGetLcr, reply *LCRCost) error {
|
||||
}
|
||||
// replace aliases
|
||||
cd := attrs.CallDescriptor
|
||||
LoadAlias(
|
||||
if err := LoadAlias(
|
||||
&AttrMatchingAlias{
|
||||
Destination: cd.Destination,
|
||||
Direction: cd.Direction,
|
||||
@@ -483,7 +482,9 @@ func (rs *Responder) GetLCR(attrs *AttrGetLcr, reply *LCRCost) error {
|
||||
Account: cd.Account,
|
||||
Subject: cd.Subject,
|
||||
Context: utils.ALIAS_CONTEXT_RATING,
|
||||
}, cd, utils.EXTRA_FIELDS)
|
||||
}, cd, utils.EXTRA_FIELDS); err != nil && err != utils.ErrNotFound {
|
||||
return err
|
||||
}
|
||||
// replace user profile fields
|
||||
if err := LoadUserProfile(attrs.CallDescriptor, utils.EXTRA_FIELDS); err != nil {
|
||||
return err
|
||||
|
||||
@@ -413,7 +413,7 @@ func TestTutFsCalls1002Cdrs(t *testing.T) {
|
||||
req := utils.RpcCdrsFilter{Accounts: []string{"1002"}, RunIds: []string{utils.META_DEFAULT}}
|
||||
if err := tutFsCallsRpc.Call("ApierV2.GetCdrs", req, &reply); err != nil {
|
||||
t.Error("Unexpected error: ", err.Error())
|
||||
} else if len(reply) != 1 {
|
||||
} else if len(reply) != 2 { // Should be counted here also call originated form 1006 which is aliased to 1002
|
||||
t.Error("Unexpected number of CDRs returned: ", len(reply))
|
||||
} else {
|
||||
if reply[0].CdrSource != "freeswitch_json" {
|
||||
@@ -487,7 +487,7 @@ func TestTutFsCalls1004Cdrs(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
// Make sure account was debited properly
|
||||
// Make sure we don't have any CDRs for 1006 since it should have been aliased to 1002
|
||||
func TestTutFsCalls1006Cdrs(t *testing.T) {
|
||||
if !*testCalls {
|
||||
return
|
||||
@@ -496,24 +496,8 @@ func TestTutFsCalls1006Cdrs(t *testing.T) {
|
||||
req := utils.RpcCdrsFilter{Accounts: []string{"1006"}, RunIds: []string{utils.META_DEFAULT}}
|
||||
if err := tutFsCallsRpc.Call("ApierV2.GetCdrs", req, &reply); err != nil {
|
||||
t.Error("Unexpected error: ", err.Error())
|
||||
} else if len(reply) != 1 {
|
||||
} else if len(reply) != 0 {
|
||||
t.Error("Unexpected number of CDRs returned: ", len(reply))
|
||||
} else {
|
||||
if reply[0].CdrSource != "freeswitch_json" {
|
||||
t.Errorf("Unexpected CdrSource for CDR: %+v", reply[0])
|
||||
}
|
||||
if reply[0].ReqType != utils.META_PREPAID {
|
||||
t.Errorf("Unexpected ReqType for CDR: %+v", reply[0])
|
||||
}
|
||||
if reply[0].Destination != "1002" {
|
||||
t.Errorf("Unexpected Destination for CDR: %+v", reply[0])
|
||||
}
|
||||
if reply[0].Usage != "63" && reply[0].Usage != "64" && reply[0].Usage != "65" { // Usage as seconds
|
||||
t.Errorf("Unexpected Usage for CDR: %+v", reply[0])
|
||||
}
|
||||
if reply[0].Cost == -1.0 { // Cost was not calculated
|
||||
t.Errorf("Unexpected Cost for CDR: %+v", reply[0])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user