mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-14 12:49:54 +05:00
Added *sipcid field type
This commit is contained in:
committed by
Dan Christian Bogos
parent
2a00b1cd5e
commit
cd7119c1ef
@@ -21,6 +21,7 @@ package engine
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -246,6 +247,15 @@ func (alS *AttributeService) processEvent(args *AttrArgsProcessEvent) (
|
||||
}
|
||||
substitute = strconv.FormatFloat(utils.Round(val*math.Pow10(exp),
|
||||
config.CgrConfig().GeneralCfg().RoundingDecimals, utils.ROUNDING_MIDDLE), 'f', -1, 64)
|
||||
case utils.MetaSIPCID:
|
||||
values := make([]string, len(attribute.Value))
|
||||
for i, val := range attribute.Value {
|
||||
if values[i], err = val.ParseDataProvider(evNm, utils.NestingSep); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
sort.Strings(values[1:])
|
||||
substitute = strings.Join(values, utils.INFIELD_SEP)
|
||||
default: // backwards compatible in case that Type is empty
|
||||
substitute, err = attribute.Value.ParseDataProvider(evNm, utils.NestingSep)
|
||||
}
|
||||
|
||||
@@ -1852,3 +1852,98 @@ func TestGetAttributeProfileFromInline(t *testing.T) {
|
||||
t.Errorf("Expecting %+v, received: %+v", utils.ToJSON(expAttrPrf1), utils.ToJSON(attr))
|
||||
}
|
||||
}
|
||||
|
||||
func TestAttributesProcessEventSIPCID(t *testing.T) {
|
||||
//refresh the DM
|
||||
if err := dmAtr.DataDB().Flush(""); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
Cache.Clear(nil)
|
||||
if test, err := dmAtr.DataDB().IsDBEmpty(); err != nil {
|
||||
t.Error(err)
|
||||
} else if test != true {
|
||||
t.Errorf("\nExpecting: true got :%+v", test)
|
||||
}
|
||||
attrPrf1 := &AttributeProfile{
|
||||
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
|
||||
ID: "ATTR_1",
|
||||
Contexts: []string{utils.MetaSessionS},
|
||||
Attributes: []*Attribute{
|
||||
{
|
||||
Path: utils.MetaReq + utils.NestingSep + "OriginID",
|
||||
Type: utils.MetaSIPCID,
|
||||
Value: config.NewRSRParsersMustCompile("~*req.cid;~*req.to;~*req.from", true, utils.INFIELD_SEP),
|
||||
},
|
||||
},
|
||||
Blocker: true,
|
||||
Weight: 10,
|
||||
}
|
||||
// Add attribute in DM
|
||||
if err := dmAtr.SetAttributeProfile(attrPrf1, true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
attrArgs := &AttrArgsProcessEvent{
|
||||
Context: utils.StringPointer(utils.MetaSessionS),
|
||||
ProcessRuns: utils.IntPointer(1),
|
||||
CGREvent: &utils.CGREvent{
|
||||
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
|
||||
ID: utils.GenUUID(),
|
||||
Event: map[string]interface{}{
|
||||
"cid": "12345",
|
||||
"to": "1001",
|
||||
"from": "1002",
|
||||
},
|
||||
},
|
||||
}
|
||||
eRply := &AttrSProcessEventReply{
|
||||
MatchedProfiles: []string{"ATTR_1"},
|
||||
AlteredFields: []string{utils.MetaReq + utils.NestingSep + "OriginID"},
|
||||
CGREvent: &utils.CGREvent{
|
||||
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
|
||||
ID: utils.GenUUID(),
|
||||
Event: map[string]interface{}{
|
||||
"cid": "12345",
|
||||
"to": "1001",
|
||||
"from": "1002",
|
||||
"OriginID": "12345;1001;1002",
|
||||
},
|
||||
},
|
||||
}
|
||||
var reply AttrSProcessEventReply
|
||||
if err := attrService.V1ProcessEvent(attrArgs, &reply); err != nil {
|
||||
t.Errorf("Error: %+v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) {
|
||||
t.Errorf("Expecting %+v, received: %+v", eRply.MatchedProfiles, reply.MatchedProfiles)
|
||||
}
|
||||
if !reflect.DeepEqual(eRply.AlteredFields, reply.AlteredFields) {
|
||||
t.Errorf("Expecting %+v, received: %+v", eRply.AlteredFields, reply.AlteredFields)
|
||||
}
|
||||
if !reflect.DeepEqual(eRply.CGREvent.Event, reply.CGREvent.Event) {
|
||||
t.Errorf("Expecting %+v, received: %+v", eRply.CGREvent.Event, reply.CGREvent.Event)
|
||||
}
|
||||
|
||||
attrArgs.CGREvent.Event = map[string]interface{}{
|
||||
"cid": "12345",
|
||||
"to": "1002",
|
||||
"from": "1001",
|
||||
}
|
||||
eRply.CGREvent.Event = map[string]interface{}{
|
||||
"cid": "12345",
|
||||
"to": "1002",
|
||||
"from": "1001",
|
||||
"OriginID": "12345;1001;1002",
|
||||
}
|
||||
if err := attrService.V1ProcessEvent(attrArgs, &reply); err != nil {
|
||||
t.Errorf("Error: %+v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) {
|
||||
t.Errorf("Expecting %+v, received: %+v", eRply.MatchedProfiles, reply.MatchedProfiles)
|
||||
}
|
||||
if !reflect.DeepEqual(eRply.AlteredFields, reply.AlteredFields) {
|
||||
t.Errorf("Expecting %+v, received: %+v", eRply.AlteredFields, reply.AlteredFields)
|
||||
}
|
||||
if !reflect.DeepEqual(eRply.CGREvent.Event, reply.CGREvent.Event) {
|
||||
t.Errorf("Expecting %+v, received: %+v", eRply.CGREvent.Event, reply.CGREvent.Event)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user