mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Unifying fallback subjects key between csv and db, first match between loaded data from csv and from stordb
This commit is contained in:
@@ -50,7 +50,6 @@ func init() {
|
||||
const (
|
||||
RECURSION_MAX_DEPTH = 3
|
||||
FALLBACK_SUBJECT = "*any"
|
||||
FALLBACK_SEP = ";"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -372,15 +372,7 @@ func (csvr *CSVReader) LoadRatingProfiles() (err error) {
|
||||
rpa := &RatingPlanActivation{
|
||||
ActivationTime: at,
|
||||
RatingPlanId: record[5],
|
||||
}
|
||||
if fallbacksubject != "" {
|
||||
var sslice utils.StringSlice = rpa.FallbackKeys
|
||||
for _, fbs := range strings.Split(fallbacksubject, FALLBACK_SEP) {
|
||||
newKey := fmt.Sprintf("%s:%s:%s:%s", direction, tenant, tor, fbs)
|
||||
if !sslice.Contains(newKey) {
|
||||
rpa.FallbackKeys = append(rpa.FallbackKeys, newKey)
|
||||
}
|
||||
}
|
||||
FallbackKeys: utils.FallbackSubjKeys(direction, tenant, tor, fallbacksubject),
|
||||
}
|
||||
rp.RatingPlanActivations = append(rp.RatingPlanActivations, rpa)
|
||||
csvr.ratingProfiles[rp.Id] = rp
|
||||
|
||||
@@ -23,7 +23,6 @@ import (
|
||||
"fmt"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"log"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type DbReader struct {
|
||||
@@ -233,7 +232,7 @@ func (dbr *DbReader) LoadRatingProfiles() error {
|
||||
&RatingPlanActivation{
|
||||
ActivationTime: at,
|
||||
RatingPlanId: tpRa.RatingPlanId,
|
||||
FallbackKeys: strings.Split(tpRa.FallbackSubjects,FALLBACK_SEP),
|
||||
FallbackKeys: utils.FallbackSubjKeys(tpRpf.Direction, tpRpf.Tenant, tpRpf.TOR, tpRa.FallbackSubjects),
|
||||
})
|
||||
}
|
||||
dbr.ratingProfiles[tpRpf.KeyId()] = rpf
|
||||
@@ -318,7 +317,8 @@ func (dbr *DbReader) LoadRatingProfileByTag(tag string) error {
|
||||
}
|
||||
}
|
||||
resultRatingProfile.RatingPlanActivations = append(resultRatingProfile.RatingPlanActivations,
|
||||
&RatingPlanActivation{at, tpRa.RatingPlanId, strings.Split(tpRa.FallbackSubjects,FALLBACK_SEP)})
|
||||
&RatingPlanActivation{at, tpRa.RatingPlanId,
|
||||
utils.FallbackSubjKeys(tpRpf.Direction, tpRpf.Tenant, tpRpf.TOR, tpRa.FallbackSubjects)})
|
||||
}
|
||||
}
|
||||
return dbr.dataDb.SetRatingProfile(resultRatingProfile)
|
||||
|
||||
@@ -21,6 +21,7 @@ package utils
|
||||
import (
|
||||
"time"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// This file deals with tp_* data definition
|
||||
@@ -142,6 +143,21 @@ type TPRatingActivation struct {
|
||||
FallbackSubjects string // So we follow the api
|
||||
}
|
||||
|
||||
// Helper to return the subject fallback keys we need in dataDb
|
||||
func FallbackSubjKeys(direction, tenant, tor, fallbackSubjects string) []string {
|
||||
var subjKeys []string
|
||||
if len(fallbackSubjects) != 0 {
|
||||
var sslice StringSlice
|
||||
for _, fbs := range strings.Split(fallbackSubjects, string(FALLBACK_SEP)) {
|
||||
newKey := fmt.Sprintf("%s:%s:%s:%s", direction, tenant, tor, fbs)
|
||||
if !sslice.Contains(newKey) {
|
||||
subjKeys = append(subjKeys, newKey)
|
||||
}
|
||||
}
|
||||
}
|
||||
return subjKeys
|
||||
}
|
||||
|
||||
type AttrTPRatingProfileIds struct {
|
||||
TPid string // Tariff plan id
|
||||
Tenant string // Tenant's Id
|
||||
|
||||
@@ -57,6 +57,8 @@ const (
|
||||
ROUNDING_MIDDLE = "*middle"
|
||||
ROUNDING_DOWN = "*down"
|
||||
COMMENT_CHAR = '#'
|
||||
FALLBACK_SEP = ';'
|
||||
JSON = "json"
|
||||
MSGPACK = "msgpack"
|
||||
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user