mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added *sipcid field type
This commit is contained in:
committed by
Dan Christian Bogos
parent
2f61746959
commit
b6de12b643
@@ -781,7 +781,8 @@ func (cfg *CGRConfig) checkConfigSanity() error {
|
||||
field.Type == utils.MetaMultiply ||
|
||||
field.Type == utils.MetaDivide ||
|
||||
field.Type == utils.MetaValueExponent ||
|
||||
field.Type == utils.MetaUnixTimestamp {
|
||||
field.Type == utils.MetaUnixTimestamp ||
|
||||
field.Type == utils.MetaSIPCID {
|
||||
for _, val := range field.Value {
|
||||
if err := utils.IsPathValidForExporters(val.path); err != nil {
|
||||
return fmt.Errorf("<%s> %s for %s at %s of %s", utils.ERs, err, val.path, utils.Values, utils.CacheDumpFieldsCfg)
|
||||
@@ -809,7 +810,8 @@ func (cfg *CGRConfig) checkConfigSanity() error {
|
||||
field.Type == utils.MetaMultiply ||
|
||||
field.Type == utils.MetaDivide ||
|
||||
field.Type == utils.MetaValueExponent ||
|
||||
field.Type == utils.MetaUnixTimestamp {
|
||||
field.Type == utils.MetaUnixTimestamp ||
|
||||
field.Type == utils.MetaSIPCID {
|
||||
for _, val := range field.Value {
|
||||
if err := utils.IsPathValidForExporters(val.path); err != nil {
|
||||
return fmt.Errorf("<%s> %s for %s at %s of %s", utils.ERs, err, val.path, utils.Values, utils.FieldsCfg)
|
||||
@@ -879,7 +881,8 @@ func (cfg *CGRConfig) checkConfigSanity() error {
|
||||
field.Type == utils.MetaMultiply ||
|
||||
field.Type == utils.MetaDivide ||
|
||||
field.Type == utils.MetaValueExponent ||
|
||||
field.Type == utils.MetaUnixTimestamp {
|
||||
field.Type == utils.MetaUnixTimestamp ||
|
||||
field.Type == utils.MetaSIPCID {
|
||||
for _, val := range field.Value {
|
||||
if err := utils.IsPathValidForExporters(val.path); err != nil {
|
||||
return fmt.Errorf("<%s> %s for %s at %s of %s", utils.EEs, err, val.path, utils.Values, utils.FieldsCfg)
|
||||
|
||||
@@ -21,6 +21,7 @@ package engine
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -542,6 +543,15 @@ func ParseAttribute(dp utils.DataProvider, attrType, path string, value config.R
|
||||
reqNr = 0
|
||||
}
|
||||
return usedCCTime + time.Duration(debitItvl.Nanoseconds()*reqNr), nil
|
||||
case utils.MetaSIPCID:
|
||||
values := make([]string, len(value))
|
||||
for i, val := range value {
|
||||
if values[i], err = val.ParseDataProvider(dp); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
sort.Strings(values[1:])
|
||||
out = strings.Join(values, utils.InfieldSep)
|
||||
default:
|
||||
return utils.EmptyString, fmt.Errorf("unsupported type: <%s>", attrType)
|
||||
}
|
||||
|
||||
@@ -1169,3 +1169,75 @@ func TestAttributesattributeProfileForEventErrPass(t *testing.T) {
|
||||
t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", nil, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAttributesParseAttributeSIPCID(t *testing.T) {
|
||||
exp := "12345;1001;1002"
|
||||
dp := utils.MapStorage{
|
||||
utils.MetaReq: utils.MapStorage{
|
||||
"cid": "12345",
|
||||
"to": "1001",
|
||||
"from": "1002",
|
||||
},
|
||||
}
|
||||
if out, err := ParseAttribute(dp, utils.MetaSIPCID, utils.EmptyString, config.NewRSRParsersMustCompile("~*req.cid;~*req.to;~*req.from", utils.InfieldSep),
|
||||
0, utils.EmptyString, utils.EmptyString, utils.InfieldSep); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if exp != out {
|
||||
t.Errorf("Expected %q, Received %q", exp, out)
|
||||
}
|
||||
|
||||
dp = utils.MapStorage{
|
||||
utils.MetaReq: utils.MapStorage{
|
||||
"cid": "12345",
|
||||
"to": "1002",
|
||||
"from": "1001",
|
||||
},
|
||||
}
|
||||
if out, err := ParseAttribute(dp, utils.MetaSIPCID, utils.EmptyString, config.NewRSRParsersMustCompile("~*req.cid;~*req.to;~*req.from", utils.InfieldSep),
|
||||
0, utils.EmptyString, utils.EmptyString, utils.InfieldSep); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if exp != out {
|
||||
t.Errorf("Expected %q, Received %q", exp, out)
|
||||
}
|
||||
|
||||
exp = "12345;1001;1002;1003"
|
||||
dp = utils.MapStorage{
|
||||
utils.MetaReq: utils.MapStorage{
|
||||
"cid": "12345",
|
||||
"to": "1001",
|
||||
"from": "1002",
|
||||
"extra": "1003",
|
||||
},
|
||||
}
|
||||
if out, err := ParseAttribute(dp, utils.MetaSIPCID, utils.EmptyString, config.NewRSRParsersMustCompile("~*req.cid;~*req.to;~*req.extra;~*req.from",
|
||||
utils.InfieldSep), 0, utils.EmptyString, utils.EmptyString, utils.InfieldSep); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if exp != out {
|
||||
t.Errorf("Expected %q, Received %q", exp, out)
|
||||
}
|
||||
|
||||
dp = utils.MapStorage{
|
||||
utils.MetaReq: utils.MapStorage{
|
||||
"cid": "12345",
|
||||
"to": "1002",
|
||||
"from": "1001",
|
||||
"extra": "1003",
|
||||
},
|
||||
}
|
||||
if out, err := ParseAttribute(dp, utils.MetaSIPCID, utils.EmptyString, config.NewRSRParsersMustCompile("~*req.cid;~*req.extra;~*req.to;~*req.from",
|
||||
utils.InfieldSep), 0, utils.EmptyString, utils.EmptyString, utils.InfieldSep); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if exp != out {
|
||||
t.Errorf("Expected %q, Received %q", exp, out)
|
||||
}
|
||||
|
||||
dp = utils.MapStorage{
|
||||
utils.MetaReq: utils.MapStorage{
|
||||
"cid": "12345",
|
||||
},
|
||||
}
|
||||
if _, err := ParseAttribute(dp, utils.MetaSIPCID, utils.EmptyString, config.NewRSRParsersMustCompile("~*req.cid;~*req.extra;~*req.to;~*req.from", utils.
|
||||
InfieldSep), 0, utils.EmptyString, utils.EmptyString, utils.InfieldSep); err != utils.ErrNotFound {
|
||||
t.Errorf("Expected <%+v>, received <%+v>", utils.ErrNotFound, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -422,6 +422,7 @@ const (
|
||||
MetaDifference = "*difference"
|
||||
MetaVariable = "*variable"
|
||||
MetaCCUsage = "*cc_usage"
|
||||
MetaSIPCID = "*sipcid"
|
||||
MetaValueExponent = "*value_exponent"
|
||||
NegativePrefix = "!"
|
||||
MatchStartPrefix = "^"
|
||||
@@ -2714,6 +2715,7 @@ var StringTmplType = StringSet{
|
||||
MetaUsageDifference: struct{}{},
|
||||
MetaPrefix: struct{}{},
|
||||
MetaSuffix: struct{}{},
|
||||
MetaSIPCID: struct{}{},
|
||||
}
|
||||
|
||||
// Time duration suffix
|
||||
|
||||
Reference in New Issue
Block a user