mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 10:06:24 +05:00
AgentRequest FieldAsInterface return Data instead NMItem
This commit is contained in:
committed by
Dan Christian Bogos
parent
eacce5c5fd
commit
109d3c2ea5
@@ -121,6 +121,12 @@ func (ar *AgentRequest) FieldAsInterface(fldPath []string) (val interface{}, err
|
||||
case utils.MetaTrl:
|
||||
val, err = ar.Trailer.FieldAsInterface(fldPath[1:])
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if nmItems, isNMItems := val.(*utils.NMSlice); isNMItems { // special handling of NMItems, take the last value out of it
|
||||
val = (*nmItems)[len(*nmItems)-1].Interface()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -149,9 +155,7 @@ func (ar *AgentRequest) FieldAsString(fldPath []string) (val string, err error)
|
||||
if iface, err = ar.FieldAsInterface(fldPath); err != nil {
|
||||
return
|
||||
}
|
||||
if nmItems, isNMItems := iface.(*utils.NMSlice); isNMItems { // special handling of NMItems, take the last value out of it
|
||||
iface = (*nmItems)[len(*nmItems)-1].Interface()
|
||||
}
|
||||
|
||||
return utils.IfaceAsString(iface), nil
|
||||
}
|
||||
|
||||
|
||||
@@ -963,7 +963,7 @@ func TestAgReqFieldAsInterface(t *testing.T) {
|
||||
|
||||
path := []string{utils.MetaCgreq, utils.Usage}
|
||||
var expVal interface{}
|
||||
expVal = &utils.NMSlice{&config.NMItem{Data: 3 * time.Minute}}
|
||||
expVal = 3 * time.Minute
|
||||
if rply, err := agReq.FieldAsInterface(path); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(rply, expVal) {
|
||||
@@ -971,7 +971,7 @@ func TestAgReqFieldAsInterface(t *testing.T) {
|
||||
}
|
||||
|
||||
path = []string{utils.MetaCgreq, utils.ToR}
|
||||
expVal = &utils.NMSlice{&config.NMItem{Data: utils.VOICE}}
|
||||
expVal = utils.VOICE
|
||||
if rply, err := agReq.FieldAsInterface(path); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(rply, expVal) {
|
||||
@@ -1540,3 +1540,78 @@ func TestAgReqGroupType(t *testing.T) {
|
||||
t.Errorf("expecting: %+v, \n received: %+v ", "test", (*sls)[1].Interface())
|
||||
}
|
||||
}
|
||||
|
||||
func TestAgReqFiltersInsideField(t *testing.T) {
|
||||
//simulate the diameter request
|
||||
m := diam.NewRequest(diam.CreditControl, 4, nil)
|
||||
m.NewAVP(avp.SessionID, avp.Mbit, 0, datatype.UTF8String("bb97be2b9f37c2be9614fff71c8b1d08b1acbff8"))
|
||||
m.NewAVP(avp.OriginHost, avp.Mbit, 0, datatype.DiameterIdentity("192.168.1.1"))
|
||||
m.NewAVP(avp.OriginRealm, avp.Mbit, 0, datatype.DiameterIdentity("cgrates.org"))
|
||||
m.NewAVP(avp.AuthApplicationID, avp.Mbit, 0, datatype.Unsigned32(4))
|
||||
m.NewAVP(avp.CCRequestType, avp.Mbit, 0, datatype.Enumerated(3))
|
||||
m.NewAVP(avp.CCRequestNumber, avp.Mbit, 0, datatype.Unsigned32(2))
|
||||
m.NewAVP(avp.DestinationHost, avp.Mbit, 0, datatype.DiameterIdentity("CGR-DA"))
|
||||
m.NewAVP(avp.DestinationRealm, avp.Mbit, 0, datatype.DiameterIdentity("cgrates.org"))
|
||||
m.NewAVP(avp.ServiceContextID, avp.Mbit, 0, datatype.UTF8String("voice@DiamItCCRInit"))
|
||||
m.NewAVP(avp.EventTimestamp, avp.Mbit, 0, datatype.Time(time.Date(2018, 10, 4, 15, 12, 20, 0, time.UTC)))
|
||||
m.NewAVP(avp.SubscriptionID, avp.Mbit, 0, &diam.GroupedAVP{
|
||||
AVP: []*diam.AVP{
|
||||
diam.NewAVP(450, avp.Mbit, 0, datatype.Enumerated(0)), // Subscription-Id-Type
|
||||
diam.NewAVP(444, avp.Mbit, 0, datatype.UTF8String("1006")), // Subscription-Id-Data
|
||||
}})
|
||||
m.NewAVP(avp.ServiceIdentifier, avp.Mbit, 0, datatype.Unsigned32(0))
|
||||
m.NewAVP(avp.RequestedServiceUnit, avp.Mbit, 0, &diam.GroupedAVP{
|
||||
AVP: []*diam.AVP{
|
||||
diam.NewAVP(420, avp.Mbit, 0, datatype.Unsigned32(0))}})
|
||||
m.NewAVP(avp.UsedServiceUnit, avp.Mbit, 0, &diam.GroupedAVP{
|
||||
AVP: []*diam.AVP{
|
||||
diam.NewAVP(420, avp.Mbit, 0, datatype.Unsigned32(250))}})
|
||||
m.NewAVP(873, avp.Mbit, 10415, &diam.GroupedAVP{
|
||||
AVP: []*diam.AVP{
|
||||
diam.NewAVP(20300, avp.Mbit, 2011, &diam.GroupedAVP{ // IN-Information
|
||||
AVP: []*diam.AVP{
|
||||
diam.NewAVP(831, avp.Mbit, 10415, datatype.UTF8String("1006")), // Calling-Party-Address
|
||||
diam.NewAVP(832, avp.Mbit, 10415, datatype.UTF8String("1002")), // Called-Party-Address
|
||||
diam.NewAVP(20327, avp.Mbit, 2011, datatype.UTF8String("1002")), // Real-Called-Number
|
||||
diam.NewAVP(20339, avp.Mbit, 2011, datatype.Unsigned32(0)), // Charge-Flow-Type
|
||||
diam.NewAVP(20302, avp.Mbit, 2011, datatype.UTF8String("")), // Calling-Vlr-Number
|
||||
diam.NewAVP(20303, avp.Mbit, 2011, datatype.UTF8String("")), // Calling-CellID-Or-SAI
|
||||
diam.NewAVP(20313, avp.Mbit, 2011, datatype.OctetString("")), // Bearer-Capability
|
||||
diam.NewAVP(20321, avp.Mbit, 2011, datatype.UTF8String("bb97be2b9f37c2be9614fff71c8b1d08b1acbff8")), // Call-Reference-Number
|
||||
diam.NewAVP(20322, avp.Mbit, 2011, datatype.UTF8String("")), // MSC-Address
|
||||
diam.NewAVP(20324, avp.Mbit, 2011, datatype.Unsigned32(0)), // Time-Zone
|
||||
diam.NewAVP(20385, avp.Mbit, 2011, datatype.UTF8String("")), // Called-Party-NP
|
||||
diam.NewAVP(20386, avp.Mbit, 2011, datatype.UTF8String("")), // SSP-Time
|
||||
},
|
||||
}),
|
||||
}})
|
||||
//create diameterDataProvider
|
||||
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)
|
||||
//pass the data provider to agent request
|
||||
agReq := NewAgentRequest(newDADataProvider(nil, m), nil, nil, nil, nil, "cgrates.org", "", filterS, nil, nil)
|
||||
|
||||
tplFlds := []*config.FCTemplate{
|
||||
{Tag: "Usage",
|
||||
Path: utils.MetaCgreq + utils.NestingSep + utils.Usage, Type: utils.MetaCCUsage,
|
||||
Value: config.NewRSRParsersMustCompile("~*req.CC-Request-Number;~*req.Used-Service-Unit.CC-Time:s/(.*)/${1}s/;5m",
|
||||
true, utils.INFIELD_SEP)},
|
||||
{Tag: "AnswerTime",
|
||||
Path: utils.MetaCgreq + utils.NestingSep + utils.AnswerTime, Type: utils.MetaDifference,
|
||||
Filters: []string{"*gt:~*cgreq.Usage:0s"}, // populate answer time if usage is greater than zero
|
||||
Value: config.NewRSRParsersMustCompile("~*req.Event-Timestamp;~*cgreq.Usage", true, utils.INFIELD_SEP)},
|
||||
}
|
||||
for _, v := range tplFlds {
|
||||
v.ComputePath()
|
||||
}
|
||||
if err := agReq.SetFields(tplFlds); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if val, err := agReq.FieldAsInterface([]string{utils.MetaCgreq, utils.AnswerTime}); err != nil {
|
||||
t.Error(err)
|
||||
} else if !val.(time.Time).Equal(time.Date(2018, 10, 4, 15, 3, 10, 0, time.UTC)) {
|
||||
t.Errorf("expecting: %+v, \n received: %+v ", time.Date(2018, 10, 4, 15, 3, 10, 0, time.UTC), val)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ cgrates (0.10.1~dev) UNRELEASED; urgency=medium
|
||||
* [Templates] Fixed missing "*" for strip and padding strategy
|
||||
* [SessionS] Update subflags for *rals ( *authorize and *initiate )
|
||||
* [AgentRequest] Improved NavigableMap
|
||||
* [AgentRequest] FieldAsInterface return Data instead of NMItem
|
||||
|
||||
-- Alexandru Tripon <alexandru.tripon@itsyscom.com> Wed, 19 Feb 2020 15:22:59 +0200
|
||||
|
||||
|
||||
Reference in New Issue
Block a user