compilation fixes

This commit is contained in:
Radu Ioan Fericean
2015-06-02 23:29:09 +03:00
parent 7330061c1f
commit 9c66af024d
11 changed files with 620 additions and 222 deletions

View File

@@ -206,11 +206,11 @@ CDRST2,,,ACD,,,,,,,,,,,,,,,,,,,
`
)
var csvr *CSVReader
var csvr *TpReader
func init() {
csvr = NewStringCSVReader(dataStorage, accountingStorage, ',', destinations, timings, rates, destinationRates, ratingPlans, ratingProfiles,
sharedGroups, lcrs, actions, actionTimings, actionTriggers, accountActions, derivedCharges, cdrStats)
csvr = NewTpReader(dataStorage, accountingStorage, NewStringCSVStorage(',', destinations, timings, rates, destinationRates, ratingPlans, ratingProfiles,
sharedGroups, lcrs, actions, actionTimings, actionTriggers, accountActions, derivedCharges, cdrStats), "")
csvr.LoadDestinations()
csvr.LoadTimings()
csvr.LoadRates()
@@ -220,7 +220,7 @@ func init() {
csvr.LoadSharedGroups()
csvr.LoadLCRs()
csvr.LoadActions()
csvr.LoadActionTimings()
csvr.LoadActionPlans()
csvr.LoadActionTriggers()
csvr.LoadAccountActions()
csvr.LoadDerivedChargers()
@@ -231,10 +231,10 @@ func init() {
}
func TestLoadDestinations(t *testing.T) {
if len(csvr.tp.destinations) != 11 {
t.Error("Failed to load destinations: ", len(csvr.tp.destinations))
if len(csvr.destinations) != 11 {
t.Error("Failed to load destinations: ", len(csvr.destinations))
}
for _, d := range csvr.tp.destinations {
for _, d := range csvr.destinations {
switch d.Id {
case "NAT":
if !reflect.DeepEqual(d.Prefixes, []string{`0256`, `0257`, `0723`, `+49`}) {
@@ -277,10 +277,10 @@ func TestLoadDestinations(t *testing.T) {
}
func TestLoadTimimgs(t *testing.T) {
if len(csvr.tp.timings) != 6 {
t.Error("Failed to load timings: ", csvr.tp.timings)
if len(csvr.timings) != 6 {
t.Error("Failed to load timings: ", csvr.timings)
}
timing := csvr.tp.timings["WORKDAYS_00"]
timing := csvr.timings["WORKDAYS_00"]
if !reflect.DeepEqual(timing, &utils.TPTiming{
Id: "WORKDAYS_00",
Years: utils.Years{},
@@ -291,7 +291,7 @@ func TestLoadTimimgs(t *testing.T) {
}) {
t.Error("Error loading timing: ", timing)
}
timing = csvr.tp.timings["WORKDAYS_18"]
timing = csvr.timings["WORKDAYS_18"]
if !reflect.DeepEqual(timing, &utils.TPTiming{
Id: "WORKDAYS_18",
Years: utils.Years{},
@@ -302,7 +302,7 @@ func TestLoadTimimgs(t *testing.T) {
}) {
t.Error("Error loading timing: ", timing)
}
timing = csvr.tp.timings["WEEKENDS"]
timing = csvr.timings["WEEKENDS"]
if !reflect.DeepEqual(timing, &utils.TPTiming{
Id: "WEEKENDS",
Years: utils.Years{},
@@ -313,7 +313,7 @@ func TestLoadTimimgs(t *testing.T) {
}) {
t.Error("Error loading timing: ", timing)
}
timing = csvr.tp.timings["ONE_TIME_RUN"]
timing = csvr.timings["ONE_TIME_RUN"]
if !reflect.DeepEqual(timing, &utils.TPTiming{
Id: "ONE_TIME_RUN",
Years: utils.Years{2012},
@@ -327,10 +327,10 @@ func TestLoadTimimgs(t *testing.T) {
}
func TestLoadRates(t *testing.T) {
if len(csvr.tp.rates) != 13 {
t.Error("Failed to load rates: ", len(csvr.tp.rates))
if len(csvr.rates) != 13 {
t.Error("Failed to load rates: ", len(csvr.rates))
}
rate := csvr.tp.rates["R1"].RateSlots[0]
rate := csvr.rates["R1"].RateSlots[0]
expctRs, err := utils.NewRateSlot(0, 0.2, "60", "1", "0")
if err != nil {
t.Error("Error loading rate: ", rate, err.Error())
@@ -340,7 +340,7 @@ func TestLoadRates(t *testing.T) {
rate.GroupIntervalStartDuration() != expctRs.GroupIntervalStartDuration() {
t.Error("Error loading rate: ", rate, expctRs)
}
rate = csvr.tp.rates["R2"].RateSlots[0]
rate = csvr.rates["R2"].RateSlots[0]
if expctRs, err = utils.NewRateSlot(0, 0.1, "60s", "1s", "0"); err != nil {
t.Error("Error loading rate: ", rate, err.Error())
} else if !reflect.DeepEqual(rate, expctRs) ||
@@ -349,7 +349,7 @@ func TestLoadRates(t *testing.T) {
rate.GroupIntervalStartDuration() != expctRs.GroupIntervalStartDuration() {
t.Error("Error loading rate: ", rate)
}
rate = csvr.tp.rates["R3"].RateSlots[0]
rate = csvr.rates["R3"].RateSlots[0]
if expctRs, err = utils.NewRateSlot(0, 0.05, "60s", "1s", "0"); err != nil {
t.Error("Error loading rate: ", rate, err.Error())
} else if !reflect.DeepEqual(rate, expctRs) ||
@@ -358,7 +358,7 @@ func TestLoadRates(t *testing.T) {
rate.GroupIntervalStartDuration() != expctRs.GroupIntervalStartDuration() {
t.Error("Error loading rate: ", rate)
}
rate = csvr.tp.rates["R4"].RateSlots[0]
rate = csvr.rates["R4"].RateSlots[0]
if expctRs, err = utils.NewRateSlot(1, 1.0, "1s", "1s", "0"); err != nil {
t.Error("Error loading rate: ", rate, err.Error())
} else if !reflect.DeepEqual(rate, expctRs) ||
@@ -367,7 +367,7 @@ func TestLoadRates(t *testing.T) {
rate.GroupIntervalStartDuration() != expctRs.GroupIntervalStartDuration() {
t.Error("Error loading rate: ", rate)
}
rate = csvr.tp.rates["R5"].RateSlots[0]
rate = csvr.rates["R5"].RateSlots[0]
if expctRs, err = utils.NewRateSlot(0, 0.5, "1s", "1s", "0"); err != nil {
t.Error("Error loading rate: ", rate, err.Error())
} else if !reflect.DeepEqual(rate, expctRs) ||
@@ -376,7 +376,7 @@ func TestLoadRates(t *testing.T) {
rate.GroupIntervalStartDuration() != expctRs.GroupIntervalStartDuration() {
t.Error("Error loading rate: ", rate)
}
rate = csvr.tp.rates["LANDLINE_OFFPEAK"].RateSlots[0]
rate = csvr.rates["LANDLINE_OFFPEAK"].RateSlots[0]
if expctRs, err = utils.NewRateSlot(0, 1, "1", "60", "0"); err != nil {
t.Error("Error loading rate: ", rate, err.Error())
} else if !reflect.DeepEqual(rate, expctRs) ||
@@ -385,7 +385,7 @@ func TestLoadRates(t *testing.T) {
rate.GroupIntervalStartDuration() != expctRs.GroupIntervalStartDuration() {
t.Error("Error loading rate: ", rate)
}
rate = csvr.tp.rates["LANDLINE_OFFPEAK"].RateSlots[1]
rate = csvr.rates["LANDLINE_OFFPEAK"].RateSlots[1]
if expctRs, err = utils.NewRateSlot(0, 1, "1", "1", "60"); err != nil {
t.Error("Error loading rate: ", rate, err.Error())
} else if !reflect.DeepEqual(rate, expctRs) ||
@@ -397,29 +397,29 @@ func TestLoadRates(t *testing.T) {
}
func TestLoadDestinationRates(t *testing.T) {
if len(csvr.tp.destinationRates) != 13 {
t.Error("Failed to load destinationrates: ", len(csvr.tp.destinationRates))
if len(csvr.destinationRates) != 13 {
t.Error("Failed to load destinationrates: ", len(csvr.destinationRates))
}
drs := csvr.tp.destinationRates["RT_STANDARD"]
drs := csvr.destinationRates["RT_STANDARD"]
dr := &utils.TPDestinationRate{
TPid: "",
DestinationRateId: "RT_STANDARD",
DestinationRates: []*utils.DestinationRate{
&utils.DestinationRate{
DestinationId: "GERMANY",
Rate: csvr.tp.rates["R1"],
Rate: csvr.rates["R1"],
RoundingMethod: utils.ROUNDING_MIDDLE,
RoundingDecimals: 4,
},
&utils.DestinationRate{
DestinationId: "GERMANY_O2",
Rate: csvr.tp.rates["R2"],
Rate: csvr.rates["R2"],
RoundingMethod: utils.ROUNDING_MIDDLE,
RoundingDecimals: 4,
},
&utils.DestinationRate{
DestinationId: "GERMANY_PREMIUM",
Rate: csvr.tp.rates["R2"],
Rate: csvr.rates["R2"],
RoundingMethod: utils.ROUNDING_MIDDLE,
RoundingDecimals: 4,
},
@@ -428,13 +428,13 @@ func TestLoadDestinationRates(t *testing.T) {
if !reflect.DeepEqual(drs, dr) {
t.Errorf("Error loading destination rate: \n%+v \n%+v", drs, dr)
}
drs = csvr.tp.destinationRates["RT_DEFAULT"]
drs = csvr.destinationRates["RT_DEFAULT"]
if !reflect.DeepEqual(drs, &utils.TPDestinationRate{
DestinationRateId: "RT_DEFAULT",
DestinationRates: []*utils.DestinationRate{
&utils.DestinationRate{
DestinationId: "ALL",
Rate: csvr.tp.rates["R2"],
Rate: csvr.rates["R2"],
RoundingMethod: utils.ROUNDING_MIDDLE,
RoundingDecimals: 4,
},
@@ -442,19 +442,19 @@ func TestLoadDestinationRates(t *testing.T) {
}) {
t.Errorf("Error loading destination rate: %+v", drs.DestinationRates[0])
}
drs = csvr.tp.destinationRates["RT_STD_WEEKEND"]
drs = csvr.destinationRates["RT_STD_WEEKEND"]
if !reflect.DeepEqual(drs, &utils.TPDestinationRate{
DestinationRateId: "RT_STD_WEEKEND",
DestinationRates: []*utils.DestinationRate{
&utils.DestinationRate{
DestinationId: "GERMANY",
Rate: csvr.tp.rates["R2"],
Rate: csvr.rates["R2"],
RoundingMethod: utils.ROUNDING_MIDDLE,
RoundingDecimals: 4,
},
&utils.DestinationRate{
DestinationId: "GERMANY_O2",
Rate: csvr.tp.rates["R3"],
Rate: csvr.rates["R3"],
RoundingMethod: utils.ROUNDING_MIDDLE,
RoundingDecimals: 4,
},
@@ -462,13 +462,13 @@ func TestLoadDestinationRates(t *testing.T) {
}) {
t.Error("Error loading destination rate: ", drs)
}
drs = csvr.tp.destinationRates["P1"]
drs = csvr.destinationRates["P1"]
if !reflect.DeepEqual(drs, &utils.TPDestinationRate{
DestinationRateId: "P1",
DestinationRates: []*utils.DestinationRate{
&utils.DestinationRate{
DestinationId: "NAT",
Rate: csvr.tp.rates["R4"],
Rate: csvr.rates["R4"],
RoundingMethod: utils.ROUNDING_MIDDLE,
RoundingDecimals: 4,
},
@@ -476,13 +476,13 @@ func TestLoadDestinationRates(t *testing.T) {
}) {
t.Error("Error loading destination rate: ", drs)
}
drs = csvr.tp.destinationRates["P2"]
drs = csvr.destinationRates["P2"]
if !reflect.DeepEqual(drs, &utils.TPDestinationRate{
DestinationRateId: "P2",
DestinationRates: []*utils.DestinationRate{
&utils.DestinationRate{
DestinationId: "NAT",
Rate: csvr.tp.rates["R5"],
Rate: csvr.rates["R5"],
RoundingMethod: utils.ROUNDING_MIDDLE,
RoundingDecimals: 4,
},
@@ -490,13 +490,13 @@ func TestLoadDestinationRates(t *testing.T) {
}) {
t.Error("Error loading destination rate: ", drs)
}
drs = csvr.tp.destinationRates["T1"]
drs = csvr.destinationRates["T1"]
if !reflect.DeepEqual(drs, &utils.TPDestinationRate{
DestinationRateId: "T1",
DestinationRates: []*utils.DestinationRate{
&utils.DestinationRate{
DestinationId: "NAT",
Rate: csvr.tp.rates["LANDLINE_OFFPEAK"],
Rate: csvr.rates["LANDLINE_OFFPEAK"],
RoundingMethod: utils.ROUNDING_MIDDLE,
RoundingDecimals: 4,
},
@@ -504,25 +504,25 @@ func TestLoadDestinationRates(t *testing.T) {
}) {
t.Error("Error loading destination rate: ", drs)
}
drs = csvr.tp.destinationRates["T2"]
drs = csvr.destinationRates["T2"]
if !reflect.DeepEqual(drs, &utils.TPDestinationRate{
DestinationRateId: "T2",
DestinationRates: []*utils.DestinationRate{
&utils.DestinationRate{
DestinationId: "GERMANY",
Rate: csvr.tp.rates["GBP_72"],
Rate: csvr.rates["GBP_72"],
RoundingMethod: utils.ROUNDING_MIDDLE,
RoundingDecimals: 4,
},
&utils.DestinationRate{
DestinationId: "GERMANY_O2",
Rate: csvr.tp.rates["GBP_70"],
Rate: csvr.rates["GBP_70"],
RoundingMethod: utils.ROUNDING_MIDDLE,
RoundingDecimals: 4,
},
&utils.DestinationRate{
DestinationId: "GERMANY_PREMIUM",
Rate: csvr.tp.rates["GBP_71"],
Rate: csvr.rates["GBP_71"],
RoundingMethod: utils.ROUNDING_MIDDLE,
RoundingDecimals: 4,
},
@@ -533,10 +533,10 @@ func TestLoadDestinationRates(t *testing.T) {
}
func TestLoadRatingPlans(t *testing.T) {
if len(csvr.tp.ratingPlans) != 11 {
t.Error("Failed to load rating plans: ", len(csvr.tp.ratingPlans))
if len(csvr.ratingPlans) != 11 {
t.Error("Failed to load rating plans: ", len(csvr.ratingPlans))
}
rplan := csvr.tp.ratingPlans["STANDARD"]
rplan := csvr.ratingPlans["STANDARD"]
expected := &RatingPlan{
Id: "STANDARD",
Timings: map[string]*RITiming{
@@ -680,10 +680,10 @@ func TestLoadRatingPlans(t *testing.T) {
}
func TestLoadRatingProfiles(t *testing.T) {
if len(csvr.tp.ratingProfiles) != 18 {
t.Error("Failed to load rating profiles: ", len(csvr.tp.ratingProfiles), csvr.tp.ratingProfiles)
if len(csvr.ratingProfiles) != 18 {
t.Error("Failed to load rating profiles: ", len(csvr.ratingProfiles), csvr.ratingProfiles)
}
rp := csvr.tp.ratingProfiles["*out:test:0:trp"]
rp := csvr.ratingProfiles["*out:test:0:trp"]
expected := &RatingProfile{
Id: "*out:test:0:trp",
RatingPlanActivations: RatingPlanActivations{&RatingPlanActivation{
@@ -699,10 +699,10 @@ func TestLoadRatingProfiles(t *testing.T) {
}
func TestLoadActions(t *testing.T) {
if len(csvr.tp.actions) != 8 {
t.Error("Failed to load actions: ", csvr.tp.actions)
if len(csvr.actions) != 8 {
t.Error("Failed to load actions: ", csvr.actions)
}
as1 := csvr.tp.actions["MINI"]
as1 := csvr.actions["MINI"]
expected := []*Action{
&Action{
Id: "MINI0",
@@ -738,7 +738,7 @@ func TestLoadActions(t *testing.T) {
if !reflect.DeepEqual(as1[1], expected[1]) {
t.Errorf("Error loading action1: %+v", as1[0].Balance)
}
as2 := csvr.tp.actions["SHARED"]
as2 := csvr.actions["SHARED"]
expected = []*Action{
&Action{
Id: "SHARED0",
@@ -758,7 +758,7 @@ func TestLoadActions(t *testing.T) {
if !reflect.DeepEqual(as2, expected) {
t.Errorf("Error loading action: %+v", as2[0].Balance)
}
as3 := csvr.tp.actions["DEFEE"]
as3 := csvr.actions["DEFEE"]
expected = []*Action{
&Action{
Id: "DEFEE0",
@@ -776,11 +776,11 @@ func TestLoadActions(t *testing.T) {
}
func TestLoadSharedGroups(t *testing.T) {
if len(csvr.tp.sharedGroups) != 3 {
t.Error("Failed to shared groups: ", csvr.tp.sharedGroups)
if len(csvr.sharedGroups) != 3 {
t.Error("Failed to shared groups: ", csvr.sharedGroups)
}
sg1 := csvr.tp.sharedGroups["SG1"]
sg1 := csvr.sharedGroups["SG1"]
expected := &SharedGroup{
Id: "SG1",
AccountParameters: map[string]*SharingParameters{
@@ -793,7 +793,7 @@ func TestLoadSharedGroups(t *testing.T) {
if !reflect.DeepEqual(sg1, expected) {
t.Error("Error loading shared group: ", sg1.AccountParameters)
}
sg2 := csvr.tp.sharedGroups["SG2"]
sg2 := csvr.sharedGroups["SG2"]
expected = &SharedGroup{
Id: "SG2",
AccountParameters: map[string]*SharingParameters{
@@ -812,7 +812,7 @@ func TestLoadSharedGroups(t *testing.T) {
}
// execute action timings to fill memebers
atm := csvr.tp.actionsTimings["MORE_MINUTES"][1]
atm := csvr.actionsTimings["MORE_MINUTES"][1]
atm.Execute()
atm.actions, atm.stCache = nil, time.Time{}
@@ -823,11 +823,11 @@ func TestLoadSharedGroups(t *testing.T) {
}
func TestLoadLCRs(t *testing.T) {
if len(csvr.tp.lcrs) != 1 {
t.Error("Failed to load LCRs: ", csvr.tp.lcrs)
if len(csvr.lcrs) != 1 {
t.Error("Failed to load LCRs: ", csvr.lcrs)
}
lcr := csvr.tp.lcrs["*in:cgrates.org:call:*any:*any"]
lcr := csvr.lcrs["*in:cgrates.org:call:*any:*any"]
expected := &LCR{
Tenant: "cgrates.org",
Category: "call",
@@ -862,10 +862,10 @@ func TestLoadLCRs(t *testing.T) {
}
func TestLoadActionTimings(t *testing.T) {
if len(csvr.tp.actionsTimings) != 5 {
t.Error("Failed to load action timings: ", csvr.tp.actionsTimings)
if len(csvr.actionsTimings) != 5 {
t.Error("Failed to load action timings: ", csvr.actionsTimings)
}
atm := csvr.tp.actionsTimings["MORE_MINUTES"][0]
atm := csvr.actionsTimings["MORE_MINUTES"][0]
expected := &ActionTiming{
Uuid: atm.Uuid,
Id: "MORE_MINUTES",
@@ -888,10 +888,10 @@ func TestLoadActionTimings(t *testing.T) {
}
func TestLoadActionTriggers(t *testing.T) {
if len(csvr.tp.actionsTriggers) != 7 {
t.Error("Failed to load action triggers: ", len(csvr.tp.actionsTriggers))
if len(csvr.actionsTriggers) != 7 {
t.Error("Failed to load action triggers: ", len(csvr.actionsTriggers))
}
atr := csvr.tp.actionsTriggers["STANDARD_TRIGGER"][0]
atr := csvr.actionsTriggers["STANDARD_TRIGGER"][0]
expected := &ActionTrigger{
Id: "st0",
BalanceType: utils.VOICE,
@@ -906,7 +906,7 @@ func TestLoadActionTriggers(t *testing.T) {
if !reflect.DeepEqual(atr, expected) {
t.Error("Error loading action trigger: ", atr)
}
atr = csvr.tp.actionsTriggers["STANDARD_TRIGGER"][1]
atr = csvr.actionsTriggers["STANDARD_TRIGGER"][1]
expected = &ActionTrigger{
Id: "st1",
BalanceType: utils.VOICE,
@@ -924,13 +924,13 @@ func TestLoadActionTriggers(t *testing.T) {
}
func TestLoadAccountActions(t *testing.T) {
if len(csvr.tp.accountActions) != 6 {
t.Error("Failed to load account actions: ", csvr.tp.accountActions)
if len(csvr.accountActions) != 6 {
t.Error("Failed to load account actions: ", csvr.accountActions)
}
aa := csvr.tp.accountActions["*out:vdf:minitsboy"]
aa := csvr.accountActions["*out:vdf:minitsboy"]
expected := &Account{
Id: "*out:vdf:minitsboy",
ActionTriggers: csvr.tp.actionsTriggers["STANDARD_TRIGGER"],
ActionTriggers: csvr.actionsTriggers["STANDARD_TRIGGER"],
}
if !reflect.DeepEqual(aa, expected) {
t.Error("Error loading account action: ", aa)
@@ -948,29 +948,29 @@ func TestLoadAccountActions(t *testing.T) {
}
func TestLoadRpAliases(t *testing.T) {
if len(csvr.tp.rpAliases) != 3 {
t.Error("Failed to load rp aliases: ", csvr.tp.rpAliases)
if len(csvr.rpAliases) != 3 {
t.Error("Failed to load rp aliases: ", csvr.rpAliases)
}
if csvr.tp.rpAliases[utils.RatingSubjectAliasKey("vdf", "a1")] != "minu" ||
csvr.tp.rpAliases[utils.RatingSubjectAliasKey("vdf", "a2")] != "minu" ||
csvr.tp.rpAliases[utils.RatingSubjectAliasKey("vdf", "a3")] != "minu" {
t.Error("Error loading rp aliases: ", csvr.tp.rpAliases)
if csvr.rpAliases[utils.RatingSubjectAliasKey("vdf", "a1")] != "minu" ||
csvr.rpAliases[utils.RatingSubjectAliasKey("vdf", "a2")] != "minu" ||
csvr.rpAliases[utils.RatingSubjectAliasKey("vdf", "a3")] != "minu" {
t.Error("Error loading rp aliases: ", csvr.rpAliases)
}
}
func TestLoadAccAliases(t *testing.T) {
if len(csvr.tp.accAliases) != 2 {
t.Error("Failed to load acc aliases: ", csvr.tp.accAliases)
if len(csvr.accAliases) != 2 {
t.Error("Failed to load acc aliases: ", csvr.accAliases)
}
if csvr.tp.accAliases[utils.AccountAliasKey("vdf", "a1")] != "minitsboy" ||
csvr.tp.accAliases[utils.AccountAliasKey("vdf", "a2")] != "minitsboy" {
t.Error("Error loading acc aliases: ", csvr.tp.accAliases)
if csvr.accAliases[utils.AccountAliasKey("vdf", "a1")] != "minitsboy" ||
csvr.accAliases[utils.AccountAliasKey("vdf", "a2")] != "minitsboy" {
t.Error("Error loading acc aliases: ", csvr.accAliases)
}
}
func TestLoadDerivedChargers(t *testing.T) {
if len(csvr.tp.derivedChargers) != 2 {
t.Error("Failed to load derivedChargers: ", csvr.tp.derivedChargers)
if len(csvr.derivedChargers) != 2 {
t.Error("Failed to load derivedChargers: ", csvr.derivedChargers)
}
expCharger1 := utils.DerivedChargers{
&utils.DerivedCharger{RunId: "extra1", RunFilters: "^filteredHeader1/filterValue1/", ReqTypeField: "^prepaid", DirectionField: utils.META_DEFAULT,
@@ -983,13 +983,13 @@ func TestLoadDerivedChargers(t *testing.T) {
DisconnectCauseField: utils.META_DEFAULT},
}
keyCharger1 := utils.DerivedChargersKey("*out", "cgrates.org", "call", "dan", "dan")
if !reflect.DeepEqual(csvr.tp.derivedChargers[keyCharger1], expCharger1) {
t.Errorf("Unexpected charger %+v", csvr.tp.derivedChargers[keyCharger1][0])
if !reflect.DeepEqual(csvr.derivedChargers[keyCharger1], expCharger1) {
t.Errorf("Unexpected charger %+v", csvr.derivedChargers[keyCharger1][0])
}
}
func TestLoadCdrStats(t *testing.T) {
if len(csvr.tp.cdrStats) != 2 {
t.Error("Failed to load cdr stats: ", csvr.tp.cdrStats)
if len(csvr.cdrStats) != 2 {
t.Error("Failed to load cdr stats: ", csvr.cdrStats)
}
cdrStats1 := &CdrStats{
Id: "CDRST1",
@@ -1018,9 +1018,9 @@ func TestLoadCdrStats(t *testing.T) {
RatedSubject: []string{"rif"},
CostInterval: []float64{0, 2},
}
cdrStats1.Triggers = append(cdrStats1.Triggers, csvr.tp.actionsTriggers["STANDARD_TRIGGERS"]...)
cdrStats1.Triggers = append(cdrStats1.Triggers, csvr.tp.actionsTriggers["STANDARD_TRIGGER"]...)
if !reflect.DeepEqual(csvr.tp.cdrStats[cdrStats1.Id], cdrStats1) {
t.Error("Unexpected stats", csvr.tp.cdrStats[cdrStats1.Id])
cdrStats1.Triggers = append(cdrStats1.Triggers, csvr.actionsTriggers["STANDARD_TRIGGERS"]...)
cdrStats1.Triggers = append(cdrStats1.Triggers, csvr.actionsTriggers["STANDARD_TRIGGER"]...)
if !reflect.DeepEqual(csvr.cdrStats[cdrStats1.Id], cdrStats1) {
t.Error("Unexpected stats", csvr.cdrStats[cdrStats1.Id])
}
}

View File

@@ -110,13 +110,13 @@ func TestLoadFromCSV(t *testing.T) {
if !*testLocal {
return
}
var err error
/*var err error
for fn, v := range FileValidators {
if err = ValidateCSVData(path.Join(*dataDir, "tariffplans", *tpCsvScenario, fn), v.Rule); err != nil {
t.Error("Failed validating data: ", err.Error())
}
}
loader := NewFileCSVReader(ratingDbCsv, accountDbCsv, utils.CSV_SEP,
}*/
loader := NewTpReader(ratingDbCsv, accountDbCsv, NewFileCSVStorage(utils.CSV_SEP,
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.DESTINATIONS_CSV),
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.TIMINGS_CSV),
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.RATES_CSV),
@@ -130,8 +130,7 @@ func TestLoadFromCSV(t *testing.T) {
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ACTION_TRIGGERS_CSV),
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ACCOUNT_ACTIONS_CSV),
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.DERIVED_CHARGERS_CSV),
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.CDR_STATS_CSV),
)
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.CDR_STATS_CSV)), "")
if err = loader.LoadDestinations(); err != nil {
t.Error("Failed loading destinations: ", err.Error())
@@ -154,7 +153,7 @@ func TestLoadFromCSV(t *testing.T) {
if err = loader.LoadActions(); err != nil {
t.Error("Failed loading actions: ", err.Error())
}
if err = loader.LoadActionTimings(); err != nil {
if err = loader.LoadActionPlans(); err != nil {
t.Error("Failed loading action timings: ", err.Error())
}
if err = loader.LoadActionTriggers(); err != nil {
@@ -176,11 +175,17 @@ func TestImportToStorDb(t *testing.T) {
if !*testLocal {
return
}
csvImporter := TPCSVImporter{TEST_SQL, storDb, path.Join(*dataDir, "tariffplans", *tpCsvScenario), utils.CSV_SEP, false, TEST_SQL}
csvImporter := TPCSVImporter{
TPid: TEST_SQL,
StorDb: storDb,
DirPath: path.Join(*dataDir, "tariffplans", *tpCsvScenario),
Sep: utils.CSV_SEP,
Verbose: false,
ImportId: TEST_SQL}
if err := csvImporter.Run(); err != nil {
t.Error("Error when importing tpdata to storDb: ", err)
}
if tpids, err := storDb.GetTPIds(); err != nil {
if tpids, err := storDb.GetTpIds(); err != nil {
t.Error("Error when querying storDb for imported data: ", err)
} else if len(tpids) != 1 || tpids[0] != TEST_SQL {
t.Errorf("Data in storDb is different than expected %v", tpids)
@@ -192,7 +197,7 @@ func TestLoadFromStorDb(t *testing.T) {
if !*testLocal {
return
}
loader := NewDbReader(storDb, ratingDbStor, accountDbStor, TEST_SQL)
loader := NewTpReader(ratingDbStor, accountDbStor, storDb, TEST_SQL)
if err := loader.LoadDestinations(); err != nil {
t.Error("Failed loading destinations: ", err.Error())
}
@@ -214,7 +219,7 @@ func TestLoadFromStorDb(t *testing.T) {
if err := loader.LoadActions(); err != nil {
t.Error("Failed loading actions: ", err.Error())
}
if err := loader.LoadActionTimings(); err != nil {
if err := loader.LoadActionPlans(); err != nil {
t.Error("Failed loading action timings: ", err.Error())
}
if err := loader.LoadActionTriggers(); err != nil {
@@ -235,13 +240,17 @@ func TestLoadIndividualProfiles(t *testing.T) {
if !*testLocal {
return
}
loader := NewDbReader(storDb, ratingDbApier, accountDbApier, TEST_SQL)
loader := NewTpReader(ratingDbApier, accountDbApier, storDb, TEST_SQL)
// Load ratingPlans. This will also set destination keys
if ratingPlans, err := storDb.GetTpRatingPlans(TEST_SQL, "", nil); err != nil {
t.Fatal("Could not retrieve rating plans")
} else {
for tag := range ratingPlans {
if loaded, err := loader.LoadRatingPlanByTag(tag); err != nil {
rpls, err := TpRatingPlans(ratingPlans).GetRatingPlans()
if err != nil {
t.Fatal("Could not convert rating plans")
}
for tag := range rpls {
if loaded, err := loader.LoadRatingPlanFiltered(tag); err != nil {
t.Fatalf("Could not load ratingPlan for tag: %s, error: %s", tag, err.Error())
} else if !loaded {
t.Fatal("Cound not find ratingPLan with id:", tag)
@@ -255,7 +264,11 @@ func TestLoadIndividualProfiles(t *testing.T) {
} else if len(ratingProfiles) == 0 {
t.Fatal("Could not retrieve rating profiles")
} else {
for rpId := range ratingProfiles {
rpfs, err := TpRatingProfiles(ratingProfiles).GetRatingProfiles()
if err != nil {
t.Fatal("Could not convert rating profiles")
}
for rpId := range rpfs {
rp, _ := utils.NewTPRatingProfileFromKeyId(TEST_SQL, loadId, rpId)
if err := loader.LoadRatingProfileFiltered(rp); err != nil {
t.Fatalf("Could not load ratingProfile with id: %s, error: %s", rpId, err.Error())
@@ -263,11 +276,15 @@ func TestLoadIndividualProfiles(t *testing.T) {
}
}
// Load account actions
if aas, err := storDb.GetTpAccountActions(&utils.TPAccountActions{TPid: TEST_SQL, LoadId: loadId}); err != nil {
if accountActions, err := storDb.GetTpAccountActions(&utils.TPAccountActions{TPid: TEST_SQL, LoadId: loadId}); err != nil {
t.Fatal("Could not retrieve account action profiles, error: ", err.Error())
} else if len(aas) == 0 {
} else if len(accountActions) == 0 {
t.Error("No account actions")
} else {
aas, err := TpAccountActions(accountActions).GetAccountActions()
if err != nil {
t.Fatal("Could not convert account actions")
}
for aaId := range aas {
aa, _ := utils.NewTPAccountActionsFromKeyId(TEST_SQL, loadId, aaId)
if err := loader.LoadAccountActionsFiltered(aa); err != nil {

View File

@@ -3,9 +3,9 @@ package engine
import "testing"
func TestModelHelperCsvLoad(t *testing.T) {
l := csvLoad(TpDestination{}, []string{"TEST_DEST", "+492"})
l, err := csvLoad(TpDestination{}, []string{"TEST_DEST", "+492"})
tpd := l.(TpDestination)
if tpd.Tag != "TEST_DEST" || tpd.Prefix != "+492" {
if err != nil || tpd.Tag != "TEST_DEST" || tpd.Prefix != "+492" {
t.Errorf("model load failed: %+v", tpd)
}
}
@@ -14,8 +14,8 @@ func TestModelHelperCsvDump(t *testing.T) {
tpd := &TpDestination{
Tag: "TEST_DEST",
Prefix: "+492"}
csv, err := csvDump(*tpd, ",")
if err != nil || csv != "TEST_DEST,+492" {
csv, err := csvDump(tpd)
if err != nil || csv[0] != "TEST_DEST" || csv[1] != "+492" {
t.Errorf("model load failed: %+v", tpd)
}
}

View File

@@ -288,7 +288,7 @@ func (csvs *CSVStorage) GetTpActions(tpid, tag string) ([]TpAction, error) {
return tpActions, nil
}
func (csvs *CSVStorage) GetTPActionPlans(tpid, tag string) ([]TpActionPlan, error) {
func (csvs *CSVStorage) GetTpActionPlans(tpid, tag string) ([]TpActionPlan, error) {
csvReader, fp, err := csvs.readerFunc(csvs.actiontimingsFn, csvs.sep, getColumnCount(TpActionPlan{}))
if err != nil {
log.Print("Could not load action plans file: ", err)
@@ -334,7 +334,7 @@ func (csvs *CSVStorage) GetTpActionTriggers(tpid, tag string) ([]TpActionTrigger
return tpActionTriggers, nil
}
func (csvs *CSVStorage) GetTpAccountActions(filter []TpAccountAction) ([]*TpAccountAction, error) {
func (csvs *CSVStorage) GetTpAccountActions(filter *utils.TPAccountActions) ([]TpAccountAction, error) {
csvReader, fp, err := csvs.readerFunc(csvs.accountactionsFn, csvs.sep, getColumnCount(TpAccountAction{}))
if err != nil {
log.Print("Could not load account actions file: ", err)
@@ -409,10 +409,10 @@ func (csvs *CSVStorage) GetTpCdrStats(tpid, tag string) ([]TpCdrStat, error) {
return tpCdrStats, nil
}
func (csvs *CSVStorage) GetTPIds() ([]string, error) {
func (csvs *CSVStorage) GetTpIds() ([]string, error) {
return nil, errors.New(utils.ERR_NOT_IMPLEMENTED)
}
func (csvs *CSVStorage) GetTPTableIds(tpid, table string, distinct utils.TPDistinctIds, filters map[string]string, p *utils.Paginator) ([]string, error) {
func (csvs *CSVStorage) GetTpTableIds(tpid, table string, distinct utils.TPDistinctIds, filters map[string]string, p *utils.Paginator) ([]string, error) {
return nil, errors.New(utils.ERR_NOT_IMPLEMENTED)
}

View File

@@ -166,9 +166,9 @@ type LoadWriter interface {
SetTpDerivedChargers([]TpDerivedCharger) error
SetTpLCRs([]TpLcrRules) error
SetTpActions([]TpAction) error
SetTpActionTimings([]TpActionPlan) error
SetTpActionPlans([]TpActionPlan) error
SetTpActionTriggers([]TpActionTrigger) error
SetTpAccountActions([]TpAccountActions) error
SetTpAccountActions([]TpAccountAction) error
}
type Marshaler interface {

View File

@@ -60,24 +60,24 @@ func TestMySQLSetGetTPTiming(t *testing.T) {
if !*testLocal {
return
}
tm := &utils.ApierTPTiming{TPid: TEST_SQL, TimingId: "ALWAYS", Time: "00:00:00"}
if err := mysqlDb.SetTPTiming(tm); err != nil {
tm := TpTiming{Tpid: TEST_SQL, Tag: "ALWAYS", Time: "00:00:00"}
if err := mysqlDb.SetTpTimings([]TpTiming{tm}); err != nil {
t.Error(err.Error())
}
if tmgs, err := mysqlDb.GetTpTimings(TEST_SQL, tm.TimingId); err != nil {
if tmgs, err := mysqlDb.GetTpTimings(TEST_SQL, tm.Tag); err != nil {
t.Error(err.Error())
} else if !reflect.DeepEqual(tm, tmgs[tm.TimingId]) {
t.Errorf("Expecting: %+v, received: %+v", tm, tmgs[tm.TimingId])
} else if !reflect.DeepEqual(tm, tmgs[0]) {
t.Errorf("Expecting: %+v, received: %+v", tm, tmgs[0])
}
// Update
tm.Time = "00:00:01"
if err := mysqlDb.SetTPTiming(tm); err != nil {
if err := mysqlDb.SetTpTimings([]TpTiming{tm}); err != nil {
t.Error(err.Error())
}
if tmgs, err := mysqlDb.GetTpTimings(TEST_SQL, tm.TimingId); err != nil {
if tmgs, err := mysqlDb.GetTpTimings(TEST_SQL, tm.Tag); err != nil {
t.Error(err.Error())
} else if !reflect.DeepEqual(tm, tmgs[tm.TimingId]) {
t.Errorf("Expecting: %+v, received: %+v", tm, tmgs[tm.TimingId])
} else if !reflect.DeepEqual(tm, tmgs[0]) {
t.Errorf("Expecting: %+v, received: %+v", tm, tmgs[0])
}
}
@@ -85,15 +85,20 @@ func TestMySQLSetGetTPDestination(t *testing.T) {
if !*testLocal {
return
}
dst := &Destination{Id: TEST_SQL, Prefixes: []string{"+49", "+49151", "+49176"}}
if err := mysqlDb.SetTPDestination(TEST_SQL, dst); err != nil {
dst := []TpDestination{
TpDestination{Tag: TEST_SQL, Prefix: "+49"},
TpDestination{Tag: TEST_SQL, Prefix: "+49151"},
TpDestination{Tag: TEST_SQL, Prefix: "+49176"},
}
if err := mysqlDb.SetTpDestinations(dst); err != nil {
t.Error(err.Error())
}
storData, err := mysqlDb.GetTpDestinations(TEST_SQL, TEST_SQL)
dsts := TpDestinations(storData).GetDestinations()
dsts, err := TpDestinations(storData).GetDestinations()
expected := &Destination{Id: TEST_SQL, Prefixes: []string{"+49", "+49151", "+49176"}}
if err != nil {
t.Error(err.Error())
} else if !reflect.DeepEqual(dst, dsts[TEST_SQL]) {
} else if !reflect.DeepEqual(expected, dsts[TEST_SQL]) {
t.Errorf("Expecting: %+v, received: %+v", dst, dsts[TEST_SQL])
}
}
@@ -112,7 +117,7 @@ func TestMySQLSetGetTPRates(t *testing.T) {
}
mpRates := map[string][]*utils.RateSlot{RT_ID: rtSlots}
expectedTPRate := &utils.TPRate{TPid: TEST_SQL, RateId: RT_ID, RateSlots: rtSlots}
if err := mysqlDb.SetTPRates(TEST_SQL, mpRates); err != nil {
if err := mysqlDb.SetTpRates(TEST_SQL, mpRates); err != nil {
t.Error(err.Error())
}
if rts, err := mysqlDb.GetTpRates(TEST_SQL, RT_ID); err != nil {
@@ -130,7 +135,7 @@ func TestMySQLSetGetTPDestinationRates(t *testing.T) {
dr := &utils.DestinationRate{DestinationId: "DST_1", RateId: "RT_1", RoundingMethod: "*up", RoundingDecimals: 4}
drs := map[string][]*utils.DestinationRate{DR_ID: []*utils.DestinationRate{dr}}
eDrs := &utils.TPDestinationRate{TPid: TEST_SQL, DestinationRateId: DR_ID, DestinationRates: []*utils.DestinationRate{dr}}
if err := mysqlDb.SetTPDestinationRates(TEST_SQL, drs); err != nil {
if err := mysqlDb.SetTpDestinationRates(TEST_SQL, drs); err != nil {
t.Error(err.Error())
}
if drs, err := mysqlDb.GetTpDestinationRates(TEST_SQL, DR_ID, nil); err != nil {
@@ -147,7 +152,7 @@ func TestMySQLSetGetTPRatingPlans(t *testing.T) {
RP_ID := "RP_1"
rbBinding := &utils.TPRatingPlanBinding{DestinationRatesId: "DR_1", TimingId: "TM_1", Weight: 10.0}
drts := map[string][]*utils.TPRatingPlanBinding{RP_ID: []*utils.TPRatingPlanBinding{rbBinding}}
if err := mysqlDb.SetTPRatingPlans(TEST_SQL, drts); err != nil {
if err := mysqlDb.SetTpRatingPlans(TEST_SQL, drts); err != nil {
t.Error(err.Error())
}
if drps, err := mysqlDb.GetTpRatingPlans(TEST_SQL, RP_ID, nil); err != nil {
@@ -164,7 +169,7 @@ func TestMySQLSetGetTPRatingProfiles(t *testing.T) {
ras := []*utils.TPRatingActivation{&utils.TPRatingActivation{ActivationTime: "2012-01-01T00:00:00Z", RatingPlanId: "RP_1"}}
rp := &utils.TPRatingProfile{TPid: TEST_SQL, LoadId: TEST_SQL, Tenant: "cgrates.org", Category: "call", Direction: "*out", Subject: "*any", RatingPlanActivations: ras}
setRps := map[string]*utils.TPRatingProfile{rp.KeyId(): rp}
if err := mysqlDb.SetTPRatingProfiles(TEST_SQL, setRps); err != nil {
if err := mysqlDb.SetTpRatingProfiles(TEST_SQL, setRps); err != nil {
t.Error(err.Error())
}
if rps, err := mysqlDb.GetTpRatingProfiles(rp); err != nil {
@@ -181,7 +186,7 @@ func TestMySQLSetGetTPSharedGroups(t *testing.T) {
}
SG_ID := "SG_1"
setSgs := map[string][]*utils.TPSharedGroup{SG_ID: []*utils.TPSharedGroup{&utils.TPSharedGroup{Account: "dan", Strategy: "*lowest_first", RatingSubject: "lowest_rates"}}}
if err := mysqlDb.SetTPSharedGroups(TEST_SQL, setSgs); err != nil {
if err := mysqlDb.SetTpSharedGroups(TEST_SQL, setSgs); err != nil {
t.Error(err.Error())
}
if sgs, err := mysqlDb.GetTpSharedGroups(TEST_SQL, SG_ID); err != nil {
@@ -199,7 +204,7 @@ func TestMySQLSetGetTPCdrStats(t *testing.T) {
setCS := map[string][]*utils.TPCdrStat{CS_ID: []*utils.TPCdrStat{
&utils.TPCdrStat{QueueLength: "10", TimeWindow: "10m", Metrics: "ASR", Tenants: "cgrates.org", Categories: "call"},
}}
if err := mysqlDb.SetTPCdrStats(TEST_SQL, setCS); err != nil {
if err := mysqlDb.SetTpCdrStats(TEST_SQL, setCS); err != nil {
t.Error(err.Error())
}
if cs, err := mysqlDb.GetTpCdrStats(TEST_SQL, CS_ID); err != nil {
@@ -218,7 +223,7 @@ func TestMySQLSetGetTPDerivedChargers(t *testing.T) {
dcs := &utils.TPDerivedChargers{TPid: TEST_SQL, Direction: utils.OUT, Tenant: "cgrates.org", Category: "call", Account: "dan", Subject: "dan", DerivedChargers: []*utils.TPDerivedCharger{dc}}
DCS_ID := dcs.GetDerivedChargesId()
setDCs := map[string][]*utils.TPDerivedCharger{DCS_ID: []*utils.TPDerivedCharger{dc}}
if err := mysqlDb.SetTPDerivedChargers(TEST_SQL, setDCs); err != nil {
if err := mysqlDb.SetTpDerivedChargers(TEST_SQL, setDCs); err != nil {
t.Error(err.Error())
}
if rDCs, err := mysqlDb.GetTpDerivedChargers(dcs); err != nil {

View File

@@ -193,7 +193,7 @@ func (self *SQLStorage) RemTpData(table, tpid string, args ...string) error {
return nil
}
func (self *PostgresStorage) SetTPTiming(timings []TpTiming) error {
func (self *SQLStorage) SetTpTimings(timings []TpTiming) error {
if len(timings) == 0 {
return nil
}
@@ -218,7 +218,7 @@ func (self *PostgresStorage) SetTPTiming(timings []TpTiming) error {
return nil
}
func (self *SQLStorage) SetTpDestination(dests []TpDestination) error {
func (self *SQLStorage) SetTpDestinations(dests []TpDestination) error {
if len(dests) == 0 {
return nil
}
@@ -258,7 +258,7 @@ func (self *SQLStorage) SetTpRates(rs []TpRate) error {
return err
}
}
save := tx.Save(rPlan)
save := tx.Save(rate)
if save.Error != nil {
tx.Rollback()
return save.Error

View File

@@ -120,6 +120,80 @@ func (tpr *TpReader) LoadDestinationRates() (err error) {
return nil
}
// Returns true, nil in case of load success, false, nil in case of RatingPlan not found ratingStorage
func (tpr *TpReader) LoadRatingPlanFiltered(tag string) (bool, error) {
mpRpls, err := tpr.lr.GetTpRatingPlans(tpr.tpid, tag, nil)
if err != nil {
return false, err
} else if len(mpRpls) == 0 {
return false, nil
}
bindings, err := TpRatingPlans(mpRpls).GetRatingPlans()
if err != nil {
return false, err
}
for tag, rplBnds := range bindings {
ratingPlan := &RatingPlan{Id: tag}
for _, rp := range rplBnds {
tptm, err := tpr.lr.GetTpTimings(tpr.tpid, rp.TimingId)
if err != nil || len(tptm) == 0 {
return false, fmt.Errorf("no timing with id %s: %v", rp.TimingId, err)
}
tm, err := TpTimings(tptm).GetTimings()
if err != nil {
return false, err
}
rp.SetTiming(tm[rp.TimingId])
tpdrm, err := tpr.lr.GetTpDestinationRates(tpr.tpid, rp.DestinationRatesId, nil)
if err != nil || len(tpdrm) == 0 {
return false, fmt.Errorf("no DestinationRates profile with id %s: %v", rp.DestinationRatesId, err)
}
drm, err := TpDestinationRates(tpdrm).GetDestinationRates()
if err != nil {
return false, err
}
for _, drate := range drm[rp.DestinationRatesId].DestinationRates {
tprt, err := tpr.lr.GetTpRates(tpr.tpid, drate.RateId)
if err != nil || len(tprt) == 0 {
return false, fmt.Errorf("no Rates profile with id %s: %v", drate.RateId, err)
}
rt, err := TpRates(tprt).GetRates()
if err != nil {
return false, err
}
drate.Rate = rt[drate.RateId]
ratingPlan.AddRateInterval(drate.DestinationId, GetRateInterval(rp, drate))
if drate.DestinationId == utils.ANY {
continue // no need of loading the destinations in this case
}
tpDests, err := tpr.lr.GetTpDestinations(tpr.tpid, drate.DestinationId)
dms, err := TpDestinations(tpDests).GetDestinations()
if err != nil {
return false, err
} else if len(dms) == 0 {
if dbExists, err := dataStorage.HasData(DESTINATION_PREFIX, drate.DestinationId); err != nil {
return false, err
} else if !dbExists {
return false, fmt.Errorf("could not get destination for tag %v", drate.DestinationId)
}
continue
}
for _, destination := range dms {
dataStorage.SetDestination(destination)
}
}
}
if err := dataStorage.SetRatingPlan(ratingPlan); err != nil {
return false, err
}
}
return true, nil
}
func (tpr *TpReader) LoadRatingPlans() (err error) {
tps, err := tpr.lr.GetTpRatingPlans(tpr.tpid, "", nil)
if err != nil {
@@ -155,6 +229,47 @@ func (tpr *TpReader) LoadRatingPlans() (err error) {
return nil
}
func (tpr *TpReader) LoadRatingProfileFiltered(qriedRpf *utils.TPRatingProfile) error {
var resultRatingProfile *RatingProfile
mpTpRpfs, err := tpr.lr.GetTpRatingProfiles(qriedRpf)
if err != nil {
return fmt.Errorf("no RateProfile for filter %v, error: %v", qriedRpf, err)
}
rpfs, err := TpRatingProfiles(mpTpRpfs).GetRatingProfiles()
if err != nil {
return err
}
for _, tpRpf := range rpfs {
resultRatingProfile = &RatingProfile{Id: tpRpf.KeyId()}
for _, tpRa := range tpRpf.RatingPlanActivations {
at, err := utils.ParseDate(tpRa.ActivationTime)
if err != nil {
return fmt.Errorf("cannot parse activation time from %v", tpRa.ActivationTime)
}
_, exists := tpr.ratingPlans[tpRa.RatingPlanId]
if !exists {
if dbExists, err := dataStorage.HasData(RATING_PLAN_PREFIX, tpRa.RatingPlanId); err != nil {
return err
} else if !dbExists {
return fmt.Errorf("could not load rating plans for tag: %v", tpRa.RatingPlanId)
}
}
resultRatingProfile.RatingPlanActivations = append(resultRatingProfile.RatingPlanActivations,
&RatingPlanActivation{
ActivationTime: at,
RatingPlanId: tpRa.RatingPlanId,
FallbackKeys: utils.FallbackSubjKeys(tpRpf.Direction, tpRpf.Tenant, tpRpf.Category, tpRa.FallbackSubjects),
CdrStatQueueIds: strings.Split(tpRa.CdrStatQueueIds, utils.INFIELD_SEP),
})
}
if err := dataStorage.SetRatingProfile(resultRatingProfile); err != nil {
return err
}
}
return nil
}
func (tpr *TpReader) LoadRatingProfiles() (err error) {
tps, err := tpr.lr.GetTpRatingProfiles(nil)
if err != nil {
@@ -202,7 +317,7 @@ func (tpr *TpReader) LoadRatingProfiles() (err error) {
return nil
}
func (tpr *TpReader) LoadSharedGroups() (err error) {
func (tpr *TpReader) LoadSharedGroupsFiltered(tag string, save bool) (err error) {
tps, err := tpr.lr.GetTpSharedGroups(tpr.tpid, "")
if err != nil {
return err
@@ -227,9 +342,20 @@ func (tpr *TpReader) LoadSharedGroups() (err error) {
}
tpr.sharedGroups[tag] = sg
}
if save {
for _, sg := range tpr.sharedGroups {
if err := tpr.accountingStorage.SetSharedGroup(sg); err != nil {
return err
}
}
}
return nil
}
func (tpr *TpReader) LoadSharedGroups() error {
return tpr.LoadSharedGroupsFiltered("", false)
}
func (tpr *TpReader) LoadLCRs() (err error) {
tps, err := tpr.lr.GetTpLCRs(tpr.tpid, "")
if err != nil {
@@ -426,6 +552,194 @@ func (tpr *TpReader) LoadActionTriggers() (err error) {
return nil
}
func (tpr *TpReader) LoadAccountActionsFiltered(qriedAA *utils.TPAccountActions) error {
accountActions, err := tpr.lr.GetTpAccountActions(qriedAA)
if err != nil {
return errors.New(err.Error() + ": " + fmt.Sprintf("%+v", qriedAA))
}
storAas, err := TpAccountActions(accountActions).GetAccountActions()
if err != nil {
return err
}
for _, accountAction := range storAas {
id := accountAction.KeyId()
var actionsIds []string // collects action ids
// action timings
if accountAction.ActionPlanId != "" {
// get old userBalanceIds
var exitingAccountIds []string
existingActionTimings, err := tpr.accountingStorage.GetActionTimings(accountAction.ActionPlanId)
if err == nil && len(existingActionTimings) > 0 {
// all action timings from a specific tag shuld have the same list of user balances from the first one
exitingAccountIds = existingActionTimings[0].AccountIds
}
tpap, err := tpr.lr.GetTpActionPlans(tpr.tpid, accountAction.ActionPlanId)
if err != nil {
return errors.New(err.Error() + " (ActionPlan): " + accountAction.ActionPlanId)
} else if len(tpap) == 0 {
return fmt.Errorf("no action plan with id <%s>", accountAction.ActionPlanId)
}
aps, err := TpActionPlans(tpap).GetActionPlans()
if err != nil {
return err
}
var actionTimings []*ActionTiming
ats := aps[accountAction.ActionPlanId]
for _, at := range ats {
// Check action exists before saving it inside actionTiming key
// ToDo: try saving the key after the actions was retrieved in order to save one query here.
if actions, err := tpr.lr.GetTpActions(tpr.tpid, at.ActionsId); err != nil {
return errors.New(err.Error() + " (Actions): " + at.ActionsId)
} else if len(actions) == 0 {
return fmt.Errorf("no action with id <%s>", at.ActionsId)
}
tptm, err := tpr.lr.GetTpTimings(tpr.tpid, at.TimingId)
if err != nil {
return errors.New(err.Error() + " (Timing): " + at.TimingId)
} else if len(tptm) == 0 {
return fmt.Errorf("no timing with id <%s>", at.TimingId)
}
tm, err := TpTimings(tptm).GetTimings()
if err != nil {
return err
}
t := tm[at.TimingId]
actTmg := &ActionTiming{
Uuid: utils.GenUUID(),
Id: accountAction.ActionPlanId,
Weight: at.Weight,
Timing: &RateInterval{
Timing: &RITiming{
Months: t.Months,
MonthDays: t.MonthDays,
WeekDays: t.WeekDays,
StartTime: t.StartTime,
},
},
ActionsId: at.ActionsId,
}
// collect action ids from timings
actionsIds = append(actionsIds, actTmg.ActionsId)
//add user balance id if no already in
found := false
for _, ubId := range exitingAccountIds {
if ubId == id {
found = true
break
}
}
if !found {
actTmg.AccountIds = append(exitingAccountIds, id)
}
actionTimings = append(actionTimings, actTmg)
}
// write action timings
err = tpr.accountingStorage.SetActionTimings(accountAction.ActionPlanId, actionTimings)
if err != nil {
return errors.New(err.Error() + " (SetActionPlan): " + accountAction.ActionPlanId)
}
}
// action triggers
var actionTriggers ActionTriggerPriotityList
//ActionTriggerPriotityList []*ActionTrigger
if accountAction.ActionTriggersId != "" {
tpatrs, err := tpr.lr.GetTpActionTriggers(tpr.tpid, accountAction.ActionTriggersId)
if err != nil {
return errors.New(err.Error() + " (ActionTriggers): " + accountAction.ActionTriggersId)
}
atrs, err := TpActionTriggers(tpatrs).GetActionTriggers()
if err != nil {
return err
}
atrsMap := make(map[string][]*ActionTrigger)
for key, atrsLst := range atrs {
atrs := make([]*ActionTrigger, len(atrsLst))
for idx, apiAtr := range atrsLst {
expTime, _ := utils.ParseDate(apiAtr.BalanceExpirationDate)
atrs[idx] = &ActionTrigger{Id: utils.GenUUID(),
ThresholdType: apiAtr.ThresholdType,
ThresholdValue: apiAtr.ThresholdValue,
BalanceId: apiAtr.BalanceId,
BalanceType: apiAtr.BalanceType,
BalanceDirection: apiAtr.BalanceDirection,
BalanceDestinationIds: apiAtr.BalanceDestinationIds,
BalanceWeight: apiAtr.BalanceWeight,
BalanceExpirationDate: expTime,
BalanceRatingSubject: apiAtr.BalanceRatingSubject,
BalanceCategory: apiAtr.BalanceCategory,
BalanceSharedGroup: apiAtr.BalanceSharedGroup,
Weight: apiAtr.Weight,
ActionsId: apiAtr.ActionsId,
}
}
atrsMap[key] = atrs
}
actionTriggers = atrsMap[accountAction.ActionTriggersId]
// collect action ids from triggers
for _, atr := range actionTriggers {
actionsIds = append(actionsIds, atr.ActionsId)
}
}
// actions
acts := make(map[string][]*Action)
for _, actId := range actionsIds {
tpas, err := tpr.lr.GetTpActions(tpr.tpid, actId)
if err != nil {
return err
}
as, err := TpActions(tpas).GetActions()
if err != nil {
return err
}
for tag, tpacts := range as {
enacts := make([]*Action, len(tpacts))
for idx, tpact := range tpacts {
enacts[idx] = &Action{
Id: tag + strconv.Itoa(idx),
ActionType: tpact.Identifier,
BalanceType: tpact.BalanceType,
Direction: tpact.Direction,
Weight: tpact.Weight,
ExtraParameters: tpact.ExtraParameters,
ExpirationString: tpact.ExpiryTime,
Balance: &Balance{
Uuid: utils.GenUUID(),
Value: tpact.Units,
Weight: tpact.BalanceWeight,
RatingSubject: tpact.RatingSubject,
DestinationIds: tpact.DestinationIds,
},
}
}
acts[tag] = enacts
}
}
// writee actions
for k, as := range acts {
err = tpr.accountingStorage.SetActions(k, as)
if err != nil {
return err
}
}
ub, err := tpr.accountingStorage.GetAccount(id)
if err != nil {
ub = &Account{
Id: id,
}
}
ub.ActionTriggers = actionTriggers
if err := tpr.accountingStorage.SetAccount(ub); err != nil {
return err
}
}
return nil
}
func (tpr *TpReader) LoadAccountActions() (err error) {
tps, err := tpr.lr.GetTpAccountActions(nil)
if err != nil {
@@ -471,8 +785,8 @@ func (tpr *TpReader) LoadAccountActions() (err error) {
return nil
}
func (tpr *TpReader) LoadDerivedChargers() (err error) {
tps, err := tpr.lr.GetTpDerivedChargers(nil)
func (tpr *TpReader) LoadDerivedChargersFiltered(filter *utils.TPDerivedChargers, save bool) (err error) {
tps, err := tpr.lr.GetTpDerivedChargers(filter)
if err != nil {
return err
}
@@ -495,11 +809,22 @@ func (tpr *TpReader) LoadDerivedChargers() (err error) {
}
}
}
if save {
for dcsKey, dcs := range tpr.derivedChargers {
if err := tpr.accountingStorage.SetDerivedChargers(dcsKey, dcs); err != nil {
return err
}
}
}
return nil
}
func (tpr *TpReader) LoadCdrStats() (err error) {
tps, err := tpr.lr.GetTpCdrStats(tpr.tpid, "")
func (tpr *TpReader) LoadDerivedChargers() (err error) {
return tpr.LoadDerivedChargersFiltered(nil, false)
}
func (tpr *TpReader) LoadCdrStatsFiltered(tag string, save bool) (err error) {
tps, err := tpr.lr.GetTpCdrStats(tpr.tpid, tag)
if err != nil {
return err
}
@@ -518,15 +843,26 @@ func (tpr *TpReader) LoadCdrStats() (err error) {
triggers, exists := tpr.actionsTriggers[triggerTag]
if triggerTag != "" && !exists {
// only return error if there was something there for the tag
return fmt.Errorf("Could not get action triggers for cdr stats id %s: %s", cs.Id, triggerTag)
return fmt.Errorf("could not get action triggers for cdr stats id %s: %s", cs.Id, triggerTag)
}
UpdateCdrStats(cs, triggers, tpStat)
tpr.cdrStats[tag] = cs
}
}
if save {
for _, stat := range tpr.cdrStats {
if err := tpr.ratingStorage.SetCdrStats(stat); err != nil {
return err
}
}
}
return nil
}
func (tpr *TpReader) LoadCdrStats() error {
return tpr.LoadCdrStatsFiltered("", false)
}
func (tpr *TpReader) LoadAll() error {
var err error
if err = tpr.LoadDestinations(); err != nil {
@@ -593,9 +929,9 @@ func (tpr *TpReader) IsValid() bool {
return valid
}
func (tpr *TpReader) WriteToDatabase(dataStorage RatingStorage, accountingStorage AccountingStorage, flush, verbose bool) (err error) {
func (tpr *TpReader) WriteToDatabase(flush, verbose bool) (err error) {
if dataStorage == nil {
return errors.New("no database connection!")
return errors.New("no database connection")
}
if flush {
dataStorage.Flush("")
@@ -616,7 +952,7 @@ func (tpr *TpReader) WriteToDatabase(dataStorage RatingStorage, accountingStorag
log.Print("Rating Plans:")
}
for _, rp := range tpr.ratingPlans {
err = dataStorage.SetRatingPlan(rp)
err = tpr.ratingStorage.SetRatingPlan(rp)
if err != nil {
return err
}
@@ -628,7 +964,7 @@ func (tpr *TpReader) WriteToDatabase(dataStorage RatingStorage, accountingStorag
log.Print("Rating Profiles:")
}
for _, rp := range tpr.ratingProfiles {
err = dataStorage.SetRatingProfile(rp)
err = tpr.ratingStorage.SetRatingProfile(rp)
if err != nil {
return err
}
@@ -640,7 +976,7 @@ func (tpr *TpReader) WriteToDatabase(dataStorage RatingStorage, accountingStorag
log.Print("Action Plans:")
}
for k, ats := range tpr.actionsTimings {
err = accountingStorage.SetActionTimings(k, ats)
err = tpr.accountingStorage.SetActionTimings(k, ats)
if err != nil {
return err
}
@@ -664,7 +1000,7 @@ func (tpr *TpReader) WriteToDatabase(dataStorage RatingStorage, accountingStorag
log.Print("LCR Rules:")
}
for k, lcr := range tpr.lcrs {
err = dataStorage.SetLCR(lcr)
err = tpr.ratingStorage.SetLCR(lcr)
if err != nil {
return err
}
@@ -676,7 +1012,7 @@ func (tpr *TpReader) WriteToDatabase(dataStorage RatingStorage, accountingStorag
log.Print("Actions:")
}
for k, as := range tpr.actions {
err = accountingStorage.SetActions(k, as)
err = tpr.accountingStorage.SetActions(k, as)
if err != nil {
return err
}
@@ -688,7 +1024,7 @@ func (tpr *TpReader) WriteToDatabase(dataStorage RatingStorage, accountingStorag
log.Print("Account Actions:")
}
for _, ub := range tpr.accountActions {
err = accountingStorage.SetAccount(ub)
err = tpr.accountingStorage.SetAccount(ub)
if err != nil {
return err
}
@@ -699,11 +1035,11 @@ func (tpr *TpReader) WriteToDatabase(dataStorage RatingStorage, accountingStorag
if verbose {
log.Print("Rating Profile Aliases:")
}
if err := dataStorage.RemoveRpAliases(tpr.dirtyRpAliases); err != nil {
if err := tpr.ratingStorage.RemoveRpAliases(tpr.dirtyRpAliases); err != nil {
return err
}
for key, alias := range tpr.rpAliases {
err = dataStorage.SetRpAlias(key, alias)
err = tpr.ratingStorage.SetRpAlias(key, alias)
if err != nil {
return err
}
@@ -714,11 +1050,11 @@ func (tpr *TpReader) WriteToDatabase(dataStorage RatingStorage, accountingStorag
if verbose {
log.Print("Account Aliases:")
}
if err := accountingStorage.RemoveAccAliases(tpr.dirtyAccAliases); err != nil {
if err := tpr.accountingStorage.RemoveAccAliases(tpr.dirtyAccAliases); err != nil {
return err
}
for key, alias := range tpr.accAliases {
err = accountingStorage.SetAccAlias(key, alias)
err = tpr.accountingStorage.SetAccAlias(key, alias)
if err != nil {
return err
}
@@ -730,7 +1066,7 @@ func (tpr *TpReader) WriteToDatabase(dataStorage RatingStorage, accountingStorag
log.Print("Derived Chargers:")
}
for key, dcs := range tpr.derivedChargers {
err = accountingStorage.SetDerivedChargers(key, dcs)
err = tpr.accountingStorage.SetDerivedChargers(key, dcs)
if err != nil {
return err
}
@@ -742,7 +1078,7 @@ func (tpr *TpReader) WriteToDatabase(dataStorage RatingStorage, accountingStorag
log.Print("CDR Stats Queues:")
}
for _, sq := range tpr.cdrStats {
err = dataStorage.SetCdrStats(sq)
err = tpr.ratingStorage.SetCdrStats(sq)
if err != nil {
return err
}

View File

@@ -86,97 +86,122 @@ type TPExporter struct {
func (self *TPExporter) Run() error {
self.removeFiles() // Make sure we clean the folder before starting with new one
toExportMap := make(map[string]interface{})
toExportMap := make(map[string][]interface{})
storData, err := self.storDb.GetTpTimings(self.tpID, "")
if err != nil {
if storData, err := self.storDb.GetTpTimings(self.tpID, ""); err != nil {
return err
} else {
for _, sd := range storData {
toExportMap[utils.TIMINGS_CSV] = append(toExportMap[utils.TIMINGS_CSV], sd)
}
}
toExportMap[utils.TIMINGS_CSV] = storData
storData, err := self.storDb.GetTpDestinations(self.tpID, "")
if err != nil {
if storData, err := self.storDb.GetTpDestinations(self.tpID, ""); err != nil {
return err
} else {
for _, sd := range storData {
toExportMap[utils.DESTINATIONS_CSV] = append(toExportMap[utils.DESTINATIONS_CSV], sd)
}
}
toExportMap[utils.DESTINATIONS_CSV] = storData
storData, err := self.storDb.GetTpRates(self.tpID, "")
if err != nil {
if storData, err := self.storDb.GetTpRates(self.tpID, ""); err != nil {
return err
} else {
for _, sd := range storData {
toExportMap[utils.RATES_CSV] = append(toExportMap[utils.RATES_CSV], sd)
}
}
toExportMap[utils.RATES_CSV] = storData
storData, err = self.storDb.GetTpRates(self.tpID, "")
if err != nil {
if storData, err := self.storDb.GetTpRates(self.tpID, ""); err != nil {
return err
} else {
for _, sd := range storData {
toExportMap[utils.RATES_CSV] = append(toExportMap[utils.RATES_CSV], sd)
}
}
toExportMap[utils.RATES_CSV] = storData
storData, err = self.storDb.GetTpDestinationRates(self.tpID, "", nil)
if err != nil {
if storData, err := self.storDb.GetTpDestinationRates(self.tpID, "", nil); err != nil {
return err
} else {
for _, sd := range storData {
toExportMap[utils.DESTINATION_RATES_CSV] = append(toExportMap[utils.DESTINATION_RATES_CSV], sd)
}
}
toExportMap[utils.DESTINATION_RATES_CSV] = storData
storData, err = self.storDb.GetTpRatingPlans(self.tpID, "", nil)
if err != nil {
if storData, err := self.storDb.GetTpRatingPlans(self.tpID, "", nil); err != nil {
return err
} else {
for _, sd := range storData {
toExportMap[utils.RATING_PLANS_CSV] = append(toExportMap[utils.RATING_PLANS_CSV], sd)
}
}
toExportMap[utils.RATING_PLANS_CSV] = storData
storData, err = self.storDb.GetTpRatingProfiles(&utils.TPRatingProfile{TPid: self.tpID})
if err != nil {
if storData, err := self.storDb.GetTpRatingProfiles(&utils.TPRatingProfile{TPid: self.tpID}); err != nil {
return err
} else {
for _, sd := range storData {
toExportMap[utils.RATING_PROFILES_CSV] = append(toExportMap[utils.RATING_PROFILES_CSV], sd)
}
}
toExportMap[utils.RATING_PROFILE_CSV] = storData
storData, err = self.storDb.GetTpSharedGroups(self.tpID, "")
if err != nil {
if storData, err := self.storDb.GetTpSharedGroups(self.tpID, ""); err != nil {
return err
} else {
for _, sd := range storData {
toExportMap[utils.SHARED_GROUPS_CSV] = append(toExportMap[utils.SHARED_GROUPS_CSV], sd)
}
}
toExportMap[utils.SHARED_GROUPS_CSV] = storData
storData, err = self.storDb.GetTpActions(self.tpID, "")
if err != nil {
if storData, err := self.storDb.GetTpActions(self.tpID, ""); err != nil {
return err
} else {
for _, sd := range storData {
toExportMap[utils.ACTIONS_CSV] = append(toExportMap[utils.ACTIONS_CSV], sd)
}
}
toExportMap[utils.ACTIONS_CSV] = storData
storData, err = self.storDb.GetTpActionPlans(self.tpID, "")
if err != nil {
if storData, err := self.storDb.GetTpActionPlans(self.tpID, ""); err != nil {
return err
} else {
for _, sd := range storData {
toExportMap[utils.ACTION_PLANS_CSV] = append(toExportMap[utils.ACTION_PLANS_CSV], sd)
}
}
toExportMap[utils.ACTION_PLANS_CSV] = storData
storData, err = self.storDb.GetTpActionTriggers(self.tpID, "")
if err != nil {
if storData, err := self.storDb.GetTpActionTriggers(self.tpID, ""); err != nil {
return err
} else {
for _, sd := range storData {
toExportMap[utils.ACTION_TRIGGERS_CSV] = append(toExportMap[utils.ACTION_TRIGGERS_CSV], sd)
}
}
toExportMap[utils.ACTIONS_TRIGGERS_CSV] = storData
storData, err = self.storDb.GetTpAccountActions(&utils.TPAccountActions{TPid: self.tpID})
if err != nil {
if storData, err := self.storDb.GetTpAccountActions(&utils.TPAccountActions{TPid: self.tpID}); err != nil {
return err
} else {
for _, sd := range storData {
toExportMap[utils.ACCOUNT_ACTIONS_CSV] = append(toExportMap[utils.ACCOUNT_ACTIONS_CSV], sd)
}
}
toExportMap[utils.ACCOUNT_ACTIONS_CSV] = storData
storData, err = self.storDb.GetTpDerivedChargers(&utils.TPDerivedChargers{TPid: self.tpID})
if err != nil {
if storData, err := self.storDb.GetTpDerivedChargers(&utils.TPDerivedChargers{TPid: self.tpID}); err != nil {
return err
} else {
for _, sd := range storData {
toExportMap[utils.DERIVED_CHARGERS_CSV] = append(toExportMap[utils.DERIVED_CHARGERS_CSV], sd)
}
}
toExportMap[utils.DERIVED_CHARGERS_CSV] = storData
storData, err = self.storDb.GetTpCdrStats(self.tpID, "")
if err != nil {
if storData, err := self.storDb.GetTpCdrStats(self.tpID, ""); err != nil {
return err
} else {
for _, sd := range storData {
toExportMap[utils.CDR_STATS_CSV] = append(toExportMap[utils.CDR_STATS_CSV], sd)
}
}
toExportMap[utils.CDR_STATS_CSV] = storData
for fileName, storData := range toExportMap {
for _, tpItem := range storData {
exportedData = append(exportedData, tpItem)
}
if err := self.writeOut(fileName, exportedData); err != nil {
if err := self.writeOut(fileName, storData); err != nil {
self.removeFiles()
return err
}
@@ -196,7 +221,7 @@ func (self *TPExporter) removeFiles() error {
if len(self.exportPath) == 0 {
return nil
}
for _, fileName := range exportedFiles {
for _, fileName := range self.exportedFiles {
os.Remove(path.Join(self.exportPath, fileName))
}
return nil

View File

@@ -30,11 +30,11 @@ import (
type TPCSVImporter struct {
TPid string // Load data on this tpid
StorDb LoadWriter // StorDb connection handle
DirPath string // Directory path to import from
Sep rune // Separator in the csv file
Verbose bool // If true will print a detailed information instead of silently discarding it
ImportId string // Use this to differentiate between imports (eg: when autogenerating fields like RatingProfileId
csvr LoadReader
DirPath string // Directory path to import from
Sep rune // Separator in the csv file
Verbose bool // If true will print a detailed information instead of silently discarding it
ImportId string // Use this to differentiate between imports (eg: when autogenerating fields like RatingProfileId
}
// Maps csv file to handler which should process it. Defined like this since tests on 1.0.3 were failing on Travis.
@@ -56,7 +56,7 @@ var fileHandlers = map[string]func(*TPCSVImporter, string) error{
}
func (self *TPCSVImporter) Run() error {
self.csvr = NewFileCSVStorage(self.sep, utils.DESTINATIONS_CSV, utils.TIMINGS_CSV, utils.RATES_CSV, utils.DESTINATION_RATES_CSV, utils.RATING_PLANS_CSV, utils.RATING_PROFILES_CSV, utils.SHARED_GROUPS_CSV, utils.LCRS_CSV, utils.ACTIONS_CSV, utils.ACTION_PLANS_CSV, utils.ACTION_TRIGGERS_CSV, utils.ACCOUNT_ACTIONS_CSV, utils.DERIVED_CHARGERS_CSV, utils.CDR_STATS_CSV)
self.csvr = NewFileCSVStorage(self.Sep, utils.DESTINATIONS_CSV, utils.TIMINGS_CSV, utils.RATES_CSV, utils.DESTINATION_RATES_CSV, utils.RATING_PLANS_CSV, utils.RATING_PROFILES_CSV, utils.SHARED_GROUPS_CSV, utils.LCRS_CSV, utils.ACTIONS_CSV, utils.ACTION_PLANS_CSV, utils.ACTION_TRIGGERS_CSV, utils.ACCOUNT_ACTIONS_CSV, utils.DERIVED_CHARGERS_CSV, utils.CDR_STATS_CSV)
files, _ := ioutil.ReadDir(self.DirPath)
for _, f := range files {
fHandler, hasName := fileHandlers[f.Name()]
@@ -80,7 +80,7 @@ func (self *TPCSVImporter) importTimings(fn string) error {
return err
}
return self.StorDb.SetTPTiming(tps)
return self.StorDb.SetTpTimings(tps)
}
func (self *TPCSVImporter) importDestinations(fn string) error {
@@ -135,7 +135,7 @@ func (self *TPCSVImporter) importRatingProfiles(fn string) error {
if self.Verbose {
log.Printf("Processing file: <%s> ", fn)
}
tps, err := self.csvr.GetTpRatingProfiles(self.TPid, "", nil)
tps, err := self.csvr.GetTpRatingProfiles(&utils.TPRatingProfile{TPid: self.TPid})
if err != nil {
return err
}
@@ -207,7 +207,7 @@ func (self *TPCSVImporter) importDerivedChargers(fn string) error {
if self.Verbose {
log.Printf("Processing file: <%s> ", fn)
}
tps, err := self.csvr.GetTpDerivedChargers(self.TPid, "")
tps, err := self.csvr.GetTpDerivedChargers(nil)
if err != nil {
return err
}
@@ -219,10 +219,10 @@ func (self *TPCSVImporter) importCdrStats(fn string) error {
if self.Verbose {
log.Printf("Processing file: <%s> ", fn)
}
tps, err := self.csvr.GetTpDerivedChargers(self.TPid, "")
tps, err := self.csvr.GetTpCdrStats(self.TPid, "")
if err != nil {
return err
}
return self.StorDb.SetTpDerivedChargers(tps)
return self.StorDb.SetTpCdrStats(tps)
}

View File

@@ -142,6 +142,21 @@ type TPTiming struct {
EndTime string
}
func NewTiming(timingInfo ...string) (rt *TPTiming) {
rt = &TPTiming{}
rt.Id = timingInfo[0]
rt.Years.Parse(timingInfo[1], INFIELD_SEP)
rt.Months.Parse(timingInfo[2], INFIELD_SEP)
rt.MonthDays.Parse(timingInfo[3], INFIELD_SEP)
rt.WeekDays.Parse(timingInfo[4], INFIELD_SEP)
times := strings.Split(timingInfo[5], INFIELD_SEP)
rt.StartTime = times[0]
if len(times) > 1 {
rt.EndTime = times[1]
}
return
}
type TPRatingPlan struct {
TPid string // Tariff plan id
RatingPlanId string // RatingPlan profile id
@@ -531,7 +546,7 @@ type CachedItemAge struct {
}
type AttrExpFileCdrs struct {
CdrFormat *string // Cdr output file format <utils.CdreCdrFormats>
CdrFormat *string // Cdr output file format <CdreCdrFormats>
FieldSeparator *string // Separator used between fields
ExportId *string // Optional exportid
ExportDir *string // If provided it overwrites the configured export directory