From 4a9da1cb1aa3600e35b42164ea6a53ab75b23bbd Mon Sep 17 00:00:00 2001 From: Trial97 Date: Thu, 14 Feb 2019 17:19:35 +0200 Subject: [PATCH] Handle missing RatingPlanIDs for SuplierS HighestCost and LeastCost sorting . fixes #1389 --- engine/spls_highestcost.go | 8 ++++++++ engine/spls_leastcost.go | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/engine/spls_highestcost.go b/engine/spls_highestcost.go index 82afdd49e..a59c431e6 100755 --- a/engine/spls_highestcost.go +++ b/engine/spls_highestcost.go @@ -19,6 +19,8 @@ along with this program. If not, see package engine import ( + "fmt" + "github.com/cgrates/cgrates/utils" ) @@ -39,6 +41,12 @@ func (hcs *HightCostSorter) SortSuppliers(prflID string, suppls []*Supplier, Sorting: hcs.sorting, SortedSuppliers: make([]*SortedSupplier, 0)} for _, s := range suppls { + if len(s.RatingPlanIDs) == 0 { + utils.Logger.Warning( + fmt.Sprintf("<%s> RatingPlanIDs is empty for suplier with ID: %s", + utils.SupplierS, s.ID)) + return nil, utils.NewErrMandatoryIeMissing("RatingPlanIDs") + } if srtSpl, pass, err := hcs.spS.populateSortingData(ev, s, extraOpts); err != nil { return nil, err } else if pass && srtSpl != nil { diff --git a/engine/spls_leastcost.go b/engine/spls_leastcost.go index 5d5d386cc..740ab66f4 100644 --- a/engine/spls_leastcost.go +++ b/engine/spls_leastcost.go @@ -19,6 +19,8 @@ along with this program. If not, see package engine import ( + "fmt" + "github.com/cgrates/cgrates/utils" ) @@ -39,6 +41,12 @@ func (lcs *LeastCostSorter) SortSuppliers(prflID string, suppls []*Supplier, Sorting: lcs.sorting, SortedSuppliers: make([]*SortedSupplier, 0)} for _, s := range suppls { + if len(s.RatingPlanIDs) == 0 { + utils.Logger.Warning( + fmt.Sprintf("<%s> RatingPlanIDs is empty for suplier with ID: %s", + utils.SupplierS, s.ID)) + return nil, utils.NewErrMandatoryIeMissing("RatingPlanIDs") + } if srtSpl, pass, err := lcs.spS.populateSortingData(ev, s, extraOpts); err != nil { return nil, err } else if pass && srtSpl != nil {