mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Updated EventCost FieldAsInterface function. Fixes #2743
This commit is contained in:
committed by
Dan Christian Bogos
parent
31b201f70d
commit
9047fab68c
@@ -1188,7 +1188,7 @@ func (acc *Account) GetBalanceWithID(blcType, blcID string) (blc *Balance) {
|
||||
|
||||
// FieldAsInterface func to help EventCost FieldAsInterface
|
||||
func (as *AccountSummary) FieldAsInterface(fldPath []string) (val interface{}, err error) {
|
||||
if len(fldPath) == 0 {
|
||||
if as == nil || len(fldPath) == 0 {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
switch fldPath[0] {
|
||||
|
||||
@@ -840,7 +840,7 @@ func (bs BalanceSummaries) BalanceSummaryWithUUD(bsUUID string) (b *BalanceSumma
|
||||
|
||||
// FieldAsInterface func to help EventCost FieldAsInterface
|
||||
func (bl *BalanceSummary) FieldAsInterface(fldPath []string) (val interface{}, err error) {
|
||||
if len(fldPath) != 1 {
|
||||
if bl == nil || len(fldPath) != 1 {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
switch fldPath[0] {
|
||||
|
||||
@@ -1090,6 +1090,9 @@ func (ec *EventCost) getChargesForPath(fldPath []string, chr *ChargingInterval)
|
||||
}
|
||||
return chr.Increments, nil
|
||||
}
|
||||
if len(chr.Increments) <= *indx {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
incr := chr.Increments[*indx]
|
||||
if len(fldPath) == 1 {
|
||||
return incr, nil
|
||||
@@ -1119,6 +1122,9 @@ func (ec *EventCost) getRatingForPath(fldPath []string, rating *RatingUnit) (val
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
if indx != nil {
|
||||
if len(rts) <= *indx {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
rt := rts[*indx]
|
||||
if len(fldPath) == 1 {
|
||||
return rt, nil
|
||||
|
||||
@@ -266,7 +266,6 @@ func TestECClone(t *testing.T) {
|
||||
if _, has := testEC.Accounting["a012888"]; !has {
|
||||
t.Error("Key removed from testEC")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestECComputeAndReset(t *testing.T) {
|
||||
@@ -3747,3 +3746,48 @@ func TestECAsCallCost3(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestECAsDataProvider2(t *testing.T) {
|
||||
ecDP := testEC
|
||||
if data, err := ecDP.FieldAsInterface([]string{"RunID"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if data != utils.MetaDefault {
|
||||
t.Errorf("Expecting: <%s> \nreceived: <%s>", utils.MetaDefault, data)
|
||||
}
|
||||
if data, err := ecDP.FieldAsInterface([]string{"AccountSummary", "ID"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if data != "dan" {
|
||||
t.Errorf("Expecting: <%s> \nreceived: <%s>", "data", data)
|
||||
}
|
||||
if data, err := ecDP.FieldAsInterface([]string{"AccountSummary", "BalanceSummaries[1]", "UUID"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if data != "7a54a9e9-d610-4c82-bcb5-a315b9a65010" {
|
||||
t.Errorf("Expecting: <%s> \nreceived: <%s>", "4b8b53d7-c1a1-4159-b845-4623a00a0165", data)
|
||||
}
|
||||
if data, err := ecDP.FieldAsInterface([]string{"AccountSummary", "BalanceSummaries[2]", "Type"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if data != "*voice" {
|
||||
t.Errorf("Expecting: <%s> \nreceived: <%s>", "*voice", data)
|
||||
}
|
||||
ecDP = &EventCost{AccountSummary: &AccountSummary{}}
|
||||
ecDP.initCache()
|
||||
if _, err := ecDP.FieldAsInterface([]string{"AccountSummary", "BalanceSummaries[0]", "Type"}); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Errorf("Unexpected error:%v", err)
|
||||
}
|
||||
if _, err := ecDP.FieldAsInterface([]string{"Charges[0]", "Increments"}); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Errorf("Unexpected error:%v", err)
|
||||
}
|
||||
ecDP.Charges = []*ChargingInterval{{}}
|
||||
if _, err := ecDP.FieldAsInterface([]string{"Charges[0]", "Increments[0]"}); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Errorf("Unexpected error:%v", err)
|
||||
}
|
||||
ecDP.Rating = Rating{"": {}}
|
||||
ecDP.Rates = ChargedRates{"": {}, "b": {}}
|
||||
if _, err := ecDP.FieldAsInterface([]string{"Charges[0]", "Rating", "Rates[0]"}); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Errorf("Unexpected error:%v", err)
|
||||
}
|
||||
|
||||
if _, err := ecDP.FieldAsInterface([]string{"Rates", "b[0]"}); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Errorf("Unexpected error:%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ type BalanceCharge struct {
|
||||
|
||||
// FieldAsInterface func to help EventCost FieldAsInterface
|
||||
func (bc *BalanceCharge) FieldAsInterface(fldPath []string) (val interface{}, err error) {
|
||||
if len(fldPath) != 1 {
|
||||
if bc == nil || len(fldPath) != 1 {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
switch fldPath[0] {
|
||||
@@ -263,11 +263,11 @@ func (rf RatingMatchedFilters) Clone() (cln map[string]interface{}) {
|
||||
}
|
||||
|
||||
// FieldAsInterface func to help EventCost FieldAsInterface
|
||||
func (rf *RatingMatchedFilters) FieldAsInterface(fldPath []string) (val interface{}, err error) {
|
||||
if len(fldPath) != 1 {
|
||||
func (rf RatingMatchedFilters) FieldAsInterface(fldPath []string) (val interface{}, err error) {
|
||||
if rf == nil || len(fldPath) != 1 {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
ct, has := (*rf)[fldPath[0]]
|
||||
ct, has := rf[fldPath[0]]
|
||||
if !has || ct == nil {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
@@ -300,7 +300,7 @@ func (ct *ChargedTiming) Clone() (cln *ChargedTiming) {
|
||||
}
|
||||
|
||||
// FieldAsInterface func to help EventCost FieldAsInterface
|
||||
func (ct *ChargedTiming) FieldAsInterface(fldPath []string) (val interface{}, err error) {
|
||||
func (ct ChargedTiming) FieldAsInterface(fldPath []string) (val interface{}, err error) {
|
||||
if len(fldPath) != 1 {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
@@ -352,7 +352,7 @@ func (ru *RatingUnit) Clone() (cln *RatingUnit) {
|
||||
}
|
||||
|
||||
// FieldAsInterface func to help EventCost FieldAsInterface
|
||||
func (ru *RatingUnit) FieldAsInterface(fldPath []string) (val interface{}, err error) {
|
||||
func (ru RatingUnit) FieldAsInterface(fldPath []string) (val interface{}, err error) {
|
||||
if len(fldPath) != 1 {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
@@ -407,11 +407,11 @@ func (rfs RatingFilters) Clone() (cln RatingFilters) {
|
||||
}
|
||||
|
||||
// FieldAsInterface func to help EventCost FieldAsInterface
|
||||
func (rfs *RatingFilters) FieldAsInterface(fldPath []string) (val interface{}, err error) {
|
||||
if len(fldPath) == 0 {
|
||||
func (rfs RatingFilters) FieldAsInterface(fldPath []string) (val interface{}, err error) {
|
||||
if rfs == nil || len(fldPath) == 0 {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
ct, has := (*rfs)[fldPath[0]]
|
||||
ct, has := rfs[fldPath[0]]
|
||||
if !has || ct == nil {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
@@ -450,11 +450,11 @@ func (crus Rating) Clone() (cln Rating) {
|
||||
}
|
||||
|
||||
// FieldAsInterface func to help EventCost FieldAsInterface
|
||||
func (crus *Rating) FieldAsInterface(fldPath []string) (val interface{}, err error) {
|
||||
if len(fldPath) == 0 {
|
||||
func (crus Rating) FieldAsInterface(fldPath []string) (val interface{}, err error) {
|
||||
if crus == nil || len(fldPath) == 0 {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
rt, has := (*crus)[fldPath[0]]
|
||||
rt, has := crus[fldPath[0]]
|
||||
if !has || rt == nil {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
@@ -468,12 +468,12 @@ func (crus *Rating) FieldAsInterface(fldPath []string) (val interface{}, err err
|
||||
type ChargedRates map[string]RateGroups
|
||||
|
||||
// FieldAsInterface func to help EventCost FieldAsInterface
|
||||
func (crs *ChargedRates) FieldAsInterface(fldPath []string) (val interface{}, err error) {
|
||||
if len(fldPath) == 0 {
|
||||
func (crs ChargedRates) FieldAsInterface(fldPath []string) (val interface{}, err error) {
|
||||
if crs == nil || len(fldPath) == 0 {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
opath, indx := utils.GetPathIndex(fldPath[0])
|
||||
cr, has := (*crs)[opath]
|
||||
cr, has := crs[opath]
|
||||
if !has || cr == nil {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
@@ -522,11 +522,11 @@ func (crs ChargedRates) Clone() (cln ChargedRates) {
|
||||
type ChargedTimings map[string]*ChargedTiming
|
||||
|
||||
// FieldAsInterface func to help EventCost FieldAsInterface
|
||||
func (cts *ChargedTimings) FieldAsInterface(fldPath []string) (val interface{}, err error) {
|
||||
if len(fldPath) == 0 {
|
||||
func (cts ChargedTimings) FieldAsInterface(fldPath []string) (val interface{}, err error) {
|
||||
if cts == nil || len(fldPath) == 0 {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
ct, has := (*cts)[fldPath[0]]
|
||||
ct, has := cts[fldPath[0]]
|
||||
if !has || ct == nil {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
@@ -590,11 +590,11 @@ func (cbs Accounting) Clone() (cln Accounting) {
|
||||
}
|
||||
|
||||
// FieldAsInterface func to help EventCost FieldAsInterface
|
||||
func (cbs *Accounting) FieldAsInterface(fldPath []string) (val interface{}, err error) {
|
||||
if len(fldPath) == 0 {
|
||||
func (cbs Accounting) FieldAsInterface(fldPath []string) (val interface{}, err error) {
|
||||
if cbs == nil || len(fldPath) == 0 {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
ac, has := (*cbs)[fldPath[0]]
|
||||
ac, has := cbs[fldPath[0]]
|
||||
if !has || ac == nil {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
|
||||
@@ -239,7 +239,7 @@ type RGRate struct {
|
||||
|
||||
// FieldAsInterface func to help EventCost FieldAsInterface
|
||||
func (r *RGRate) FieldAsInterface(fldPath []string) (val interface{}, err error) {
|
||||
if len(fldPath) != 1 {
|
||||
if r == nil || len(fldPath) != 1 {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
switch fldPath[0] {
|
||||
|
||||
Reference in New Issue
Block a user