From 20ad7a848752a74f59c4dc9d906c56e1201e0888 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Wed, 13 Nov 2013 00:35:29 +0200 Subject: [PATCH] cleaned exists functions --- apier/v1/tpratingprofiles.go | 3 ++- engine/loader_db.go | 21 ++++++++++----------- engine/storage_interface.go | 2 -- engine/storage_map.go | 10 ---------- engine/storage_redis.go | 8 -------- engine/tpimporter_csv.go | 3 ++- 6 files changed, 14 insertions(+), 33 deletions(-) diff --git a/apier/v1/tpratingprofiles.go b/apier/v1/tpratingprofiles.go index 8f5e026f8..259488e90 100644 --- a/apier/v1/tpratingprofiles.go +++ b/apier/v1/tpratingprofiles.go @@ -39,7 +39,8 @@ func (self *ApierV1) SetTPRatingProfile(attrs utils.TPRatingProfile, reply *stri } rps := make([]*engine.RatingProfile, len(attrs.RatingActivations)) for idx, ra := range attrs.RatingActivations { - rps[idx] = &engine.RatingProfile{Tag: attrs.RatingProfileId, + rps[idx] = &engine.RatingProfile{ + Tag: attrs.RatingProfileId, Tenant: attrs.Tenant, TOR: attrs.TOR, Direction: attrs.Direction, diff --git a/engine/loader_db.go b/engine/loader_db.go index 4edf87ce2..ce1e5bb2f 100644 --- a/engine/loader_db.go +++ b/engine/loader_db.go @@ -167,9 +167,9 @@ func (dbr *DbReader) LoadDestinationRates() (err error) { } } if !destinationExists { - if dbExists, err := dbr.dataDb.ExistsDestination(dr.DestinationsTag); err != nil { + if dest, err := dbr.dataDb.GetDestination(dr.DestinationsTag); err != nil { return err - } else if !dbExists { + } else if dest == nil { return errors.New(fmt.Sprintf("Could not get destination for tag %v", dr.DestinationsTag)) } } @@ -218,9 +218,9 @@ func (dbr *DbReader) LoadRatingProfiles() error { } _, exists := dbr.ratingPlans[rp.DestRatesTimingTag] if !exists { - if dbExists, err := dbr.dataDb.ExistsRatingPlan(rp.DestRatesTimingTag); err != nil { + if rpl, err := dbr.dataDb.GetRatingPlan(rp.DestRatesTimingTag); err != nil { return err - } else if !dbExists { + } else if rpl == nil { return errors.New(fmt.Sprintf("Could not load rating plans for tag: %v", rp.DestRatesTimingTag)) } } @@ -237,7 +237,7 @@ func (dbr *DbReader) LoadRatingProfiles() error { func (dbr *DbReader) LoadRatingPlanByTag(tag string) error { ratingPlan := &RatingPlan{} - rps, err := dbr.storDb.GetTpDestinationRateTimings(dbr.tpid, tag) + rps, err := dbr.storDb.GetTpRatingPlans(dbr.tpid, tag) if err != nil || len(rps) == 0 { return fmt.Errorf("No DestRateTimings profile with id %s: %v", tag, err) } @@ -266,11 +266,11 @@ func (dbr *DbReader) LoadRatingPlanByTag(tag string) error { dms, err := dbr.storDb.GetTpDestinations(dbr.tpid, drate.DestinationsTag) if err != nil || len(dms) == 0 { - if dbExists, err := dbr.dataDb.ExistsDestination(drate.DestinationsTag); err != nil { - return err - } else if !dbExists { - return fmt.Errorf("Could not get destination for tag %v", drate.DestinationsTag) - } + if dest, err := dbr.dataDb.GetDestination(drate.DestinationsTag); err != nil { + return err + } else if dest == nil { + return fmt.Errorf("Could not get destination for tag %v", drate.DestinationsTag) + } } Logger.Debug(fmt.Sprintf("Tag: %s Destinations: %v", drate.DestinationsTag, dms)) for _, destination := range dms { @@ -283,7 +283,6 @@ func (dbr *DbReader) LoadRatingPlanByTag(tag string) error { } func (dbr *DbReader) LoadRatingProfileByTag(tag string) error { - ratingPlans := make(map[string]*RatingPlan) resultRatingProfile := &RatingProfile{} rpm, err := dbr.storDb.GetTpRatingProfiles(dbr.tpid, tag) if err != nil || len(rpm) == 0 { diff --git a/engine/storage_interface.go b/engine/storage_interface.go index c349cf6aa..c2260c773 100644 --- a/engine/storage_interface.go +++ b/engine/storage_interface.go @@ -65,13 +65,11 @@ type DataStorage interface { PreCache([]string, []string) error GetRatingPlan(string) (*RatingPlan, error) SetRatingPlan(*RatingPlan) error - ExistsRatingPlan(string) (bool, error) GetRatingProfile(string) (*RatingProfile, error) SetRatingProfile(*RatingProfile) error GetDestination(string) (*Destination, error) // DestinationContainsPrefix(string, string) (int, error) SetDestination(*Destination) error - ExistsDestination(string) (bool, error) GetActions(string) (Actions, error) SetActions(string, Actions) error GetUserBalance(string) (*UserBalance, error) diff --git a/engine/storage_map.go b/engine/storage_map.go index f78e9c2c8..891bab511 100644 --- a/engine/storage_map.go +++ b/engine/storage_map.go @@ -83,11 +83,6 @@ func (ms *MapStorage) SetRatingPlan(rp *RatingPlan) (err error) { return } -func (ms *MapStorage) ExistsRatingPlan(rpId string) (bool, error) { - _, exists := ms.dict[RATING_PLAN_PREFIX+rpId] - return exists, nil -} - func (ms *MapStorage) GetRatingProfile(key string) (rp *RatingProfile, err error) { if values, ok := ms.dict[RATING_PROFILE_PREFIX+key]; ok { rp = new(RatingProfile) @@ -142,11 +137,6 @@ func (ms *MapStorage) SetDestination(dest *Destination) (err error) { return } -func (ms *MapStorage) ExistsDestination(destId string) (bool, error) { - _, exists := ms.dict[DESTINATION_PREFIX+destId] - return exists, nil -} - func (ms *MapStorage) GetActions(key string) (as Actions, err error) { if values, ok := ms.dict[ACTION_PREFIX+key]; ok { err = ms.ms.Unmarshal(values, &as) diff --git a/engine/storage_redis.go b/engine/storage_redis.go index ede874395..d7dfdb897 100644 --- a/engine/storage_redis.go +++ b/engine/storage_redis.go @@ -141,10 +141,6 @@ func (rs *RedisStorage) SetRatingPlan(rp *RatingPlan) (err error) { return } -func (rs *RedisStorage) ExistsRatingPlan(rpId string) (bool, error) { - return rs.db.Exists(RATING_PLAN_PREFIX + rpId) -} - func (rs *RedisStorage) GetRatingProfile(key string) (rp *RatingProfile, err error) { var values string if values, err = rs.db.Get(RATING_PROFILE_PREFIX + key); err == nil { @@ -219,10 +215,6 @@ func (rs *RedisStorage) SetDestination(dest *Destination) (err error) { return } -func (rs *RedisStorage) ExistsDestination(destId string) (bool, error) { - return rs.db.Exists(DESTINATION_PREFIX+destId) -} - func (rs *RedisStorage) GetActions(key string) (as Actions, err error) { var values string if values, err = rs.db.Get(ACTION_PREFIX + key); err == nil { diff --git a/engine/tpimporter_csv.go b/engine/tpimporter_csv.go index 0ad7f7fbe..e1688e0ad 100644 --- a/engine/tpimporter_csv.go +++ b/engine/tpimporter_csv.go @@ -249,7 +249,8 @@ func (self *TPCSVImporter) importRatingProfiles(fn string) error { if self.ImportId != "" { rpTag += "_" + self.ImportId } - rp := &RatingProfile{Tag: rpTag, + rp := &RatingProfile{ + Tag: rpTag, Tenant: tenant, TOR: tor, Direction: direction,