cleaned exists functions

This commit is contained in:
Radu Ioan Fericean
2013-11-13 00:35:29 +02:00
parent c6752be776
commit 20ad7a8487
6 changed files with 14 additions and 33 deletions

View File

@@ -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,

View File

@@ -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 {

View File

@@ -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)

View File

@@ -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)

View File

@@ -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 {

View File

@@ -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,