From c831f5749a5d67a3ccd05733f8ea02f7e4a8bcf1 Mon Sep 17 00:00:00 2001 From: Tripon Alexandru-Ionut Date: Wed, 17 Apr 2019 17:53:04 +0300 Subject: [PATCH] Added GetRatingProfileIDs --- apier/v1/apier.go | 21 ++++++++++++ apier/v1/apier_it_test.go | 8 +++++ console/ratingprofile.go | 2 +- console/ratingprofile_rem.go | 2 +- console/ratingprofile_set.go | 2 +- console/rattingprofile_ids.go | 64 +++++++++++++++++++++++++++++++++++ utils/consts.go | 4 +++ 7 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 console/rattingprofile_ids.go diff --git a/apier/v1/apier.go b/apier/v1/apier.go index f474a284d..b7b6ed123 100644 --- a/apier/v1/apier.go +++ b/apier/v1/apier.go @@ -393,6 +393,27 @@ func (self *ApierV1) SetRatingProfile(attrs utils.AttrSetRatingProfile, reply *s return nil } +// GetRatingProfileIDs returns list of resourceProfile IDs registered for a tenant +func (apierV1 *ApierV1) GetRatingProfileIDs(args utils.TenantArgWithPaginator, rsPrfIDs *[]string) error { + if missing := utils.MissingStructFields(&args, []string{utils.Tenant}); len(missing) != 0 { //Params missing + return utils.NewErrMandatoryIeMissing(missing...) + } + prfx := utils.RATING_PROFILE_PREFIX + "*out:" + args.Tenant + ":" + keys, err := apierV1.DataManager.DataDB().GetKeysForPrefix(prfx) + if err != nil { + return err + } + if len(keys) == 0 { + return utils.ErrNotFound + } + retIDs := make([]string, len(keys)) + for i, key := range keys { + retIDs[i] = key[len(prfx):] + } + *rsPrfIDs = args.PaginateStringSlice(retIDs) + return nil +} + func (self *ApierV1) GetRatingProfile(attrs utils.AttrGetRatingProfile, reply *engine.RatingProfile) (err error) { if missing := utils.MissingStructFields(&attrs, []string{"Tenant", "Category", "Direction", "Subject"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) diff --git a/apier/v1/apier_it_test.go b/apier/v1/apier_it_test.go index ea8132ee9..2691b1e8c 100644 --- a/apier/v1/apier_it_test.go +++ b/apier/v1/apier_it_test.go @@ -819,6 +819,14 @@ func TestApierV1GetRatingProfile(t *testing.T) { if err := rater.Call("ApierV1.GetRatingProfile", attrGetRatingPlan, &rpl); err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expected error on ApierV1.GetRatingProfile, recived : %+v", err) } + + expectedIds := []string{"call:dan", "call:*any"} + var result []string + if err := rater.Call(utils.ApierV1GetRatingProfileIDs, utils.TenantArgWithPaginator{TenantArg: utils.TenantArg{Tenant: "cgrates.org"}}, &result); err != nil { + t.Error(err) + } else if len(expectedIds) != len(result) { + t.Errorf("Expecting : %+v, received: %+v", expected, result) + } } // Test here ReloadCache diff --git a/console/ratingprofile.go b/console/ratingprofile.go index 540be6b95..664cb241e 100755 --- a/console/ratingprofile.go +++ b/console/ratingprofile.go @@ -26,7 +26,7 @@ import ( func init() { c := &CmdGetRatingProfile{ name: "ratingprofile", - rpcMethod: "ApierV1.GetRatingProfile", + rpcMethod: utils.ApierV1GetRatingProfile, } commands[c.Name()] = c c.CommandExecuter = &CommandExecuter{c} diff --git a/console/ratingprofile_rem.go b/console/ratingprofile_rem.go index b4906ca75..b8348af7f 100644 --- a/console/ratingprofile_rem.go +++ b/console/ratingprofile_rem.go @@ -28,7 +28,7 @@ import ( func init() { c := &CmdRemRatingProfile{ name: "ratingprofile_rem", - rpcMethod: "ApierV1.RemoveRatingProfile", + rpcMethod: utils.ApierV1RemoveRatingProfile, } commands[c.Name()] = c c.CommandExecuter = &CommandExecuter{c} diff --git a/console/ratingprofile_set.go b/console/ratingprofile_set.go index f92defddc..ac59054d4 100644 --- a/console/ratingprofile_set.go +++ b/console/ratingprofile_set.go @@ -25,7 +25,7 @@ import ( func init() { c := &CmdSetRatingProfile{ name: "ratingprofile_set", - rpcMethod: "ApierV1.SetRatingProfile", + rpcMethod: utils.ApierV1SetRatingProfile, } commands[c.Name()] = c c.CommandExecuter = &CommandExecuter{c} diff --git a/console/rattingprofile_ids.go b/console/rattingprofile_ids.go new file mode 100644 index 000000000..7b38daa0e --- /dev/null +++ b/console/rattingprofile_ids.go @@ -0,0 +1,64 @@ +/* +Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments +Copyright (C) ITsysCOM GmbH + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see +*/ + +package console + +import ( + "github.com/cgrates/cgrates/utils" +) + +func init() { + c := &CmdGetRatingProfileIDs{ + name: "ratingprofil_ids", + rpcMethod: utils.ApierV1GetRatingProfileIDs, + } + commands[c.Name()] = c + c.CommandExecuter = &CommandExecuter{c} +} + +// Commander implementation +type CmdGetRatingProfileIDs struct { + name string + rpcMethod string + rpcParams *utils.TenantArgWithPaginator + *CommandExecuter +} + +func (self *CmdGetRatingProfileIDs) Name() string { + return self.name +} + +func (self *CmdGetRatingProfileIDs) RpcMethod() string { + return self.rpcMethod +} + +func (self *CmdGetRatingProfileIDs) RpcParams(reset bool) interface{} { + if reset || self.rpcParams == nil { + self.rpcParams = new(utils.TenantArgWithPaginator) + } + return self.rpcParams +} + +func (self *CmdGetRatingProfileIDs) PostprocessRpcParams() error { + return nil +} + +func (self *CmdGetRatingProfileIDs) RpcResult() interface{} { + var s []string + return &s +} diff --git a/utils/consts.go b/utils/consts.go index eef36ae09..4a7824397 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -728,6 +728,10 @@ const ( ApierV1RemoveFilter = "ApierV1.RemoveFilter" ApierV1SetFilter = "ApierV1.SetFilter" ApierV1GetFilterIDs = "ApierV1.GetFilterIDs" + ApierV1GetRatingProfile = "ApierV1.GetRatingProfile" + ApierV1RemoveRatingProfile = "ApierV1.RemoveRatingProfile" + ApierV1SetRatingProfile = "ApierV1.SetRatingProfile" + ApierV1GetRatingProfileIDs = "ApierV1.GetRatingProfileIDs" ) const (