From c732a18ae97b58b093872b62576bdbf254c8826c Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Wed, 10 Jun 2015 20:49:19 +0300 Subject: [PATCH] more checks for tags existance --- engine/history_test.go | 1 + engine/loader_csv_test.go | 6 ++++-- engine/tp_reader.go | 29 +++++++++++++++++++++++++++-- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/engine/history_test.go b/engine/history_test.go index b74f85fd6..2f01bc9f8 100644 --- a/engine/history_test.go +++ b/engine/history_test.go @@ -38,6 +38,7 @@ func TestHistoryDestinations(t *testing.T) { buf := scribe.GetBuffer(history.DESTINATIONS_FN) expected := `[{"Id":"ALL","Prefixes":["49","41","43"]}, {"Id":"DST_UK_Mobile_BIG5","Prefixes":["447956"]}, +{"Id":"EU_LANDLINE","Prefixes":["444"]}, {"Id":"GERMANY","Prefixes":["49"]}, {"Id":"GERMANY_O2","Prefixes":["41"]}, {"Id":"GERMANY_PREMIUM","Prefixes":["43"]}, diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index 8613df0d3..6da9a089a 100644 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -47,6 +47,7 @@ PSTN_72,+4972 PSTN_70,+4970 DST_UK_Mobile_BIG5,447956 URG,112 +EU_LANDLINE,444 ` timings = ` WORKDAYS_00,*any,*any,*any,1;2;3;4;5,00:00:00 @@ -136,6 +137,7 @@ RP_MX,MX_FREE,WORKDAYS_18,10 *out,cgrates.org,call,discounted_minutes,2013-01-06T00:00:00Z,RP_UK_Mobile_BIG5_PKG,, *out,cgrates.org,data,rif,2013-01-06T00:00:00Z,RP_DATA,, *out,cgrates.org,call,max,2013-03-23T00:00:00Z,RP_MX,, +*in,cgrates.org,LCR_STANDARD,max,2013-03-23T00:00:00Z,RP_MX,, ` sharedGroups = ` SG1,*any,*lowest, @@ -260,7 +262,7 @@ func init() { } func TestLoadDestinations(t *testing.T) { - if len(csvr.destinations) != 11 { + if len(csvr.destinations) != 12 { t.Error("Failed to load destinations: ", len(csvr.destinations)) } for _, d := range csvr.destinations { @@ -732,7 +734,7 @@ func TestLoadRatingPlans(t *testing.T) { } func TestLoadRatingProfiles(t *testing.T) { - if len(csvr.ratingProfiles) != 18 { + if len(csvr.ratingProfiles) != 19 { t.Error("Failed to load rating profiles: ", len(csvr.ratingProfiles), csvr.ratingProfiles) } rp := csvr.ratingProfiles["*out:test:0:trp"] diff --git a/engine/tp_reader.go b/engine/tp_reader.go index c1272e36a..e73f4bbe8 100644 --- a/engine/tp_reader.go +++ b/engine/tp_reader.go @@ -374,6 +374,28 @@ func (tpr *TpReader) LoadLCRs() (err error) { } for _, tpLcr := range tps { + // check the rating profiles + ratingProfileSearchKey := utils.ConcatenatedKey(tpLcr.Direction, tpLcr.Tenant, tpLcr.RpCategory) + found := false + for rpfKey := range tpr.ratingProfiles { + if strings.HasPrefix(rpfKey, ratingProfileSearchKey) { + found = true + break + } + } + if !found { + if keys, err := tpr.ratingStorage.GetKeysForPrefix(RATING_PROFILE_PREFIX + ratingProfileSearchKey); err != nil || len(keys) == 0 { + return fmt.Errorf("[LCR] could not find ratingProfiles with prefix %s", ratingProfileSearchKey) + } + } + // check destination tags + if tpLcr.DestinationTag != "" && tpLcr.DestinationTag != utils.ANY { + if _, found := tpr.destinations[tpLcr.DestinationTag]; !found { + if found, err := tpr.ratingStorage.HasData(DESTINATION_PREFIX, tpLcr.DestinationTag); err != nil || !found { + return fmt.Errorf("[LCR] could not find destination with tag %s", tpLcr.DestinationTag) + } + } + } tag := utils.LCRKey(tpLcr.Direction, tpLcr.Tenant, tpLcr.Category, tpLcr.Account, tpLcr.Subject) activationTime, _ := utils.ParseTimeDetectLayout(tpLcr.ActivationTime) @@ -485,11 +507,14 @@ func (tpr *TpReader) LoadActionPlans() (err error) { _, exists := tpr.actions[at.ActionsId] if !exists { - return fmt.Errorf("actionTiming: Could not load the action for tag: %v", at.ActionsId) + if dbExists, err := tpr.ratingStorage.HasData(ACTION_PREFIX, at.ActionsId); err != nil || !dbExists { + return fmt.Errorf("[ActionPlans] Could not load the action for tag: %v", + at.ActionsId) + } } t, exists := tpr.timings[at.TimingId] if !exists { - return fmt.Errorf("actionTiming: Could not load the timing for tag: %v", at.TimingId) + return fmt.Errorf("[ActionPlans] Could not load the timing for tag: %v", at.TimingId) } actTmg := &ActionPlan{ Uuid: utils.GenUUID(),