diff --git a/engine/loader_local_test.go b/engine/loader_local_test.go index 6a2606d95..11c6ba22b 100644 --- a/engine/loader_local_test.go +++ b/engine/loader_local_test.go @@ -250,7 +250,7 @@ func TestLoadIndividualProfiles(t *testing.T) { t.Fatal("Could not convert rating plans") } for tag := range rpls { - if loaded, err := loader.LoadRatingPlanFiltered(tag); err != nil { + if loaded, err := loader.LoadRatingPlansFiltered(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) @@ -259,7 +259,7 @@ func TestLoadIndividualProfiles(t *testing.T) { } // Load rating profiles loadId := utils.CSV_LOAD + "_" + TEST_SQL - if ratingProfiles, err := storDb.GetTpRatingProfiles(&utils.TPRatingProfile{TPid: TEST_SQL, LoadId: loadId}); err != nil { + if ratingProfiles, err := storDb.GetTpRatingProfiles(&TpRatingProfile{Tpid: TEST_SQL, Loadid: loadId}); err != nil { t.Fatal("Could not retrieve rating profiles, error: ", err.Error()) } else if len(ratingProfiles) == 0 { t.Fatal("Could not retrieve rating profiles") @@ -270,13 +270,14 @@ func TestLoadIndividualProfiles(t *testing.T) { } for rpId := range rpfs { rp, _ := utils.NewTPRatingProfileFromKeyId(TEST_SQL, loadId, rpId) - if err := loader.LoadRatingProfileFiltered(rp); err != nil { + mrp := APItoModelRatingProfile(rp) + if err := loader.LoadRatingProfilesFiltered(&mrp[0]); err != nil { t.Fatalf("Could not load ratingProfile with id: %s, error: %s", rpId, err.Error()) } } } // Load account actions - if accountActions, err := storDb.GetTpAccountActions(&utils.TPAccountActions{TPid: TEST_SQL, LoadId: loadId}); err != nil { + if accountActions, err := storDb.GetTpAccountActions(&TpAccountAction{Tpid: TEST_SQL, Loadid: loadId}); err != nil { t.Fatal("Could not retrieve account action profiles, error: ", err.Error()) } else if len(accountActions) == 0 { t.Error("No account actions") @@ -287,7 +288,8 @@ func TestLoadIndividualProfiles(t *testing.T) { } for aaId := range aas { aa, _ := utils.NewTPAccountActionsFromKeyId(TEST_SQL, loadId, aaId) - if err := loader.LoadAccountActionsFiltered(aa); err != nil { + maa := APItoModelAccountAction(aa) + if err := loader.LoadAccountActionsFiltered(maa); err != nil { t.Fatalf("Could not load account actions with id: %s, error: %s", aaId, err.Error()) } } diff --git a/engine/model_converters.go b/engine/model_converters.go new file mode 100644 index 000000000..c48c73934 --- /dev/null +++ b/engine/model_converters.go @@ -0,0 +1,262 @@ +package engine + +import ( + "strconv" + + "github.com/cgrates/cgrates/utils" +) + +func APItoModelTiming(t *utils.ApierTPTiming) (result *TpTiming) { + return &TpTiming{ + Tpid: t.TPid, + Tag: t.TimingId, + Years: t.Years, + Months: t.Months, + MonthDays: t.MonthDays, + WeekDays: t.WeekDays, + Time: t.Time, + } +} +func APItoModelDestination(dest *utils.TPDestination) (result []TpDestination) { + for _, p := range dest.Prefixes { + result = append(result, TpDestination{ + Tpid: dest.TPid, + Tag: dest.DestinationId, + Prefix: p, + }) + } + return +} + +func APItoModelRate(r *utils.TPRate) (result []TpRate) { + for _, rs := range r.RateSlots { + result = append(result, TpRate{ + Tpid: r.TPid, + Tag: r.RateId, + ConnectFee: rs.ConnectFee, + Rate: rs.Rate, + RateUnit: rs.RateUnit, + RateIncrement: rs.RateIncrement, + GroupIntervalStart: rs.GroupIntervalStart, + }) + } + return +} + +func APItoModelDestinationRate(drs *utils.TPDestinationRate) (result []TpDestinationRate) { + for _, dr := range drs.DestinationRates { + result = append(result, TpDestinationRate{ + Tpid: drs.TPid, + Tag: drs.DestinationRateId, + DestinationsTag: dr.DestinationId, + RatesTag: dr.RateId, + RoundingMethod: dr.RoundingMethod, + RoundingDecimals: dr.RoundingDecimals, + MaxCost: dr.MaxCost, + MaxCostStrategy: dr.MaxCostStrategy, + }) + } + return +} + +func APItoModelRatingPlan(rps *utils.TPRatingPlan) (result []TpRatingPlan) { + for _, rp := range rps.RatingPlanBindings { + result = append(result, TpRatingPlan{ + Tpid: rps.TPid, + Tag: rps.RatingPlanId, + DestratesTag: rp.DestinationRatesId, + TimingTag: rp.TimingId, + Weight: rp.Weight, + }) + } + return +} + +func APItoModelRatingProfile(rpf *utils.TPRatingProfile) (result []TpRatingProfile) { + for _, ra := range rpf.RatingPlanActivations { + result = append(result, TpRatingProfile{ + Tpid: rpf.TPid, + Loadid: rpf.LoadId, + Direction: rpf.Direction, + Tenant: rpf.Tenant, + Category: rpf.Category, + Subject: rpf.Subject, + ActivationTime: ra.ActivationTime, + RatingPlanTag: ra.RatingPlanId, + FallbackSubjects: ra.FallbackSubjects, + CdrStatQueueIds: ra.CdrStatQueueIds, + }) + } + return +} + +func APItoModelLcrRule(lcrs *utils.TPLcrRules) (result []TpLcrRule) { + for _, lcr := range lcrs.LcrRules { + result = append(result, TpLcrRule{ + Tpid: lcrs.TPid, + Direction: lcr.Direction, + Tenant: lcr.Tenant, + Category: lcr.Category, + Account: lcr.Account, + Subject: lcr.Subject, + DestinationTag: lcr.DestinationId, + RpCategory: lcr.RpCategory, + Strategy: lcr.Strategy, + StrategyParams: lcr.StrategyParams, + ActivationTime: lcr.ActivationTime, + }) + } + return +} + +func APItoModelAction(as *utils.TPActions) (result []TpAction) { + for _, a := range as.Actions { + result = append(result, TpAction{ + Tpid: as.TPid, + Tag: as.ActionsId, + Action: a.Identifier, + BalanceTag: a.BalanceId, + BalanceType: a.BalanceType, + Direction: a.Direction, + Units: a.Units, + ExpiryTime: a.ExpiryTime, + TimingTags: a.TimingTags, + DestinationTags: a.DestinationIds, + RatingSubject: a.RatingSubject, + Category: a.Category, + SharedGroup: a.SharedGroup, + BalanceWeight: a.BalanceWeight, + ExtraParameters: a.ExtraParameters, + Weight: a.Weight, + }) + } + return +} + +func APItoModelActionPlan(aps *utils.TPActionPlan) (result []TpActionPlan) { + for _, ap := range aps.ActionPlan { + result = append(result, TpActionPlan{ + Tpid: aps.TPid, + Tag: aps.Id, + ActionsTag: ap.ActionsId, + TimingTag: ap.TimingId, + Weight: ap.Weight, + }) + } + return +} + +func APItoModelActionTrigger(ats *utils.TPActionTriggers) (result []TpActionTrigger) { + for _, at := range ats.ActionTriggers { + result = append(result, TpActionTrigger{ + Tpid: ats.TPid, + Tag: ats.ActionTriggersId, + UniqueId: at.Id, + ThresholdType: at.ThresholdType, + ThresholdValue: at.ThresholdValue, + Recurrent: at.Recurrent, + MinSleep: at.MinSleep, + BalanceTag: at.BalanceId, + BalanceType: at.BalanceType, + BalanceDirection: at.BalanceDirection, + BalanceDestinationTags: at.BalanceDestinationIds, + BalanceWeight: at.BalanceWeight, + BalanceExpiryTime: at.BalanceExpirationDate, + BalanceTimingTags: at.BalanceTimingTags, + BalanceRatingSubject: at.BalanceRatingSubject, + BalanceCategory: at.BalanceCategory, + BalanceSharedGroup: at.BalanceSharedGroup, + MinQueuedItems: at.MinQueuedItems, + ActionsTag: at.ActionsId, + Weight: at.Weight, + }) + } + return +} + +func APItoModelAccountAction(aa *utils.TPAccountActions) *TpAccountAction { + return &TpAccountAction{ + Tpid: aa.TPid, + Loadid: aa.LoadId, + Direction: aa.Direction, + Tenant: aa.Tenant, + Account: aa.Account, + ActionPlanTag: aa.ActionPlanId, + ActionTriggersTag: aa.ActionTriggersId, + } +} + +func APItoModelSharedGroup(sgs *utils.TPSharedGroups) (result []TpSharedGroup) { + for _, sg := range sgs.SharedGroups { + result = append(result, TpSharedGroup{ + Tpid: sgs.TPid, + Tag: sgs.SharedGroupsId, + Account: sg.Account, + Strategy: sg.Strategy, + RatingSubject: sg.RatingSubject, + }) + } + return +} + +func APItoModelDerivedCharger(dcs *utils.TPDerivedChargers) (result []TpDerivedCharger) { + for _, dc := range dcs.DerivedChargers { + result = append(result, TpDerivedCharger{ + Tpid: dcs.TPid, + Loadid: dcs.Loadid, + Direction: dcs.Direction, + Tenant: dcs.Tenant, + Category: dcs.Category, + Account: dcs.Account, + Subject: dcs.Subject, + Runid: dc.RunId, + RunFilters: dc.RunFilters, + ReqTypeField: dc.ReqTypeField, + DirectionField: dc.DirectionField, + TenantField: dc.TenantField, + CategoryField: dc.CategoryField, + AccountField: dc.AccountField, + SubjectField: dc.SubjectField, + DestinationField: dc.DestinationField, + SetupTimeField: dc.SetupTimeField, + AnswerTimeField: dc.AnswerTimeField, + UsageField: dc.UsageField, + SupplierField: dc.SupplierField, + DisconnectCauseField: dc.DisconnectCauseField, + }) + } + return +} + +func APItoModelCdrStat(stats *utils.TPCdrStats) (result []TpCdrStat) { + for _, st := range stats.CdrStats { + ql, _ := strconv.Atoi(st.QueueLength) + result = append(result, TpCdrStat{ + Tpid: stats.TPid, + Tag: stats.CdrStatsId, + QueueLength: ql, + TimeWindow: st.TimeWindow, + Metrics: st.Metrics, + SetupInterval: st.SetupInterval, + Tors: st.TORs, + CdrHosts: st.CdrHosts, + CdrSources: st.CdrSources, + ReqTypes: st.ReqTypes, + Directions: st.Directions, + Tenants: st.Tenants, + Categories: st.Categories, + Accounts: st.Accounts, + Subjects: st.Subjects, + DestinationPrefixes: st.DestinationPrefixes, + UsageInterval: st.UsageInterval, + Suppliers: st.Suppliers, + DisconnectCauses: st.DisconnectCauses, + MediationRunids: st.MediationRunIds, + RatedAccounts: st.RatedAccounts, + RatedSubjects: st.RatedSubjects, + CostInterval: st.CostInterval, + ActionTriggers: st.ActionTriggers, + }) + } + return +} diff --git a/engine/models.go b/engine/models.go index e81b2919b..f95698ffd 100644 --- a/engine/models.go +++ b/engine/models.go @@ -116,7 +116,7 @@ func (rpf *TpRatingProfile) GetRatingProfileId() string { return utils.ConcatenatedKey(rpf.Loadid, rpf.Direction, rpf.Tenant, rpf.Category, rpf.Subject) } -type TpLcrRules struct { +type TpLcrRule struct { Id int64 Tpid string Direction string `index:"0" re:""` @@ -133,10 +133,10 @@ type TpLcrRules struct { CreatedAt time.Time } -func (lcr *TpLcrRules) SetLcrRulesId(id string) error { +func (lcr *TpLcrRule) SetLcrRuleId(id string) error { ids := strings.Split(id, utils.CONCATENATED_KEY_SEP) if len(ids) != 5 { - return fmt.Errorf("wrong LcrRules Id: %s", id) + return fmt.Errorf("wrong LcrRule Id: %s", id) } lcr.Direction = ids[0] lcr.Tenant = ids[2] @@ -146,7 +146,7 @@ func (lcr *TpLcrRules) SetLcrRulesId(id string) error { return nil } -func (lcr *TpLcrRules) GetLcrRulesId() string { +func (lcr *TpLcrRule) GetLcrRuleId() string { return utils.LCRKey(lcr.Direction, lcr.Tenant, lcr.Category, lcr.Account, lcr.Subject) } diff --git a/engine/storage_csv.go b/engine/storage_csv.go index b32a313be..aeb77cc69 100644 --- a/engine/storage_csv.go +++ b/engine/storage_csv.go @@ -187,7 +187,7 @@ func (csvs *CSVStorage) GetTpRatingPlans(tpid, tag string, p *utils.Paginator) ( return tpRatingPlans, nil } -func (csvs *CSVStorage) GetTpRatingProfiles(filter *utils.TPRatingProfile) ([]TpRatingProfile, error) { +func (csvs *CSVStorage) GetTpRatingProfiles(filter *TpRatingProfile) ([]TpRatingProfile, error) { csvReader, fp, err := csvs.readerFunc(csvs.ratingprofilesFn, csvs.sep, getColumnCount(TpRatingProfile{})) if err != nil { log.Print("Could not load rating profiles file: ", err) @@ -238,8 +238,8 @@ func (csvs *CSVStorage) GetTpSharedGroups(tpid, tag string) ([]TpSharedGroup, er return tpSharedGroups, nil } -func (csvs *CSVStorage) GetTpLCRs(tpid, tag string) ([]TpLcrRules, error) { - csvReader, fp, err := csvs.readerFunc(csvs.lcrFn, csvs.sep, getColumnCount(TpLcrRules{})) +func (csvs *CSVStorage) GetTpLCRs(tpid, tag string) ([]TpLcrRule, error) { + csvReader, fp, err := csvs.readerFunc(csvs.lcrFn, csvs.sep, getColumnCount(TpLcrRule{})) if err != nil { log.Print("Could not load LCR rules file: ", err) // allow writing of the other values @@ -248,16 +248,16 @@ func (csvs *CSVStorage) GetTpLCRs(tpid, tag string) ([]TpLcrRules, error) { if fp != nil { defer fp.Close() } - var tpLCRs []TpLcrRules + var tpLCRs []TpLcrRule for record, err := csvReader.Read(); err != io.EOF; record, err = csvReader.Read() { - if tpRate, err := csvLoad(TpLcrRules{}, record); err != nil { + if tpRate, err := csvLoad(TpLcrRule{}, record); err != nil { if err != nil { log.Print("bad line in lcr rules csv: ", err) return nil, err } return nil, err } else { - tpLCRs = append(tpLCRs, tpRate.(TpLcrRules)) + tpLCRs = append(tpLCRs, tpRate.(TpLcrRule)) } } return tpLCRs, nil @@ -334,7 +334,7 @@ func (csvs *CSVStorage) GetTpActionTriggers(tpid, tag string) ([]TpActionTrigger return tpActionTriggers, nil } -func (csvs *CSVStorage) GetTpAccountActions(filter *utils.TPAccountActions) ([]TpAccountAction, error) { +func (csvs *CSVStorage) GetTpAccountActions(filter *TpAccountAction) ([]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) @@ -359,7 +359,7 @@ func (csvs *CSVStorage) GetTpAccountActions(filter *utils.TPAccountActions) ([]T return tpAccountActions, nil } -func (csvs *CSVStorage) GetTpDerivedChargers(filter *utils.TPDerivedChargers) ([]TpDerivedCharger, error) { +func (csvs *CSVStorage) GetTpDerivedChargers(filter *TpDerivedCharger) ([]TpDerivedCharger, error) { csvReader, fp, err := csvs.readerFunc(csvs.derivedChargersFn, csvs.sep, getColumnCount(TpDerivedCharger{})) if err != nil { log.Print("Could not load derivedChargers file: ", err) diff --git a/engine/storage_interface.go b/engine/storage_interface.go index 0cf711078..9481b86e0 100644 --- a/engine/storage_interface.go +++ b/engine/storage_interface.go @@ -142,15 +142,15 @@ type LoadReader interface { GetTpRates(string, string) ([]TpRate, error) GetTpDestinationRates(string, string, *utils.Paginator) ([]TpDestinationRate, error) GetTpRatingPlans(string, string, *utils.Paginator) ([]TpRatingPlan, error) - GetTpRatingProfiles(*utils.TPRatingProfile) ([]TpRatingProfile, error) + GetTpRatingProfiles(*TpRatingProfile) ([]TpRatingProfile, error) GetTpSharedGroups(string, string) ([]TpSharedGroup, error) GetTpCdrStats(string, string) ([]TpCdrStat, error) - GetTpDerivedChargers(*utils.TPDerivedChargers) ([]TpDerivedCharger, error) - GetTpLCRs(string, string) ([]TpLcrRules, error) + GetTpDerivedChargers(*TpDerivedCharger) ([]TpDerivedCharger, error) + GetTpLCRs(string, string) ([]TpLcrRule, error) GetTpActions(string, string) ([]TpAction, error) GetTpActionPlans(string, string) ([]TpActionPlan, error) GetTpActionTriggers(string, string) ([]TpActionTrigger, error) - GetTpAccountActions(*utils.TPAccountActions) ([]TpAccountAction, error) + GetTpAccountActions(*TpAccountAction) ([]TpAccountAction, error) } type LoadWriter interface { @@ -164,7 +164,7 @@ type LoadWriter interface { SetTpSharedGroups([]TpSharedGroup) error SetTpCdrStats([]TpCdrStat) error SetTpDerivedChargers([]TpDerivedCharger) error - SetTpLCRs([]TpLcrRules) error + SetTpLCRs([]TpLcrRule) error SetTpActions([]TpAction) error SetTpActionPlans([]TpActionPlan) error SetTpActionTriggers([]TpActionTrigger) error diff --git a/engine/storage_mysql_local_test.go b/engine/storage_mysql_local_test.go index acb26f81d..6338e05df 100644 --- a/engine/storage_mysql_local_test.go +++ b/engine/storage_mysql_local_test.go @@ -115,15 +115,19 @@ func TestMySQLSetGetTPRates(t *testing.T) { for _, rs := range rtSlots { rs.SetDurations() } - 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 { + rates := &utils.TPRate{ + TPid: TEST_SQL, + RateId: RT_ID, + RateSlots: rtSlots, + } + mRates := APItoModelRate(rates) + if err := mysqlDb.SetTpRates(mRates); err != nil { t.Error(err.Error()) } if rts, err := mysqlDb.GetTpRates(TEST_SQL, RT_ID); err != nil { t.Error(err.Error()) - } else if !reflect.DeepEqual(expectedTPRate, rts[RT_ID]) { - t.Errorf("Expecting: %+v, received: %+v", expectedTPRate, rts[RT_ID]) + } else if !reflect.DeepEqual(mRates, rts) { + t.Errorf("Expecting: %+v, received: %+v", mRates, rts) } } @@ -133,15 +137,16 @@ func TestMySQLSetGetTPDestinationRates(t *testing.T) { } DR_ID := "DR_1" 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 { + mdrs := APItoModelDestinationRate(eDrs) + if err := mysqlDb.SetTpDestinationRates(mdrs); err != nil { t.Error(err.Error()) } if drs, err := mysqlDb.GetTpDestinationRates(TEST_SQL, DR_ID, nil); err != nil { t.Error(err.Error()) - } else if !reflect.DeepEqual(eDrs, drs[DR_ID]) { - t.Errorf("Expecting: %+v, received: %+v", eDrs, drs[DR_ID]) + } else if !reflect.DeepEqual(mdrs, drs) { + t.Errorf("Expecting: %+v, received: %+v", mdrs, drs) } } @@ -151,14 +156,19 @@ 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 { + rp := &utils.TPRatingPlan{ + TPid: TEST_SQL, + RatingPlanId: RP_ID, + RatingPlanBindings: []*utils.TPRatingPlanBinding{rbBinding}, + } + mrp := APItoModelRatingPlan(rp) + if err := mysqlDb.SetTpRatingPlans(mrp); err != nil { t.Error(err.Error()) } if drps, err := mysqlDb.GetTpRatingPlans(TEST_SQL, RP_ID, nil); err != nil { t.Error(err.Error()) - } else if !reflect.DeepEqual(drts, drps) { - t.Errorf("Expecting: %+v, received: %+v", drts, drps) + } else if !reflect.DeepEqual(mrp, drps) { + t.Errorf("Expecting: %+v, received: %+v", mrp, drps) } } @@ -168,14 +178,14 @@ 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 { + mrp := APItoModelRatingProfile(rp) + if err := mysqlDb.SetTpRatingProfiles(mrp); err != nil { t.Error(err.Error()) } - if rps, err := mysqlDb.GetTpRatingProfiles(rp); err != nil { + if rps, err := mysqlDb.GetTpRatingProfiles(&mrp[0]); err != nil { t.Error(err.Error()) - } else if !reflect.DeepEqual(setRps, rps) { - t.Errorf("Expecting: %+v, received: %+v", setRps, rps) + } else if !reflect.DeepEqual(mrp, rps) { + t.Errorf("Expecting: %+v, received: %+v", mrp, rps) } } @@ -185,14 +195,21 @@ func TestMySQLSetGetTPSharedGroups(t *testing.T) { return } 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 { + tpSgs := &utils.TPSharedGroups{ + TPid: TEST_SQL, + SharedGroupsId: SG_ID, + SharedGroups: []*utils.TPSharedGroup{ + &utils.TPSharedGroup{Account: "dan", Strategy: "*lowest_first", RatingSubject: "lowest_rates"}, + }, + } + mSgs := APItoModelSharedGroup(tpSgs) + if err := mysqlDb.SetTpSharedGroups(mSgs); err != nil { t.Error(err.Error()) } if sgs, err := mysqlDb.GetTpSharedGroups(TEST_SQL, SG_ID); err != nil { t.Error(err.Error()) - } else if !reflect.DeepEqual(setSgs, sgs) { - t.Errorf("Expecting: %+v, received: %+v", setSgs, sgs) + } else if !reflect.DeepEqual(mSgs, sgs) { + t.Errorf("Expecting: %+v, received: %+v", mSgs, sgs) } } @@ -201,16 +218,21 @@ func TestMySQLSetGetTPCdrStats(t *testing.T) { return } CS_ID := "CDRSTATS_1" - 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 { + setCS := &utils.TPCdrStats{ + TPid: TEST_SQL, + CdrStatsId: CS_ID, + CdrStats: []*utils.TPCdrStat{ + &utils.TPCdrStat{QueueLength: "10", TimeWindow: "10m", Metrics: "ASR", Tenants: "cgrates.org", Categories: "call"}, + }, + } + mcs := APItoModelCdrStat(setCS) + if err := mysqlDb.SetTpCdrStats(mcs); err != nil { t.Error(err.Error()) } if cs, err := mysqlDb.GetTpCdrStats(TEST_SQL, CS_ID); err != nil { t.Error(err.Error()) - } else if !reflect.DeepEqual(setCS, cs) { - t.Errorf("Expecting: %+v, received: %+v", setCS, cs) + } else if !reflect.DeepEqual(mcs, cs) { + t.Errorf("Expecting: %+v, received: %+v", mcs, cs) } } @@ -221,15 +243,15 @@ func TestMySQLSetGetTPDerivedChargers(t *testing.T) { dc := &utils.TPDerivedCharger{RunId: utils.DEFAULT_RUNID, ReqTypeField: "^" + utils.META_PREPAID, AccountField: "^rif", SubjectField: "^rif", UsageField: "cgr_duration", SupplierField: "^supplier1"} 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 { + + mdcs := APItoModelDerivedCharger(dcs) + if err := mysqlDb.SetTpDerivedChargers(mdcs); err != nil { t.Error(err.Error()) } - if rDCs, err := mysqlDb.GetTpDerivedChargers(dcs); err != nil { + if rDCs, err := mysqlDb.GetTpDerivedChargers(&mdcs[0]); err != nil { t.Error(err.Error()) - } else if !reflect.DeepEqual(dcs, rDCs[DCS_ID]) { - t.Errorf("Expecting: %+v, received: %+v", dcs, rDCs[DCS_ID]) + } else if !reflect.DeepEqual(mdcs, rDCs) { + t.Errorf("Expecting: %+v, received: %+v", mdcs, rDCs) } } @@ -242,13 +264,14 @@ func TestMySQLSetGetTPActions(t *testing.T) { &utils.TPAction{Identifier: "*topup_reset", BalanceType: "*monetary", Direction: "*out", Units: 10, ExpiryTime: "*unlimited", DestinationIds: "*any", BalanceWeight: 10, Weight: 10}} tpActions := &utils.TPActions{TPid: TEST_SQL, ActionsId: ACTS_ID, Actions: acts} - if err := mysqlDb.SetTPActions(TEST_SQL, map[string][]*utils.TPAction{ACTS_ID: acts}); err != nil { + mas := APItoModelAction(tpActions) + if err := mysqlDb.SetTpActions(mas); err != nil { t.Error(err.Error()) } - if rTpActs, err := mysqlDb.GetTPActions(TEST_SQL, ACTS_ID); err != nil { + if rTpActs, err := mysqlDb.GetTpActions(TEST_SQL, ACTS_ID); err != nil { t.Error(err.Error()) - } else if !reflect.DeepEqual(tpActions, rTpActs) { - t.Errorf("Expecting: %+v, received: %+v", tpActions, rTpActs) + } else if !reflect.DeepEqual(mas, rTpActs) { + t.Errorf("Expecting: %+v, received: %+v", mas, rTpActs) } } @@ -257,14 +280,19 @@ func TestMySQLTPActionTimings(t *testing.T) { return } AP_ID := "AP_1" - ap := map[string][]*utils.TPActionTiming{AP_ID: []*utils.TPActionTiming{&utils.TPActionTiming{ActionsId: "ACTS_1", TimingId: "TM_1", Weight: 10.0}}} - if err := mysqlDb.SetTPActionTimings(TEST_SQL, ap); err != nil { + ap := &utils.TPActionPlan{ + TPid: TEST_SQL, + Id: AP_ID, + ActionPlan: []*utils.TPActionTiming{&utils.TPActionTiming{ActionsId: "ACTS_1", TimingId: "TM_1", Weight: 10.0}}, + } + maps := APItoModelActionPlan(ap) + if err := mysqlDb.SetTpActionPlans(maps); err != nil { t.Error(err.Error()) } - if rAP, err := mysqlDb.GetTPActionTimings(TEST_SQL, AP_ID); err != nil { + if rAP, err := mysqlDb.GetTpActionPlans(TEST_SQL, AP_ID); err != nil { t.Error(err.Error()) - } else if !reflect.DeepEqual(ap, rAP) { - t.Errorf("Expecting: %+v, received: %+v", ap, rAP) + } else if !reflect.DeepEqual(maps, rAP) { + t.Errorf("Expecting: %+v, received: %+v", maps, rAP) } } @@ -283,14 +311,19 @@ func TestMySQLSetGetTPActionTriggers(t *testing.T) { Weight: 10.0, ActionsId: "LOG_BALANCE", } - mpAtrgs := map[string][]*utils.TPActionTrigger{TEST_SQL: []*utils.TPActionTrigger{atrg}} - if err := mysqlDb.SetTPActionTriggers(TEST_SQL, mpAtrgs); err != nil { + atrgs := &utils.TPActionTriggers{ + TPid: TEST_SQL, + ActionTriggersId: TEST_SQL, + ActionTriggers: []*utils.TPActionTrigger{atrg}, + } + matrg := APItoModelActionTrigger(atrgs) + if err := mysqlDb.SetTpActionTriggers(matrg); err != nil { t.Error("Unexpected error: ", err.Error()) } if rcvMpAtrgs, err := mysqlDb.GetTpActionTriggers(TEST_SQL, TEST_SQL); err != nil { t.Error("Unexpected error: ", err.Error()) - } else if !reflect.DeepEqual(mpAtrgs, rcvMpAtrgs) { - t.Errorf("Expecting: %v, received: %v", mpAtrgs, rcvMpAtrgs) + } else if !reflect.DeepEqual(matrg, rcvMpAtrgs) { + t.Errorf("Expecting: %v, received: %v", matrg, rcvMpAtrgs) } } @@ -300,13 +333,14 @@ func TestMySQLSetGetTpAccountActions(t *testing.T) { } aa := &utils.TPAccountActions{TPid: TEST_SQL, Tenant: "cgrates.org", Account: "1001", Direction: "*out", ActionPlanId: "PREPAID_10", ActionTriggersId: "STANDARD_TRIGGERS"} - if err := mysqlDb.SetTPAccountActions(aa.TPid, map[string]*utils.TPAccountActions{aa.KeyId(): aa}); err != nil { + maa := APItoModelAccountAction(aa) + if err := mysqlDb.SetTpAccountActions([]TpAccountAction{*maa}); err != nil { t.Error(err.Error()) } - if aas, err := mysqlDb.GetTpAccountActions(aa); err != nil { + if aas, err := mysqlDb.GetTpAccountActions(maa); err != nil { t.Error(err.Error()) - } else if !reflect.DeepEqual(aa, aas[aa.KeyId()]) { - t.Errorf("Expecting: %+v, received: %+v", aa, aas[aa.KeyId()]) + } else if !reflect.DeepEqual(maa, aas) { + t.Errorf("Expecting: %+v, received: %+v", maa, aas) } } @@ -315,7 +349,7 @@ func TestMySQLGetTPIds(t *testing.T) { return } eTPIds := []string{TEST_SQL} - if tpIds, err := mysqlDb.GetTPIds(); err != nil { + if tpIds, err := mysqlDb.GetTpIds(); err != nil { t.Error(err.Error()) } else if !reflect.DeepEqual(eTPIds, tpIds) { t.Errorf("Expecting: %+v, received: %+v", eTPIds, tpIds) @@ -328,7 +362,8 @@ func TestMySQLRemoveTPData(t *testing.T) { } // Create Timings tm := &utils.ApierTPTiming{TPid: TEST_SQL, TimingId: "ALWAYS", Time: "00:00:00"} - if err := mysqlDb.SetTPTiming(tm); err != nil { + tms := APItoModelTiming(tm) + if err := mysqlDb.SetTpTimings([]TpTiming{*tms}); err != nil { t.Error(err.Error()) } if tmgs, err := mysqlDb.GetTpTimings(TEST_SQL, tm.TimingId); err != nil { @@ -337,7 +372,7 @@ func TestMySQLRemoveTPData(t *testing.T) { t.Error("Could not store TPTiming") } // Remove Timings - if err := mysqlDb.RemTPData(utils.TBL_TP_TIMINGS, TEST_SQL, tm.TimingId); err != nil { + if err := mysqlDb.RemTpData(utils.TBL_TP_TIMINGS, TEST_SQL, tm.TimingId); err != nil { t.Error(err.Error()) } if tmgs, err := mysqlDb.GetTpTimings(TEST_SQL, tm.TimingId); err != nil { @@ -348,19 +383,20 @@ func TestMySQLRemoveTPData(t *testing.T) { // Create RatingProfile ras := []*utils.TPRatingActivation{&utils.TPRatingActivation{ActivationTime: "2012-01-01T00:00:00Z", RatingPlanId: "RETAIL1"}} rp := &utils.TPRatingProfile{TPid: TEST_SQL, LoadId: TEST_SQL, Tenant: "cgrates.org", Category: "call", Direction: "*out", Subject: "*any", RatingPlanActivations: ras} - if err := mysqlDb.SetTPRatingProfiles(TEST_SQL, map[string]*utils.TPRatingProfile{rp.KeyId(): rp}); err != nil { + mrp := APItoModelRatingProfile(rp) + if err := mysqlDb.SetTpRatingProfiles(mrp); err != nil { t.Error(err.Error()) } - if rps, err := mysqlDb.GetTpRatingProfiles(rp); err != nil { + if rps, err := mysqlDb.GetTpRatingProfiles(&mrp[0]); err != nil { t.Error(err.Error()) } else if len(rps) == 0 { t.Error("Could not store TPRatingProfile") } // Remove RatingProfile - if err := mysqlDb.RemTPData(utils.TBL_TP_RATE_PROFILES, rp.TPid, rp.LoadId, rp.Direction, rp.Tenant, rp.Category, rp.Subject); err != nil { + if err := mysqlDb.RemTpData(utils.TBL_TP_RATE_PROFILES, rp.TPid, rp.LoadId, rp.Direction, rp.Tenant, rp.Category, rp.Subject); err != nil { t.Error(err.Error()) } - if rps, err := mysqlDb.GetTpRatingProfiles(rp); err != nil { + if rps, err := mysqlDb.GetTpRatingProfiles(&mrp[0]); err != nil { t.Error(err) } else if len(rps) != 0 { t.Errorf("RatingProfiles different than 0: %+v", rps) @@ -368,25 +404,26 @@ func TestMySQLRemoveTPData(t *testing.T) { // Create AccountActions aa := &utils.TPAccountActions{TPid: TEST_SQL, LoadId: TEST_SQL, Tenant: "cgrates.org", Account: "1001", Direction: "*out", ActionPlanId: "PREPAID_10", ActionTriggersId: "STANDARD_TRIGGERS"} - if err := mysqlDb.SetTPAccountActions(aa.TPid, map[string]*utils.TPAccountActions{aa.KeyId(): aa}); err != nil { + maa := APItoModelAccountAction(aa) + if err := mysqlDb.SetTpAccountActions([]TpAccountAction{*maa}); err != nil { t.Error(err.Error()) } - if aas, err := mysqlDb.GetTpAccountActions(aa); err != nil { + if aas, err := mysqlDb.GetTpAccountActions(maa); err != nil { t.Error(err.Error()) } else if len(aas) == 0 { t.Error("Could not create TPAccountActions") } // Remove AccountActions - if err := mysqlDb.RemTPData(utils.TBL_TP_ACCOUNT_ACTIONS, aa.TPid, aa.LoadId, aa.Direction, aa.Tenant, aa.Account); err != nil { + if err := mysqlDb.RemTpData(utils.TBL_TP_ACCOUNT_ACTIONS, aa.TPid, aa.LoadId, aa.Direction, aa.Tenant, aa.Account); err != nil { t.Error(err.Error()) } - if aas, err := mysqlDb.GetTpAccountActions(aa); err != nil { + if aas, err := mysqlDb.GetTpAccountActions(maa); err != nil { t.Error(err) } else if len(aas) != 0 { t.Errorf("Non empty account actions: %+v", aas) } // Create again so we can test complete TP removal - if err := mysqlDb.SetTPTiming(tm); err != nil { + if err := mysqlDb.SetTpTimings([]TpTiming{*tms}); err != nil { t.Error(err.Error()) } if tmgs, err := mysqlDb.GetTpTimings(TEST_SQL, tm.TimingId); err != nil { @@ -395,25 +432,25 @@ func TestMySQLRemoveTPData(t *testing.T) { t.Error("Could not store TPTiming") } // Create RatingProfile - if err := mysqlDb.SetTPRatingProfiles(TEST_SQL, map[string]*utils.TPRatingProfile{rp.KeyId(): rp}); err != nil { + if err := mysqlDb.SetTpRatingProfiles(mrp); err != nil { t.Error(err.Error()) } - if rps, err := mysqlDb.GetTpRatingProfiles(rp); err != nil { + if rps, err := mysqlDb.GetTpRatingProfiles(&mrp[0]); err != nil { t.Error(err.Error()) } else if len(rps) == 0 { t.Error("Could not store TPRatingProfile") } // Create AccountActions - if err := mysqlDb.SetTPAccountActions(aa.TPid, map[string]*utils.TPAccountActions{aa.KeyId(): aa}); err != nil { + if err := mysqlDb.SetTpAccountActions([]TpAccountAction{*maa}); err != nil { t.Error(err.Error()) } - if aas, err := mysqlDb.GetTpAccountActions(aa); err != nil { + if aas, err := mysqlDb.GetTpAccountActions(maa); err != nil { t.Error(err.Error()) } else if len(aas) == 0 { t.Error("Could not create TPAccountActions") } // Remove TariffPlan completely - if err := mysqlDb.RemTPData("", TEST_SQL); err != nil { + if err := mysqlDb.RemTpData("", TEST_SQL); err != nil { t.Error(err.Error()) } // Make sure we have removed it @@ -422,12 +459,12 @@ func TestMySQLRemoveTPData(t *testing.T) { } else if len(tms) != 0 { t.Errorf("Non empty timings: %+v", tms) } - if rpfs, err := mysqlDb.GetTpRatingProfiles(rp); err != nil { + if rpfs, err := mysqlDb.GetTpRatingProfiles(&mrp[0]); err != nil { t.Error(err) } else if len(rpfs) != 0 { t.Errorf("Non empty rpfs: %+v", rpfs) } - if aas, err := mysqlDb.GetTpAccountActions(aa); err != nil { + if aas, err := mysqlDb.GetTpAccountActions(maa); err != nil { t.Error(err) } else if len(aas) != 0 { t.Errorf("Non empty account actions: %+v", aas) diff --git a/engine/storage_psql_local_test.go b/engine/storage_psql_local_test.go index 55a6e3465..e2482e352 100644 --- a/engine/storage_psql_local_test.go +++ b/engine/storage_psql_local_test.go @@ -61,23 +61,25 @@ func TestPSQLSetGetTPTiming(t *testing.T) { return } tm := &utils.ApierTPTiming{TPid: TEST_SQL, TimingId: "ALWAYS", Time: "00:00:00"} - if err := psqlDb.SetTPTiming(tm); err != nil { + mtm := APItoModelTiming(tm) + mtms := []TpTiming{*mtm} + if err := psqlDb.SetTpTimings(mtms); err != nil { t.Error(err.Error()) } if tmgs, err := psqlDb.GetTpTimings(TEST_SQL, tm.TimingId); 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(mtms, tmgs) { + t.Errorf("Expecting: %+v, received: %+v", mtms, tmgs) } // Update tm.Time = "00:00:01" - if err := psqlDb.SetTPTiming(tm); err != nil { + if err := psqlDb.SetTpTimings(mtms); err != nil { t.Error(err.Error()) } if tmgs, err := psqlDb.GetTpTimings(TEST_SQL, tm.TimingId); 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(mtms, tmgs) { + t.Errorf("Expecting: %+v, received: %+v", mtms, tmgs) } } @@ -85,12 +87,13 @@ func TestPSQLSetGetTPDestination(t *testing.T) { if !*testLocal { return } - dst := &Destination{Id: TEST_SQL, Prefixes: []string{"+49", "+49151", "+49176"}} - if err := psqlDb.SetTPDestination(TEST_SQL, dst); err != nil { + dst := &utils.TPDestination{TPid: TEST_SQL, DestinationId: TEST_SQL, Prefixes: []string{"+49", "+49151", "+49176"}} + dests := APItoModelDestination(dst) + if err := psqlDb.SetTpDestinations(dests); err != nil { t.Error(err.Error()) } storData, err := psqlDb.GetTpDestinations(TEST_SQL, TEST_SQL) - dsts := TpDestinations(storData).GetDestinations() + dsts, err := TpDestinations(storData).GetDestinations() if err != nil { t.Error(err.Error()) } else if len(dst.Prefixes) != len(dsts[TEST_SQL].Prefixes) { @@ -110,15 +113,17 @@ func TestPSQLSetGetTPRates(t *testing.T) { for _, rs := range rtSlots { rs.SetDurations() } - mpRates := map[string][]*utils.RateSlot{RT_ID: rtSlots} expectedTPRate := &utils.TPRate{TPid: TEST_SQL, RateId: RT_ID, RateSlots: rtSlots} - if err := psqlDb.SetTPRates(TEST_SQL, mpRates); err != nil { + mRates := APItoModelRate(expectedTPRate) + if err := psqlDb.SetTpRates(mRates); err != nil { t.Error(err.Error()) } - if rts, err := psqlDb.GetTpRates(TEST_SQL, RT_ID); err != nil { + rts, err := psqlDb.GetTpRates(TEST_SQL, RT_ID) + trts, err := TpRates(rts).GetRates() + if err != nil { t.Error(err.Error()) - } else if len(expectedTPRate.RateSlots) != len(rts[RT_ID].RateSlots) { - t.Errorf("Expecting: %+v, received: %+v", expectedTPRate, rts[RT_ID]) + } else if len(expectedTPRate.RateSlots) != len(trts[RT_ID].RateSlots) { + t.Errorf("Expecting: %+v, received: %+v", expectedTPRate, trts[RT_ID]) } } @@ -128,15 +133,15 @@ func TestPSQLSetGetTPDestinationRates(t *testing.T) { } DR_ID := "DR_1" 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 := psqlDb.SetTPDestinationRates(TEST_SQL, drs); err != nil { + mdrs := APItoModelDestinationRate(eDrs) + if err := psqlDb.SetTpDestinationRates(mdrs); err != nil { t.Error(err.Error()) } if drs, err := psqlDb.GetTpDestinationRates(TEST_SQL, DR_ID, nil); err != nil { t.Error(err.Error()) - } else if !reflect.DeepEqual(eDrs, drs[DR_ID]) { - t.Errorf("Expecting: %+v, received: %+v", eDrs, drs[DR_ID]) + } else if !reflect.DeepEqual(mdrs, drs) { + t.Errorf("Expecting: %+v, received: %+v", mdrs, drs) } } @@ -146,14 +151,20 @@ func TestPSQLSetGetTPRatingPlans(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 := psqlDb.SetTPRatingPlans(TEST_SQL, drts); err != nil { + rp := &utils.TPRatingPlan{ + TPid: TEST_SQL, + RatingPlanId: RP_ID, + RatingPlanBindings: []*utils.TPRatingPlanBinding{rbBinding}, + } + mrp := APItoModelRatingPlan(rp) + + if err := psqlDb.SetTpRatingPlans(mrp); err != nil { t.Error(err.Error()) } if drps, err := psqlDb.GetTpRatingPlans(TEST_SQL, RP_ID, nil); err != nil { t.Error(err.Error()) - } else if !reflect.DeepEqual(drts, drps) { - t.Errorf("Expecting: %+v, received: %+v", drts, drps) + } else if !reflect.DeepEqual(mrp, drps) { + t.Errorf("Expecting: %+v, received: %+v", mrp, drps) } } @@ -163,14 +174,15 @@ func TestPSQLSetGetTPRatingProfiles(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 := psqlDb.SetTPRatingProfiles(TEST_SQL, setRps); err != nil { + + mrp := APItoModelRatingProfile(rp) + if err := psqlDb.SetTpRatingProfiles(mrp); err != nil { t.Error(err.Error()) } - if rps, err := psqlDb.GetTpRatingProfiles(rp); err != nil { + if rps, err := psqlDb.GetTpRatingProfiles(&mrp[0]); err != nil { t.Error(err.Error()) - } else if !reflect.DeepEqual(setRps, rps) { - t.Errorf("Expecting: %+v, received: %+v", setRps, rps) + } else if !reflect.DeepEqual(mrp, rps) { + t.Errorf("Expecting: %+v, received: %+v", mrp, rps) } } @@ -179,14 +191,21 @@ func TestPSQLSetGetTPSharedGroups(t *testing.T) { return } 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 := psqlDb.SetTPSharedGroups(TEST_SQL, setSgs); err != nil { + tpSgs := &utils.TPSharedGroups{ + TPid: TEST_SQL, + SharedGroupsId: SG_ID, + SharedGroups: []*utils.TPSharedGroup{ + &utils.TPSharedGroup{Account: "dan", Strategy: "*lowest_first", RatingSubject: "lowest_rates"}, + }, + } + mSgs := APItoModelSharedGroup(tpSgs) + if err := psqlDb.SetTpSharedGroups(mSgs); err != nil { t.Error(err.Error()) } if sgs, err := psqlDb.GetTpSharedGroups(TEST_SQL, SG_ID); err != nil { t.Error(err.Error()) - } else if !reflect.DeepEqual(setSgs, sgs) { - t.Errorf("Expecting: %+v, received: %+v", setSgs, sgs) + } else if !reflect.DeepEqual(mSgs, sgs) { + t.Errorf("Expecting: %+v, received: %+v", mSgs, sgs) } } @@ -195,16 +214,21 @@ func TestPSQLSetGetTPCdrStats(t *testing.T) { return } CS_ID := "CDRSTATS_1" - setCS := map[string][]*utils.TPCdrStat{CS_ID: []*utils.TPCdrStat{ - &utils.TPCdrStat{QueueLength: "10", TimeWindow: "10m", Metrics: "ASR", Tenants: "cgrates.org", Categories: "call"}, - }} - if err := psqlDb.SetTPCdrStats(TEST_SQL, setCS); err != nil { + setCS := &utils.TPCdrStats{ + TPid: TEST_SQL, + CdrStatsId: CS_ID, + CdrStats: []*utils.TPCdrStat{ + &utils.TPCdrStat{QueueLength: "10", TimeWindow: "10m", Metrics: "ASR", Tenants: "cgrates.org", Categories: "call"}, + }, + } + mcs := APItoModelCdrStat(setCS) + if err := psqlDb.SetTpCdrStats(mcs); err != nil { t.Error(err.Error()) } if cs, err := psqlDb.GetTpCdrStats(TEST_SQL, CS_ID); err != nil { t.Error(err.Error()) - } else if !reflect.DeepEqual(setCS, cs) { - t.Errorf("Expecting: %+v, received: %+v", setCS, cs) + } else if !reflect.DeepEqual(mcs, cs) { + t.Errorf("Expecting: %+v, received: %+v", mcs, cs) } } @@ -215,15 +239,14 @@ func TestPSQLSetGetTPDerivedChargers(t *testing.T) { dc := &utils.TPDerivedCharger{RunId: utils.DEFAULT_RUNID, ReqTypeField: "^" + utils.META_PREPAID, AccountField: "^rif", SubjectField: "^rif", UsageField: "cgr_duration", SupplierField: "^supplier1"} 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 := psqlDb.SetTPDerivedChargers(TEST_SQL, setDCs); err != nil { + mdcs := APItoModelDerivedCharger(dcs) + if err := psqlDb.SetTpDerivedChargers(mdcs); err != nil { t.Error(err.Error()) } - if rDCs, err := psqlDb.GetTpDerivedChargers(dcs); err != nil { + if rDCs, err := psqlDb.GetTpDerivedChargers(&mdcs[0]); err != nil { t.Error(err.Error()) - } else if !reflect.DeepEqual(dcs, rDCs[DCS_ID]) { - t.Errorf("Expecting: %+v, received: %+v", dcs, rDCs[DCS_ID]) + } else if !reflect.DeepEqual(mdcs, rDCs) { + t.Errorf("Expecting: %+v, received: %+v", mdcs, rDCs) } } @@ -236,13 +259,14 @@ func TestPSQLSetGetTPActions(t *testing.T) { &utils.TPAction{Identifier: "*topup_reset", BalanceType: "*monetary", Direction: "*out", Units: 10, ExpiryTime: "*unlimited", DestinationIds: "*any", BalanceWeight: 10, Weight: 10}} tpActions := &utils.TPActions{TPid: TEST_SQL, ActionsId: ACTS_ID, Actions: acts} - if err := psqlDb.SetTPActions(TEST_SQL, map[string][]*utils.TPAction{ACTS_ID: acts}); err != nil { + mas := APItoModelAction(tpActions) + if err := psqlDb.SetTpActions(mas); err != nil { t.Error(err.Error()) } - if rTpActs, err := psqlDb.GetTPActions(TEST_SQL, ACTS_ID); err != nil { + if rTpActs, err := psqlDb.GetTpActions(TEST_SQL, ACTS_ID); err != nil { t.Error(err.Error()) - } else if !reflect.DeepEqual(tpActions, rTpActs) { - t.Errorf("Expecting: %+v, received: %+v", tpActions, rTpActs) + } else if !reflect.DeepEqual(mas, rTpActs) { + t.Errorf("Expecting: %+v, received: %+v", mas, rTpActs) } } @@ -251,14 +275,19 @@ func TestPSQLTPActionTimings(t *testing.T) { return } AP_ID := "AP_1" - ap := map[string][]*utils.TPActionTiming{AP_ID: []*utils.TPActionTiming{&utils.TPActionTiming{ActionsId: "ACTS_1", TimingId: "TM_1", Weight: 10.0}}} - if err := psqlDb.SetTPActionTimings(TEST_SQL, ap); err != nil { + ap := &utils.TPActionPlan{ + TPid: TEST_SQL, + Id: AP_ID, + ActionPlan: []*utils.TPActionTiming{&utils.TPActionTiming{ActionsId: "ACTS_1", TimingId: "TM_1", Weight: 10.0}}, + } + maps := APItoModelActionPlan(ap) + if err := psqlDb.SetTpActionPlans(maps); err != nil { t.Error(err.Error()) } - if rAP, err := psqlDb.GetTPActionTimings(TEST_SQL, AP_ID); err != nil { + if rAP, err := psqlDb.GetTpActionPlans(TEST_SQL, AP_ID); err != nil { t.Error(err.Error()) - } else if !reflect.DeepEqual(ap, rAP) { - t.Errorf("Expecting: %+v, received: %+v", ap, rAP) + } else if !reflect.DeepEqual(maps, rAP) { + t.Errorf("Expecting: %+v, received: %+v", maps, rAP) } } @@ -277,14 +306,19 @@ func TestPSQLSetGetTPActionTriggers(t *testing.T) { Weight: 10.0, ActionsId: "LOG_BALANCE", } - mpAtrgs := map[string][]*utils.TPActionTrigger{TEST_SQL: []*utils.TPActionTrigger{atrg}} - if err := psqlDb.SetTPActionTriggers(TEST_SQL, mpAtrgs); err != nil { + atrgs := &utils.TPActionTriggers{ + TPid: TEST_SQL, + ActionTriggersId: TEST_SQL, + ActionTriggers: []*utils.TPActionTrigger{atrg}, + } + matrg := APItoModelActionTrigger(atrgs) + if err := psqlDb.SetTpActionTriggers(matrg); err != nil { t.Error("Unexpected error: ", err.Error()) } if rcvMpAtrgs, err := psqlDb.GetTpActionTriggers(TEST_SQL, TEST_SQL); err != nil { t.Error("Unexpected error: ", err.Error()) - } else if !reflect.DeepEqual(mpAtrgs, rcvMpAtrgs) { - t.Errorf("Expecting: %v, received: %v", mpAtrgs, rcvMpAtrgs) + } else if !reflect.DeepEqual(matrg, rcvMpAtrgs) { + t.Errorf("Expecting: %v, received: %v", matrg, rcvMpAtrgs) } } @@ -294,13 +328,14 @@ func TestPSQLSetGetTpAccountActions(t *testing.T) { } aa := &utils.TPAccountActions{TPid: TEST_SQL, Tenant: "cgrates.org", Account: "1001", Direction: "*out", ActionPlanId: "PREPAID_10", ActionTriggersId: "STANDARD_TRIGGERS"} - if err := psqlDb.SetTPAccountActions(aa.TPid, map[string]*utils.TPAccountActions{aa.KeyId(): aa}); err != nil { + maa := APItoModelAccountAction(aa) + if err := psqlDb.SetTpAccountActions([]TpAccountAction{*maa}); err != nil { t.Error(err.Error()) } - if aas, err := psqlDb.GetTpAccountActions(aa); err != nil { + if aas, err := psqlDb.GetTpAccountActions(maa); err != nil { t.Error(err.Error()) - } else if !reflect.DeepEqual(aa, aas[aa.KeyId()]) { - t.Errorf("Expecting: %+v, received: %+v", aa, aas[aa.KeyId()]) + } else if !reflect.DeepEqual(maa, aas) { + t.Errorf("Expecting: %+v, received: %+v", maa, aas) } } @@ -309,7 +344,7 @@ func TestPSQLGetTPIds(t *testing.T) { return } eTPIds := []string{TEST_SQL} - if tpIds, err := psqlDb.GetTPIds(); err != nil { + if tpIds, err := psqlDb.GetTpIds(); err != nil { t.Error(err.Error()) } else if !reflect.DeepEqual(eTPIds, tpIds) { t.Errorf("Expecting: %+v, received: %+v", eTPIds, tpIds) @@ -322,7 +357,8 @@ func TestPSQLRemoveTPData(t *testing.T) { } // Create Timings tm := &utils.ApierTPTiming{TPid: TEST_SQL, TimingId: "ALWAYS", Time: "00:00:00"} - if err := psqlDb.SetTPTiming(tm); err != nil { + tms := APItoModelTiming(tm) + if err := psqlDb.SetTpTimings([]TpTiming{*tms}); err != nil { t.Error(err.Error()) } if tmgs, err := psqlDb.GetTpTimings(TEST_SQL, tm.TimingId); err != nil { @@ -331,7 +367,7 @@ func TestPSQLRemoveTPData(t *testing.T) { t.Error("Could not store TPTiming") } // Remove Timings - if err := psqlDb.RemTPData(utils.TBL_TP_TIMINGS, TEST_SQL, tm.TimingId); err != nil { + if err := psqlDb.RemTpData(utils.TBL_TP_TIMINGS, TEST_SQL, tm.TimingId); err != nil { t.Error(err.Error()) } if tmgs, err := psqlDb.GetTpTimings(TEST_SQL, tm.TimingId); err != nil { @@ -342,19 +378,20 @@ func TestPSQLRemoveTPData(t *testing.T) { // Create RatingProfile ras := []*utils.TPRatingActivation{&utils.TPRatingActivation{ActivationTime: "2012-01-01T00:00:00Z", RatingPlanId: "RETAIL1"}} rp := &utils.TPRatingProfile{TPid: TEST_SQL, LoadId: TEST_SQL, Tenant: "cgrates.org", Category: "call", Direction: "*out", Subject: "*any", RatingPlanActivations: ras} - if err := psqlDb.SetTPRatingProfiles(TEST_SQL, map[string]*utils.TPRatingProfile{rp.KeyId(): rp}); err != nil { + mrp := APItoModelRatingProfile(rp) + if err := psqlDb.SetTpRatingProfiles(mrp); err != nil { t.Error(err.Error()) } - if rps, err := psqlDb.GetTpRatingProfiles(rp); err != nil { + if rps, err := psqlDb.GetTpRatingProfiles(&mrp[0]); err != nil { t.Error(err.Error()) } else if len(rps) == 0 { t.Error("Could not store TPRatingProfile") } // Remove RatingProfile - if err := psqlDb.RemTPData(utils.TBL_TP_RATE_PROFILES, rp.TPid, rp.LoadId, rp.Direction, rp.Tenant, rp.Category, rp.Subject); err != nil { + if err := psqlDb.RemTpData(utils.TBL_TP_RATE_PROFILES, rp.TPid, rp.LoadId, rp.Direction, rp.Tenant, rp.Category, rp.Subject); err != nil { t.Error(err.Error()) } - if rps, err := psqlDb.GetTpRatingProfiles(rp); err != nil { + if rps, err := psqlDb.GetTpRatingProfiles(&mrp[0]); err != nil { t.Error(err) } else if len(rps) != 0 { t.Errorf("RatingProfiles different than 0: %+v", rps) @@ -362,25 +399,26 @@ func TestPSQLRemoveTPData(t *testing.T) { // Create AccountActions aa := &utils.TPAccountActions{TPid: TEST_SQL, LoadId: TEST_SQL, Tenant: "cgrates.org", Account: "1001", Direction: "*out", ActionPlanId: "PREPAID_10", ActionTriggersId: "STANDARD_TRIGGERS"} - if err := psqlDb.SetTPAccountActions(aa.TPid, map[string]*utils.TPAccountActions{aa.KeyId(): aa}); err != nil { + maa := APItoModelAccountAction(aa) + if err := psqlDb.SetTpAccountActions([]TpAccountAction{*maa}); err != nil { t.Error(err.Error()) } - if aas, err := psqlDb.GetTpAccountActions(aa); err != nil { + if aas, err := psqlDb.GetTpAccountActions(maa); err != nil { t.Error(err.Error()) } else if len(aas) == 0 { t.Error("Could not create TPAccountActions") } // Remove AccountActions - if err := psqlDb.RemTPData(utils.TBL_TP_ACCOUNT_ACTIONS, aa.TPid, aa.LoadId, aa.Direction, aa.Tenant, aa.Account); err != nil { + if err := psqlDb.RemTpData(utils.TBL_TP_ACCOUNT_ACTIONS, aa.TPid, aa.LoadId, aa.Direction, aa.Tenant, aa.Account); err != nil { t.Error(err.Error()) } - if aas, err := psqlDb.GetTpAccountActions(aa); err != nil { + if aas, err := psqlDb.GetTpAccountActions(maa); err != nil { t.Error(err) } else if len(aas) != 0 { t.Errorf("Non empty account actions: %+v", aas) } // Create again so we can test complete TP removal - if err := psqlDb.SetTPTiming(tm); err != nil { + if err := psqlDb.SetTpTimings([]TpTiming{*tms}); err != nil { t.Error(err.Error()) } if tmgs, err := psqlDb.GetTpTimings(TEST_SQL, tm.TimingId); err != nil { @@ -389,25 +427,25 @@ func TestPSQLRemoveTPData(t *testing.T) { t.Error("Could not store TPTiming") } // Create RatingProfile - if err := psqlDb.SetTPRatingProfiles(TEST_SQL, map[string]*utils.TPRatingProfile{rp.KeyId(): rp}); err != nil { + if err := psqlDb.SetTpRatingProfiles(mrp); err != nil { t.Error(err.Error()) } - if rps, err := psqlDb.GetTpRatingProfiles(rp); err != nil { + if rps, err := psqlDb.GetTpRatingProfiles(&mrp[0]); err != nil { t.Error(err.Error()) } else if len(rps) == 0 { t.Error("Could not store TPRatingProfile") } // Create AccountActions - if err := psqlDb.SetTPAccountActions(aa.TPid, map[string]*utils.TPAccountActions{aa.KeyId(): aa}); err != nil { + if err := psqlDb.SetTpAccountActions([]TpAccountAction{*maa}); err != nil { t.Error(err.Error()) } - if aas, err := psqlDb.GetTpAccountActions(aa); err != nil { + if aas, err := psqlDb.GetTpAccountActions(maa); err != nil { t.Error(err.Error()) } else if len(aas) == 0 { t.Error("Could not create TPAccountActions") } // Remove TariffPlan completely - if err := psqlDb.RemTPData("", TEST_SQL); err != nil { + if err := psqlDb.RemTpData("", TEST_SQL); err != nil { t.Error(err.Error()) } // Make sure we have removed it @@ -416,12 +454,12 @@ func TestPSQLRemoveTPData(t *testing.T) { } else if len(tms) != 0 { t.Errorf("Non empty timings: %+v", tms) } - if rpfs, err := psqlDb.GetTpRatingProfiles(rp); err != nil { + if rpfs, err := psqlDb.GetTpRatingProfiles(&mrp[0]); err != nil { t.Error(err) } else if len(rpfs) != 0 { t.Errorf("Non empty rpfs: %+v", rpfs) } - if aas, err := psqlDb.GetTpAccountActions(aa); err != nil { + if aas, err := psqlDb.GetTpAccountActions(maa); err != nil { t.Error(err) } else if len(aas) != 0 { t.Errorf("Non empty account actions: %+v", aas) diff --git a/engine/storage_sql.go b/engine/storage_sql.go index 2eea1b622..7d4bc03f2 100644 --- a/engine/storage_sql.go +++ b/engine/storage_sql.go @@ -427,7 +427,7 @@ func (self *SQLStorage) SetTpDerivedChargers(sgs []TpDerivedCharger) error { return nil } -func (self *SQLStorage) SetTpLcrRules(sgs []TpLcrRules) error { +func (self *SQLStorage) SetTpLCRs(sgs []TpLcrRule) error { if len(sgs) == 0 { return nil //Nothing to set } @@ -435,15 +435,15 @@ func (self *SQLStorage) SetTpLcrRules(sgs []TpLcrRules) error { tx := self.db.Begin() for _, lcr := range sgs { - if found, _ := m[lcr.GetLcrRulesId()]; !found { - m[lcr.GetLcrRulesId()] = true - tmpDc := &TpLcrRules{} - if err := tmpDc.SetLcrRulesId(lcr.GetLcrRulesId()); err != nil { + if found, _ := m[lcr.GetLcrRuleId()]; !found { + m[lcr.GetLcrRuleId()] = true + tmpDc := &TpLcrRule{} + if err := tmpDc.SetLcrRuleId(lcr.GetLcrRuleId()); err != nil { tx.Rollback() return err } - if err := tx.Where(tmpDc).Delete(TpLcrRules{}).Error; err != nil { + if err := tx.Where(tmpDc).Delete(TpLcrRule{}).Error; err != nil { tx.Rollback() return err } @@ -483,7 +483,7 @@ func (self *SQLStorage) SetTpActions(acts []TpAction) error { return nil } -func (self *SQLStorage) SetTpActionPlan(ats []TpActionPlan) error { +func (self *SQLStorage) SetTpActionPlans(ats []TpActionPlan) error { if len(ats) == 0 { return nil //Nothing to set } @@ -1141,23 +1141,23 @@ func (self *SQLStorage) GetTpRatingPlans(tpid, tag string, pagination *utils.Pag return tpRatingPlans, nil } -func (self *SQLStorage) GetTpRatingProfiles(qryRpf *utils.TPRatingProfile) ([]TpRatingProfile, error) { +func (self *SQLStorage) GetTpRatingProfiles(filter *TpRatingProfile) ([]TpRatingProfile, error) { var tpRpfs []TpRatingProfile - q := self.db.Where("tpid = ?", qryRpf.TPid) - if len(qryRpf.Direction) != 0 { - q = q.Where("direction = ?", qryRpf.Direction) + q := self.db.Where("tpid = ?", filter.Tpid) + if len(filter.Direction) != 0 { + q = q.Where("direction = ?", filter.Direction) } - if len(qryRpf.Tenant) != 0 { - q = q.Where("tenant = ?", qryRpf.Tenant) + if len(filter.Tenant) != 0 { + q = q.Where("tenant = ?", filter.Tenant) } - if len(qryRpf.Category) != 0 { - q = q.Where("category = ?", qryRpf.Category) + if len(filter.Category) != 0 { + q = q.Where("category = ?", filter.Category) } - if len(qryRpf.Subject) != 0 { - q = q.Where("subject = ?", qryRpf.Subject) + if len(filter.Subject) != 0 { + q = q.Where("subject = ?", filter.Subject) } - if len(qryRpf.LoadId) != 0 { - q = q.Where("loadid = ?", qryRpf.LoadId) + if len(filter.Loadid) != 0 { + q = q.Where("loadid = ?", filter.Loadid) } if err := q.Find(&tpRpfs).Error; err != nil { return nil, err @@ -1179,17 +1179,17 @@ func (self *SQLStorage) GetTpSharedGroups(tpid, tag string) ([]TpSharedGroup, er } -func (self *SQLStorage) GetTpLCRs(tpid, tag string) ([]TpLcrRules, error) { - var tpLcrRules []TpLcrRules +func (self *SQLStorage) GetTpLCRs(tpid, tag string) ([]TpLcrRule, error) { + var tpLcrRule []TpLcrRule q := self.db.Where("tpid = ?", tpid) if len(tag) != 0 { q = q.Where("tag = ?", tag) } - if err := q.Find(&tpLcrRules).Error; err != nil { + if err := q.Find(&tpLcrRule).Error; err != nil { return nil, err } - return tpLcrRules, nil + return tpLcrRule, nil } func (self *SQLStorage) GetTpActions(tpid, tag string) ([]TpAction, error) { @@ -1218,7 +1218,7 @@ func (self *SQLStorage) GetTpActionTriggers(tpid, tag string) ([]TpActionTrigger return tpActionTriggers, nil } -func (self *SQLStorage) GetTpActionPlan(tpid, tag string) ([]*TpActionPlan, error) { +func (self *SQLStorage) GetTpActionPlans(tpid, tag string) ([]*TpActionPlan, error) { var tpActionPlans []*TpActionPlan q := self.db.Where("tpid = ?", tpid) if len(tag) != 0 { @@ -1231,21 +1231,21 @@ func (self *SQLStorage) GetTpActionPlan(tpid, tag string) ([]*TpActionPlan, erro return tpActionPlans, nil } -func (self *SQLStorage) GetTpAccountActions(aaFltr *utils.TPAccountActions) ([]TpAccountAction, error) { +func (self *SQLStorage) GetTpAccountActions(filter *TpAccountAction) ([]TpAccountAction, error) { var tpAccActs []TpAccountAction - q := self.db.Where("tpid = ?", aaFltr.TPid) - if len(aaFltr.Direction) != 0 { - q = q.Where("direction = ?", aaFltr.Direction) + q := self.db.Where("tpid = ?", filter.Tpid) + if len(filter.Direction) != 0 { + q = q.Where("direction = ?", filter.Direction) } - if len(aaFltr.Tenant) != 0 { - q = q.Where("tenant = ?", aaFltr.Tenant) + if len(filter.Tenant) != 0 { + q = q.Where("tenant = ?", filter.Tenant) } - if len(aaFltr.Account) != 0 { - q = q.Where("account = ?", aaFltr.Account) + if len(filter.Account) != 0 { + q = q.Where("account = ?", filter.Account) } - if len(aaFltr.LoadId) != 0 { - q = q.Where("loadid = ?", aaFltr.LoadId) + if len(filter.Loadid) != 0 { + q = q.Where("loadid = ?", filter.Loadid) } if err := q.Find(&tpAccActs).Error; err != nil { return nil, err @@ -1253,26 +1253,26 @@ func (self *SQLStorage) GetTpAccountActions(aaFltr *utils.TPAccountActions) ([]T return tpAccActs, nil } -func (self *SQLStorage) GetTpDerivedChargers(dc *utils.TPDerivedChargers) ([]TpDerivedCharger, error) { +func (self *SQLStorage) GetTpDerivedChargers(filter *TpDerivedCharger) ([]TpDerivedCharger, error) { var tpDerivedChargers []TpDerivedCharger - q := self.db.Where("tpid = ?", dc.TPid) - if len(dc.Direction) != 0 { - q = q.Where("direction = ?", dc.Direction) + q := self.db.Where("tpid = ?", filter.Tpid) + if len(filter.Direction) != 0 { + q = q.Where("direction = ?", filter.Direction) } - if len(dc.Tenant) != 0 { - q = q.Where("tenant = ?", dc.Tenant) + if len(filter.Tenant) != 0 { + q = q.Where("tenant = ?", filter.Tenant) } - if len(dc.Account) != 0 { - q = q.Where("account = ?", dc.Account) + if len(filter.Account) != 0 { + q = q.Where("account = ?", filter.Account) } - if len(dc.Category) != 0 { - q = q.Where("category = ?", dc.Category) + if len(filter.Category) != 0 { + q = q.Where("category = ?", filter.Category) } - if len(dc.Subject) != 0 { - q = q.Where("subject = ?", dc.Subject) + if len(filter.Subject) != 0 { + q = q.Where("subject = ?", filter.Subject) } - if len(dc.Loadid) != 0 { - q = q.Where("loadid = ?", dc.Loadid) + if len(filter.Loadid) != 0 { + q = q.Where("loadid = ?", filter.Loadid) } if err := q.Find(&tpDerivedChargers).Error; err != nil { return nil, err diff --git a/engine/tp_reader.go b/engine/tp_reader.go index 4e2365b9b..db89e9a65 100644 --- a/engine/tp_reader.go +++ b/engine/tp_reader.go @@ -240,7 +240,7 @@ func (tpr *TpReader) LoadRatingPlans() (err error) { return nil } -func (tpr *TpReader) LoadRatingProfilesFiltered(qriedRpf *utils.TPRatingProfile) error { +func (tpr *TpReader) LoadRatingProfilesFiltered(qriedRpf *TpRatingProfile) error { var resultRatingProfile *RatingProfile mpTpRpfs, err := tpr.lr.GetTpRatingProfiles(qriedRpf) if err != nil { @@ -563,7 +563,7 @@ func (tpr *TpReader) LoadActionTriggers() (err error) { return nil } -func (tpr *TpReader) LoadAccountActionsFiltered(qriedAA *utils.TPAccountActions) error { +func (tpr *TpReader) LoadAccountActionsFiltered(qriedAA *TpAccountAction) error { accountActions, err := tpr.lr.GetTpAccountActions(qriedAA) if err != nil { return errors.New(err.Error() + ": " + fmt.Sprintf("%+v", qriedAA)) @@ -796,7 +796,7 @@ func (tpr *TpReader) LoadAccountActions() (err error) { return nil } -func (tpr *TpReader) LoadDerivedChargersFiltered(filter *utils.TPDerivedChargers, save bool) (err error) { +func (tpr *TpReader) LoadDerivedChargersFiltered(filter *TpDerivedCharger, save bool) (err error) { tps, err := tpr.lr.GetTpDerivedChargers(filter) if err != nil { return err diff --git a/engine/tpexporter.go b/engine/tpexporter.go index c0703fb16..16fae45cc 100644 --- a/engine/tpexporter.go +++ b/engine/tpexporter.go @@ -136,7 +136,7 @@ func (self *TPExporter) Run() error { } } - if storData, err := self.storDb.GetTpRatingProfiles(&utils.TPRatingProfile{TPid: self.tpID}); err != nil { + if storData, err := self.storDb.GetTpRatingProfiles(&TpRatingProfile{Tpid: self.tpID}); err != nil { return err } else { for _, sd := range storData { @@ -176,7 +176,7 @@ func (self *TPExporter) Run() error { } } - if storData, err := self.storDb.GetTpAccountActions(&utils.TPAccountActions{TPid: self.tpID}); err != nil { + if storData, err := self.storDb.GetTpAccountActions(&TpAccountAction{Tpid: self.tpID}); err != nil { return err } else { for _, sd := range storData { @@ -184,7 +184,7 @@ func (self *TPExporter) Run() error { } } - if storData, err := self.storDb.GetTpDerivedChargers(&utils.TPDerivedChargers{TPid: self.tpID}); err != nil { + if storData, err := self.storDb.GetTpDerivedChargers(&TpDerivedCharger{Tpid: self.tpID}); err != nil { return err } else { for _, sd := range storData { diff --git a/engine/tpimporter_csv.go b/engine/tpimporter_csv.go index 567ee690f..6ed8d6206 100644 --- a/engine/tpimporter_csv.go +++ b/engine/tpimporter_csv.go @@ -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(&utils.TPRatingProfile{TPid: self.TPid}) + tps, err := self.csvr.GetTpRatingProfiles(&TpRatingProfile{Tpid: self.TPid}) if err != nil { return err } @@ -195,7 +195,7 @@ func (self *TPCSVImporter) importAccountActions(fn string) error { if self.Verbose { log.Printf("Processing file: <%s> ", fn) } - tps, err := self.csvr.GetTpAccountActions(&utils.TPAccountActions{TPid: self.TPid}) + tps, err := self.csvr.GetTpAccountActions(&TpAccountAction{Tpid: self.TPid}) if err != nil { return err } diff --git a/utils/apitpdata.go b/utils/apitpdata.go index 2585513f9..b3f856f19 100644 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -301,15 +301,17 @@ type TPLcrRules struct { } type TPLcrRule struct { - Direction string - Tenant string - Customer string - DestinationId string - Category string - Strategy string - Suppliers string - ActivatinTime string - Weight float64 + Direction string + Tenant string + Category string + Account string + Subject string + DestinationId string + RpCategory string + Strategy string + StrategyParams string + ActivationTime string + Weight float64 } type TPCdrStats struct { @@ -453,7 +455,7 @@ func NewTPAccountActionsFromKeyId(tpid, loadId, keyId string) (*TPAccountActions if len(s) != 3 { return nil, fmt.Errorf("Cannot parse key %s into AccountActions", keyId) } - return &TPAccountActions{TPid: tpid, LoadId: loadId, Tenant: s[1], Account: s[2], Direction: s[0]}, nil + return &TPAccountActions{TPid: tpid, LoadId: loadId, Direction: s[0], Tenant: s[1], Account: s[2]}, nil } type TPAccountActions struct {