Add ThresholdIDs to AccountProfiles

This commit is contained in:
TeoV
2020-12-21 17:22:59 +02:00
committed by Dan Christian Bogos
parent 9c5b50a1de
commit 4eefdc9a03
7 changed files with 41 additions and 11 deletions

View File

@@ -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,
1 #Tenant ID FilterIDs ActivationInterval Weight BalanceID BalanceFilterIDs BalanceWeight BalanceBlocker BalanceType BalanceOpts BalanceValue ThresholdIDs
2 cgrates.org 1001 20 MonetaryBalance 10 *monetary 14 *none
3 cgrates.org 1001 VoiceBalance 10 *voice 3600000000000

View File

@@ -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,
`
)

View File

@@ -1648,6 +1648,7 @@ func TestLoadAccountProfiles(t *testing.T) {
Value: 3600000000000,
},
},
ThresholdIDs: []string{utils.META_NONE},
}
if len(csvr.accountProfiles) != 1 {

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -28,6 +28,8 @@ type AccountProfile struct {
Weight float64
Balances []*Balance
ThresholdIDs []string
}
type Balance struct {

View File

@@ -1550,6 +1550,7 @@ type TPAccountProfile struct {
ActivationInterval *TPActivationInterval
Weight float64
Balances []*TPAccountBalance
ThresholdIDs []string
}
type TPAccountBalance struct {