From 4eefdc9a03a3f5eb5b8fc54e31cbe4d848eff67e Mon Sep 17 00:00:00 2001 From: TeoV Date: Mon, 21 Dec 2020 17:22:59 +0200 Subject: [PATCH] Add ThresholdIDs to AccountProfiles --- .../tutaccounts/AccountProfiles.csv | 5 +-- engine/libtest.go | 6 ++-- engine/loader_csv_test.go | 1 + engine/model_helpers.go | 36 +++++++++++++++---- engine/models.go | 1 + utils/accountprofile.go | 2 ++ utils/apitpdata.go | 1 + 7 files changed, 41 insertions(+), 11 deletions(-) diff --git a/data/tariffplans/tutaccounts/AccountProfiles.csv b/data/tariffplans/tutaccounts/AccountProfiles.csv index b00f75691..df4b0d4a2 100644 --- a/data/tariffplans/tutaccounts/AccountProfiles.csv +++ b/data/tariffplans/tutaccounts/AccountProfiles.csv @@ -1,2 +1,3 @@ -#Tenant,ID,FilterIDs,ActivationInterval,Weight,BalanceID,BalanceFilterIDs,BalanceWeight,BalanceBlocker,BalanceType,BalanceOpts,BalanceValue - +#Tenant,ID,FilterIDs,ActivationInterval,Weight,BalanceID,BalanceFilterIDs,BalanceWeight,BalanceBlocker,BalanceType,BalanceOpts,BalanceValue,ThresholdIDs +cgrates.org,1001,,,20,MonetaryBalance,,10,,*monetary,,14,*none +cgrates.org,1001,,,,VoiceBalance,,10,,*voice,,3600000000000, \ No newline at end of file diff --git a/engine/libtest.go b/engine/libtest.go index b3359e675..de5e197da 100644 --- a/engine/libtest.go +++ b/engine/libtest.go @@ -298,9 +298,9 @@ cgrates.org,ONE_TIME_ACT,,,,,,,TOPUP_TEST_VOICE,,false,0s,*topup,,~*balance.Test ` AccountProfileCSVContent = ` -#Tenant,ID,FilterIDs,ActivationInterval,Weight,BalanceID,BalanceFilterIDs,BalanceWeight,BalanceBlocker,BalanceType,BalanceOpts,BalanceValue -cgrates.org,1001,,,20,MonetaryBalance,,10,,*monetary,,14 -cgrates.org,1001,,,,VoiceBalance,,10,,*voice,,3600000000000 +#Tenant,ID,FilterIDs,ActivationInterval,Weight,BalanceID,BalanceFilterIDs,BalanceWeight,BalanceBlocker,BalanceType,BalanceOpts,BalanceValue,ThresholdIDs +cgrates.org,1001,,,20,MonetaryBalance,,10,,*monetary,,14,*none +cgrates.org,1001,,,,VoiceBalance,,10,,*voice,,3600000000000, ` ) diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index c8369a2e3..8f5942685 100644 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -1648,6 +1648,7 @@ func TestLoadAccountProfiles(t *testing.T) { Value: 3600000000000, }, }, + ThresholdIDs: []string{utils.META_NONE}, } if len(csvr.accountProfiles) != 1 { diff --git a/engine/model_helpers.go b/engine/model_helpers.go index b5626fa79..689beb9de 100644 --- a/engine/model_helpers.go +++ b/engine/model_helpers.go @@ -3507,13 +3507,13 @@ func (apm AccountProfileMdls) CSVHeader() (result []string) { return []string{"#" + utils.Tenant, utils.ID, utils.FilterIDs, utils.ActivationIntervalString, utils.Weight, utils.BalanceID, utils.BalanceFilterIDs, utils.BalanceWeight, utils.BalanceBlocker, - utils.BalanceType, utils.BalanceOpts, utils.BalanceValue, + utils.BalanceType, utils.BalanceOpts, utils.BalanceValue, utils.ThresholdIDs, } } func (tps AccountProfileMdls) AsTPAccountProfile() (result []*utils.TPAccountProfile) { filterIDsMap := make(map[string]utils.StringMap) - + thresholdIDsMap := make(map[string]utils.StringMap) actPrfMap := make(map[string]*utils.TPAccountProfile) for _, tp := range tps { tenID := (&utils.TenantID{Tenant: tp.Tenant, ID: tp.ID}).TenantID() @@ -3534,6 +3534,15 @@ func (tps AccountProfileMdls) AsTPAccountProfile() (result []*utils.TPAccountPro filterIDsMap[tenID][filter] = true } } + if tp.ThresholdIDs != utils.EmptyString { + if _, has := thresholdIDsMap[tenID]; !has { + thresholdIDsMap[tenID] = make(utils.StringMap) + } + thresholdSplit := strings.Split(tp.ThresholdIDs, utils.INFIELD_SEP) + for _, thresholdID := range thresholdSplit { + thresholdIDsMap[tenID][thresholdID] = true + } + } if tp.ActivationInterval != utils.EmptyString { aPrf.ActivationInterval = new(utils.TPActivationInterval) aiSplt := strings.Split(tp.ActivationInterval, utils.INFIELD_SEP) @@ -3575,6 +3584,9 @@ func (tps AccountProfileMdls) AsTPAccountProfile() (result []*utils.TPAccountPro for filterID := range filterIDsMap[tntID] { result[i].FilterIDs = append(result[i].FilterIDs, filterID) } + for thresholdID := range thresholdIDsMap[tntID] { + result[i].ThresholdIDs = append(result[i].ThresholdIDs, thresholdID) + } i++ } return @@ -3598,7 +3610,12 @@ func APItoModelTPAccountProfile(tPrf *utils.TPAccountProfile) (mdls AccountProfi } mdl.FilterIDs += val } - + for i, val := range tPrf.ThresholdIDs { + if i != 0 { + mdl.ThresholdIDs += utils.INFIELD_SEP + } + mdl.ThresholdIDs += val + } if tPrf.ActivationInterval != nil { if tPrf.ActivationInterval.ActivationTime != utils.EmptyString { mdl.ActivationInterval = tPrf.ActivationInterval.ActivationTime @@ -3634,7 +3651,8 @@ func APItoAccountProfile(tpAp *utils.TPAccountProfile, timezone string) (ap *uti FilterIDs: make([]string, len(tpAp.FilterIDs)), Weight: tpAp.Weight, - Balances: make([]*utils.Balance, len(tpAp.Balances)), + Balances: make([]*utils.Balance, len(tpAp.Balances)), + ThresholdIDs: make([]string, len(tpAp.ThresholdIDs)), } for i, stp := range tpAp.FilterIDs { ap.FilterIDs[i] = stp @@ -3666,6 +3684,9 @@ func APItoAccountProfile(tpAp *utils.TPAccountProfile, timezone string) (ap *uti } } } + for i, stp := range tpAp.ThresholdIDs { + ap.ThresholdIDs[i] = stp + } return } @@ -3676,8 +3697,8 @@ func AccountProfileToAPI(ap *utils.AccountProfile) (tpAp *utils.TPAccountProfile FilterIDs: make([]string, len(ap.FilterIDs)), ActivationInterval: new(utils.TPActivationInterval), Weight: ap.Weight, - - Balances: make([]*utils.TPAccountBalance, len(ap.Balances)), + Balances: make([]*utils.TPAccountBalance, len(ap.Balances)), + ThresholdIDs: make([]string, len(ap.ThresholdIDs)), } for i, fli := range ap.FilterIDs { tpAp.FilterIDs[i] = fli @@ -3707,5 +3728,8 @@ func AccountProfileToAPI(ap *utils.AccountProfile) (tpAp *utils.TPAccountProfile } tpAp.Balances[i].Opts = strings.Join(elems, utils.INFIELD_SEP) } + for i, fli := range ap.ThresholdIDs { + tpAp.ThresholdIDs[i] = fli + } return } diff --git a/engine/models.go b/engine/models.go index 27e9714d8..dcce95951 100644 --- a/engine/models.go +++ b/engine/models.go @@ -584,6 +584,7 @@ type AccountProfileMdl struct { BalanceType string `index:"9" re:""` BalanceOpts string `index:"10" re:""` BalanceValue float64 `index:"11" re:"\d+\.?\d*"` + ThresholdIDs string `index:"12" re:""` CreatedAt time.Time } diff --git a/utils/accountprofile.go b/utils/accountprofile.go index 180cf6f1b..7e6d1827a 100644 --- a/utils/accountprofile.go +++ b/utils/accountprofile.go @@ -28,6 +28,8 @@ type AccountProfile struct { Weight float64 Balances []*Balance + + ThresholdIDs []string } type Balance struct { diff --git a/utils/apitpdata.go b/utils/apitpdata.go index cfa383b01..e1bdc0ad6 100755 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -1550,6 +1550,7 @@ type TPAccountProfile struct { ActivationInterval *TPActivationInterval Weight float64 Balances []*TPAccountBalance + ThresholdIDs []string } type TPAccountBalance struct {