mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-21 15:18:44 +05:00
RequestFilter with *destinations type
This commit is contained in:
@@ -106,30 +106,32 @@ func (fltr *RequestFilter) passTimings(req interface{}, extraFieldsLabel string)
|
||||
return false, utils.ErrNotImplemented
|
||||
}
|
||||
|
||||
// ToDo
|
||||
func (fltr *RequestFilter) passDestinations(req interface{}, extraFieldsLabel string) (bool, error) {
|
||||
/*for _, p := range utils.SplitPrefix(cd.Destination, MIN_PREFIX_MATCH) {
|
||||
if x, err := CacheGet(utils.DESTINATION_PREFIX + p); err == nil {
|
||||
destIds := x.(map[string]struct{})
|
||||
var bestWeight float64
|
||||
for dID := range destIds {
|
||||
if _, ok := rpl.DestinationRates[dID]; ok {
|
||||
ril := rpl.RateIntervalList(dID)
|
||||
currentWeight := ril.GetWeight()
|
||||
if currentWeight > bestWeight {
|
||||
bestWeight = currentWeight
|
||||
rps = ril
|
||||
prefix = p
|
||||
destinationId = dID
|
||||
dst, err := utils.ReflectFieldAsString(req, fltr.FieldName, extraFieldsLabel)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
var matched bool
|
||||
for _, p := range utils.SplitPrefix(dst, MIN_PREFIX_MATCH) {
|
||||
if x, err := CacheGet(utils.DESTINATION_PREFIX + p); err == nil {
|
||||
destIds := x.(map[string]struct{})
|
||||
for dID := range destIds {
|
||||
for _, valDstID := range fltr.Values {
|
||||
if valDstID == dID {
|
||||
matched = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if matched {
|
||||
break
|
||||
}
|
||||
}
|
||||
if matched {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if rps != nil {
|
||||
break
|
||||
}
|
||||
*/
|
||||
return false, utils.ErrNotImplemented
|
||||
return matched, nil
|
||||
}
|
||||
|
||||
func (fltr *RequestFilter) passRSRFields(req interface{}, extraFieldsLabel string) (bool, error) {
|
||||
|
||||
@@ -97,3 +97,29 @@ func TestPassRSRFields(t *testing.T) {
|
||||
t.Error("Not passing")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPassDestinations(t *testing.T) {
|
||||
x := struct{}{}
|
||||
CacheSet(utils.DESTINATION_PREFIX+"+49", map[string]struct{}{"DE": x, "EU_LANDLINE": x})
|
||||
cd := &CallDescriptor{Direction: "*out", Category: "call", Tenant: "cgrates.org", Subject: "dan", Destination: "+4986517174963",
|
||||
TimeStart: time.Date(2013, time.October, 7, 14, 50, 0, 0, time.UTC), TimeEnd: time.Date(2013, time.October, 7, 14, 52, 12, 0, time.UTC),
|
||||
DurationIndex: 132 * time.Second, ExtraFields: map[string]string{"navigation": "off"}}
|
||||
rf, err := NewRequestFilter(MetaDestinations, "Destination", []string{"DE"}, nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if passes, err := rf.passDestinations(cd, "ExtraFields"); err != nil {
|
||||
t.Error(err)
|
||||
} else if !passes {
|
||||
t.Error("Not passing")
|
||||
}
|
||||
rf, err = NewRequestFilter(MetaDestinations, "Destination", []string{"RO"}, nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if passes, err := rf.passDestinations(cd, "ExtraFields"); err != nil {
|
||||
t.Error(err)
|
||||
} else if passes {
|
||||
t.Error("Passing")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user