Replacing DESTINATION and RATING_PLAN consts with their prefix versions for compressing code

This commit is contained in:
DanB
2013-11-14 13:03:15 +01:00
parent 408047dd1c
commit 26bb99bd64
5 changed files with 10 additions and 13 deletions

View File

@@ -280,7 +280,7 @@ func (csvr *CSVReader) LoadDestinationRates() (err error) {
}
}
if !destinationExists {
if dbExists, err := csvr.storage.ExistsData(DESTINATION, record[1]); err != nil {
if dbExists, err := csvr.storage.ExistsData(DESTINATION_PREFIX, record[1]); err != nil {
return err
} else if !dbExists {
return fmt.Errorf("Could not get destination for tag %v", record[1])
@@ -363,7 +363,7 @@ func (csvr *CSVReader) LoadRatingProfiles() (err error) {
}
_, exists := csvr.ratingPlans[record[5]]
if !exists {
if dbExists, err := csvr.storage.ExistsData(RATING_PLAN, record[5]); err != nil {
if dbExists, err := csvr.storage.ExistsData(RATING_PLAN_PREFIX, record[5]); err != nil {
return err
} else if !dbExists {
return errors.New(fmt.Sprintf("Could not load rating plans for tag: %v", record[5]))

View File

@@ -167,7 +167,7 @@ func (dbr *DbReader) LoadDestinationRates() (err error) {
}
}
if !destinationExists {
if dbExists, err := dbr.dataDb.ExistsData(DESTINATION, dr.DestinationId); err != nil {
if dbExists, err := dbr.dataDb.ExistsData(DESTINATION_PREFIX, dr.DestinationId); err != nil {
return err
} else if !dbExists {
return errors.New(fmt.Sprintf("Could not get destination for tag %v", dr.DestinationId))
@@ -219,7 +219,7 @@ func (dbr *DbReader) LoadRatingProfiles() error {
}
_, exists := dbr.ratingPlans[rp.RatingPlanId]
if !exists {
if dbExists, err := dbr.dataDb.ExistsData(RATING_PLAN, rp.RatingPlanId); err != nil {
if dbExists, err := dbr.dataDb.ExistsData(RATING_PLAN_PREFIX, rp.RatingPlanId); err != nil {
return err
} else if !dbExists {
return errors.New(fmt.Sprintf("Could not load rating plans for tag: %v", rp.RatingPlanId))
@@ -268,7 +268,7 @@ func (dbr *DbReader) LoadRatingPlanByTag(tag string) error {
if err != nil {
return err
} else if len(dms) == 0 {
if dbExists, err := dbr.dataDb.ExistsData(DESTINATION, drate.DestinationId); err != nil {
if dbExists, err := dbr.dataDb.ExistsData(DESTINATION_PREFIX, drate.DestinationId); err != nil {
return err
} else if !dbExists {
return fmt.Errorf("Could not get destination for tag %v", drate.DestinationId)
@@ -301,7 +301,7 @@ func (dbr *DbReader) LoadRatingProfileByTag(tag string) error {
// Check if referenced RatingPlan exists
_, exists := dbr.ratingPlans[rp.RatingPlanId]
if !exists {
if dbExists, err := dbr.dataDb.ExistsData(RATING_PLAN, rp.RatingPlanId); err != nil {
if dbExists, err := dbr.dataDb.ExistsData(RATING_PLAN_PREFIX, rp.RatingPlanId); err != nil {
return err
} else if !dbExists {
return errors.New(fmt.Sprintf("Could not load rating plans for tag: %v", rp.RatingPlanId))

View File

@@ -50,9 +50,6 @@ const (
MEDIATOR_SOURCE = "MED"
SCHED_SOURCE = "SCH"
RATER_SOURCE = "RAT"
DESTINATION = "destination"
RATING_PLAN = "rating_plan"
)
type Storage interface {

View File

@@ -63,10 +63,10 @@ func (ms *MapStorage) PreCache(dKeys, rppKeys []string) error {
// Used to check if specific subject is stored using prefix key attached to entity
func (ms *MapStorage) ExistsData(categ, subject string) (bool, error) {
switch categ {
case DESTINATION:
case DESTINATION_PREFIX:
_, exists := ms.dict[DESTINATION_PREFIX+subject]
return exists, nil
case RATING_PLAN:
case RATING_PLAN_PREFIX:
_, exists := ms.dict[RATING_PLAN_PREFIX+subject]
return exists, nil
}

View File

@@ -108,9 +108,9 @@ func (rs *RedisStorage) PreCache(dKeys, rpKeys []string) (err error) {
// Used to check if specific subject is stored using prefix key attached to entity
func (rs *RedisStorage) ExistsData(entity, subject string) (bool, error) {
switch entity {
case DESTINATION:
case DESTINATION_PREFIX:
return rs.db.Exists(DESTINATION_PREFIX+subject)
case RATING_PLAN:
case RATING_PLAN_PREFIX:
return rs.db.Exists(RATING_PLAN_PREFIX+subject)
}
return false, errors.New("Unsupported entity in ExistsData")