From e75f05e0d3bd407c84a357f4de9a78d809e3d13b Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Tue, 2 Jun 2015 23:44:22 +0300 Subject: [PATCH] apier compilation fixes --- apier/v1/apier.go | 34 +++++++++++++++++----------------- apier/v1/tp.go | 2 +- engine/storage_sql.go | 1 - engine/tp_reader.go | 15 +++++++++++++-- 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/apier/v1/apier.go b/apier/v1/apier.go index 21699f4db..805e56426 100644 --- a/apier/v1/apier.go +++ b/apier/v1/apier.go @@ -189,8 +189,8 @@ func (self *ApierV1) LoadDestination(attrs AttrLoadDestination, reply *string) e if len(attrs.TPid) == 0 { return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "TPid") } - dbReader := engine.NewDbReader(self.StorDb, self.RatingDb, self.AccountDb, attrs.TPid) - if loaded, err := dbReader.LoadDestinationByTag(attrs.DestinationId); err != nil { + dbReader := engine.NewTpReader(self.RatingDb, self.AccountDb, self.StorDb, attrs.TPid) + if loaded, err := dbReader.LoadDestinationsFiltered(attrs.DestinationId); err != nil { return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error()) } else if !loaded { return errors.New(utils.ERR_NOT_FOUND) @@ -213,7 +213,7 @@ func (self *ApierV1) LoadDerivedChargers(attrs utils.TPDerivedChargers, reply *s if len(attrs.TPid) == 0 { return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "TPid") } - dbReader := engine.NewDbReader(self.StorDb, self.RatingDb, self.AccountDb, attrs.TPid) + dbReader := engine.NewTpReader(self.RatingDb, self.AccountDb, self.StorDb, attrs.TPid) if err := dbReader.LoadDerivedChargersFiltered(&attrs, true); err != nil { return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error()) } @@ -240,8 +240,8 @@ func (self *ApierV1) LoadRatingPlan(attrs AttrLoadRatingPlan, reply *string) err if len(attrs.TPid) == 0 { return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "TPid") } - dbReader := engine.NewDbReader(self.StorDb, self.RatingDb, self.AccountDb, attrs.TPid) - if loaded, err := dbReader.LoadRatingPlanByTag(attrs.RatingPlanId); err != nil { + dbReader := engine.NewTpReader(self.RatingDb, self.AccountDb, self.StorDb, attrs.TPid) + if loaded, err := dbReader.LoadRatingPlansFiltered(attrs.RatingPlanId); err != nil { return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error()) } else if !loaded { return errors.New(utils.ERR_NOT_FOUND) @@ -264,8 +264,8 @@ func (self *ApierV1) LoadRatingProfile(attrs utils.TPRatingProfile, reply *strin if len(attrs.TPid) == 0 { return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "TPid") } - dbReader := engine.NewDbReader(self.StorDb, self.RatingDb, self.AccountDb, attrs.TPid) - if err := dbReader.LoadRatingProfileFiltered(&attrs); err != nil { + dbReader := engine.NewTpReader(self.RatingDb, self.AccountDb, self.StorDb, attrs.TPid) + if err := dbReader.LoadRatingProfilesFiltered(&attrs); err != nil { return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error()) } //Automatic cache of the newly inserted rating profile @@ -291,8 +291,8 @@ func (self *ApierV1) LoadSharedGroup(attrs AttrLoadSharedGroup, reply *string) e if len(attrs.TPid) == 0 { return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "TPid") } - dbReader := engine.NewDbReader(self.StorDb, self.RatingDb, self.AccountDb, attrs.TPid) - if err := dbReader.LoadSharedGroupByTag(attrs.SharedGroupId, true); err != nil { + dbReader := engine.NewTpReader(self.RatingDb, self.AccountDb, self.StorDb, attrs.TPid) + if err := dbReader.LoadSharedGroupsFiltered(attrs.SharedGroupId, true); err != nil { return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error()) } //Automatic cache of the newly inserted rating plan @@ -318,8 +318,8 @@ func (self *ApierV1) LoadCdrStats(attrs AttrLoadCdrStats, reply *string) error { if len(attrs.TPid) == 0 { return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "TPid") } - dbReader := engine.NewDbReader(self.StorDb, self.RatingDb, self.AccountDb, attrs.TPid) - if err := dbReader.LoadCdrStatsByTag(attrs.CdrStatsId, true); err != nil { + dbReader := engine.NewTpReader(self.RatingDb, self.AccountDb, self.StorDb, attrs.TPid) + if err := dbReader.LoadCdrStatsFiltered(attrs.CdrStatsId, true); err != nil { return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error()) } *reply = OK @@ -338,12 +338,12 @@ func (self *ApierV1) LoadTariffPlanFromStorDb(attrs AttrLoadTpFromStorDb, reply if len(attrs.TPid) == 0 { return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "TPid") } - dbReader := engine.NewDbReader(self.StorDb, self.RatingDb, self.AccountDb, attrs.TPid) + dbReader := engine.NewTpReader(self.RatingDb, self.AccountDb, self.StorDb, attrs.TPid) if err := dbReader.LoadAll(); err != nil { return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error()) } if attrs.Validate { - if !dbReader.IsDataValid() { + if !dbReader.IsValid() { *reply = OK return errors.New("invalid data") } @@ -805,7 +805,7 @@ func (self *ApierV1) LoadAccountActions(attrs utils.TPAccountActions, reply *str if len(attrs.TPid) == 0 { return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "TPid") } - dbReader := engine.NewDbReader(self.StorDb, self.RatingDb, self.AccountDb, attrs.TPid) + dbReader := engine.NewTpReader(self.RatingDb, self.AccountDb, self.StorDb, attrs.TPid) if _, err := engine.AccLock.Guard(func() (interface{}, error) { if err := dbReader.LoadAccountActionsFiltered(&attrs); err != nil { return 0, err @@ -970,7 +970,7 @@ func (self *ApierV1) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder, } else if !fi.IsDir() { return errors.New(utils.ERR_INVALID_PATH) } - loader := engine.NewFileCSVReader(self.RatingDb, self.AccountDb, utils.CSV_SEP, + loader := engine.NewTpReader(self.RatingDb, self.AccountDb, engine.NewFileCSVStorage(utils.CSV_SEP, path.Join(attrs.FolderPath, utils.DESTINATIONS_CSV), path.Join(attrs.FolderPath, utils.TIMINGS_CSV), path.Join(attrs.FolderPath, utils.RATES_CSV), @@ -984,7 +984,7 @@ func (self *ApierV1) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder, path.Join(attrs.FolderPath, utils.ACTION_TRIGGERS_CSV), path.Join(attrs.FolderPath, utils.ACCOUNT_ACTIONS_CSV), path.Join(attrs.FolderPath, utils.DERIVED_CHARGERS_CSV), - path.Join(attrs.FolderPath, utils.CDR_STATS_CSV)) + path.Join(attrs.FolderPath, utils.CDR_STATS_CSV)), "") if err := loader.LoadAll(); err != nil { return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error()) } @@ -994,7 +994,7 @@ func (self *ApierV1) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder, } if attrs.Validate { - if !loader.IsDataValid() { + if !loader.IsValid() { *reply = OK return errors.New("invalid data") } diff --git a/apier/v1/tp.go b/apier/v1/tp.go index b53992c2e..c5bf47512 100644 --- a/apier/v1/tp.go +++ b/apier/v1/tp.go @@ -36,7 +36,7 @@ type AttrGetTPIds struct { // Queries tarrif plan identities gathered from all tables. func (self *ApierV1) GetTPIds(attrs AttrGetTPIds, reply *[]string) error { - if ids, err := self.StorDb.GetTPIds(); err != nil { + if ids, err := self.StorDb.GetTpIds(); err != nil { return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error()) } else if ids == nil { return errors.New(utils.ERR_NOT_FOUND) diff --git a/engine/storage_sql.go b/engine/storage_sql.go index 4e3c32a69..2eea1b622 100644 --- a/engine/storage_sql.go +++ b/engine/storage_sql.go @@ -1076,7 +1076,6 @@ func (self *SQLStorage) GetTpDestinations(tpid, tag string) ([]TpDestination, er } func (self *SQLStorage) GetTpRates(tpid, tag string) ([]TpRate, error) { - rts := make(map[string]*utils.TPRate) var tpRates []TpRate q := self.db.Where("tpid = ?", tpid).Order("id") if len(tag) != 0 { diff --git a/engine/tp_reader.go b/engine/tp_reader.go index d5cb16bf1..4e2365b9b 100644 --- a/engine/tp_reader.go +++ b/engine/tp_reader.go @@ -60,6 +60,17 @@ func NewTpReader(rs RatingStorage, as AccountingStorage, lr LoadReader, tpid str } } +func (tpr *TpReader) LoadDestinationsFiltered(tag string) (bool, error) { + tpDests, err := tpr.lr.GetTpDestinations(tpr.tpid, tag) + + dest := &Destination{Id: tag} + for _, tpDest := range tpDests { + dest.AddPrefix(tpDest.Prefix) + } + dataStorage.SetDestination(dest) + return len(tpDests) > 0, err +} + func (tpr *TpReader) LoadDestinations() (err error) { tps, err := tpr.lr.GetTpDestinations(tpr.tpid, "") if err != nil { @@ -121,7 +132,7 @@ func (tpr *TpReader) LoadDestinationRates() (err error) { } // Returns true, nil in case of load success, false, nil in case of RatingPlan not found ratingStorage -func (tpr *TpReader) LoadRatingPlanFiltered(tag string) (bool, error) { +func (tpr *TpReader) LoadRatingPlansFiltered(tag string) (bool, error) { mpRpls, err := tpr.lr.GetTpRatingPlans(tpr.tpid, tag, nil) if err != nil { return false, err @@ -229,7 +240,7 @@ func (tpr *TpReader) LoadRatingPlans() (err error) { return nil } -func (tpr *TpReader) LoadRatingProfileFiltered(qriedRpf *utils.TPRatingProfile) error { +func (tpr *TpReader) LoadRatingProfilesFiltered(qriedRpf *utils.TPRatingProfile) error { var resultRatingProfile *RatingProfile mpTpRpfs, err := tpr.lr.GetTpRatingProfiles(qriedRpf) if err != nil {