mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Updated account interface
This commit is contained in:
committed by
Dan Christian Bogos
parent
61b823443d
commit
df5adc6c96
@@ -220,7 +220,7 @@ func (at *ActionTiming) Execute(fltrS *FilterS) (err error) {
|
||||
// check action filter
|
||||
if len(a.Filters) > 0 {
|
||||
if pass, err := fltrS.Pass(utils.NewTenantID(accID).Tenant, a.Filters,
|
||||
utils.MapStorage{utils.MetaReq: config.NewObjectDP(acc)}); err != nil {
|
||||
utils.MapStorage{utils.MetaReq: acc}); err != nil {
|
||||
return err
|
||||
} else if !pass {
|
||||
continue
|
||||
|
||||
@@ -70,7 +70,7 @@ func (at *ActionTrigger) Execute(ub *Account, fltrS *FilterS) (err error) {
|
||||
// check action filter
|
||||
if len(a.Filters) > 0 {
|
||||
if pass, err := fltrS.Pass(utils.NewTenantID(a.Id).Tenant, a.Filters,
|
||||
utils.MapStorage{utils.MetaReq: config.NewObjectDP(ub)}); err != nil {
|
||||
utils.MapStorage{utils.MetaReq: ub}); err != nil {
|
||||
return err
|
||||
} else if !pass {
|
||||
continue
|
||||
|
||||
@@ -1107,6 +1107,13 @@ func (bc Balances) FieldAsInterface(fldPath []string) (val interface{}, err erro
|
||||
if bc == nil || len(fldPath) == 0 {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
|
||||
if fldPath[0] == utils.GetTotalValue {
|
||||
if len(fldPath) != 1 {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
return bc.GetTotalValue(), nil
|
||||
}
|
||||
for _, at := range bc {
|
||||
if at.ID == fldPath[0] {
|
||||
if len(fldPath) == 1 {
|
||||
|
||||
@@ -96,9 +96,8 @@ func (dDP *dynamicDP) fieldAsInterface(fldPath []string) (val interface{}, err e
|
||||
return
|
||||
}
|
||||
//construct dataProvider from account and set it further
|
||||
dp := config.NewObjectDP(account)
|
||||
dDP.cache.Set(fldPath[:2], dp)
|
||||
return dp.FieldAsInterface(fldPath[2:])
|
||||
dDP.cache.Set(fldPath[:2], account)
|
||||
return account.FieldAsInterface(fldPath[2:])
|
||||
case utils.MetaResources:
|
||||
// sample of fieldName : ~*resources.ResourceID.Field
|
||||
var reply ResourceWithConfig
|
||||
|
||||
@@ -600,7 +600,7 @@ func TestLoadRatingPlans(t *testing.T) {
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(csvr.ratingPlans["ANY_PLAN"].Timings["b9b78731"], anyTiming) {
|
||||
t.Errorf("Error using *any timing in rating plans: %+v : %+v", csvr.ratingPlans["ANY_PLAN"].Timings["b9b78731"], anyTiming)
|
||||
t.Errorf("Error using *any timing in rating plans: %+v : %+v", utils.ToJSON(csvr.ratingPlans["ANY_PLAN"].Timings["b9b78731"]), utils.ToJSON(anyTiming))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -529,10 +529,6 @@ func (r *RGRate) Clone() (cln *RGRate) {
|
||||
return
|
||||
}
|
||||
|
||||
func (rit *RITiming) String() string {
|
||||
return utils.ToJSON(rit)
|
||||
}
|
||||
|
||||
func (rit *RITiming) FieldAsInterface(fldPath []string) (val interface{}, err error) {
|
||||
if rit == nil || len(fldPath) == 0 {
|
||||
return nil, utils.ErrNotFound
|
||||
|
||||
@@ -20,7 +20,6 @@ package general_tests
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
@@ -37,18 +36,18 @@ func TestAccountNewObjectDPFieldAsInterface(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
accDP := config.NewObjectDP(acc)
|
||||
accDP := acc
|
||||
if data, err := accDP.FieldAsInterface([]string{"BalanceMap", "*monetary[0]", "Value"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if data != 20. {
|
||||
t.Errorf("Expected: %+v ,received: %+v", 20., data)
|
||||
}
|
||||
if _, err := accDP.FieldAsInterface([]string{"BalanceMap", "*monetary[1]", "Value"}); err == nil ||
|
||||
err.Error() != "index out of range" {
|
||||
err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
if _, err := accDP.FieldAsInterface([]string{"BalanceMap", "*monetary[0]", "InexistentField"}); err == nil ||
|
||||
err != utils.ErrNotFound {
|
||||
err.Error() != `unsupported field prefix: <InexistentField>` {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
@@ -65,7 +64,7 @@ func TestAccountNewObjectDPFieldAsInterfaceFromCache(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
accDP := config.NewObjectDP(acc)
|
||||
accDP := acc
|
||||
|
||||
if data, err := accDP.FieldAsInterface([]string{"BalanceMap", "*monetary[0]", "Value"}); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
@@ -858,6 +858,7 @@ const (
|
||||
Method = "Method"
|
||||
Static = "Static"
|
||||
Params = "Params"
|
||||
GetTotalValue = "GetTotalValue"
|
||||
Increment = "Increment"
|
||||
FixedFee = "FixedFee"
|
||||
RecurrentFee = "RecurrentFee"
|
||||
|
||||
Reference in New Issue
Block a user