mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Updated filter CSV loading
This commit is contained in:
committed by
Dan Christian Bogos
parent
243242360f
commit
93e79b3b88
@@ -1693,6 +1693,7 @@ func (tps FilterMdls) CSVHeader() (result []string) {
|
||||
|
||||
func (tps FilterMdls) AsTPFilter() (result []*utils.TPFilterProfile) {
|
||||
mst := make(map[string]*utils.TPFilterProfile)
|
||||
filterRules := make(map[string]*utils.TPFilter)
|
||||
for _, tp := range tps {
|
||||
tenID := (&utils.TenantID{Tenant: tp.Tenant, ID: tp.ID}).TenantID()
|
||||
th, found := mst[tenID]
|
||||
@@ -1718,11 +1719,18 @@ func (tps FilterMdls) AsTPFilter() (result []*utils.TPFilterProfile) {
|
||||
if tp.Values != utils.EmptyString {
|
||||
vals = splitDynFltrValues(tp.Values, utils.InfieldSep)
|
||||
}
|
||||
th.Filters = append(th.Filters, &utils.TPFilter{
|
||||
Type: tp.Type,
|
||||
Element: tp.Element,
|
||||
Values: vals,
|
||||
})
|
||||
key := utils.ConcatenatedKey(tenID, tp.Type, tp.Element)
|
||||
if f, has := filterRules[key]; has {
|
||||
f.Values = append(f.Values, vals...)
|
||||
} else {
|
||||
f = &utils.TPFilter{
|
||||
Type: tp.Type,
|
||||
Element: tp.Element,
|
||||
Values: vals,
|
||||
}
|
||||
th.Filters = append(th.Filters, f)
|
||||
filterRules[key] = f
|
||||
}
|
||||
}
|
||||
mst[tenID] = th
|
||||
}
|
||||
|
||||
@@ -2651,6 +2651,67 @@ func TestTPFilterAsTPFilter2(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTPFilterAsTPFilter3(t *testing.T) {
|
||||
tps := []*FilterMdl{
|
||||
{
|
||||
Tpid: "TEST_TPID",
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Filter1",
|
||||
Type: utils.MetaPrefix,
|
||||
Element: "Account",
|
||||
Values: "1001",
|
||||
},
|
||||
{
|
||||
Tpid: "TEST_TPID",
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Filter1",
|
||||
Type: utils.MetaPrefix,
|
||||
Element: "Account",
|
||||
Values: "1001",
|
||||
},
|
||||
{
|
||||
Tpid: "TEST_TPID",
|
||||
Tenant: "anotherTenant",
|
||||
ID: "Filter1",
|
||||
Type: utils.MetaPrefix,
|
||||
Element: "Account",
|
||||
Values: "1010",
|
||||
},
|
||||
}
|
||||
eTPs := []*utils.TPFilterProfile{
|
||||
{
|
||||
TPid: tps[0].Tpid,
|
||||
Tenant: "cgrates.org",
|
||||
ID: tps[0].ID,
|
||||
Filters: []*utils.TPFilter{
|
||||
{
|
||||
Type: utils.MetaPrefix,
|
||||
Element: "Account",
|
||||
Values: []string{"1001", "1002"},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
TPid: tps[1].Tpid,
|
||||
Tenant: "anotherTenant",
|
||||
ID: tps[1].ID,
|
||||
Filters: []*utils.TPFilter{
|
||||
{
|
||||
Type: utils.MetaPrefix,
|
||||
Element: "Account",
|
||||
Values: []string{"1010"},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
rcvTPs := FilterMdls(tps).AsTPFilter()
|
||||
sort.Strings(rcvTPs[0].Filters[0].Values)
|
||||
if len(eTPs) != len(rcvTPs) {
|
||||
t.Errorf("Expecting: %+v ,Received: %+v", utils.ToIJSON(eTPs), utils.ToIJSON(rcvTPs))
|
||||
}
|
||||
}
|
||||
|
||||
func TestAPItoModelTPFilter(t *testing.T) {
|
||||
var th *utils.TPFilterProfile
|
||||
if rcv := APItoModelTPFilter(th); rcv != nil {
|
||||
|
||||
Reference in New Issue
Block a user