Added *sipcid field type

This commit is contained in:
Trial97
2021-07-01 12:31:45 +03:00
committed by Dan Christian Bogos
parent 2a00b1cd5e
commit cd7119c1ef
5 changed files with 159 additions and 0 deletions

View File

@@ -22,6 +22,7 @@ import (
"fmt"
"math"
"net"
"sort"
"strconv"
"strings"
"time"
@@ -429,6 +430,16 @@ func (ar *AgentRequest) ParseField(
return nil, err
}
out = strconv.Itoa(int(t.Unix()))
case utils.MetaSIPCID:
isString = true
values := make([]string, len(cfgFld.Value))
for i, val := range cfgFld.Value {
if values[i], err = val.ParseDataProvider(ar, utils.NestingSep); err != nil {
return nil, err
}
}
sort.Strings(values[1:])
out = strings.Join(values, utils.INFIELD_SEP)
}
if err != nil &&

View File

@@ -1734,3 +1734,45 @@ func BenchmarkAgReqSetField(b *testing.B) {
}
}
}
func TestAgReqSetFieldsSIPCID(t *testing.T) {
cfg, _ := config.NewDefaultCGRConfig()
data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
dm := engine.NewDataManager(data, config.CgrConfig().CacheCfg(), nil)
filterS := engine.NewFilterS(cfg, nil, dm)
agReq := NewAgentRequest(nil, nil, nil, nil, nil, "cgrates.org", "", filterS, nil, nil)
agReq.CGRRequest.Set(&utils.FullPath{Path: "cid", PathItems: utils.PathItems{{Field: "cid"}}}, utils.NewNMData("12345"))
agReq.CGRRequest.Set(&utils.FullPath{Path: "to", PathItems: utils.PathItems{{Field: "to"}}}, utils.NewNMData("1001"))
agReq.CGRRequest.Set(&utils.FullPath{Path: "from", PathItems: utils.PathItems{{Field: "from"}}}, utils.NewNMData("1002"))
tplFlds := []*config.FCTemplate{
{Tag: "OriginID",
Path: utils.MetaVars + utils.NestingSep + "OriginID", Type: utils.MetaSIPCID,
Value: config.NewRSRParsersMustCompile("~*cgreq.cid;~*cgreq.to;~*cgreq.from", true, utils.INFIELD_SEP)},
}
for _, v := range tplFlds {
v.ComputePath()
}
eMp := utils.NavigableMap2{}
eMp.Set(utils.PathItems{{Field: utils.NodeID}}, utils.NewNMData(config.CgrConfig().GeneralCfg().NodeID))
eMp.Set(utils.PathItems{{Field: "OriginID"}}, &utils.NMSlice{
&config.NMItem{Data: "12345;1001;1002", Path: []string{"OriginID"},
Config: tplFlds[0]}})
if err := agReq.SetFields(tplFlds); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(agReq.Vars, eMp) {
t.Errorf("expecting: %+v,\n received: %+v", eMp, agReq.Vars)
}
agReq = NewAgentRequest(nil, nil, nil, nil, nil, "cgrates.org", "", filterS, nil, nil)
agReq.CGRRequest.Set(&utils.FullPath{Path: "cid", PathItems: utils.PathItems{{Field: "cid"}}}, utils.NewNMData("12345"))
agReq.CGRRequest.Set(&utils.FullPath{Path: "to", PathItems: utils.PathItems{{Field: "to"}}}, utils.NewNMData("1002"))
agReq.CGRRequest.Set(&utils.FullPath{Path: "from", PathItems: utils.PathItems{{Field: "from"}}}, utils.NewNMData("1001"))
if err := agReq.SetFields(tplFlds); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(agReq.Vars, eMp) {
t.Errorf("expecting: %+v,\n received: %+v", eMp, agReq.Vars)
}
}