mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Changing GetRatingProfileByTag into GetRatingProfileFiltered; local tests for ApierV1.SetRatingPlan and ApierV1.SetRatingProfile
This commit is contained in:
@@ -164,19 +164,14 @@ func (self *ApierV1) SetRatingPlan(attrs AttrSetRatingPlan, reply *string) error
|
||||
return nil
|
||||
}
|
||||
|
||||
type AttrSetRatingProfile struct {
|
||||
TPid string
|
||||
RatingProfileId string
|
||||
}
|
||||
|
||||
// Process dependencies and load a specific rating profile from storDb into dataDb.
|
||||
func (self *ApierV1) SetRatingProfile(attrs AttrSetRatingProfile, reply *string) error {
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "RatingProfileId"}); len(missing) != 0 {
|
||||
func (self *ApierV1) SetRatingProfile(attrs utils.TPRatingProfile, reply *string) error {
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "LoadId", "Tenant", "TOR", "Direction", "Subject"}); len(missing) != 0 {
|
||||
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
|
||||
}
|
||||
dbReader := engine.NewDbReader(self.StorDb, self.DataDb, attrs.TPid)
|
||||
|
||||
if err := dbReader.LoadRatingProfileByTag(attrs.RatingProfileId); err != nil {
|
||||
if err := dbReader.LoadRatingProfileFiltered(&attrs); err != nil {
|
||||
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
|
||||
}
|
||||
|
||||
|
||||
@@ -454,4 +454,32 @@ func TestApierTPRatingProfile(t *testing.T) {
|
||||
t.Errorf("Calling ApierV1.GetTPRatingProfileLoadIds expected: %v, received: %v", expectedRpIds, rplyRpIds)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Test here SetRatingPlan
|
||||
func TestApierSetRatingPlan(t *testing.T) {
|
||||
if !*testLocal {
|
||||
return
|
||||
}
|
||||
reply := ""
|
||||
//SetRatingPlan(attrs AttrSetRatingPlan
|
||||
if err := rater.Call("ApierV1.SetRatingPlan", AttrSetRatingPlan{TPid:engine.TEST_SQL,RatingPlanId:"RETAIL1"}, &reply); err!=nil {
|
||||
t.Error("Got error on second ApierV1.SetRatingPlan: ", err.Error())
|
||||
} else if reply != "OK" {
|
||||
t.Error("Calling ApierV1.SetRatingPlan got reply: ", reply)
|
||||
}
|
||||
}
|
||||
|
||||
// Test here SetRatingProfile
|
||||
func TestApierSetRatingProfile(t *testing.T) {
|
||||
if !*testLocal {
|
||||
return
|
||||
}
|
||||
reply := ""
|
||||
rpf := &utils.TPRatingProfile{TPid:engine.TEST_SQL, LoadId:engine.TEST_SQL, Tenant:"cgrates.org", TOR:"call", Direction:"*out", Subject:"*any"}
|
||||
if err := rater.Call("ApierV1.SetRatingProfile", rpf, &reply); err!=nil {
|
||||
t.Error("Got error on second ApierV1.SetRatingProfile: ", err.Error())
|
||||
} else if reply != "OK" {
|
||||
t.Error("Calling ApierV1.SetRatingProfile got reply: ", reply)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ package console
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/cgrates/cgrates/apier/v1"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -30,19 +30,19 @@ func init() {
|
||||
// Commander implementation
|
||||
type CmdSetrRatingProfile struct {
|
||||
rpcMethod string
|
||||
rpcParams *apier.AttrSetRatingProfile
|
||||
rpcParams *utils.TPRatingProfile
|
||||
rpcResult string
|
||||
}
|
||||
|
||||
// name should be exec's name
|
||||
func (self *CmdSetrRatingProfile) Usage(name string) string {
|
||||
return fmt.Sprintf("\n\tUsage: cgr-console [cfg_opts...{-h}] set_ratingprofile <tpid> <rateprofileid>")
|
||||
return fmt.Sprintf("\n\tUsage: cgr-console [cfg_opts...{-h}] set_ratingprofile <tpid> <loadid> <tenant> <tor> <subject>")
|
||||
}
|
||||
|
||||
// set param defaults
|
||||
func (self *CmdSetrRatingProfile) defaults() error {
|
||||
self.rpcMethod = "ApierV1.SetRatingProfile"
|
||||
self.rpcParams = &apier.AttrSetRatingProfile{}
|
||||
self.rpcParams = &utils.TPRatingProfile{Direction:"*out"}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -54,7 +54,10 @@ func (self *CmdSetrRatingProfile) FromArgs(args []string) error {
|
||||
// Args look OK, set defaults before going further
|
||||
self.defaults()
|
||||
self.rpcParams.TPid = args[2]
|
||||
self.rpcParams.RatingProfileId = args[3]
|
||||
self.rpcParams.LoadId = args[3]
|
||||
self.rpcParams.Tenant = args[4]
|
||||
self.rpcParams.TOR = args[5]
|
||||
self.rpcParams.Direction = args[6]
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -243,7 +243,7 @@ func (dbr *DbReader) LoadRatingProfiles() error {
|
||||
func (dbr *DbReader) LoadRatingPlanByTag(tag string) error {
|
||||
mpRpls, err := dbr.storDb.GetTpRatingPlans(dbr.tpid, tag)
|
||||
if err != nil || len(mpRpls) == 0 {
|
||||
return fmt.Errorf("No DestRateTimings profile with id %s: %v", tag, err)
|
||||
return fmt.Errorf("No RatingPlan profile with id %s: %v", tag, err)
|
||||
}
|
||||
for tag, rplBnds := range mpRpls {
|
||||
ratingPlan := &RatingPlan{Id: tag}
|
||||
@@ -294,15 +294,17 @@ func (dbr *DbReader) LoadRatingPlanByTag(tag string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dbr *DbReader) LoadRatingProfileByTag(tag string) error {
|
||||
resultRatingProfile := &RatingProfile{}
|
||||
mpTpRpfs, err := dbr.storDb.GetTpRatingProfiles(&utils.TPRatingProfile{TPid: dbr.tpid, LoadId: tag}) //map[string]*utils.TPRatingProfile
|
||||
func (dbr *DbReader) LoadRatingProfileFiltered(qriedRpf *utils.TPRatingProfile) error {
|
||||
var resultRatingProfile *RatingProfile
|
||||
mpTpRpfs, err := dbr.storDb.GetTpRatingProfiles(qriedRpf) //map[string]*utils.TPRatingProfile
|
||||
if err != nil || len(mpTpRpfs) == 0 {
|
||||
return fmt.Errorf("No RateProfile with id %s: %v", tag, err)
|
||||
return fmt.Errorf("No RateProfile for filter %v, error: %s", qriedRpf, err.Error())
|
||||
} else if len(mpTpRpfs) > 1 {
|
||||
return fmt.Errorf("More than one rating profile returned in LoadRatingProfileFiltered") // Should never reach here
|
||||
}
|
||||
for _, tpRpf := range mpTpRpfs {
|
||||
Logger.Debug(fmt.Sprintf("Rating profile: %v", tpRpf))
|
||||
resultRatingProfile.Id = tpRpf.KeyId()
|
||||
resultRatingProfile = &RatingProfile{Id: tpRpf.KeyId()}
|
||||
for _, tpRa := range tpRpf.RatingPlanActivations {
|
||||
at, err := utils.ParseDate(tpRa.ActivationTime)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user