From e3d825c1cc6fcf0500e8387df5e8977e613ff8bd Mon Sep 17 00:00:00 2001 From: andronache Date: Thu, 3 Dec 2020 15:30:33 +0200 Subject: [PATCH] Renamed in models.go --- apier/v1/apier.go | 10 +- apier/v1/tpaccountactions.go | 2 +- engine/model_helpers.go | 207 +++++++++++++------------- engine/model_helpers_test.go | 278 +++++++++++++++++------------------ engine/models.go | 100 ++++++++++--- engine/storage_csv.go | 96 ++++++------ engine/storage_sql.go | 66 ++++----- loaders/loader.go | 20 +-- 8 files changed, 422 insertions(+), 357 deletions(-) diff --git a/apier/v1/apier.go b/apier/v1/apier.go index 7c7396c1d..d639109f4 100644 --- a/apier/v1/apier.go +++ b/apier/v1/apier.go @@ -1642,7 +1642,7 @@ func (apierSv1 *APIerSv1) ExportToFolder(arg *utils.ArgExportToFolder, reply *st csvWriter := csv.NewWriter(f) csvWriter.Comma = utils.CSV_SEP //write the header of the file - if err := csvWriter.Write(engine.TpFilterS{}.CSVHeader()); err != nil { + if err := csvWriter.Write(engine.FilterMdls{}.CSVHeader()); err != nil { return err } for _, key := range keys { @@ -1680,7 +1680,7 @@ func (apierSv1 *APIerSv1) ExportToFolder(arg *utils.ArgExportToFolder, reply *st csvWriter := csv.NewWriter(f) csvWriter.Comma = utils.CSV_SEP //write the header of the file - if err := csvWriter.Write(engine.TpResources{}.CSVHeader()); err != nil { + if err := csvWriter.Write(engine.ResourceMdls{}.CSVHeader()); err != nil { return err } for _, key := range keys { @@ -1718,7 +1718,7 @@ func (apierSv1 *APIerSv1) ExportToFolder(arg *utils.ArgExportToFolder, reply *st csvWriter := csv.NewWriter(f) csvWriter.Comma = utils.CSV_SEP //write the header of the file - if err := csvWriter.Write(engine.TpStats{}.CSVHeader()); err != nil { + if err := csvWriter.Write(engine.StatMdls{}.CSVHeader()); err != nil { return err } for _, key := range keys { @@ -1756,7 +1756,7 @@ func (apierSv1 *APIerSv1) ExportToFolder(arg *utils.ArgExportToFolder, reply *st csvWriter := csv.NewWriter(f) csvWriter.Comma = utils.CSV_SEP //write the header of the file - if err := csvWriter.Write(engine.TPRoutes{}.CSVHeader()); err != nil { + if err := csvWriter.Write(engine.RouteMdls{}.CSVHeader()); err != nil { return err } for _, key := range keys { @@ -1794,7 +1794,7 @@ func (apierSv1 *APIerSv1) ExportToFolder(arg *utils.ArgExportToFolder, reply *st csvWriter := csv.NewWriter(f) csvWriter.Comma = utils.CSV_SEP //write the header of the file - if err := csvWriter.Write(engine.TpThresholds{}.CSVHeader()); err != nil { + if err := csvWriter.Write(engine.ThresholdMdls{}.CSVHeader()); err != nil { return err } for _, key := range keys { diff --git a/apier/v1/tpaccountactions.go b/apier/v1/tpaccountactions.go index c4bfd8644..0ae4abeda 100644 --- a/apier/v1/tpaccountactions.go +++ b/apier/v1/tpaccountactions.go @@ -130,7 +130,7 @@ func (apierSv1 *APIerSv1) RemoveTPAccountActions(attrs *AttrGetTPAccountActions, if missing := utils.MissingStructFields(attrs, []string{"TPid", "LoadId", "Tenant", "Account"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - aa := engine.TpAccountActionMdl{Tpid: attrs.TPid} + aa := engine.AccountActionMdl{Tpid: attrs.TPid} if err := aa.SetAccountActionId(attrs.AccountActionsId); err != nil { return err } diff --git a/engine/model_helpers.go b/engine/model_helpers.go index 69879f657..7476bb6c8 100644 --- a/engine/model_helpers.go +++ b/engine/model_helpers.go @@ -146,9 +146,9 @@ func getColumnCount(s interface{}) int { return count } -type TpDestinations []TpDestinationMdl +type DestinationMdls []DestinationMdl -func (tps TpDestinations) AsMapDestinations() (map[string]*Destination, error) { +func (tps DestinationMdls) AsMapDestinations() (map[string]*Destination, error) { result := make(map[string]*Destination) for _, tp := range tps { var d *Destination @@ -162,8 +162,8 @@ func (tps TpDestinations) AsMapDestinations() (map[string]*Destination, error) { return result, nil } -// AsTPDestination converts TpDestinations into *utils.TPDestination -func (tps TpDestinations) AsTPDestinations() (result []*utils.TPDestination) { +// AsTPDestination converts DestinationMdls into *utils.TPDestination +func (tps DestinationMdls) AsTPDestinations() (result []*utils.TPDestination) { md := make(map[string]*utils.TPDestination) // Should save us some CPU if we index here for big number of destinations to search for _, tp := range tps { if d, hasIt := md[tp.Tag]; !hasIt { @@ -181,17 +181,17 @@ func (tps TpDestinations) AsTPDestinations() (result []*utils.TPDestination) { return } -func APItoModelDestination(d *utils.TPDestination) (result TpDestinations) { +func APItoModelDestination(d *utils.TPDestination) (result DestinationMdls) { if d != nil { for _, p := range d.Prefixes { - result = append(result, TpDestinationMdl{ + result = append(result, DestinationMdl{ Tpid: d.TPid, Tag: d.ID, Prefix: p, }) } if len(d.Prefixes) == 0 { - result = append(result, TpDestinationMdl{ + result = append(result, DestinationMdl{ Tpid: d.TPid, Tag: d.ID, }) @@ -200,9 +200,9 @@ func APItoModelDestination(d *utils.TPDestination) (result TpDestinations) { return } -type TpTimings []TpTimingMdl +type TimingMdls []TimingMdl -func (tps TpTimings) AsMapTPTimings() (map[string]*utils.ApierTPTiming, error) { +func (tps TimingMdls) AsMapTPTimings() (map[string]*utils.ApierTPTiming, error) { result := make(map[string]*utils.ApierTPTiming) for _, tp := range tps { t := &utils.ApierTPTiming{ @@ -231,7 +231,7 @@ func MapTPTimings(tps []*utils.ApierTPTiming) (map[string]*utils.TPTiming, error return result, nil } -func (tps TpTimings) AsTPTimings() (result []*utils.ApierTPTiming) { +func (tps TimingMdls) AsTPTimings() (result []*utils.ApierTPTiming) { ats, _ := tps.AsMapTPTimings() for _, tp := range ats { result = append(result, tp) @@ -239,8 +239,8 @@ func (tps TpTimings) AsTPTimings() (result []*utils.ApierTPTiming) { return result } -func APItoModelTiming(t *utils.ApierTPTiming) (result TpTimingMdl) { - return TpTimingMdl{ +func APItoModelTiming(t *utils.ApierTPTiming) (result TimingMdl) { + return TimingMdl{ Tpid: t.TPid, Tag: t.ID, Years: t.Years, @@ -251,7 +251,7 @@ func APItoModelTiming(t *utils.ApierTPTiming) (result TpTimingMdl) { } } -func APItoModelTimings(ts []*utils.ApierTPTiming) (result TpTimings) { +func APItoModelTimings(ts []*utils.ApierTPTiming) (result TimingMdls) { for _, t := range ts { if t != nil { at := APItoModelTiming(t) @@ -261,9 +261,9 @@ func APItoModelTimings(ts []*utils.ApierTPTiming) (result TpTimings) { return result } -type TpRates []TpRateMdl +type RateMdls []RateMdl -func (tps TpRates) AsMapRates() (map[string]*utils.TPRateRALs, error) { +func (tps RateMdls) AsMapRates() (map[string]*utils.TPRateRALs, error) { result := make(map[string]*utils.TPRateRALs) for _, tp := range tps { r := &utils.TPRateRALs{ @@ -290,7 +290,7 @@ func (tps TpRates) AsMapRates() (map[string]*utils.TPRateRALs, error) { return result, nil } -func (tps TpRates) AsTPRates() (result []*utils.TPRateRALs, err error) { +func (tps RateMdls) AsTPRates() (result []*utils.TPRateRALs, err error) { if atps, err := tps.AsMapRates(); err != nil { return nil, err } else { @@ -313,10 +313,10 @@ func MapTPRates(s []*utils.TPRateRALs) (map[string]*utils.TPRateRALs, error) { return result, nil } -func APItoModelRate(r *utils.TPRateRALs) (result TpRates) { +func APItoModelRate(r *utils.TPRateRALs) (result RateMdls) { if r != nil { for _, rs := range r.RateSlots { - result = append(result, TpRateMdl{ + result = append(result, RateMdl{ Tpid: r.TPid, Tag: r.ID, ConnectFee: rs.ConnectFee, @@ -327,7 +327,7 @@ func APItoModelRate(r *utils.TPRateRALs) (result TpRates) { }) } if len(r.RateSlots) == 0 { - result = append(result, TpRateMdl{ + result = append(result, RateMdl{ Tpid: r.TPid, Tag: r.ID, }) @@ -336,7 +336,7 @@ func APItoModelRate(r *utils.TPRateRALs) (result TpRates) { return } -func APItoModelRates(rs []*utils.TPRateRALs) (result TpRates) { +func APItoModelRates(rs []*utils.TPRateRALs) (result RateMdls) { for _, r := range rs { for _, sr := range APItoModelRate(r) { result = append(result, sr) @@ -345,9 +345,9 @@ func APItoModelRates(rs []*utils.TPRateRALs) (result TpRates) { return result } -type TpDestinationRates []TpDestinationRateMdl +type DestinationRateMdls []DestinationRateMdl -func (tps TpDestinationRates) AsMapDestinationRates() (map[string]*utils.TPDestinationRate, error) { +func (tps DestinationRateMdls) AsMapDestinationRates() (map[string]*utils.TPDestinationRate, error) { result := make(map[string]*utils.TPDestinationRate) for _, tp := range tps { dr := &utils.TPDestinationRate{ @@ -375,7 +375,7 @@ func (tps TpDestinationRates) AsMapDestinationRates() (map[string]*utils.TPDesti return result, nil } -func (tps TpDestinationRates) AsTPDestinationRates() (result []*utils.TPDestinationRate, err error) { +func (tps DestinationRateMdls) AsTPDestinationRates() (result []*utils.TPDestinationRate, err error) { if atps, err := tps.AsMapDestinationRates(); err != nil { return nil, err } else { @@ -398,10 +398,10 @@ func MapTPDestinationRates(s []*utils.TPDestinationRate) (map[string]*utils.TPDe return result, nil } -func APItoModelDestinationRate(d *utils.TPDestinationRate) (result TpDestinationRates) { +func APItoModelDestinationRate(d *utils.TPDestinationRate) (result DestinationRateMdls) { if d != nil { for _, dr := range d.DestinationRates { - result = append(result, TpDestinationRateMdl{ + result = append(result, DestinationRateMdl{ Tpid: d.TPid, Tag: d.ID, DestinationsTag: dr.DestinationId, @@ -413,7 +413,7 @@ func APItoModelDestinationRate(d *utils.TPDestinationRate) (result TpDestination }) } if len(d.DestinationRates) == 0 { - result = append(result, TpDestinationRateMdl{ + result = append(result, DestinationRateMdl{ Tpid: d.TPid, Tag: d.ID, }) @@ -422,7 +422,7 @@ func APItoModelDestinationRate(d *utils.TPDestinationRate) (result TpDestination return } -func APItoModelDestinationRates(drs []*utils.TPDestinationRate) (result TpDestinationRates) { +func APItoModelDestinationRates(drs []*utils.TPDestinationRate) (result DestinationRateMdls) { if drs != nil { for _, dr := range drs { for _, sdr := range APItoModelDestinationRate(dr) { @@ -433,9 +433,9 @@ func APItoModelDestinationRates(drs []*utils.TPDestinationRate) (result TpDestin return result } -type TpRatingPlans []TpRatingPlanMdl +type RatingPlanMdls []RatingPlanMdl -func (tps TpRatingPlans) AsMapTPRatingPlans() (map[string]*utils.TPRatingPlan, error) { +func (tps RatingPlanMdls) AsMapTPRatingPlans() (map[string]*utils.TPRatingPlan, error) { result := make(map[string]*utils.TPRatingPlan) for _, tp := range tps { rp := &utils.TPRatingPlan{ @@ -457,7 +457,7 @@ func (tps TpRatingPlans) AsMapTPRatingPlans() (map[string]*utils.TPRatingPlan, e return result, nil } -func (tps TpRatingPlans) AsTPRatingPlans() (result []*utils.TPRatingPlan, err error) { +func (tps RatingPlanMdls) AsTPRatingPlans() (result []*utils.TPRatingPlan, err error) { if atps, err := tps.AsMapTPRatingPlans(); err != nil { return nil, err } else { @@ -514,10 +514,10 @@ func MapTPRatingPlanBindings(s []*utils.TPRatingPlan) map[string][]*utils.TPRati return result } -func APItoModelRatingPlan(rp *utils.TPRatingPlan) (result TpRatingPlans) { +func APItoModelRatingPlan(rp *utils.TPRatingPlan) (result RatingPlanMdls) { if rp != nil { for _, rpb := range rp.RatingPlanBindings { - result = append(result, TpRatingPlanMdl{ + result = append(result, RatingPlanMdl{ Tpid: rp.TPid, Tag: rp.ID, DestratesTag: rpb.DestinationRatesId, @@ -526,7 +526,7 @@ func APItoModelRatingPlan(rp *utils.TPRatingPlan) (result TpRatingPlans) { }) } if len(rp.RatingPlanBindings) == 0 { - result = append(result, TpRatingPlanMdl{ + result = append(result, RatingPlanMdl{ Tpid: rp.TPid, Tag: rp.ID, }) @@ -535,7 +535,7 @@ func APItoModelRatingPlan(rp *utils.TPRatingPlan) (result TpRatingPlans) { return } -func APItoModelRatingPlans(rps []*utils.TPRatingPlan) (result TpRatingPlans) { +func APItoModelRatingPlans(rps []*utils.TPRatingPlan) (result RatingPlanMdls) { for _, rp := range rps { for _, srp := range APItoModelRatingPlan(rp) { result = append(result, srp) @@ -544,9 +544,9 @@ func APItoModelRatingPlans(rps []*utils.TPRatingPlan) (result TpRatingPlans) { return result } -type TpRatingProfiles []TpRatingProfileMdl +type RatingProfileMdls []RatingProfileMdl -func (tps TpRatingProfiles) AsMapTPRatingProfiles() (map[string]*utils.TPRatingProfile, error) { +func (tps RatingProfileMdls) AsMapTPRatingProfiles() (map[string]*utils.TPRatingProfile, error) { result := make(map[string]*utils.TPRatingProfile) for _, tp := range tps { rp := &utils.TPRatingProfile{ @@ -571,7 +571,7 @@ func (tps TpRatingProfiles) AsMapTPRatingProfiles() (map[string]*utils.TPRatingP return result, nil } -func (tps TpRatingProfiles) AsTPRatingProfiles() (result []*utils.TPRatingProfile, err error) { +func (tps RatingProfileMdls) AsTPRatingProfiles() (result []*utils.TPRatingProfile, err error) { if atps, err := tps.AsMapTPRatingProfiles(); err != nil { return nil, err } else { @@ -594,10 +594,10 @@ func MapTPRatingProfiles(s []*utils.TPRatingProfile) (map[string]*utils.TPRating return result, nil } -func APItoModelRatingProfile(rp *utils.TPRatingProfile) (result TpRatingProfiles) { +func APItoModelRatingProfile(rp *utils.TPRatingProfile) (result RatingProfileMdls) { if rp != nil { for _, rpa := range rp.RatingPlanActivations { - result = append(result, TpRatingProfileMdl{ + result = append(result, RatingProfileMdl{ Tpid: rp.TPid, Loadid: rp.LoadId, Tenant: rp.Tenant, @@ -609,7 +609,7 @@ func APItoModelRatingProfile(rp *utils.TPRatingProfile) (result TpRatingProfiles }) } if len(rp.RatingPlanActivations) == 0 { - result = append(result, TpRatingProfileMdl{ + result = append(result, RatingProfileMdl{ Tpid: rp.TPid, Loadid: rp.LoadId, Tenant: rp.Tenant, @@ -621,7 +621,7 @@ func APItoModelRatingProfile(rp *utils.TPRatingProfile) (result TpRatingProfiles return } -func APItoModelRatingProfiles(rps []*utils.TPRatingProfile) (result TpRatingProfiles) { +func APItoModelRatingProfiles(rps []*utils.TPRatingProfile) (result RatingProfileMdls) { for _, rp := range rps { for _, srp := range APItoModelRatingProfile(rp) { result = append(result, srp) @@ -630,9 +630,9 @@ func APItoModelRatingProfiles(rps []*utils.TPRatingProfile) (result TpRatingProf return result } -type TpSharedGroups []TpSharedGroupMdl +type SharedGroupMdls []SharedGroupMdl -func (tps TpSharedGroups) AsMapTPSharedGroups() (map[string]*utils.TPSharedGroups, error) { +func (tps SharedGroupMdls) AsMapTPSharedGroups() (map[string]*utils.TPSharedGroups, error) { result := make(map[string]*utils.TPSharedGroups) for _, tp := range tps { sgs := &utils.TPSharedGroups{ @@ -654,7 +654,7 @@ func (tps TpSharedGroups) AsMapTPSharedGroups() (map[string]*utils.TPSharedGroup return result, nil } -func (tps TpSharedGroups) AsTPSharedGroups() (result []*utils.TPSharedGroups, err error) { +func (tps SharedGroupMdls) AsTPSharedGroups() (result []*utils.TPSharedGroups, err error) { if atps, err := tps.AsMapTPSharedGroups(); err != nil { return nil, err } else { @@ -679,10 +679,10 @@ func MapTPSharedGroup(s []*utils.TPSharedGroups) map[string][]*utils.TPSharedGro return result } -func APItoModelSharedGroup(sgs *utils.TPSharedGroups) (result TpSharedGroups) { +func APItoModelSharedGroup(sgs *utils.TPSharedGroups) (result SharedGroupMdls) { if sgs != nil { for _, sg := range sgs.SharedGroups { - result = append(result, TpSharedGroupMdl{ + result = append(result, SharedGroupMdl{ Tpid: sgs.TPid, Tag: sgs.ID, Account: sg.Account, @@ -691,7 +691,7 @@ func APItoModelSharedGroup(sgs *utils.TPSharedGroups) (result TpSharedGroups) { }) } if len(sgs.SharedGroups) == 0 { - result = append(result, TpSharedGroupMdl{ + result = append(result, SharedGroupMdl{ Tpid: sgs.TPid, Tag: sgs.ID, }) @@ -700,7 +700,7 @@ func APItoModelSharedGroup(sgs *utils.TPSharedGroups) (result TpSharedGroups) { return } -func APItoModelSharedGroups(sgs []*utils.TPSharedGroups) (result TpSharedGroups) { +func APItoModelSharedGroups(sgs []*utils.TPSharedGroups) (result SharedGroupMdls) { for _, sg := range sgs { for _, ssg := range APItoModelSharedGroup(sg) { result = append(result, ssg) @@ -709,9 +709,9 @@ func APItoModelSharedGroups(sgs []*utils.TPSharedGroups) (result TpSharedGroups) return result } -type TpActions []TpActionMdl +type ActionMdls []ActionMdl -func (tps TpActions) AsMapTPActions() (map[string]*utils.TPActions, error) { +func (tps ActionMdls) AsMapTPActions() (map[string]*utils.TPActions, error) { result := make(map[string]*utils.TPActions) for _, tp := range tps { as := &utils.TPActions{ @@ -746,7 +746,7 @@ func (tps TpActions) AsMapTPActions() (map[string]*utils.TPActions, error) { return result, nil } -func (tps TpActions) AsTPActions() (result []*utils.TPActions, err error) { +func (tps ActionMdls) AsTPActions() (result []*utils.TPActions, err error) { if atps, err := tps.AsMapTPActions(); err != nil { return nil, err } else { @@ -771,10 +771,10 @@ func MapTPActions(s []*utils.TPActions) map[string][]*utils.TPAction { return result } -func APItoModelAction(as *utils.TPActions) (result TpActions) { +func APItoModelAction(as *utils.TPActions) (result ActionMdls) { if as != nil { for _, a := range as.Actions { - result = append(result, TpActionMdl{ + result = append(result, ActionMdl{ Tpid: as.TPid, Tag: as.ID, Action: a.Identifier, @@ -796,7 +796,7 @@ func APItoModelAction(as *utils.TPActions) (result TpActions) { }) } if len(as.Actions) == 0 { - result = append(result, TpActionMdl{ + result = append(result, ActionMdl{ Tpid: as.TPid, Tag: as.ID, }) @@ -805,7 +805,7 @@ func APItoModelAction(as *utils.TPActions) (result TpActions) { return } -func APItoModelActions(as []*utils.TPActions) (result TpActions) { +func APItoModelActions(as []*utils.TPActions) (result ActionMdls) { for _, a := range as { for _, sa := range APItoModelAction(a) { result = append(result, sa) @@ -814,9 +814,9 @@ func APItoModelActions(as []*utils.TPActions) (result TpActions) { return result } -type TpActionPlans []TpActionPlanMdl +type ActionPlanMdls []ActionPlanMdl -func (tps TpActionPlans) AsMapTPActionPlans() (map[string]*utils.TPActionPlan, error) { +func (tps ActionPlanMdls) AsMapTPActionPlans() (map[string]*utils.TPActionPlan, error) { result := make(map[string]*utils.TPActionPlan) for _, tp := range tps { as := &utils.TPActionPlan{ @@ -838,7 +838,7 @@ func (tps TpActionPlans) AsMapTPActionPlans() (map[string]*utils.TPActionPlan, e return result, nil } -func (tps TpActionPlans) AsTPActionPlans() (result []*utils.TPActionPlan, err error) { +func (tps ActionPlanMdls) AsTPActionPlans() (result []*utils.TPActionPlan, err error) { if atps, err := tps.AsMapTPActionPlans(); err != nil { return nil, err } else { @@ -863,10 +863,10 @@ func MapTPActionTimings(s []*utils.TPActionPlan) map[string][]*utils.TPActionTim return result } -func APItoModelActionPlan(a *utils.TPActionPlan) (result TpActionPlans) { +func APItoModelActionPlan(a *utils.TPActionPlan) (result ActionPlanMdls) { if a != nil { for _, ap := range a.ActionPlan { - result = append(result, TpActionPlanMdl{ + result = append(result, ActionPlanMdl{ Tpid: a.TPid, Tag: a.ID, ActionsTag: ap.ActionsId, @@ -875,7 +875,7 @@ func APItoModelActionPlan(a *utils.TPActionPlan) (result TpActionPlans) { }) } if len(a.ActionPlan) == 0 { - result = append(result, TpActionPlanMdl{ + result = append(result, ActionPlanMdl{ Tpid: a.TPid, Tag: a.ID, }) @@ -884,7 +884,7 @@ func APItoModelActionPlan(a *utils.TPActionPlan) (result TpActionPlans) { return } -func APItoModelActionPlans(aps []*utils.TPActionPlan) (result TpActionPlans) { +func APItoModelActionPlans(aps []*utils.TPActionPlan) (result ActionPlanMdls) { for _, ap := range aps { for _, sap := range APItoModelActionPlan(ap) { result = append(result, sap) @@ -893,9 +893,9 @@ func APItoModelActionPlans(aps []*utils.TPActionPlan) (result TpActionPlans) { return result } -type TpActionTriggers []TpActionTriggerMdl +type ActionTriggerMdls []ActionTriggerMdl -func (tps TpActionTriggers) AsMapTPActionTriggers() (map[string]*utils.TPActionTriggers, error) { +func (tps ActionTriggerMdls) AsMapTPActionTriggers() (map[string]*utils.TPActionTriggers, error) { result := make(map[string]*utils.TPActionTriggers) for _, tp := range tps { ats := &utils.TPActionTriggers{ @@ -935,7 +935,7 @@ func (tps TpActionTriggers) AsMapTPActionTriggers() (map[string]*utils.TPActionT return result, nil } -func (tps TpActionTriggers) AsTPActionTriggers() (result []*utils.TPActionTriggers, err error) { +func (tps ActionTriggerMdls) AsTPActionTriggers() (result []*utils.TPActionTriggers, err error) { if atps, err := tps.AsMapTPActionTriggers(); err != nil { return nil, err } else { @@ -960,10 +960,10 @@ func MapTPActionTriggers(s []*utils.TPActionTriggers) map[string][]*utils.TPActi return result } -func APItoModelActionTrigger(ats *utils.TPActionTriggers) (result TpActionTriggers) { +func APItoModelActionTrigger(ats *utils.TPActionTriggers) (result ActionTriggerMdls) { if ats != nil { for _, at := range ats.ActionTriggers { - result = append(result, TpActionTriggerMdl{ + result = append(result, ActionTriggerMdl{ Tpid: ats.TPid, Tag: ats.ID, UniqueId: at.UniqueID, @@ -989,7 +989,7 @@ func APItoModelActionTrigger(ats *utils.TPActionTriggers) (result TpActionTrigge }) } if len(ats.ActionTriggers) == 0 { - result = append(result, TpActionTriggerMdl{ + result = append(result, ActionTriggerMdl{ Tpid: ats.TPid, Tag: ats.ID, }) @@ -998,7 +998,7 @@ func APItoModelActionTrigger(ats *utils.TPActionTriggers) (result TpActionTrigge return } -func APItoModelActionTriggers(ts []*utils.TPActionTriggers) (result TpActionTriggers) { +func APItoModelActionTriggers(ts []*utils.TPActionTriggers) (result ActionTriggerMdls) { for _, t := range ts { for _, st := range APItoModelActionTrigger(t) { result = append(result, st) @@ -1007,9 +1007,9 @@ func APItoModelActionTriggers(ts []*utils.TPActionTriggers) (result TpActionTrig return result } -type TpAccountActions []TpAccountActionMdl +type AccountActionMdls []AccountActionMdl -func (tps TpAccountActions) AsMapTPAccountActions() (map[string]*utils.TPAccountActions, error) { +func (tps AccountActionMdls) AsMapTPAccountActions() (map[string]*utils.TPAccountActions, error) { result := make(map[string]*utils.TPAccountActions) for _, tp := range tps { aas := &utils.TPAccountActions{ @@ -1027,7 +1027,7 @@ func (tps TpAccountActions) AsMapTPAccountActions() (map[string]*utils.TPAccount return result, nil } -func (tps TpAccountActions) AsTPAccountActions() (result []*utils.TPAccountActions, err error) { +func (tps AccountActionMdls) AsTPAccountActions() (result []*utils.TPAccountActions, err error) { if atps, err := tps.AsMapTPAccountActions(); err != nil { return nil, err } else { @@ -1050,8 +1050,8 @@ func MapTPAccountActions(s []*utils.TPAccountActions) (map[string]*utils.TPAccou return result, nil } -func APItoModelAccountAction(aa *utils.TPAccountActions) *TpAccountActionMdl { - return &TpAccountActionMdl{ +func APItoModelAccountAction(aa *utils.TPAccountActions) *AccountActionMdl { + return &AccountActionMdl{ Tpid: aa.TPid, Loadid: aa.LoadId, Tenant: aa.Tenant, @@ -1063,7 +1063,7 @@ func APItoModelAccountAction(aa *utils.TPAccountActions) *TpAccountActionMdl { } } -func APItoModelAccountActions(aas []*utils.TPAccountActions) (result TpAccountActions) { +func APItoModelAccountActions(aas []*utils.TPAccountActions) (result AccountActionMdls) { for _, aa := range aas { if aa != nil { result = append(result, *APItoModelAccountAction(aa)) @@ -1072,16 +1072,16 @@ func APItoModelAccountActions(aas []*utils.TPAccountActions) (result TpAccountAc return result } -type TpResources []*TpResourceMdl +type ResourceMdls []*ResourceMdl // CSVHeader return the header for csv fields as a slice of string -func (tps TpResources) CSVHeader() (result []string) { +func (tps ResourceMdls) CSVHeader() (result []string) { return []string{"#" + utils.Tenant, utils.ID, utils.FilterIDs, utils.ActivationIntervalString, utils.UsageTTL, utils.Limit, utils.AllocationMessage, utils.Blocker, utils.Stored, utils.Weight, utils.ThresholdIDs} } -func (tps TpResources) AsTPResources() (result []*utils.TPResourceProfile) { +func (tps ResourceMdls) AsTPResources() (result []*utils.TPResourceProfile) { mrl := make(map[string]*utils.TPResourceProfile) filterMap := make(map[string]utils.StringMap) thresholdMap := make(map[string]utils.StringMap) @@ -1161,13 +1161,13 @@ func (tps TpResources) AsTPResources() (result []*utils.TPResourceProfile) { return } -func APItoModelResource(rl *utils.TPResourceProfile) (mdls TpResources) { +func APItoModelResource(rl *utils.TPResourceProfile) (mdls ResourceMdls) { if rl == nil { return } // In case that TPResourceProfile don't have filter if len(rl.FilterIDs) == 0 { - mdl := &TpResourceMdl{ + mdl := &ResourceMdl{ Tpid: rl.TPid, Tenant: rl.Tenant, ID: rl.ID, @@ -1195,7 +1195,7 @@ func APItoModelResource(rl *utils.TPResourceProfile) (mdls TpResources) { mdls = append(mdls, mdl) } for i, fltr := range rl.FilterIDs { - mdl := &TpResourceMdl{ + mdl := &ResourceMdl{ Tpid: rl.TPid, Tenant: rl.Tenant, ID: rl.ID, @@ -1297,16 +1297,16 @@ func ResourceProfileToAPI(rp *ResourceProfile) (tpRL *utils.TPResourceProfile) { return } -type TpStats []*TpStatMdl +type StatMdls []*StatMdl // CSVHeader return the header for csv fields as a slice of string -func (tps TpStats) CSVHeader() (result []string) { +func (tps StatMdls) CSVHeader() (result []string) { return []string{"#" + utils.Tenant, utils.ID, utils.FilterIDs, utils.ActivationIntervalString, utils.QueueLength, utils.TTL, utils.MinItems, utils.MetricIDs, utils.MetricFilterIDs, utils.Stored, utils.Blocker, utils.Weight, utils.ThresholdIDs} } -func (models TpStats) AsTPStats() (result []*utils.TPStatProfile) { +func (models StatMdls) AsTPStats() (result []*utils.TPStatProfile) { filterMap := make(map[string]utils.StringMap) thresholdMap := make(map[string]utils.StringMap) statMetricsMap := make(map[string]map[string]*utils.MetricWithFilters) @@ -1412,10 +1412,10 @@ func (models TpStats) AsTPStats() (result []*utils.TPStatProfile) { return } -func APItoModelStats(st *utils.TPStatProfile) (mdls TpStats) { +func APItoModelStats(st *utils.TPStatProfile) (mdls StatMdls) { if st != nil && len(st.Metrics) != 0 { for i, metric := range st.Metrics { - mdl := &TpStatMdl{ + mdl := &StatMdl{ Tpid: st.TPid, Tenant: st.Tenant, ID: st.ID, @@ -1546,16 +1546,16 @@ func StatQueueProfileToAPI(st *StatQueueProfile) (tpST *utils.TPStatProfile) { return } -type TpThresholds []*TpThresholdMdl +type ThresholdMdls []*ThresholdMdl // CSVHeader return the header for csv fields as a slice of string -func (tps TpThresholds) CSVHeader() (result []string) { +func (tps ThresholdMdls) CSVHeader() (result []string) { return []string{"#" + utils.Tenant, utils.ID, utils.FilterIDs, utils.ActivationIntervalString, utils.MaxHits, utils.MinHits, utils.MinSleep, utils.Blocker, utils.Weight, utils.ActionIDs, utils.Async} } -func (tps TpThresholds) AsTPThreshold() (result []*utils.TPThresholdProfile) { +func (tps ThresholdMdls) AsTPThreshold() (result []*utils.TPThresholdProfile) { mst := make(map[string]*utils.TPThresholdProfile) filterMap := make(map[string]utils.StringMap) actionMap := make(map[string]utils.StringMap) @@ -1622,7 +1622,7 @@ func (tps TpThresholds) AsTPThreshold() (result []*utils.TPThresholdProfile) { return } -func APItoModelTPThreshold(th *utils.TPThresholdProfile) (mdls TpThresholds) { +func APItoModelTPThreshold(th *utils.TPThresholdProfile) (mdls ThresholdMdls) { if th != nil { if len(th.ActionIDs) == 0 { return @@ -1632,7 +1632,7 @@ func APItoModelTPThreshold(th *utils.TPThresholdProfile) (mdls TpThresholds) { min = len(th.ActionIDs) } for i := 0; i < min; i++ { - mdl := &TpThresholdMdl{ + mdl := &ThresholdMdl{ Tpid: th.TPid, Tenant: th.Tenant, ID: th.ID, @@ -1660,7 +1660,7 @@ func APItoModelTPThreshold(th *utils.TPThresholdProfile) (mdls TpThresholds) { if len(th.FilterIDs)-min > 0 { for i := min; i < len(th.FilterIDs); i++ { - mdl := &TpThresholdMdl{ + mdl := &ThresholdMdl{ Tpid: th.TPid, Tenant: th.Tenant, ID: th.ID, @@ -1671,7 +1671,7 @@ func APItoModelTPThreshold(th *utils.TPThresholdProfile) (mdls TpThresholds) { } if len(th.ActionIDs)-min > 0 { for i := min; i < len(th.ActionIDs); i++ { - mdl := &TpThresholdMdl{ + mdl := &ThresholdMdl{ Tpid: th.TPid, Tenant: th.Tenant, ID: th.ID, @@ -1766,15 +1766,16 @@ func ThresholdProfileToAPI(th *ThresholdProfile) (tpTH *utils.TPThresholdProfile return } -type TpFilterS []*TpFilterMdl +type FilterMdls []*FilterMdl +type TpFilterS []*FilterMdl // CSVHeader return the header for csv fields as a slice of string -func (tps TpFilterS) CSVHeader() (result []string) { +func (tps FilterMdls) CSVHeader() (result []string) { return []string{"#" + utils.Tenant, utils.ID, utils.Type, utils.Element, utils.Values, utils.ActivationIntervalString} } -func (tps TpFilterS) AsTPFilter() (result []*utils.TPFilterProfile) { +func (tps FilterMdls) AsTPFilter() (result []*utils.TPFilterProfile) { mst := make(map[string]*utils.TPFilterProfile) for _, tp := range tps { th, found := mst[(&utils.TenantID{Tenant: tp.Tenant, ID: tp.ID}).TenantID()] @@ -1817,12 +1818,12 @@ func (tps TpFilterS) AsTPFilter() (result []*utils.TPFilterProfile) { return } -func APItoModelTPFilter(th *utils.TPFilterProfile) (mdls TpFilterS) { +func APItoModelTPFilter(th *utils.TPFilterProfile) (mdls FilterMdls) { if th == nil || len(th.Filters) == 0 { return } for _, fltr := range th.Filters { - mdl := &TpFilterMdl{ + mdl := &FilterMdl{ Tpid: th.TPid, Tenant: th.Tenant, ID: th.ID, @@ -1895,10 +1896,10 @@ func FilterToTPFilter(f *Filter) (tpFltr *utils.TPFilterProfile) { return } -type TPRoutes []*TpRouteMdl +type RouteMdls []*RouteMdl // CSVHeader return the header for csv fields as a slice of string -func (tps TPRoutes) CSVHeader() (result []string) { +func (tps RouteMdls) CSVHeader() (result []string) { return []string{"#" + utils.Tenant, utils.ID, utils.FilterIDs, utils.ActivationIntervalString, utils.Sorting, utils.SortingParameters, utils.RouteID, utils.RouteFilterIDs, utils.RouteAccountIDs, utils.RouteRatingplanIDs, utils.RouteRateProfileIDs, utils.RouteResourceIDs, @@ -1907,7 +1908,7 @@ func (tps TPRoutes) CSVHeader() (result []string) { } } -func (tps TPRoutes) AsTPRouteProfile() (result []*utils.TPRouteProfile) { +func (tps RouteMdls) AsTPRouteProfile() (result []*utils.TPRouteProfile) { filtermap := make(map[string]utils.StringMap) mst := make(map[string]*utils.TPRouteProfile) routeMap := make(map[string]map[string]*utils.TPRoute) @@ -2021,12 +2022,12 @@ func (tps TPRoutes) AsTPRouteProfile() (result []*utils.TPRouteProfile) { return } -func APItoModelTPRoutes(st *utils.TPRouteProfile) (mdls TPRoutes) { +func APItoModelTPRoutes(st *utils.TPRouteProfile) (mdls RouteMdls) { if len(st.Routes) == 0 { return } for i, supl := range st.Routes { - mdl := &TpRouteMdl{ + mdl := &RouteMdl{ Tenant: st.Tenant, Tpid: st.TPid, ID: st.ID, diff --git a/engine/model_helpers_test.go b/engine/model_helpers_test.go index 775eaa6bc..db8dabecd 100644 --- a/engine/model_helpers_test.go +++ b/engine/model_helpers_test.go @@ -30,15 +30,15 @@ import ( ) func TestModelHelperCsvLoad(t *testing.T) { - l, err := csvLoad(TpDestinationMdl{}, []string{"TEST_DEST", "+492"}) - tpd, ok := l.(TpDestinationMdl) + l, err := csvLoad(DestinationMdl{}, []string{"TEST_DEST", "+492"}) + tpd, ok := l.(DestinationMdl) if err != nil || !ok || tpd.Tag != "TEST_DEST" || tpd.Prefix != "+492" { t.Errorf("model load failed: %+v", tpd) } } func TestModelHelperCsvDump(t *testing.T) { - tpd := TpDestinationMdl{ + tpd := DestinationMdl{ Tag: "TEST_DEST", Prefix: "+492"} csv, err := CsvDump(tpd) @@ -73,7 +73,7 @@ func TestTPDestinationAsExportSlice(t *testing.T) { } func TestTpDestinationsAsMapDestinations(t *testing.T) { - in := &TpDestinations{} + in := &DestinationMdls{} eOut := map[string]*Destination{} if rcv, err := in.AsMapDestinations(); err != nil { @@ -81,9 +81,9 @@ func TestTpDestinationsAsMapDestinations(t *testing.T) { } else if !reflect.DeepEqual(rcv, eOut) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(eOut), utils.ToJSON(rcv)) } - in = &TpDestinations{ - TpDestinationMdl{Tpid: "TEST_TPID", Tag: "TEST_DEST1", Prefix: "+491"}, - TpDestinationMdl{Tpid: "TEST_TPID", Tag: "TEST_DEST2", Prefix: "+492"}, + in = &DestinationMdls{ + DestinationMdl{Tpid: "TEST_TPID", Tag: "TEST_DEST1", Prefix: "+491"}, + DestinationMdl{Tpid: "TEST_TPID", Tag: "TEST_DEST2", Prefix: "+492"}, } eOut = map[string]*Destination{ "TEST_DEST1": { @@ -104,10 +104,10 @@ func TestTpDestinationsAsMapDestinations(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(eOut[key]), utils.ToJSON(rcv[key])) } } - in = &TpDestinations{ - TpDestinationMdl{Tpid: "TEST_TPID", Tag: "TEST_DEST1", Prefix: "+491"}, - TpDestinationMdl{Tpid: "TEST_TPID", Tag: "TEST_DEST2", Prefix: "+492"}, - TpDestinationMdl{Tpid: "TEST_ID", Tag: "", Prefix: ""}, + in = &DestinationMdls{ + DestinationMdl{Tpid: "TEST_TPID", Tag: "TEST_DEST1", Prefix: "+491"}, + DestinationMdl{Tpid: "TEST_TPID", Tag: "TEST_DEST2", Prefix: "+492"}, + DestinationMdl{Tpid: "TEST_ID", Tag: "", Prefix: ""}, } eOut = map[string]*Destination{ "TEST_DEST1": { @@ -135,8 +135,8 @@ func TestTpDestinationsAsMapDestinations(t *testing.T) { func TestTpDestinationsAPItoModelDestination(t *testing.T) { d := &utils.TPDestination{} - eOut := TpDestinations{ - TpDestinationMdl{}, + eOut := DestinationMdls{ + DestinationMdl{}, } if rcv := APItoModelDestination(d); rcv != nil { if !reflect.DeepEqual(rcv, eOut) { @@ -149,8 +149,8 @@ func TestTpDestinationsAPItoModelDestination(t *testing.T) { ID: "TEST_ID", Prefixes: []string{"+491"}, } - eOut = TpDestinations{ - TpDestinationMdl{ + eOut = DestinationMdls{ + DestinationMdl{ Tpid: "TEST_TPID", Tag: "TEST_ID", Prefix: "+491", @@ -164,12 +164,12 @@ func TestTpDestinationsAPItoModelDestination(t *testing.T) { } func TestTpDestinationsAsTPDestinations(t *testing.T) { - tpd1 := TpDestinationMdl{Tpid: "TEST_TPID", Tag: "TEST_DEST", Prefix: "+491"} - tpd2 := TpDestinationMdl{Tpid: "TEST_TPID", Tag: "TEST_DEST", Prefix: "+492"} - tpd3 := TpDestinationMdl{Tpid: "TEST_TPID", Tag: "TEST_DEST", Prefix: "+493"} + tpd1 := DestinationMdl{Tpid: "TEST_TPID", Tag: "TEST_DEST", Prefix: "+491"} + tpd2 := DestinationMdl{Tpid: "TEST_TPID", Tag: "TEST_DEST", Prefix: "+492"} + tpd3 := DestinationMdl{Tpid: "TEST_TPID", Tag: "TEST_DEST", Prefix: "+493"} eTPDestinations := []*utils.TPDestination{{TPid: "TEST_TPID", ID: "TEST_DEST", Prefixes: []string{"+491", "+492", "+493"}}} - if tpDst := TpDestinations([]TpDestinationMdl{tpd1, tpd2, tpd3}).AsTPDestinations(); !reflect.DeepEqual(eTPDestinations, tpDst) { + if tpDst := DestinationMdls([]DestinationMdl{tpd1, tpd2, tpd3}).AsTPDestinations(); !reflect.DeepEqual(eTPDestinations, tpDst) { t.Errorf("Expecting: %+v, received: %+v", eTPDestinations, tpDst) } @@ -358,7 +358,7 @@ func TestMapTPRates(t *testing.T) { func TestAPItoModelTimings(t *testing.T) { ts := []*utils.ApierTPTiming{} - eOut := TpTimings{} + eOut := TimingMdls{} if rcv := APItoModelTimings(ts); rcv != nil { t.Errorf("Expecting: nil, received: %+v", utils.ToJSON(rcv)) } @@ -370,8 +370,8 @@ func TestAPItoModelTimings(t *testing.T) { Months: "1;2;3;4", }, } - eOut = TpTimings{ - TpTimingMdl{ + eOut = TimingMdls{ + TimingMdl{ Tpid: "TPid1", Months: "1;2;3;4", Tag: "ID1", @@ -395,13 +395,13 @@ func TestAPItoModelTimings(t *testing.T) { WeekDays: "4;5", }, } - eOut = TpTimings{ - TpTimingMdl{ + eOut = TimingMdls{ + TimingMdl{ Tpid: "TPid1", Months: "1;2;3;4", Tag: "ID1", }, - TpTimingMdl{ + TimingMdl{ Tpid: "TPid2", Tag: "ID2", Months: "1;2;3;4", @@ -455,7 +455,7 @@ func TestTPRateAsExportSlice(t *testing.T) { func TestAPItoModelRates(t *testing.T) { rs := []*utils.TPRateRALs{} - eOut := TpRates{} + eOut := RateMdls{} if rcv := APItoModelRates(rs); rcv != nil { t.Errorf("Expecting: nil, received: %+v", utils.ToJSON(rcv)) } @@ -476,14 +476,14 @@ func TestAPItoModelRates(t *testing.T) { }, }, } - eOut = TpRates{ - TpRateMdl{ + eOut = RateMdls{ + RateMdl{ Tpid: "TPid", Tag: "SomeID", ConnectFee: 0.7, Rate: 0.8, }, - TpRateMdl{ + RateMdl{ Tpid: "TPid", Tag: "SomeID", ConnectFee: 0.77, @@ -500,8 +500,8 @@ func TestAPItoModelRates(t *testing.T) { RateSlots: []*utils.RateSlot{}, }, } - eOut = TpRates{ - TpRateMdl{ + eOut = RateMdls{ + RateMdl{ Tpid: "TPid", Tag: "SomeID", }, @@ -551,8 +551,8 @@ func TestTPDestinationRateAsExportSlice(t *testing.T) { ID: "TEST_DSTRATE", DestinationRates: []*utils.DestinationRate{}, } - eOut := TpDestinationRates{ - TpDestinationRateMdl{ + eOut := DestinationRateMdls{ + DestinationRateMdl{ Tpid: "TEST_TPID", Tag: "TEST_DSTRATE", }, @@ -586,8 +586,8 @@ func TestAPItoModelDestinationRates(t *testing.T) { }, }, } - eOut := TpDestinationRates{ - TpDestinationRateMdl{ + eOut := DestinationRateMdls{ + DestinationRateMdl{ Tpid: "TEST_TPID", Tag: "TEST_DSTRATE", DestinationsTag: "TEST_DEST1", @@ -595,7 +595,7 @@ func TestAPItoModelDestinationRates(t *testing.T) { RoundingMethod: "*up", RoundingDecimals: 4, }, - TpDestinationRateMdl{ + DestinationRateMdl{ Tpid: "TEST_TPID", Tag: "TEST_DSTRATE", DestinationsTag: "TEST_DEST2", @@ -610,7 +610,7 @@ func TestAPItoModelDestinationRates(t *testing.T) { } func TestTpDestinationRatesAsTPDestinationRates(t *testing.T) { - pts := TpDestinationRates{} + pts := DestinationRateMdls{} eOut := []*utils.TPDestinationRate{} if rcv, err := pts.AsTPDestinationRates(); err != nil { t.Error(err) @@ -618,8 +618,8 @@ func TestTpDestinationRatesAsTPDestinationRates(t *testing.T) { t.Errorf("Expecting: nil, received: %+v", utils.ToJSON(rcv)) } - pts = TpDestinationRates{ - TpDestinationRateMdl{ + pts = DestinationRateMdls{ + DestinationRateMdl{ Id: 66, Tpid: "Tpid", Tag: "Tag", @@ -788,7 +788,7 @@ func TestTPRatingPlanAsExportSlice(t *testing.T) { func TestAPItoModelRatingPlan(t *testing.T) { rp := &utils.TPRatingPlan{} - eOut := TpRatingPlans{TpRatingPlanMdl{}} + eOut := RatingPlanMdls{RatingPlanMdl{}} if rcv := APItoModelRatingPlan(rp); !reflect.DeepEqual(eOut, rcv) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(eOut), utils.ToJSON(rcv)) } @@ -806,15 +806,15 @@ func TestAPItoModelRatingPlan(t *testing.T) { Weight: 20.0}, }} - eOut = TpRatingPlans{ - TpRatingPlanMdl{ + eOut = RatingPlanMdls{ + RatingPlanMdl{ Tpid: "TEST_TPID", Tag: "TEST_RPLAN", DestratesTag: "TEST_DSTRATE1", TimingTag: "TEST_TIMING1", Weight: 10.0, }, - TpRatingPlanMdl{ + RatingPlanMdl{ Tpid: "TEST_TPID", Tag: "TEST_RPLAN", DestratesTag: "TEST_DSTRATE2", @@ -829,8 +829,8 @@ func TestAPItoModelRatingPlan(t *testing.T) { TPid: "TEST_TPID", ID: "TEST_RPLAN", } - eOut = TpRatingPlans{ - TpRatingPlanMdl{ + eOut = RatingPlanMdls{ + RatingPlanMdl{ Tpid: "TEST_TPID", Tag: "TEST_RPLAN", }, @@ -858,8 +858,8 @@ func TestAPItoModelRatingPlans(t *testing.T) { }, }, } - eOut := TpRatingPlans{ - TpRatingPlanMdl{ + eOut := RatingPlanMdls{ + RatingPlanMdl{ Tag: "ID", Tpid: "TPid", DestratesTag: "DestinationRatesId", @@ -933,8 +933,8 @@ func TestAPItoModelRatingProfile(t *testing.T) { FallbackSubjects: "subj1;subj2"}, }, } - eOut := TpRatingProfiles{ - TpRatingProfileMdl{ + eOut := RatingProfileMdls{ + RatingProfileMdl{ Tpid: "TEST_TPID", Loadid: "TEST_LOADID", Tenant: "cgrates.org", @@ -944,7 +944,7 @@ func TestAPItoModelRatingProfile(t *testing.T) { FallbackSubjects: "subj1;subj2", ActivationTime: "2014-01-14T00:00:00Z", }, - TpRatingProfileMdl{ + RatingProfileMdl{ Tpid: "TEST_TPID", Loadid: "TEST_LOADID", Tenant: "cgrates.org", @@ -965,8 +965,8 @@ func TestAPItoModelRatingProfile(t *testing.T) { Category: "call", Subject: "*any", } - eOut = TpRatingProfiles{ - TpRatingProfileMdl{ + eOut = RatingProfileMdls{ + RatingProfileMdl{ Tpid: "TEST_TPID", Loadid: "TEST_LOADID", Tenant: "cgrates.org", @@ -1000,15 +1000,15 @@ func TestAPItoModelRatingProfiles(t *testing.T) { Subject: "*any", }, } - eOut := TpRatingProfiles{ - TpRatingProfileMdl{ + eOut := RatingProfileMdls{ + RatingProfileMdl{ Tpid: "TEST_TPID", Loadid: "TEST_LOADID", Tenant: "cgrates.org", Category: "call", Subject: "*any", }, - TpRatingProfileMdl{ + RatingProfileMdl{ Tpid: "TEST_TPID2", Loadid: "TEST_LOADID2", Tenant: "cgrates.org", @@ -1128,15 +1128,15 @@ func TestAPItoModelSharedGroups(t *testing.T) { }, }, } - eOut := TpSharedGroups{ - TpSharedGroupMdl{ + eOut := SharedGroupMdls{ + SharedGroupMdl{ Tpid: "TEST_TPID", Tag: "SHARED_GROUP_TEST", Account: "*any", Strategy: "*highest", RatingSubject: "special1", }, - TpSharedGroupMdl{ + SharedGroupMdl{ Tpid: "TEST_TPID", Tag: "SHARED_GROUP_TEST", Account: "*second", @@ -1153,8 +1153,8 @@ func TestAPItoModelSharedGroups(t *testing.T) { ID: "SHARED_GROUP_TEST", }, } - eOut = TpSharedGroups{ - TpSharedGroupMdl{ + eOut = SharedGroupMdls{ + SharedGroupMdl{ Tpid: "TEST_TPID", Tag: "SHARED_GROUP_TEST", }, @@ -1192,29 +1192,29 @@ func TestAPItoModelSharedGroups(t *testing.T) { }, }, } - eOut = TpSharedGroups{ - TpSharedGroupMdl{ + eOut = SharedGroupMdls{ + SharedGroupMdl{ Tpid: "TEST_TPID", Tag: "SHARED_GROUP_TEST", Account: "*any", Strategy: "*highest", RatingSubject: "special1", }, - TpSharedGroupMdl{ + SharedGroupMdl{ Tpid: "TEST_TPID", Tag: "SHARED_GROUP_TEST", Account: "*second", Strategy: "*highest", RatingSubject: "special2", }, - TpSharedGroupMdl{ + SharedGroupMdl{ Tpid: "TEST_TPID2", Tag: "SHARED_GROUP_TEST2", Account: "*any", Strategy: "*highest", RatingSubject: "special1", }, - TpSharedGroupMdl{ + SharedGroupMdl{ Tpid: "TEST_TPID2", Tag: "SHARED_GROUP_TEST2", Account: "second", @@ -1280,15 +1280,15 @@ func TestAPItoModelActionPlan(t *testing.T) { }, } - eOut := TpActionPlans{ - TpActionPlanMdl{ + eOut := ActionPlanMdls{ + ActionPlanMdl{ Tpid: "TEST_TPID", Tag: "PACKAGE_10", ActionsTag: "TOPUP_RST_10", TimingTag: "ASAP", Weight: 10, }, - TpActionPlanMdl{ + ActionPlanMdl{ Tpid: "TEST_TPID", Tag: "PACKAGE_10", ActionsTag: "TOPUP_RST_5", @@ -1303,8 +1303,8 @@ func TestAPItoModelActionPlan(t *testing.T) { TPid: "TEST_TPID", ID: "PACKAGE_10", } - eOut = TpActionPlans{ - TpActionPlanMdl{ + eOut = ActionPlanMdls{ + ActionPlanMdl{ Tpid: "TEST_TPID", Tag: "PACKAGE_10", }, @@ -1335,15 +1335,15 @@ func TestAPItoModelActionPlans(t *testing.T) { }, }, } - eOut := TpActionPlans{ - TpActionPlanMdl{ + eOut := ActionPlanMdls{ + ActionPlanMdl{ Tpid: "TEST_TPID", Tag: "PACKAGE_10", ActionsTag: "TOPUP_RST_10", TimingTag: "ASAP", Weight: 10, }, - TpActionPlanMdl{ + ActionPlanMdl{ Tpid: "TEST_TPID", Tag: "PACKAGE_10", ActionsTag: "TOPUP_RST_5", @@ -1360,8 +1360,8 @@ func TestAPItoModelActionPlans(t *testing.T) { ID: "PACKAGE_10", }, } - eOut = TpActionPlans{ - TpActionPlanMdl{ + eOut = ActionPlanMdls{ + ActionPlanMdl{ Tpid: "TEST_TPID", Tag: "PACKAGE_10", }, @@ -1488,8 +1488,8 @@ func TestAPItoModelActionTrigger(t *testing.T) { Weight: 10}, }, } - eOut := TpActionTriggers{ - TpActionTriggerMdl{ + eOut := ActionTriggerMdls{ + ActionTriggerMdl{ Tpid: "TEST_TPID", Tag: "STANDARD_TRIGGERS", UniqueId: "1", @@ -1509,7 +1509,7 @@ func TestAPItoModelActionTrigger(t *testing.T) { ActionsTag: "LOG_WARNING", Weight: 10, }, - TpActionTriggerMdl{ + ActionTriggerMdl{ Tpid: "TEST_TPID", Tag: "STANDARD_TRIGGERS", UniqueId: "2", @@ -1538,8 +1538,8 @@ func TestAPItoModelActionTrigger(t *testing.T) { TPid: "TEST_TPID", ID: "STANDARD_TRIGGERS", } - eOut = TpActionTriggers{ - TpActionTriggerMdl{ + eOut = ActionTriggerMdls{ + ActionTriggerMdl{ Tpid: "TEST_TPID", Tag: "STANDARD_TRIGGERS", }, @@ -1595,15 +1595,15 @@ func TestAPItoModelActionTriggers(t *testing.T) { }, }, } - eOut := TpActionTriggers{ - TpActionTriggerMdl{ + eOut := ActionTriggerMdls{ + ActionTriggerMdl{ Tpid: "TEST_TPID", Tag: "STANDARD_TRIGGERS", UniqueId: "1", ThresholdType: "*min_balance", Weight: 0.7, }, - TpActionTriggerMdl{ + ActionTriggerMdl{ Tpid: "TEST_TPID", Tag: "STANDARD_TRIGGERS", UniqueId: "2", @@ -1625,8 +1625,8 @@ func TestAPItoModelAction(t *testing.T) { TPid: "TEST_TPID", ID: "TEST_ACTIONS", } - eOut := TpActions{ - TpActionMdl{ + eOut := ActionMdls{ + ActionMdl{ Tpid: "TEST_TPID", Tag: "TEST_ACTIONS", }, @@ -1664,8 +1664,8 @@ func TestAPItoModelAction(t *testing.T) { Weight: 20.0}, }, } - eOut = TpActions{ - TpActionMdl{ + eOut = ActionMdls{ + ActionMdl{ Tpid: "TEST_TPID", Tag: "TEST_ACTIONS", BalanceType: "*monetary", @@ -1679,7 +1679,7 @@ func TestAPItoModelAction(t *testing.T) { Weight: 10, Action: "*topup_reset", }, - TpActionMdl{ + ActionMdl{ Tpid: "TEST_TPID", Tag: "TEST_ACTIONS", Action: "*http_post", @@ -1709,12 +1709,12 @@ func TestAPItoModelActions(t *testing.T) { ID: "TEST_ACTIONS2", }, } - eOut := TpActions{ - TpActionMdl{ + eOut := ActionMdls{ + ActionMdl{ Tpid: "TEST_TPID", Tag: "TEST_ACTIONS", }, - TpActionMdl{ + ActionMdl{ Tpid: "TEST_TPID2", Tag: "TEST_ACTIONS2", }, @@ -1749,8 +1749,8 @@ func TestAPItoModelActions(t *testing.T) { }, }, } - eOut = TpActions{ - TpActionMdl{ + eOut = ActionMdls{ + ActionMdl{ Tpid: "TEST_TPID", Tag: "TEST_ACTIONS", BalanceType: "*monetary", @@ -1764,7 +1764,7 @@ func TestAPItoModelActions(t *testing.T) { Weight: 10, Action: "*topup_reset", }, - TpActionMdl{ + ActionMdl{ Tpid: "TEST_TPID", Tag: "TEST_ACTIONS", Action: "*http_post", @@ -1780,7 +1780,7 @@ func TestAPItoModelActions(t *testing.T) { } func TestTpResourcesAsTpResources(t *testing.T) { - tps := []*TpResourceMdl{ + tps := []*ResourceMdl{ { Tpid: "TEST_TPID", Tenant: "cgrates.org", @@ -1838,7 +1838,7 @@ func TestTpResourcesAsTpResources(t *testing.T) { Limit: tps[2].Limit, }, } - rcvTPs := TpResources(tps).AsTPResources() + rcvTPs := ResourceMdls(tps).AsTPResources() if len(rcvTPs) != len(eTPs) { t.Errorf("Expecting: %+v Received: %+v", utils.ToIJSON(eTPs), utils.ToIJSON(rcvTPs)) } @@ -1918,7 +1918,7 @@ func TestAPItoModelResource(t *testing.T) { ThresholdIDs: []string{"TRes1"}, AllocationMessage: "test", } - expModel := &TpResourceMdl{ + expModel := &ResourceMdl{ Tpid: testTPID, Tenant: "cgrates.org", ID: "ResGroup1", @@ -1937,8 +1937,8 @@ func TestAPItoModelResource(t *testing.T) { } func TestTPStatsAsTPStats(t *testing.T) { - tps := TpStats{ - &TpStatMdl{ + tps := StatMdls{ + &StatMdl{ Tpid: "TEST_TPID", Tenant: "cgrates.org", ID: "Stats1", @@ -1952,7 +1952,7 @@ func TestTPStatsAsTPStats(t *testing.T) { Blocker: true, Weight: 20.0, }, - &TpStatMdl{ + &StatMdl{ Tpid: "TEST_TPID", Tenant: "cgrates.org", ID: "Stats1", @@ -1967,7 +1967,7 @@ func TestTPStatsAsTPStats(t *testing.T) { Blocker: true, Weight: 20.0, }, - &TpStatMdl{ + &StatMdl{ Tpid: "TEST_TPID", Tenant: "itsyscom.com", ID: "Stats1", @@ -2138,8 +2138,8 @@ func TestAPItoModelStats(t *testing.T) { ThresholdIDs: []string{"Th1"}, } rcv := APItoModelStats(tpS) - eRcv := TpStats{ - &TpStatMdl{ + eRcv := StatMdls{ + &StatMdl{ Tpid: "TPS1", Tenant: "cgrates.org", ID: "Stat1", @@ -2154,7 +2154,7 @@ func TestAPItoModelStats(t *testing.T) { Weight: 20.0, ThresholdIDs: "Th1", }, - &TpStatMdl{ + &StatMdl{ Tpid: "TPS1", Tenant: "cgrates.org", ID: "Stat1", @@ -2169,7 +2169,7 @@ func TestAPItoModelStats(t *testing.T) { } func TestTPThresholdsAsTPThreshold(t *testing.T) { - tps := []*TpThresholdMdl{ + tps := []*ThresholdMdl{ { Tpid: "TEST_TPID", ID: "Threhold", @@ -2213,7 +2213,7 @@ func TestTPThresholdsAsTPThreshold(t *testing.T) { ActionIDs: []string{"WARN3"}, }, } - rcvTPs := TpThresholds(tps).AsTPThreshold() + rcvTPs := ThresholdMdls(tps).AsTPThreshold() if !reflect.DeepEqual(eTPs[0], rcvTPs[0]) && !reflect.DeepEqual(eTPs[1], rcvTPs[0]) { t.Errorf("Expecting: %+v , Received: %+v", utils.ToIJSON(eTPs), utils.ToIJSON(rcvTPs)) } @@ -2242,8 +2242,8 @@ func TestAPItoModelAccountActions(t *testing.T) { ActionTriggersId: "STANDARD_TRIGGERS", }, } - eOut := TpAccountActions{ - TpAccountActionMdl{ + eOut := AccountActionMdls{ + AccountActionMdl{ Tpid: "TEST_TPID", Loadid: "TEST_LOADID", Tenant: "cgrates.org", @@ -2251,7 +2251,7 @@ func TestAPItoModelAccountActions(t *testing.T) { ActionPlanTag: "PACKAGE_10_SHARED_A_5", ActionTriggersTag: "STANDARD_TRIGGERS", }, - TpAccountActionMdl{ + AccountActionMdl{ Tpid: "TEST_TPID2", Loadid: "TEST_LOADID2", Tenant: "cgrates.org", @@ -2266,7 +2266,7 @@ func TestAPItoModelAccountActions(t *testing.T) { } func TestCSVHeader(t *testing.T) { - var tps TpResources + var tps ResourceMdls eOut := []string{ "#Tenant", "ID", "FilterIDs", "ActivationInterval", "UsageTTL", "Limit", "AllocationMessage", "Blocker", "Stored", "Weight", "ThresholdIDs", } @@ -2293,7 +2293,7 @@ func TestAPItoModelTPThreshold(t *testing.T) { Weight: 20.0, ActionIDs: []string{"WARN3"}, } - models := TpThresholds{ + models := ThresholdMdls{ { Tpid: "TP1", Tenant: "cgrates.org", @@ -2331,7 +2331,7 @@ func TestAPItoModelTPThreshold2(t *testing.T) { Weight: 20.0, ActionIDs: []string{"WARN3"}, } - models := TpThresholds{ + models := ThresholdMdls{ { Tpid: "TP1", Tenant: "cgrates.org", @@ -2375,7 +2375,7 @@ func TestAPItoModelTPThreshold3(t *testing.T) { Weight: 20.0, ActionIDs: []string{"WARN3", "LOG"}, } - models := TpThresholds{ + models := ThresholdMdls{ { Tpid: "TP1", Tenant: "cgrates.org", @@ -2419,7 +2419,7 @@ func TestAPItoModelTPThreshold4(t *testing.T) { Weight: 20.0, ActionIDs: []string{"WARN3", "LOG"}, } - models := TpThresholds{ + models := ThresholdMdls{ { Tpid: "TP1", Tenant: "cgrates.org", @@ -2537,7 +2537,7 @@ func TestThresholdProfileToAPI(t *testing.T) { } func TestTPFilterAsTPFilter(t *testing.T) { - tps := []*TpFilterMdl{ + tps := []*FilterMdl{ { Tpid: "TEST_TPID", ID: "Filter1", @@ -2560,14 +2560,14 @@ func TestTPFilterAsTPFilter(t *testing.T) { }, } - rcvTPs := TpFilterS(tps).AsTPFilter() + rcvTPs := FilterMdls(tps).AsTPFilter() if !(reflect.DeepEqual(eTPs, rcvTPs) || reflect.DeepEqual(eTPs[0], rcvTPs[0])) { t.Errorf("Expecting:\n%+v\nReceived:\n%+v", utils.ToIJSON(eTPs), utils.ToIJSON(rcvTPs)) } } func TestTPFilterAsTPFilterWithDynValues(t *testing.T) { - tps := []*TpFilterMdl{ + tps := []*FilterMdl{ { Tpid: "TEST_TPID", ID: "Filter1", @@ -2595,14 +2595,14 @@ func TestTPFilterAsTPFilterWithDynValues(t *testing.T) { }, } - rcvTPs := TpFilterS(tps).AsTPFilter() + rcvTPs := FilterMdls(tps).AsTPFilter() if !(reflect.DeepEqual(eTPs, rcvTPs) || reflect.DeepEqual(eTPs[0], rcvTPs[0])) { t.Errorf("Expecting:\n%+v\nReceived:\n%+v", utils.ToIJSON(eTPs), utils.ToIJSON(rcvTPs)) } } func TestTPFilterAsTPFilter2(t *testing.T) { - tps := []*TpFilterMdl{ + tps := []*FilterMdl{ { Tpid: "TEST_TPID", Tenant: "cgrates.org", @@ -2647,7 +2647,7 @@ func TestTPFilterAsTPFilter2(t *testing.T) { }, } - rcvTPs := TpFilterS(tps).AsTPFilter() + rcvTPs := FilterMdls(tps).AsTPFilter() if len(eTPs) != len(rcvTPs) { t.Errorf("Expecting: %+v ,Received: %+v", utils.ToIJSON(eTPs), utils.ToIJSON(rcvTPs)) } @@ -2680,14 +2680,14 @@ func TestAPItoModelTPFilter(t *testing.T) { }, }, } - eOut := TpFilterS{ - &TpFilterMdl{ + eOut := FilterMdls{ + &FilterMdl{ ID: "someID", Type: "*prefix", Element: "Account", Values: "1010", }, - &TpFilterMdl{ + &FilterMdl{ ID: "someID", Type: "*prefix", Element: "Account", @@ -2709,7 +2709,7 @@ func TestAPItoModelTPFilter(t *testing.T) { }, }, } - eOut = TpFilterS{ + eOut = FilterMdls{ { Tpid: "TPid", Tenant: "cgrates.org", @@ -2738,7 +2738,7 @@ func TestAPItoModelTPFilter(t *testing.T) { }, }, } - eOut = TpFilterS{ + eOut = FilterMdls{ { Tpid: "TPid", Tenant: "cgrates.org", @@ -2827,7 +2827,7 @@ func TestFilterToTPFilter(t *testing.T) { } func TestCsvHeader(t *testing.T) { - var tps TPRoutes + var tps RouteMdls eOut := []string{ "#" + utils.Tenant, utils.ID, utils.FilterIDs, utils.ActivationIntervalString, utils.Sorting, utils.SortingParameters, utils.RouteID, utils.RouteFilterIDs, @@ -3882,8 +3882,8 @@ func TestDispatcherHostToAPI(t *testing.T) { } func TestTPRoutesAsTPRouteProfile(t *testing.T) { - mdl := TPRoutes{ - &TpRouteMdl{ + mdl := RouteMdls{ + &RouteMdl{ PK: 1, Tpid: "TP", Tenant: "cgrates.org", @@ -3904,7 +3904,7 @@ func TestTPRoutesAsTPRouteProfile(t *testing.T) { Weight: 10.0, CreatedAt: time.Time{}, }, - &TpRouteMdl{ + &RouteMdl{ PK: 2, Tpid: "TP", Tenant: "cgrates.org", @@ -3959,8 +3959,8 @@ func TestTPRoutesAsTPRouteProfile(t *testing.T) { t.Errorf("Expecting: %+v,\nReceived: %+v", utils.ToJSON(expPrf), utils.ToJSON(rcv)) } - mdlReverse := TPRoutes{ - &TpRouteMdl{ + mdlReverse := RouteMdls{ + &RouteMdl{ PK: 2, Tpid: "TP", Tenant: "cgrates.org", @@ -3981,7 +3981,7 @@ func TestTPRoutesAsTPRouteProfile(t *testing.T) { Weight: 0, CreatedAt: time.Time{}, }, - &TpRouteMdl{ + &RouteMdl{ PK: 1, Tpid: "TP", Tenant: "cgrates.org", @@ -4575,7 +4575,7 @@ func TestModelHelpersCsvDumpError(t *testing.T) { } func TestModelHelpersAsMapRatesError(t *testing.T) { - tps := TpRates{{RateUnit: "true"}} + tps := RateMdls{{RateUnit: "true"}} _, err := tps.AsMapRates() if err == nil || err.Error() != "time: invalid duration \"true\"" { t.Errorf("Expecting: ,\n Received: <%+v>", err) @@ -4583,7 +4583,7 @@ func TestModelHelpersAsMapRatesError(t *testing.T) { } func TestModelHelpersAsTPRatesError(t *testing.T) { - tps := TpRates{{RateUnit: "true"}} + tps := RateMdls{{RateUnit: "true"}} _, err := tps.AsTPRates() if err == nil || err.Error() != "time: invalid duration \"true\"" { t.Errorf("Expecting: ,\n Received: <%+v>", err) @@ -4593,7 +4593,7 @@ func TestModelHelpersAsTPRatesError(t *testing.T) { func TestAPItoModelTPRoutesCase1(t *testing.T) { structTest := &utils.TPRouteProfile{} - structTest2 := TPRoutes{} + structTest2 := RouteMdls{} structTest2 = nil result := APItoModelTPRoutes(structTest) if !reflect.DeepEqual(structTest2, result) { @@ -4629,7 +4629,7 @@ func TestAPItoModelTPRoutesCase2(t *testing.T) { }, Weight: 20, } - expStructTest := TPRoutes{{ + expStructTest := RouteMdls{{ Tpid: "TP1", Tenant: "cgrates.org", ID: "RoutePrf", @@ -4659,7 +4659,7 @@ func TestAPItoModelTPRoutesCase2(t *testing.T) { func TestAPItoModelResourceCase1(t *testing.T) { var testStruct *utils.TPResourceProfile - var testStruct2 TpResources + var testStruct2 ResourceMdls testStruct = nil result := APItoModelResource(testStruct) if !reflect.DeepEqual(result, testStruct2) { @@ -4683,7 +4683,7 @@ func TestAPItoModelResourceCase2(t *testing.T) { ThresholdIDs: []string{"TRes1", "TRes2"}, AllocationMessage: "test", } - expectedStruct := TpResources{ + expectedStruct := ResourceMdls{ { Tenant: "cgrates.org", Tpid: "LoaderCSVTests", @@ -4719,7 +4719,7 @@ func TestAPItoModelResourceCase3(t *testing.T) { ThresholdIDs: []string{"TRes1", "TRes2"}, AllocationMessage: "test", } - expStruct := TpResources{{ + expStruct := ResourceMdls{{ Tenant: "cgrates.org", Tpid: testTPID, ID: "ResGroup1", diff --git a/engine/models.go b/engine/models.go index 36e5658c9..a9a80a1db 100644 --- a/engine/models.go +++ b/engine/models.go @@ -29,7 +29,7 @@ import ( // Structs here are one to one mapping of the tables and fields // to be used by gorm orm -type TpTimingMdl struct { +type TimingMdl struct { Id int64 Tpid string Tag string `index:"0" re:"\w+\s*,\s*"` @@ -41,7 +41,11 @@ type TpTimingMdl struct { CreatedAt time.Time } -type TpDestinationMdl struct { +func (TimingMdl) TableName() string { + return utils.TBLTPTimings +} + +type DestinationMdl struct { Id int64 Tpid string Tag string `index:"0" re:"\w+\s*,\s*"` @@ -49,7 +53,11 @@ type TpDestinationMdl struct { CreatedAt time.Time } -type TpRateMdl struct { +func (DestinationMdl) TableName() string { + return utils.TBLTPDestinations +} + +type RateMdl struct { Id int64 Tpid string Tag string `index:"0" re:"\w+\s*"` @@ -61,7 +69,11 @@ type TpRateMdl struct { CreatedAt time.Time } -type TpDestinationRateMdl struct { +func (RateMdl) TableName() string { + return utils.TBLTPRates +} + +type DestinationRateMdl struct { Id int64 Tpid string Tag string `index:"0" re:"\w+\s*"` @@ -74,7 +86,11 @@ type TpDestinationRateMdl struct { CreatedAt time.Time } -type TpRatingPlanMdl struct { +func (DestinationRateMdl) TableName() string { + return utils.TBLTPDestinationRates +} + +type RatingPlanMdl struct { Id int64 Tpid string Tag string `index:"0" re:"\w+\s*,\s*"` @@ -84,7 +100,11 @@ type TpRatingPlanMdl struct { CreatedAt time.Time } -type TpRatingProfileMdl struct { +func (RatingPlanMdl) TableName() string { + return utils.TBLTPRatingPlans +} + +type RatingProfileMdl struct { Id int64 Tpid string Loadid string @@ -97,7 +117,11 @@ type TpRatingProfileMdl struct { CreatedAt time.Time } -type TpActionMdl struct { +func (RatingProfileMdl) TableName() string { + return utils.TBLTPRatingProfiles +} + +type ActionMdl struct { Id int64 Tpid string Tag string `index:"0" re:"\w+\s*"` @@ -120,7 +144,11 @@ type TpActionMdl struct { CreatedAt time.Time } -type TpActionPlanMdl struct { +func (ActionMdl) TableName() string { + return utils.TBLTPActions +} + +type ActionPlanMdl struct { Id int64 Tpid string Tag string `index:"0" re:"\w+\s*,\s*"` @@ -130,7 +158,11 @@ type TpActionPlanMdl struct { CreatedAt time.Time } -type TpActionTriggerMdl struct { +func (ActionPlanMdl) TableName() string { + return utils.TBLTPActionPlans +} + +type ActionTriggerMdl struct { Id int64 Tpid string Tag string `index:"0" re:"\w+"` @@ -157,7 +189,11 @@ type TpActionTriggerMdl struct { CreatedAt time.Time } -type TpAccountActionMdl struct { +func (ActionTriggerMdl) TableName() string { + return utils.TBLTPActionTriggers +} + +type AccountActionMdl struct { Id int64 Tpid string Loadid string @@ -170,7 +206,11 @@ type TpAccountActionMdl struct { CreatedAt time.Time } -func (aa *TpAccountActionMdl) SetAccountActionId(id string) error { +func (AccountActionMdl) TableName() string { + return utils.TBLTPAccountActions +} + +func (aa *AccountActionMdl) SetAccountActionId(id string) error { ids := strings.Split(id, utils.CONCATENATED_KEY_SEP) if len(ids) != 3 { return fmt.Errorf("Wrong TP Account Action Id: %s", id) @@ -181,11 +221,11 @@ func (aa *TpAccountActionMdl) SetAccountActionId(id string) error { return nil } -func (aa *TpAccountActionMdl) GetAccountActionId() string { +func (aa *AccountActionMdl) GetAccountActionId() string { return utils.ConcatenatedKey(aa.Tenant, aa.Account) } -type TpSharedGroupMdl struct { +type SharedGroupMdl struct { Id int64 Tpid string Tag string `index:"0" re:"\w+\s*"` @@ -195,7 +235,11 @@ type TpSharedGroupMdl struct { CreatedAt time.Time } -type TpResourceMdl struct { +func (SharedGroupMdl) TableName() string { + return utils.TBLTPSharedGroups +} + +type ResourceMdl struct { PK uint `gorm:"primary_key"` Tpid string Tenant string `index:"0" re:""` @@ -212,7 +256,11 @@ type TpResourceMdl struct { CreatedAt time.Time } -type TpStatMdl struct { +func (ResourceMdl) TableName() string { + return utils.TBLTPResources +} + +type StatMdl struct { PK uint `gorm:"primary_key"` Tpid string Tenant string `index:"0" re:""` @@ -231,7 +279,11 @@ type TpStatMdl struct { CreatedAt time.Time } -type TpThresholdMdl struct { +func (StatMdl) TableName() string { + return utils.TBLTPStats +} + +type ThresholdMdl struct { PK uint `gorm:"primary_key"` Tpid string Tenant string `index:"0" re:""` @@ -248,7 +300,11 @@ type TpThresholdMdl struct { CreatedAt time.Time } -type TpFilterMdl struct { +func (ThresholdMdl) TableName() string { + return utils.TBLTPThresholds +} + +type FilterMdl struct { PK uint `gorm:"primary_key"` Tpid string Tenant string `index:"0" re:""` @@ -260,6 +316,10 @@ type TpFilterMdl struct { CreatedAt time.Time } +func (FilterMdl) TableName() string { + return utils.TBLTPFilters +} + type CDRsql struct { ID int64 Cgrid string @@ -348,7 +408,7 @@ func (t TBLVersion) TableName() string { return utils.TBLVersions } -type TpRouteMdl struct { +type RouteMdl struct { PK uint `gorm:"primary_key"` Tpid string Tenant string `index:"0" re:""` @@ -371,6 +431,10 @@ type TpRouteMdl struct { CreatedAt time.Time } +func (RouteMdl) TableName() string { + return utils.TBLTPRoutes +} + type TPAttributeMdl struct { PK uint `gorm:"primary_key"` Tpid string diff --git a/engine/storage_csv.go b/engine/storage_csv.go index e80565ed3..11dfb1160 100644 --- a/engine/storage_csv.go +++ b/engine/storage_csv.go @@ -418,9 +418,9 @@ func (csvs *CSVStorage) proccesData(listType interface{}, fns []string, process } func (csvs *CSVStorage) GetTPTimings(tpid, id string) ([]*utils.ApierTPTiming, error) { - var tpTimings TpTimings - if err := csvs.proccesData(TpTimingMdl{}, csvs.timingsFn, func(tp interface{}) { - tm := tp.(TpTimingMdl) + var tpTimings TimingMdls + if err := csvs.proccesData(TimingMdl{}, csvs.timingsFn, func(tp interface{}) { + tm := tp.(TimingMdl) tm.Tpid = tpid tpTimings = append(tpTimings, tm) }); err != nil { @@ -430,9 +430,9 @@ func (csvs *CSVStorage) GetTPTimings(tpid, id string) ([]*utils.ApierTPTiming, e } func (csvs *CSVStorage) GetTPDestinations(tpid, id string) ([]*utils.TPDestination, error) { - var tpDests TpDestinations - if err := csvs.proccesData(TpDestinationMdl{}, csvs.destinationsFn, func(tp interface{}) { - d := tp.(TpDestinationMdl) + var tpDests DestinationMdls + if err := csvs.proccesData(DestinationMdl{}, csvs.destinationsFn, func(tp interface{}) { + d := tp.(DestinationMdl) d.Tpid = tpid tpDests = append(tpDests, d) }); err != nil { @@ -442,9 +442,9 @@ func (csvs *CSVStorage) GetTPDestinations(tpid, id string) ([]*utils.TPDestinati } func (csvs *CSVStorage) GetTPRates(tpid, id string) ([]*utils.TPRateRALs, error) { - var tpRates TpRates - if err := csvs.proccesData(TpRateMdl{}, csvs.ratesFn, func(tp interface{}) { - r := tp.(TpRateMdl) + var tpRates RateMdls + if err := csvs.proccesData(RateMdl{}, csvs.ratesFn, func(tp interface{}) { + r := tp.(RateMdl) r.Tpid = tpid tpRates = append(tpRates, r) }); err != nil { @@ -454,9 +454,9 @@ func (csvs *CSVStorage) GetTPRates(tpid, id string) ([]*utils.TPRateRALs, error) } func (csvs *CSVStorage) GetTPDestinationRates(tpid, id string, p *utils.Paginator) ([]*utils.TPDestinationRate, error) { - var tpDestinationRates TpDestinationRates - if err := csvs.proccesData(TpDestinationRateMdl{}, csvs.destinationratesFn, func(tp interface{}) { - dr := tp.(TpDestinationRateMdl) + var tpDestinationRates DestinationRateMdls + if err := csvs.proccesData(DestinationRateMdl{}, csvs.destinationratesFn, func(tp interface{}) { + dr := tp.(DestinationRateMdl) dr.Tpid = tpid tpDestinationRates = append(tpDestinationRates, dr) }); err != nil { @@ -466,9 +466,9 @@ func (csvs *CSVStorage) GetTPDestinationRates(tpid, id string, p *utils.Paginato } func (csvs *CSVStorage) GetTPRatingPlans(tpid, id string, p *utils.Paginator) ([]*utils.TPRatingPlan, error) { - var tpRatingPlans TpRatingPlans - if err := csvs.proccesData(TpRatingPlanMdl{}, csvs.destinationratetimingsFn, func(tp interface{}) { - rp := tp.(TpRatingPlanMdl) + var tpRatingPlans RatingPlanMdls + if err := csvs.proccesData(RatingPlanMdl{}, csvs.destinationratetimingsFn, func(tp interface{}) { + rp := tp.(RatingPlanMdl) rp.Tpid = tpid tpRatingPlans = append(tpRatingPlans, rp) }); err != nil { @@ -478,9 +478,9 @@ func (csvs *CSVStorage) GetTPRatingPlans(tpid, id string, p *utils.Paginator) ([ } func (csvs *CSVStorage) GetTPRatingProfiles(filter *utils.TPRatingProfile) ([]*utils.TPRatingProfile, error) { - var tpRatingProfiles TpRatingProfiles - if err := csvs.proccesData(TpRatingProfileMdl{}, csvs.ratingprofilesFn, func(tp interface{}) { - rpf := tp.(TpRatingProfileMdl) + var tpRatingProfiles RatingProfileMdls + if err := csvs.proccesData(RatingProfileMdl{}, csvs.ratingprofilesFn, func(tp interface{}) { + rpf := tp.(RatingProfileMdl) if filter != nil { rpf.Tpid = filter.TPid rpf.Loadid = filter.LoadId @@ -493,9 +493,9 @@ func (csvs *CSVStorage) GetTPRatingProfiles(filter *utils.TPRatingProfile) ([]*u } func (csvs *CSVStorage) GetTPSharedGroups(tpid, id string) ([]*utils.TPSharedGroups, error) { - var tpSharedGroups TpSharedGroups - if err := csvs.proccesData(TpSharedGroupMdl{}, csvs.sharedgroupsFn, func(tp interface{}) { - sg := tp.(TpSharedGroupMdl) + var tpSharedGroups SharedGroupMdls + if err := csvs.proccesData(SharedGroupMdl{}, csvs.sharedgroupsFn, func(tp interface{}) { + sg := tp.(SharedGroupMdl) sg.Tpid = tpid tpSharedGroups = append(tpSharedGroups, sg) }); err != nil { @@ -505,9 +505,9 @@ func (csvs *CSVStorage) GetTPSharedGroups(tpid, id string) ([]*utils.TPSharedGro } func (csvs *CSVStorage) GetTPActions(tpid, id string) ([]*utils.TPActions, error) { - var tpActions TpActions - if err := csvs.proccesData(TpActionMdl{}, csvs.actionsFn, func(tp interface{}) { - a := tp.(TpActionMdl) + var tpActions ActionMdls + if err := csvs.proccesData(ActionMdl{}, csvs.actionsFn, func(tp interface{}) { + a := tp.(ActionMdl) a.Tpid = tpid tpActions = append(tpActions, a) }); err != nil { @@ -517,9 +517,9 @@ func (csvs *CSVStorage) GetTPActions(tpid, id string) ([]*utils.TPActions, error } func (csvs *CSVStorage) GetTPActionPlans(tpid, id string) ([]*utils.TPActionPlan, error) { - var tpActionPlans TpActionPlans - if err := csvs.proccesData(TpActionPlanMdl{}, csvs.actiontimingsFn, func(tp interface{}) { - ap := tp.(TpActionPlanMdl) + var tpActionPlans ActionPlanMdls + if err := csvs.proccesData(ActionPlanMdl{}, csvs.actiontimingsFn, func(tp interface{}) { + ap := tp.(ActionPlanMdl) ap.Tpid = tpid tpActionPlans = append(tpActionPlans, ap) }); err != nil { @@ -529,9 +529,9 @@ func (csvs *CSVStorage) GetTPActionPlans(tpid, id string) ([]*utils.TPActionPlan } func (csvs *CSVStorage) GetTPActionTriggers(tpid, id string) ([]*utils.TPActionTriggers, error) { - var tpActionTriggers TpActionTriggers - if err := csvs.proccesData(TpActionTriggerMdl{}, csvs.actiontriggersFn, func(tp interface{}) { - at := tp.(TpActionTriggerMdl) + var tpActionTriggers ActionTriggerMdls + if err := csvs.proccesData(ActionTriggerMdl{}, csvs.actiontriggersFn, func(tp interface{}) { + at := tp.(ActionTriggerMdl) at.Tpid = tpid tpActionTriggers = append(tpActionTriggers, at) }); err != nil { @@ -541,9 +541,9 @@ func (csvs *CSVStorage) GetTPActionTriggers(tpid, id string) ([]*utils.TPActionT } func (csvs *CSVStorage) GetTPAccountActions(filter *utils.TPAccountActions) ([]*utils.TPAccountActions, error) { - var tpAccountActions TpAccountActions - if err := csvs.proccesData(TpAccountActionMdl{}, csvs.accountactionsFn, func(tp interface{}) { - aa := tp.(TpAccountActionMdl) + var tpAccountActions AccountActionMdls + if err := csvs.proccesData(AccountActionMdl{}, csvs.accountactionsFn, func(tp interface{}) { + aa := tp.(AccountActionMdl) if filter != nil { aa.Tpid = filter.TPid aa.Loadid = filter.LoadId @@ -556,9 +556,9 @@ func (csvs *CSVStorage) GetTPAccountActions(filter *utils.TPAccountActions) ([]* } func (csvs *CSVStorage) GetTPResources(tpid, tenant, id string) ([]*utils.TPResourceProfile, error) { - var tpResLimits TpResources - if err := csvs.proccesData(TpResourceMdl{}, csvs.resProfilesFn, func(tp interface{}) { - tpLimit := tp.(TpResourceMdl) + var tpResLimits ResourceMdls + if err := csvs.proccesData(ResourceMdl{}, csvs.resProfilesFn, func(tp interface{}) { + tpLimit := tp.(ResourceMdl) tpLimit.Tpid = tpid tpResLimits = append(tpResLimits, &tpLimit) }); err != nil { @@ -568,9 +568,9 @@ func (csvs *CSVStorage) GetTPResources(tpid, tenant, id string) ([]*utils.TPReso } func (csvs *CSVStorage) GetTPStats(tpid, tenant, id string) ([]*utils.TPStatProfile, error) { - var tpStats TpStats - if err := csvs.proccesData(TpStatMdl{}, csvs.statsFn, func(tp interface{}) { - tPstats := tp.(TpStatMdl) + var tpStats StatMdls + if err := csvs.proccesData(StatMdl{}, csvs.statsFn, func(tp interface{}) { + tPstats := tp.(StatMdl) tPstats.Tpid = tpid tpStats = append(tpStats, &tPstats) }); err != nil { @@ -580,9 +580,9 @@ func (csvs *CSVStorage) GetTPStats(tpid, tenant, id string) ([]*utils.TPStatProf } func (csvs *CSVStorage) GetTPThresholds(tpid, tenant, id string) ([]*utils.TPThresholdProfile, error) { - var tpThreshold TpThresholds - if err := csvs.proccesData(TpThresholdMdl{}, csvs.thresholdsFn, func(tp interface{}) { - tHresholdCfg := tp.(TpThresholdMdl) + var tpThreshold ThresholdMdls + if err := csvs.proccesData(ThresholdMdl{}, csvs.thresholdsFn, func(tp interface{}) { + tHresholdCfg := tp.(ThresholdMdl) tHresholdCfg.Tpid = tpid tpThreshold = append(tpThreshold, &tHresholdCfg) }); err != nil { @@ -592,9 +592,9 @@ func (csvs *CSVStorage) GetTPThresholds(tpid, tenant, id string) ([]*utils.TPThr } func (csvs *CSVStorage) GetTPFilters(tpid, tenant, id string) ([]*utils.TPFilterProfile, error) { - var tpFilter TpFilterS - if err := csvs.proccesData(TpFilterMdl{}, csvs.filterFn, func(tp interface{}) { - fIlterCfg := tp.(TpFilterMdl) + var tpFilter FilterMdls + if err := csvs.proccesData(FilterMdl{}, csvs.filterFn, func(tp interface{}) { + fIlterCfg := tp.(FilterMdl) fIlterCfg.Tpid = tpid tpFilter = append(tpFilter, &fIlterCfg) }); err != nil { @@ -604,9 +604,9 @@ func (csvs *CSVStorage) GetTPFilters(tpid, tenant, id string) ([]*utils.TPFilter } func (csvs *CSVStorage) GetTPRoutes(tpid, tenant, id string) ([]*utils.TPRouteProfile, error) { - var tpRoutes TPRoutes - if err := csvs.proccesData(TpRouteMdl{}, csvs.routeProfilesFn, func(tp interface{}) { - suppProfile := tp.(TpRouteMdl) + var tpRoutes RouteMdls + if err := csvs.proccesData(RouteMdl{}, csvs.routeProfilesFn, func(tp interface{}) { + suppProfile := tp.(RouteMdl) suppProfile.Tpid = tpid tpRoutes = append(tpRoutes, &suppProfile) }); err != nil { diff --git a/engine/storage_sql.go b/engine/storage_sql.go index 078a08f94..ed981374d 100644 --- a/engine/storage_sql.go +++ b/engine/storage_sql.go @@ -268,7 +268,7 @@ func (self *SQLStorage) SetTPTimings(timings []*utils.ApierTPTiming) error { tx := self.db.Begin() for _, timing := range timings { - if err := tx.Where(&TpTimingMdl{Tpid: timing.TPid, Tag: timing.ID}).Delete(TpTimingMdl{}).Error; err != nil { + if err := tx.Where(&TimingMdl{Tpid: timing.TPid, Tag: timing.ID}).Delete(TimingMdl{}).Error; err != nil { tx.Rollback() return err } @@ -289,7 +289,7 @@ func (self *SQLStorage) SetTPDestinations(dests []*utils.TPDestination) error { tx := self.db.Begin() for _, dst := range dests { // Remove previous - if err := tx.Where(&TpDestinationMdl{Tpid: dst.TPid, Tag: dst.ID}).Delete(TpDestinationMdl{}).Error; err != nil { + if err := tx.Where(&DestinationMdl{Tpid: dst.TPid, Tag: dst.ID}).Delete(DestinationMdl{}).Error; err != nil { tx.Rollback() return err } @@ -313,7 +313,7 @@ func (self *SQLStorage) SetTPRates(rs []*utils.TPRateRALs) error { for _, rate := range rs { if found, _ := m[rate.ID]; !found { m[rate.ID] = true - if err := tx.Where(&TpRateMdl{Tpid: rate.TPid, Tag: rate.ID}).Delete(TpRateMdl{}).Error; err != nil { + if err := tx.Where(&RateMdl{Tpid: rate.TPid, Tag: rate.ID}).Delete(RateMdl{}).Error; err != nil { tx.Rollback() return err } @@ -338,7 +338,7 @@ func (self *SQLStorage) SetTPDestinationRates(drs []*utils.TPDestinationRate) er for _, dRate := range drs { if found, _ := m[dRate.ID]; !found { m[dRate.ID] = true - if err := tx.Where(&TpDestinationRateMdl{Tpid: dRate.TPid, Tag: dRate.ID}).Delete(TpDestinationRateMdl{}).Error; err != nil { + if err := tx.Where(&DestinationRateMdl{Tpid: dRate.TPid, Tag: dRate.ID}).Delete(DestinationRateMdl{}).Error; err != nil { tx.Rollback() return err } @@ -363,7 +363,7 @@ func (self *SQLStorage) SetTPRatingPlans(rps []*utils.TPRatingPlan) error { for _, rPlan := range rps { if found, _ := m[rPlan.ID]; !found { m[rPlan.ID] = true - if err := tx.Where(&TpRatingPlanMdl{Tpid: rPlan.TPid, Tag: rPlan.ID}).Delete(TpRatingPlanMdl{}).Error; err != nil { + if err := tx.Where(&RatingPlanMdl{Tpid: rPlan.TPid, Tag: rPlan.ID}).Delete(RatingPlanMdl{}).Error; err != nil { tx.Rollback() return err } @@ -385,9 +385,9 @@ func (self *SQLStorage) SetTPRatingProfiles(rpfs []*utils.TPRatingProfile) error } tx := self.db.Begin() for _, rpf := range rpfs { - if err := tx.Where(&TpRatingProfileMdl{Tpid: rpf.TPid, Loadid: rpf.LoadId, + if err := tx.Where(&RatingProfileMdl{Tpid: rpf.TPid, Loadid: rpf.LoadId, Tenant: rpf.Tenant, Category: rpf.Category, - Subject: rpf.Subject}).Delete(TpRatingProfileMdl{}).Error; err != nil { + Subject: rpf.Subject}).Delete(RatingProfileMdl{}).Error; err != nil { tx.Rollback() return err } @@ -411,7 +411,7 @@ func (self *SQLStorage) SetTPSharedGroups(sgs []*utils.TPSharedGroups) error { for _, sGroup := range sgs { if found, _ := m[sGroup.ID]; !found { m[sGroup.ID] = true - if err := tx.Where(&TpSharedGroupMdl{Tpid: sGroup.TPid, Tag: sGroup.ID}).Delete(TpSharedGroupMdl{}).Error; err != nil { + if err := tx.Where(&SharedGroupMdl{Tpid: sGroup.TPid, Tag: sGroup.ID}).Delete(SharedGroupMdl{}).Error; err != nil { tx.Rollback() return err } @@ -436,7 +436,7 @@ func (self *SQLStorage) SetTPActions(acts []*utils.TPActions) error { for _, a := range acts { if found, _ := m[a.ID]; !found { m[a.ID] = true - if err := tx.Where(&TpActionMdl{Tpid: a.TPid, Tag: a.ID}).Delete(TpActionMdl{}).Error; err != nil { + if err := tx.Where(&ActionMdl{Tpid: a.TPid, Tag: a.ID}).Delete(ActionMdl{}).Error; err != nil { tx.Rollback() return err } @@ -462,7 +462,7 @@ func (self *SQLStorage) SetTPActionPlans(ats []*utils.TPActionPlan) error { for _, aPlan := range ats { if found, _ := m[aPlan.ID]; !found { m[aPlan.ID] = true - if err := tx.Where(&TpActionPlanMdl{Tpid: aPlan.TPid, Tag: aPlan.ID}).Delete(TpActionPlanMdl{}).Error; err != nil { + if err := tx.Where(&ActionPlanMdl{Tpid: aPlan.TPid, Tag: aPlan.ID}).Delete(ActionPlanMdl{}).Error; err != nil { tx.Rollback() return err } @@ -487,7 +487,7 @@ func (self *SQLStorage) SetTPActionTriggers(ats []*utils.TPActionTriggers) error for _, aTrigger := range ats { if found, _ := m[aTrigger.ID]; !found { m[aTrigger.ID] = true - if err := tx.Where(&TpActionTriggerMdl{Tpid: aTrigger.TPid, Tag: aTrigger.ID}).Delete(TpActionTriggerMdl{}).Error; err != nil { + if err := tx.Where(&ActionTriggerMdl{Tpid: aTrigger.TPid, Tag: aTrigger.ID}).Delete(ActionTriggerMdl{}).Error; err != nil { tx.Rollback() return err } @@ -514,7 +514,7 @@ func (self *SQLStorage) SetTPAccountActions(aas []*utils.TPAccountActions) error for _, aa := range aas { if found, _ := m[aa.GetId()]; !found { m[aa.GetId()] = true - if err := tx.Where(&TpAccountActionMdl{Tpid: aa.TPid, Loadid: aa.LoadId, Tenant: aa.Tenant, Account: aa.Account}).Delete(&TpAccountActionMdl{}).Error; err != nil { + if err := tx.Where(&AccountActionMdl{Tpid: aa.TPid, Loadid: aa.LoadId, Tenant: aa.Tenant, Account: aa.Account}).Delete(&AccountActionMdl{}).Error; err != nil { tx.Rollback() return err } @@ -536,7 +536,7 @@ func (self *SQLStorage) SetTPResources(rls []*utils.TPResourceProfile) error { tx := self.db.Begin() for _, rl := range rls { // Remove previous - if err := tx.Where(&TpResourceMdl{Tpid: rl.TPid, ID: rl.ID}).Delete(TpResourceMdl{}).Error; err != nil { + if err := tx.Where(&ResourceMdl{Tpid: rl.TPid, ID: rl.ID}).Delete(ResourceMdl{}).Error; err != nil { tx.Rollback() return err } @@ -558,7 +558,7 @@ func (self *SQLStorage) SetTPStats(sts []*utils.TPStatProfile) error { tx := self.db.Begin() for _, stq := range sts { // Remove previous - if err := tx.Where(&TpStatMdl{Tpid: stq.TPid, ID: stq.ID}).Delete(TpStatMdl{}).Error; err != nil { + if err := tx.Where(&StatMdl{Tpid: stq.TPid, ID: stq.ID}).Delete(StatMdl{}).Error; err != nil { tx.Rollback() return err } @@ -580,7 +580,7 @@ func (self *SQLStorage) SetTPThresholds(ths []*utils.TPThresholdProfile) error { tx := self.db.Begin() for _, th := range ths { // Remove previous - if err := tx.Where(&TpThresholdMdl{Tpid: th.TPid, ID: th.ID}).Delete(TpThresholdMdl{}).Error; err != nil { + if err := tx.Where(&ThresholdMdl{Tpid: th.TPid, ID: th.ID}).Delete(ThresholdMdl{}).Error; err != nil { tx.Rollback() return err } @@ -602,7 +602,7 @@ func (self *SQLStorage) SetTPFilters(ths []*utils.TPFilterProfile) error { tx := self.db.Begin() for _, th := range ths { // Remove previous - if err := tx.Where(&TpFilterMdl{Tpid: th.TPid, ID: th.ID}).Delete(TpFilterMdl{}).Error; err != nil { + if err := tx.Where(&FilterMdl{Tpid: th.TPid, ID: th.ID}).Delete(FilterMdl{}).Error; err != nil { tx.Rollback() return err } @@ -624,7 +624,7 @@ func (self *SQLStorage) SetTPRoutes(tpRoutes []*utils.TPRouteProfile) error { tx := self.db.Begin() for _, tpRoute := range tpRoutes { // Remove previous - if err := tx.Where(&TpRouteMdl{Tpid: tpRoute.TPid, ID: tpRoute.ID}).Delete(TpRouteMdl{}).Error; err != nil { + if err := tx.Where(&RouteMdl{Tpid: tpRoute.TPid, ID: tpRoute.ID}).Delete(RouteMdl{}).Error; err != nil { tx.Rollback() return err } @@ -1211,7 +1211,7 @@ func (self *SQLStorage) GetCDRs(qryFltr *utils.CDRsFilter, remove bool) ([]*CDR, } func (self *SQLStorage) GetTPDestinations(tpid, id string) (uTPDsts []*utils.TPDestination, err error) { - var tpDests TpDestinations + var tpDests DestinationMdls q := self.db.Where("tpid = ?", tpid) if len(id) != 0 { q = q.Where("tag = ?", id) @@ -1226,7 +1226,7 @@ func (self *SQLStorage) GetTPDestinations(tpid, id string) (uTPDsts []*utils.TPD } func (self *SQLStorage) GetTPRates(tpid, id string) ([]*utils.TPRateRALs, error) { - var tpRates TpRates + var tpRates RateMdls q := self.db.Where("tpid = ?", tpid).Order("id") if len(id) != 0 { q = q.Where("tag = ?", id) @@ -1245,7 +1245,7 @@ func (self *SQLStorage) GetTPRates(tpid, id string) ([]*utils.TPRateRALs, error) } func (self *SQLStorage) GetTPDestinationRates(tpid, id string, pagination *utils.Paginator) ([]*utils.TPDestinationRate, error) { - var tpDestinationRates TpDestinationRates + var tpDestinationRates DestinationRateMdls q := self.db.Where("tpid = ?", tpid) if len(id) != 0 { q = q.Where("tag = ?", id) @@ -1272,7 +1272,7 @@ func (self *SQLStorage) GetTPDestinationRates(tpid, id string, pagination *utils } func (self *SQLStorage) GetTPTimings(tpid, id string) ([]*utils.ApierTPTiming, error) { - var tpTimings TpTimings + var tpTimings TimingMdls q := self.db.Where("tpid = ?", tpid) if len(id) != 0 { q = q.Where("tag = ?", id) @@ -1288,7 +1288,7 @@ func (self *SQLStorage) GetTPTimings(tpid, id string) ([]*utils.ApierTPTiming, e } func (self *SQLStorage) GetTPRatingPlans(tpid, id string, pagination *utils.Paginator) ([]*utils.TPRatingPlan, error) { - var tpRatingPlans TpRatingPlans + var tpRatingPlans RatingPlanMdls q := self.db.Where("tpid = ?", tpid) if len(id) != 0 { q = q.Where("tag = ?", id) @@ -1315,7 +1315,7 @@ func (self *SQLStorage) GetTPRatingPlans(tpid, id string, pagination *utils.Pagi } func (self *SQLStorage) GetTPRatingProfiles(filter *utils.TPRatingProfile) ([]*utils.TPRatingProfile, error) { - var tpRpfs TpRatingProfiles + var tpRpfs RatingProfileMdls q := self.db.Where("tpid = ?", filter.TPid) if len(filter.LoadId) != 0 { q = q.Where("loadid = ?", filter.LoadId) @@ -1343,7 +1343,7 @@ func (self *SQLStorage) GetTPRatingProfiles(filter *utils.TPRatingProfile) ([]*u } func (self *SQLStorage) GetTPSharedGroups(tpid, id string) ([]*utils.TPSharedGroups, error) { - var tpShareGroups TpSharedGroups + var tpShareGroups SharedGroupMdls q := self.db.Where("tpid = ?", tpid) if len(id) != 0 { q = q.Where("tag = ?", id) @@ -1362,7 +1362,7 @@ func (self *SQLStorage) GetTPSharedGroups(tpid, id string) ([]*utils.TPSharedGro } func (self *SQLStorage) GetTPActions(tpid, id string) ([]*utils.TPActions, error) { - var tpActions TpActions + var tpActions ActionMdls q := self.db.Where("tpid = ?", tpid) if len(id) != 0 { q = q.Where("tag = ?", id) @@ -1381,7 +1381,7 @@ func (self *SQLStorage) GetTPActions(tpid, id string) ([]*utils.TPActions, error } func (self *SQLStorage) GetTPActionTriggers(tpid, id string) ([]*utils.TPActionTriggers, error) { - var tpActionTriggers TpActionTriggers + var tpActionTriggers ActionTriggerMdls q := self.db.Where("tpid = ?", tpid) if len(id) != 0 { q = q.Where("tag = ?", id) @@ -1400,7 +1400,7 @@ func (self *SQLStorage) GetTPActionTriggers(tpid, id string) ([]*utils.TPActionT } func (self *SQLStorage) GetTPActionPlans(tpid, id string) ([]*utils.TPActionPlan, error) { - var tpActionPlans TpActionPlans + var tpActionPlans ActionPlanMdls q := self.db.Where("tpid = ?", tpid) if len(id) != 0 { q = q.Where("tag = ?", id) @@ -1419,7 +1419,7 @@ func (self *SQLStorage) GetTPActionPlans(tpid, id string) ([]*utils.TPActionPlan } func (self *SQLStorage) GetTPAccountActions(filter *utils.TPAccountActions) ([]*utils.TPAccountActions, error) { - var tpAccActs TpAccountActions + var tpAccActs AccountActionMdls q := self.db.Where("tpid = ?", filter.TPid) if len(filter.LoadId) != 0 { q = q.Where("loadid = ?", filter.LoadId) @@ -1444,7 +1444,7 @@ func (self *SQLStorage) GetTPAccountActions(filter *utils.TPAccountActions) ([]* } func (self *SQLStorage) GetTPResources(tpid, tenant, id string) ([]*utils.TPResourceProfile, error) { - var rls TpResources + var rls ResourceMdls q := self.db.Where("tpid = ?", tpid) if len(id) != 0 { q = q.Where("id = ?", id) @@ -1463,7 +1463,7 @@ func (self *SQLStorage) GetTPResources(tpid, tenant, id string) ([]*utils.TPReso } func (self *SQLStorage) GetTPStats(tpid, tenant, id string) ([]*utils.TPStatProfile, error) { - var sts TpStats + var sts StatMdls q := self.db.Where("tpid = ?", tpid) if len(id) != 0 { q = q.Where("id = ?", id) @@ -1482,7 +1482,7 @@ func (self *SQLStorage) GetTPStats(tpid, tenant, id string) ([]*utils.TPStatProf } func (self *SQLStorage) GetTPThresholds(tpid, tenant, id string) ([]*utils.TPThresholdProfile, error) { - var ths TpThresholds + var ths ThresholdMdls q := self.db.Where("tpid = ?", tpid) if len(id) != 0 { q = q.Where("id = ?", id) @@ -1501,7 +1501,7 @@ func (self *SQLStorage) GetTPThresholds(tpid, tenant, id string) ([]*utils.TPThr } func (self *SQLStorage) GetTPFilters(tpid, tenant, id string) ([]*utils.TPFilterProfile, error) { - var ths TpFilterS + var ths FilterMdls q := self.db.Where("tpid = ?", tpid) if len(id) != 0 { q = q.Where("id = ?", id) @@ -1520,7 +1520,7 @@ func (self *SQLStorage) GetTPFilters(tpid, tenant, id string) ([]*utils.TPFilter } func (self *SQLStorage) GetTPRoutes(tpid, tenant, id string) ([]*utils.TPRouteProfile, error) { - var tpRoutes TPRoutes + var tpRoutes RouteMdls q := self.db.Where("tpid = ?", tpid) if len(id) != 0 { q = q.Where("id = ?", id) diff --git a/loaders/loader.go b/loaders/loader.go index 981c5dc02..82db30d44 100644 --- a/loaders/loader.go +++ b/loaders/loader.go @@ -312,9 +312,9 @@ func (ldr *Loader) storeLoadedData(loaderType string, case utils.MetaResources: cacheIDs = []string{utils.CacheResourceFilterIndexes} for _, lDataSet := range lds { - resModels := make(engine.TpResources, len(lDataSet)) + resModels := make(engine.ResourceMdls, len(lDataSet)) for i, ld := range lDataSet { - resModels[i] = new(engine.TpResourceMdl) + resModels[i] = new(engine.ResourceMdl) if err = utils.UpdateStructWithIfaceMap(resModels[i], ld); err != nil { return } @@ -351,9 +351,9 @@ func (ldr *Loader) storeLoadedData(loaderType string, } case utils.MetaFilters: for _, lDataSet := range lds { - fltrModels := make(engine.TpFilterS, len(lDataSet)) + fltrModels := make(engine.FilterMdls, len(lDataSet)) for i, ld := range lDataSet { - fltrModels[i] = new(engine.TpFilterMdl) + fltrModels[i] = new(engine.FilterMdl) if err = utils.UpdateStructWithIfaceMap(fltrModels[i], ld); err != nil { return } @@ -381,9 +381,9 @@ func (ldr *Loader) storeLoadedData(loaderType string, case utils.MetaStats: cacheIDs = []string{utils.CacheStatFilterIndexes} for _, lDataSet := range lds { - stsModels := make(engine.TpStats, len(lDataSet)) + stsModels := make(engine.StatMdls, len(lDataSet)) for i, ld := range lDataSet { - stsModels[i] = new(engine.TpStatMdl) + stsModels[i] = new(engine.StatMdl) if err = utils.UpdateStructWithIfaceMap(stsModels[i], ld); err != nil { return } @@ -427,9 +427,9 @@ func (ldr *Loader) storeLoadedData(loaderType string, case utils.MetaThresholds: cacheIDs = []string{utils.CacheThresholdFilterIndexes} for _, lDataSet := range lds { - thModels := make(engine.TpThresholds, len(lDataSet)) + thModels := make(engine.ThresholdMdls, len(lDataSet)) for i, ld := range lDataSet { - thModels[i] = new(engine.TpThresholdMdl) + thModels[i] = new(engine.ThresholdMdl) if err = utils.UpdateStructWithIfaceMap(thModels[i], ld); err != nil { return } @@ -460,9 +460,9 @@ func (ldr *Loader) storeLoadedData(loaderType string, case utils.MetaRoutes: cacheIDs = []string{utils.CacheRouteFilterIndexes} for _, lDataSet := range lds { - sppModels := make(engine.TPRoutes, len(lDataSet)) + sppModels := make(engine.RouteMdls, len(lDataSet)) for i, ld := range lDataSet { - sppModels[i] = new(engine.TpRouteMdl) + sppModels[i] = new(engine.RouteMdl) if err = utils.UpdateStructWithIfaceMap(sppModels[i], ld); err != nil { return }