Unifying fallback subjects key between csv and db, first match between loaded data from csv and from stordb

This commit is contained in:
DanB
2013-11-18 10:28:27 +01:00
parent f38f04f6c5
commit 4e0ccbfa19
5 changed files with 22 additions and 13 deletions

View File

@@ -50,7 +50,6 @@ func init() {
const (
RECURSION_MAX_DEPTH = 3
FALLBACK_SUBJECT = "*any"
FALLBACK_SEP = ";"
)
var (

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -57,6 +57,8 @@ const (
ROUNDING_MIDDLE = "*middle"
ROUNDING_DOWN = "*down"
COMMENT_CHAR = '#'
FALLBACK_SEP = ';'
JSON = "json"
MSGPACK = "msgpack"
)