mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
lcr load and torfield to categoryfield
This commit is contained in:
@@ -649,6 +649,7 @@ func (self *ApierV1) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder,
|
||||
path.Join(attrs.FolderPath, utils.RATING_PLANS_CSV),
|
||||
path.Join(attrs.FolderPath, utils.RATING_PROFILES_CSV),
|
||||
path.Join(attrs.FolderPath, utils.SHARED_GROUPS_CSV),
|
||||
path.Join(attrs.FolderPath, utils.LCRS_CSV),
|
||||
path.Join(attrs.FolderPath, utils.ACTIONS_CSV),
|
||||
path.Join(attrs.FolderPath, utils.ACTION_PLANS_CSV),
|
||||
path.Join(attrs.FolderPath, utils.ACTION_TRIGGERS_CSV),
|
||||
|
||||
@@ -86,7 +86,7 @@ func (self *Cdrc) parseFieldsConfig() error {
|
||||
utils.REQTYPE: self.cgrCfg.CdrcReqTypeField,
|
||||
utils.DIRECTION: self.cgrCfg.CdrcDirectionField,
|
||||
utils.TENANT: self.cgrCfg.CdrcTenantField,
|
||||
utils.Category: self.cgrCfg.CdrcTorField,
|
||||
utils.Category: self.cgrCfg.CdrcCategoryField,
|
||||
utils.ACCOUNT: self.cgrCfg.CdrcAccountField,
|
||||
utils.SUBJECT: self.cgrCfg.CdrcSubjectField,
|
||||
utils.DESTINATION: self.cgrCfg.CdrcDestinationField,
|
||||
|
||||
@@ -109,7 +109,7 @@ type CGRConfig struct {
|
||||
CdrcReqTypeField string // Request type field identifier. Use index number in case of .csv cdrs.
|
||||
CdrcDirectionField string // Direction field identifier. Use index numbers in case of .csv cdrs.
|
||||
CdrcTenantField string // Tenant field identifier. Use index numbers in case of .csv cdrs.
|
||||
CdrcTorField string // Type of Record field identifier. Use index numbers in case of .csv cdrs.
|
||||
CdrcCategoryField string // Type of Record field identifier. Use index numbers in case of .csv cdrs.
|
||||
CdrcAccountField string // Account field identifier. Use index numbers in case of .csv cdrs.
|
||||
CdrcSubjectField string // Subject field identifier. Use index numbers in case of .csv CDRs.
|
||||
CdrcDestinationField string // Destination field identifier. Use index numbers in case of .csv cdrs.
|
||||
@@ -196,7 +196,7 @@ func (self *CGRConfig) setDefaults() error {
|
||||
self.CdrcReqTypeField = "1"
|
||||
self.CdrcDirectionField = "2"
|
||||
self.CdrcTenantField = "3"
|
||||
self.CdrcTorField = "4"
|
||||
self.CdrcCategoryField = "4"
|
||||
self.CdrcAccountField = "5"
|
||||
self.CdrcSubjectField = "6"
|
||||
self.CdrcDestinationField = "7"
|
||||
@@ -496,7 +496,7 @@ func loadConfig(c *conf.ConfigFile) (*CGRConfig, error) {
|
||||
cfg.CdrcTenantField, _ = c.GetString("cdrc", "tenant_field")
|
||||
}
|
||||
if hasOpt = c.HasOption("cdrc", "tor_field"); hasOpt {
|
||||
cfg.CdrcTorField, _ = c.GetString("cdrc", "tor_field")
|
||||
cfg.CdrcCategoryField, _ = c.GetString("cdrc", "tor_field")
|
||||
}
|
||||
if hasOpt = c.HasOption("cdrc", "account_field"); hasOpt {
|
||||
cfg.CdrcAccountField, _ = c.GetString("cdrc", "account_field")
|
||||
|
||||
@@ -99,7 +99,7 @@ func TestDefaults(t *testing.T) {
|
||||
eCfg.CdrcReqTypeField = "1"
|
||||
eCfg.CdrcDirectionField = "2"
|
||||
eCfg.CdrcTenantField = "3"
|
||||
eCfg.CdrcTorField = "4"
|
||||
eCfg.CdrcCategoryField = "4"
|
||||
eCfg.CdrcAccountField = "5"
|
||||
eCfg.CdrcSubjectField = "6"
|
||||
eCfg.CdrcDestinationField = "7"
|
||||
@@ -233,7 +233,7 @@ func TestConfigFromFile(t *testing.T) {
|
||||
eCfg.CdrcReqTypeField = "test"
|
||||
eCfg.CdrcDirectionField = "test"
|
||||
eCfg.CdrcTenantField = "test"
|
||||
eCfg.CdrcTorField = "test"
|
||||
eCfg.CdrcCategoryField = "test"
|
||||
eCfg.CdrcAccountField = "test"
|
||||
eCfg.CdrcSubjectField = "test"
|
||||
eCfg.CdrcDestinationField = "test"
|
||||
@@ -254,7 +254,7 @@ func TestConfigFromFile(t *testing.T) {
|
||||
eCfg.FreeswitchPass = "test"
|
||||
eCfg.FreeswitchReconnects = 99
|
||||
eCfg.DerivedChargers = utils.DerivedChargers{&utils.DerivedCharger{RunId: "test", ReqTypeField: "test", DirectionField: "test", TenantField: "test",
|
||||
TorField: "test", AccountField: "test", SubjectField: "test", DestinationField: "test", SetupTimeField: "test", AnswerTimeField: "test", DurationField: "test"}}
|
||||
CategoryField: "test", AccountField: "test", SubjectField: "test", DestinationField: "test", SetupTimeField: "test", AnswerTimeField: "test", DurationField: "test"}}
|
||||
eCfg.CombinedDerivedChargers = true
|
||||
eCfg.HistoryAgentEnabled = true
|
||||
eCfg.HistoryServer = "test"
|
||||
|
||||
@@ -53,9 +53,9 @@ answer_time_fields = test1, test2
|
||||
duration_fields = test1, test2
|
||||
`)
|
||||
edcs := utils.DerivedChargers{
|
||||
&utils.DerivedCharger{RunId: "run1", ReqTypeField: "test1", DirectionField: "test1", TenantField: "test1", TorField: "test1",
|
||||
&utils.DerivedCharger{RunId: "run1", ReqTypeField: "test1", DirectionField: "test1", TenantField: "test1", CategoryField: "test1",
|
||||
AccountField: "test1", SubjectField: "test1", DestinationField: "test1", SetupTimeField: "test1", AnswerTimeField: "test1", DurationField: "test1"},
|
||||
&utils.DerivedCharger{RunId: "run2", ReqTypeField: "test2", DirectionField: "test2", TenantField: "test2", TorField: "test2",
|
||||
&utils.DerivedCharger{RunId: "run2", ReqTypeField: "test2", DirectionField: "test2", TenantField: "test2", CategoryField: "test2",
|
||||
AccountField: "test2", SubjectField: "test2", DestinationField: "test2", SetupTimeField: "test2", AnswerTimeField: "test2", DurationField: "test2"}}
|
||||
if cfg, err := NewCGRConfigFromBytes(eFieldsCfg); err != nil {
|
||||
t.Error("Could not parse the config", err.Error())
|
||||
|
||||
@@ -19,10 +19,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package engine
|
||||
|
||||
import (
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
var cfgDcT *config.CGRConfig
|
||||
@@ -47,7 +48,7 @@ func TestHandleGetEmptyDC(t *testing.T) {
|
||||
// Accounting db has no DerivedChargers, configured defaults
|
||||
func TestHandleGetConfiguredDC(t *testing.T) {
|
||||
cfgedDC := utils.DerivedChargers{&utils.DerivedCharger{RunId: "responder1", ReqTypeField: "test", DirectionField: "test", TenantField: "test",
|
||||
TorField: "test", AccountField: "test", SubjectField: "test", DestinationField: "test", SetupTimeField: "test", AnswerTimeField: "test", DurationField: "test"}}
|
||||
CategoryField: "test", AccountField: "test", SubjectField: "test", DestinationField: "test", SetupTimeField: "test", AnswerTimeField: "test", DurationField: "test"}}
|
||||
cfgDcT.DerivedChargers = cfgedDC
|
||||
attrs := utils.AttrDerivedChargers{Tenant: "cgrates.org", Tor: "call", Direction: "*out", Account: "test3", Subject: "test3"}
|
||||
if dcs, err := HandleGetDerivedChargers(acntDb, cfgDcT, attrs); err != nil {
|
||||
@@ -61,9 +62,9 @@ func TestHandleGetConfiguredDC(t *testing.T) {
|
||||
func TestHandleGetStoredDC(t *testing.T) {
|
||||
keyCharger1 := utils.DerivedChargersKey("cgrates.org", "call", "*out", "rif", "rif")
|
||||
charger1 := utils.DerivedChargers{
|
||||
&utils.DerivedCharger{RunId: "extra1", ReqTypeField: "^prepaid", DirectionField: "*default", TenantField: "*default", TorField: "*default",
|
||||
&utils.DerivedCharger{RunId: "extra1", ReqTypeField: "^prepaid", DirectionField: "*default", TenantField: "*default", CategoryField: "*default",
|
||||
AccountField: "rif", SubjectField: "rif", DestinationField: "*default", SetupTimeField: "*default", AnswerTimeField: "*default", DurationField: "*default"},
|
||||
&utils.DerivedCharger{RunId: "extra2", ReqTypeField: "*default", DirectionField: "*default", TenantField: "*default", TorField: "*default",
|
||||
&utils.DerivedCharger{RunId: "extra2", ReqTypeField: "*default", DirectionField: "*default", TenantField: "*default", CategoryField: "*default",
|
||||
AccountField: "ivo", SubjectField: "ivo", DestinationField: "*default", SetupTimeField: "*default", AnswerTimeField: "*default", DurationField: "*default"},
|
||||
}
|
||||
if err := acntDb.SetDerivedChargers(keyCharger1, charger1); err != nil {
|
||||
@@ -71,7 +72,7 @@ func TestHandleGetStoredDC(t *testing.T) {
|
||||
}
|
||||
// Expected Charger should have default configured values added
|
||||
expCharger1 := append(charger1, &utils.DerivedCharger{RunId: "responder1", ReqTypeField: "test", DirectionField: "test", TenantField: "test",
|
||||
TorField: "test", AccountField: "test", SubjectField: "test", DestinationField: "test", SetupTimeField: "test", AnswerTimeField: "test", DurationField: "test"})
|
||||
CategoryField: "test", AccountField: "test", SubjectField: "test", DestinationField: "test", SetupTimeField: "test", AnswerTimeField: "test", DurationField: "test"})
|
||||
acntDb.CacheAccounting(nil, nil, nil, nil)
|
||||
attrs := utils.AttrDerivedChargers{Tenant: "cgrates.org", Tor: "call", Direction: "*out", Account: "rif", Subject: "rif"}
|
||||
if dcs, err := HandleGetDerivedChargers(acntDb, cfgDcT, attrs); err != nil {
|
||||
|
||||
@@ -835,7 +835,7 @@ func (csvr *CSVReader) LoadDerivedChargers() (err error) {
|
||||
ReqTypeField: ValueOrDefault(record[6], "*default"),
|
||||
DirectionField: ValueOrDefault(record[7], "*default"),
|
||||
TenantField: ValueOrDefault(record[8], "*default"),
|
||||
TorField: ValueOrDefault(record[9], "*default"),
|
||||
CategoryField: ValueOrDefault(record[9], "*default"),
|
||||
AccountField: ValueOrDefault(record[10], "*default"),
|
||||
SubjectField: ValueOrDefault(record[11], "*default"),
|
||||
DestinationField: ValueOrDefault(record[12], "*default"),
|
||||
@@ -854,7 +854,7 @@ func (csvr *CSVReader) LoadDerivedChargers() (err error) {
|
||||
ReqTypeField: ValueOrDefault(record[6], "*default"),
|
||||
DirectionField: ValueOrDefault(record[7], "*default"),
|
||||
TenantField: ValueOrDefault(record[8], "*default"),
|
||||
TorField: ValueOrDefault(record[9], "*default"),
|
||||
CategoryField: ValueOrDefault(record[9], "*default"),
|
||||
AccountField: ValueOrDefault(record[10], "*default"),
|
||||
SubjectField: ValueOrDefault(record[11], "*default"),
|
||||
DestinationField: ValueOrDefault(record[12], "*default"),
|
||||
|
||||
@@ -909,9 +909,9 @@ func TestLoadDerivedChargers(t *testing.T) {
|
||||
t.Error("Failed to load derivedChargers: ", csvr.derivedChargers)
|
||||
}
|
||||
expCharger1 := utils.DerivedChargers{
|
||||
&utils.DerivedCharger{RunId: "extra1", ReqTypeField: "^prepaid", DirectionField: "*default", TenantField: "*default", TorField: "*default",
|
||||
&utils.DerivedCharger{RunId: "extra1", ReqTypeField: "^prepaid", DirectionField: "*default", TenantField: "*default", CategoryField: "*default",
|
||||
AccountField: "rif", SubjectField: "rif", DestinationField: "*default", SetupTimeField: "*default", AnswerTimeField: "*default", DurationField: "*default"},
|
||||
&utils.DerivedCharger{RunId: "extra2", ReqTypeField: "*default", DirectionField: "*default", TenantField: "*default", TorField: "*default",
|
||||
&utils.DerivedCharger{RunId: "extra2", ReqTypeField: "*default", DirectionField: "*default", TenantField: "*default", CategoryField: "*default",
|
||||
AccountField: "ivo", SubjectField: "ivo", DestinationField: "*default", SetupTimeField: "*default", AnswerTimeField: "*default", DurationField: "*default"},
|
||||
}
|
||||
keyCharger1 := utils.DerivedChargersKey("cgrates.org", "call", "*out", "dan", "dan")
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
@@ -474,59 +473,8 @@ func (dbr *DbReader) LoadSharedGroups() (err error) {
|
||||
}
|
||||
|
||||
func (dbr *DbReader) LoadLCRs() (err error) {
|
||||
dbr.sharedGroups, err = dbr.storDb.GetTpSharedGroups(dbr.tpid, "")
|
||||
dbr.lcrs, err = dbr.storDb.GetTpLCRs(dbr.tpid, "")
|
||||
return err
|
||||
csvReader, fp, err := csvr.readerFunc(csvr.lcrFn, csvr.sep, utils.LCRS_NRCOLS)
|
||||
if err != nil {
|
||||
log.Print("Could not load LCR rules file: ", err)
|
||||
// allow writing of the other values
|
||||
return nil
|
||||
}
|
||||
if fp != nil {
|
||||
defer fp.Close()
|
||||
}
|
||||
for record, err := csvReader.Read(); err == nil; record, err = csvReader.Read() {
|
||||
direction, tenant, customer := record[0], record[1], record[2]
|
||||
id := fmt.Sprintf("%s:%s:%s", direction, tenant, customer)
|
||||
lcr, found := csvr.lcrs[id]
|
||||
activationTime, err := utils.ParseTimeDetectLayout(record[7])
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not parse LCR activation time: %v", err)
|
||||
}
|
||||
weight, err := strconv.ParseFloat(record[8], 64)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not parse LCR weight: %v", err)
|
||||
}
|
||||
if !found {
|
||||
lcr = &LCR{
|
||||
Direction: direction,
|
||||
Tenant: tenant,
|
||||
Customer: customer,
|
||||
}
|
||||
}
|
||||
var act *LCRActivation
|
||||
for _, existingAct := range lcr.Activations {
|
||||
if existingAct.ActivationTime.Equal(activationTime) {
|
||||
act = existingAct
|
||||
break
|
||||
}
|
||||
}
|
||||
if act == nil {
|
||||
act = &LCRActivation{
|
||||
ActivationTime: activationTime,
|
||||
}
|
||||
lcr.Activations = append(lcr.Activations, act)
|
||||
}
|
||||
act.Entries = append(act.Entries, &LCREntry{
|
||||
DestinationId: record[3],
|
||||
Category: record[4],
|
||||
Strategy: record[5],
|
||||
Suppliers: record[6],
|
||||
Weight: weight,
|
||||
})
|
||||
csvr.lcrs[id] = lcr
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (dbr *DbReader) LoadActions() (err error) {
|
||||
|
||||
@@ -19,17 +19,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package engine
|
||||
|
||||
import (
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
// Test internal abilites of GetDerivedChargers
|
||||
func TestResponderGetDerivedChargers(t *testing.T) {
|
||||
cfg, _ := config.NewDefaultCGRConfig()
|
||||
cfgedDC := utils.DerivedChargers{&utils.DerivedCharger{RunId: "responder1", ReqTypeField: "test", DirectionField: "test", TenantField: "test",
|
||||
TorField: "test", AccountField: "test", SubjectField: "test", DestinationField: "test", SetupTimeField: "test", AnswerTimeField: "test", DurationField: "test"}}
|
||||
CategoryField: "test", AccountField: "test", SubjectField: "test", DestinationField: "test", SetupTimeField: "test", AnswerTimeField: "test", DurationField: "test"}}
|
||||
cfg.DerivedChargers = cfgedDC
|
||||
config.SetCgrConfig(cfg)
|
||||
r := Responder{}
|
||||
|
||||
@@ -57,9 +57,9 @@ func TestSetGetDerivedCharges(t *testing.T) {
|
||||
}
|
||||
keyCharger1 := utils.ConcatenatedKey("cgrates.org", "call", "*out", "dan", "dan")
|
||||
charger1 := utils.DerivedChargers{
|
||||
&utils.DerivedCharger{RunId: "extra1", ReqTypeField: "^prepaid", DirectionField: "*default", TenantField: "*default", TorField: "*default",
|
||||
&utils.DerivedCharger{RunId: "extra1", ReqTypeField: "^prepaid", DirectionField: "*default", TenantField: "*default", CategoryField: "*default",
|
||||
AccountField: "rif", SubjectField: "rif", DestinationField: "*default", SetupTimeField: "*default", AnswerTimeField: "*default", DurationField: "*default"},
|
||||
&utils.DerivedCharger{RunId: "extra2", ReqTypeField: "*default", DirectionField: "*default", TenantField: "*default", TorField: "*default",
|
||||
&utils.DerivedCharger{RunId: "extra2", ReqTypeField: "*default", DirectionField: "*default", TenantField: "*default", CategoryField: "*default",
|
||||
AccountField: "ivo", SubjectField: "ivo", DestinationField: "*default", SetupTimeField: "*default", AnswerTimeField: "*default", DurationField: "*default"},
|
||||
}
|
||||
if err := rds.SetDerivedChargers(keyCharger1, charger1); err != nil {
|
||||
|
||||
@@ -51,6 +51,7 @@ RP_UK,DR_UK_Mobile_BIG5,ALWAYS,10`
|
||||
ratingProfiles := `*out,cgrates.org,call,*any,2013-01-06T00:00:00Z,RP_UK,
|
||||
*out,cgrates.org,call,discounted_minutes,2013-01-06T00:00:00Z,RP_UK_Mobile_BIG5_PKG,`
|
||||
sharedGroups := ``
|
||||
lcrs := ``
|
||||
actions := `TOPUP10_AC,*topup_reset,*monetary,*out,10,*unlimited,*any,,10,,,10
|
||||
TOPUP10_AC1,*topup_reset,*call_duration,*out,40,*unlimited,DST_UK_Mobile_BIG5,discounted_minutes,10,,,10`
|
||||
actionPlans := `TOPUP10_AT,TOPUP10_AC,ASAP,10
|
||||
@@ -59,7 +60,7 @@ TOPUP10_AT,TOPUP10_AC1,ASAP,10`
|
||||
accountActions := `cgrates.org,12345,*out,TOPUP10_AT,`
|
||||
derivedCharges := ``
|
||||
csvr := engine.NewStringCSVReader(ratingDb, acntDb, ',', destinations, timings, rates, destinationRates, ratingPlans, ratingProfiles,
|
||||
sharedGroups, actions, actionPlans, actionTriggers, accountActions, derivedCharges)
|
||||
sharedGroups, lcrs, actions, actionPlans, actionTriggers, accountActions, derivedCharges)
|
||||
if err := csvr.LoadDestinations(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -81,6 +82,9 @@ TOPUP10_AT,TOPUP10_AC1,ASAP,10`
|
||||
if err := csvr.LoadSharedGroups(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := csvr.LoadLCRs(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := csvr.LoadActions(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ RP_UK,DR_UK_Mobile_BIG5,ALWAYS,10`
|
||||
ratingProfiles := `*out,cgrates.org,call,*any,2013-01-06T00:00:00Z,RP_UK,
|
||||
*out,cgrates.org,call,discounted_minutes,2013-01-06T00:00:00Z,RP_UK_Mobile_BIG5_PKG,`
|
||||
sharedGroups := ``
|
||||
lcrs := ``
|
||||
actions := `TOPUP10_AC,*topup_reset,*monetary,*out,0,*unlimited,*any,,10,,,10
|
||||
TOPUP10_AC1,*topup_reset,*call_duration,*out,40,*unlimited,DST_UK_Mobile_BIG5,discounted_minutes,10,,,10`
|
||||
actionPlans := `TOPUP10_AT,TOPUP10_AC,ASAP,10
|
||||
@@ -59,7 +60,7 @@ TOPUP10_AT,TOPUP10_AC1,ASAP,10`
|
||||
accountActions := `cgrates.org,12345,*out,TOPUP10_AT,`
|
||||
derivedCharges := ``
|
||||
csvr := engine.NewStringCSVReader(ratingDb2, acntDb2, ',', destinations, timings, rates, destinationRates, ratingPlans, ratingProfiles,
|
||||
sharedGroups, actions, actionPlans, actionTriggers, accountActions, derivedCharges)
|
||||
sharedGroups, lcrs, actions, actionPlans, actionTriggers, accountActions, derivedCharges)
|
||||
if err := csvr.LoadDestinations(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -81,6 +82,9 @@ TOPUP10_AT,TOPUP10_AC1,ASAP,10`
|
||||
if err := csvr.LoadSharedGroups(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := csvr.LoadLCRs(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := csvr.LoadActions(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -51,13 +51,14 @@ RP_UK,DR_UK_Mobile_BIG5,ALWAYS,10`
|
||||
ratingProfiles := `*out,cgrates.org,call,*any,2013-01-06T00:00:00Z,RP_UK,
|
||||
*out,cgrates.org,call,discounted_minutes,2013-01-06T00:00:00Z,RP_UK_Mobile_BIG5_PKG,`
|
||||
sharedGroups := ``
|
||||
lcrs := ``
|
||||
actions := `TOPUP10_AC1,*topup_reset,*call_duration,*out,40,*unlimited,DST_UK_Mobile_BIG5,discounted_minutes,10,,,10`
|
||||
actionPlans := `TOPUP10_AT,TOPUP10_AC1,ASAP,10`
|
||||
actionTriggers := ``
|
||||
accountActions := `cgrates.org,12345,*out,TOPUP10_AT,`
|
||||
derivedCharges := ``
|
||||
csvr := engine.NewStringCSVReader(ratingDb3, acntDb3, ',', destinations, timings, rates, destinationRates, ratingPlans, ratingProfiles,
|
||||
sharedGroups, actions, actionPlans, actionTriggers, accountActions, derivedCharges)
|
||||
sharedGroups, lcrs, actions, actionPlans, actionTriggers, accountActions, derivedCharges)
|
||||
if err := csvr.LoadDestinations(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -79,6 +80,9 @@ RP_UK,DR_UK_Mobile_BIG5,ALWAYS,10`
|
||||
if err := csvr.LoadSharedGroups(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := csvr.LoadLCRs(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := csvr.LoadActions(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ func (self *Mediator) RateCdr(dbcdr utils.RawCDR) error {
|
||||
}
|
||||
for _, dc := range dcs {
|
||||
forkedCdr, err := dbcdr.AsStoredCdr(dc.RunId, dc.ReqTypeField, dc.DirectionField,
|
||||
dc.TenantField, dc.TorField, dc.AccountField, dc.SubjectField, dc.DestinationField, dc.SetupTimeField, dc.AnswerTimeField, dc.DurationField, []string{}, true)
|
||||
dc.TenantField, dc.CategoryField, dc.AccountField, dc.SubjectField, dc.DestinationField, dc.SetupTimeField, dc.AnswerTimeField, dc.DurationField, []string{}, true)
|
||||
if err != nil { // Errors on fork, cannot calculate further, write that into db for later analysis
|
||||
self.cdrDb.SetRatedCdr(&utils.StoredCdr{CgrId: dbcdr.GetCgrId(), MediationRunId: dc.RunId, Cost: -1.0}, err.Error()) // Cannot fork CDR, important just runid and error
|
||||
continue
|
||||
|
||||
@@ -178,7 +178,7 @@ func (sm *FSSessionManager) OnChannelPark(ev Event) {
|
||||
cd := engine.CallDescriptor{
|
||||
Direction: ev.GetDirection(dc.DirectionField),
|
||||
Tenant: ev.GetTenant(dc.TenantField),
|
||||
Category: ev.GetCategory(dc.TorField),
|
||||
Category: ev.GetCategory(dc.CategoryField),
|
||||
Subject: ev.GetSubject(dc.SubjectField),
|
||||
Account: ev.GetAccount(dc.AccountField),
|
||||
Destination: ev.GetDestination(dc.DestinationField),
|
||||
@@ -266,7 +266,7 @@ func (sm *FSSessionManager) OnChannelHangupComplete(ev Event) {
|
||||
cd := engine.CallDescriptor{
|
||||
Direction: ev.GetDirection(dc.DirectionField),
|
||||
Tenant: ev.GetTenant(dc.TenantField),
|
||||
Category: ev.GetCategory(dc.TorField),
|
||||
Category: ev.GetCategory(dc.CategoryField),
|
||||
Subject: ev.GetSubject(dc.SubjectField),
|
||||
Account: ev.GetAccount(dc.AccountField),
|
||||
LoopIndex: 0,
|
||||
|
||||
@@ -61,7 +61,7 @@ func NewSession(ev Event, sm SessionManager, dcs utils.DerivedChargers) *Session
|
||||
cd := &engine.CallDescriptor{
|
||||
Direction: ev.GetDirection(dc.DirectionField),
|
||||
Tenant: ev.GetTenant(dc.TenantField),
|
||||
Category: ev.GetCategory(dc.TorField),
|
||||
Category: ev.GetCategory(dc.CategoryField),
|
||||
Subject: ev.GetSubject(dc.SubjectField),
|
||||
Account: ev.GetAccount(dc.AccountField),
|
||||
Destination: ev.GetDestination(dc.DestinationField),
|
||||
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
)
|
||||
|
||||
// Wraps regexp compiling in case of rsr fields
|
||||
func NewDerivedCharger(runId, reqTypeFld, dirFld, tenantFld, totFld, acntFld, subjFld, dstFld, sTimeFld, aTimeFld, durFld string) (dc *DerivedCharger, err error) {
|
||||
func NewDerivedCharger(runId, reqTypeFld, dirFld, tenantFld, catFld, acntFld, subjFld, dstFld, sTimeFld, aTimeFld, durFld string) (dc *DerivedCharger, err error) {
|
||||
if len(runId) == 0 {
|
||||
return nil, errors.New("Empty run id field")
|
||||
}
|
||||
@@ -47,9 +47,9 @@ func NewDerivedCharger(runId, reqTypeFld, dirFld, tenantFld, totFld, acntFld, su
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
dc.TorField = totFld
|
||||
if strings.HasPrefix(dc.TorField, REGEXP_PREFIX) {
|
||||
if dc.rsrTorField, err = NewRSRField(dc.TorField); err != nil {
|
||||
dc.CategoryField = catFld
|
||||
if strings.HasPrefix(dc.CategoryField, REGEXP_PREFIX) {
|
||||
if dc.rsrCategoryField, err = NewRSRField(dc.CategoryField); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
@@ -97,7 +97,7 @@ type DerivedCharger struct {
|
||||
ReqTypeField string // Field containing request type info, number in case of csv source, '^' as prefix in case of static values
|
||||
DirectionField string // Field containing direction info
|
||||
TenantField string // Field containing tenant info
|
||||
TorField string // Field containing tor info
|
||||
CategoryField string // Field containing tor info
|
||||
AccountField string // Field containing account information
|
||||
SubjectField string // Field containing subject information
|
||||
DestinationField string // Field containing destination information
|
||||
@@ -107,7 +107,7 @@ type DerivedCharger struct {
|
||||
rsrReqTypeField *RSRField // Storage for compiled Regexp in case of RSRFields
|
||||
rsrDirectionField *RSRField
|
||||
rsrTenantField *RSRField
|
||||
rsrTorField *RSRField
|
||||
rsrCategoryField *RSRField
|
||||
rsrAccountField *RSRField
|
||||
rsrSubjectField *RSRField
|
||||
rsrDestinationField *RSRField
|
||||
|
||||
@@ -50,7 +50,7 @@ func TestNewDerivedCharger(t *testing.T) {
|
||||
ReqTypeField: "reqtype1",
|
||||
DirectionField: "direction1",
|
||||
TenantField: "tenant1",
|
||||
TorField: "tor1",
|
||||
CategoryField: "tor1",
|
||||
AccountField: "account1",
|
||||
SubjectField: "subject1",
|
||||
DestinationField: "destination1",
|
||||
@@ -69,7 +69,7 @@ func TestNewDerivedCharger(t *testing.T) {
|
||||
ReqTypeField: "~reqtype2:s/sip:(.+)/$1/",
|
||||
DirectionField: "~direction2:s/sip:(.+)/$1/",
|
||||
TenantField: "~tenant2:s/sip:(.+)/$1/",
|
||||
TorField: "~tor2:s/sip:(.+)/$1/",
|
||||
CategoryField: "~tor2:s/sip:(.+)/$1/",
|
||||
AccountField: "~account2:s/sip:(.+)/$1/",
|
||||
SubjectField: "~subject2:s/sip:(.+)/$1/",
|
||||
DestinationField: "~destination2:s/sip:(.+)/$1/",
|
||||
@@ -80,7 +80,7 @@ func TestNewDerivedCharger(t *testing.T) {
|
||||
edc2.rsrReqTypeField, _ = NewRSRField("~reqtype2:s/sip:(.+)/$1/")
|
||||
edc2.rsrDirectionField, _ = NewRSRField("~direction2:s/sip:(.+)/$1/")
|
||||
edc2.rsrTenantField, _ = NewRSRField("~tenant2:s/sip:(.+)/$1/")
|
||||
edc2.rsrTorField, _ = NewRSRField("~tor2:s/sip:(.+)/$1/")
|
||||
edc2.rsrCategoryField, _ = NewRSRField("~tor2:s/sip:(.+)/$1/")
|
||||
edc2.rsrAccountField, _ = NewRSRField("~account2:s/sip:(.+)/$1/")
|
||||
edc2.rsrSubjectField, _ = NewRSRField("~subject2:s/sip:(.+)/$1/")
|
||||
edc2.rsrDestinationField, _ = NewRSRField("~destination2:s/sip:(.+)/$1/")
|
||||
@@ -113,16 +113,16 @@ func TestDerivedChargersKey(t *testing.T) {
|
||||
func TestAppendDefaultRun(t *testing.T) {
|
||||
var dc1 DerivedChargers
|
||||
dcDf := &DerivedCharger{RunId: DEFAULT_RUNID, ReqTypeField: META_DEFAULT, DirectionField: META_DEFAULT,
|
||||
TenantField: META_DEFAULT, TorField: META_DEFAULT, AccountField: META_DEFAULT, SubjectField: META_DEFAULT,
|
||||
TenantField: META_DEFAULT, CategoryField: META_DEFAULT, AccountField: META_DEFAULT, SubjectField: META_DEFAULT,
|
||||
DestinationField: META_DEFAULT, SetupTimeField: META_DEFAULT, AnswerTimeField: META_DEFAULT, DurationField: META_DEFAULT}
|
||||
eDc1 := DerivedChargers{dcDf}
|
||||
if dc1, _ = dc1.AppendDefaultRun(); !reflect.DeepEqual(dc1, eDc1) {
|
||||
t.Error("Unexpected result.")
|
||||
}
|
||||
dc2 := DerivedChargers{
|
||||
&DerivedCharger{RunId: "extra1", ReqTypeField: "^prepaid", DirectionField: "*default", TenantField: "*default", TorField: "*default",
|
||||
&DerivedCharger{RunId: "extra1", ReqTypeField: "^prepaid", DirectionField: "*default", TenantField: "*default", CategoryField: "*default",
|
||||
AccountField: "rif", SubjectField: "rif", DestinationField: "*default", SetupTimeField: "*default", AnswerTimeField: "*default", DurationField: "*default"},
|
||||
&DerivedCharger{RunId: "extra2", ReqTypeField: "*default", DirectionField: "*default", TenantField: "*default", TorField: "*default",
|
||||
&DerivedCharger{RunId: "extra2", ReqTypeField: "*default", DirectionField: "*default", TenantField: "*default", CategoryField: "*default",
|
||||
AccountField: "ivo", SubjectField: "ivo", DestinationField: "*default", SetupTimeField: "*default", AnswerTimeField: "*default", DurationField: "*default"},
|
||||
}
|
||||
eDc2 := append(dc2, dcDf)
|
||||
|
||||
Reference in New Issue
Block a user