diff --git a/apier/v1/apier.go b/apier/v1/apier.go index ea96341d3..ba77a6d1c 100644 --- a/apier/v1/apier.go +++ b/apier/v1/apier.go @@ -444,6 +444,19 @@ func (self *ApierV1) SetRatingProfile(attrs utils.AttrSetRatingProfile, reply *s 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...) + } + if rpPrf, err := self.DataManager.GetRatingProfile(attrs.GetID(), + false, utils.NonTransactional); err != nil { + return utils.APIErrorHandler(err) + } else { + *reply = *rpPrf + } + return +} + // Deprecated attrs type V1AttrSetActions struct { ActionsId string // Actions id diff --git a/console/ratingprofile.go b/console/ratingprofile.go new file mode 100755 index 000000000..540be6b95 --- /dev/null +++ b/console/ratingprofile.go @@ -0,0 +1,66 @@ +/* +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/engine" + "github.com/cgrates/cgrates/utils" +) + +func init() { + c := &CmdGetRatingProfile{ + name: "ratingprofile", + rpcMethod: "ApierV1.GetRatingProfile", + } + commands[c.Name()] = c + c.CommandExecuter = &CommandExecuter{c} +} + +// Commander implementation +type CmdGetRatingProfile struct { + name string + rpcMethod string + rpcParams *utils.AttrGetRatingProfile + rpcResult string + *CommandExecuter +} + +func (self *CmdGetRatingProfile) Name() string { + return self.name +} + +func (self *CmdGetRatingProfile) RpcMethod() string { + return self.rpcMethod +} + +func (self *CmdGetRatingProfile) RpcParams(reset bool) interface{} { + if reset || self.rpcParams == nil { + self.rpcParams = new(utils.AttrGetRatingProfile) + } + return self.rpcParams +} + +func (self *CmdGetRatingProfile) PostprocessRpcParams() error { + return nil +} + +func (self *CmdGetRatingProfile) RpcResult() interface{} { + var s engine.RatingProfile + return &s +} diff --git a/utils/apitpdata.go b/utils/apitpdata.go index a70ff7078..3c4986d83 100755 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -263,6 +263,17 @@ type AttrSetRatingProfile struct { RatingPlanActivations []*TPRatingActivation // Activate rating plans at specific time } +type AttrGetRatingProfile struct { + Tenant string // Tenant's Id + Category string // TypeOfRecord + Direction string // Traffic direction, OUT is the only one supported for now + Subject string // Rating subject, usually the same as account +} + +func (self *AttrGetRatingProfile) GetID() string { + return ConcatenatedKey(self.Direction, self.Tenant, self.Category, self.Subject) +} + type TPRatingActivation struct { ActivationTime string // Time when this profile will become active, defined as unix epoch time RatingPlanId string // Id of RatingPlan profile diff --git a/utils/coreutils.go b/utils/coreutils.go index ca43fd293..e13b6c880 100644 --- a/utils/coreutils.go +++ b/utils/coreutils.go @@ -352,7 +352,6 @@ func ConcatenatedKey(keyVals ...string) string { func LCRKey(direction, tenant, category, account, subject string) string { return ConcatenatedKey(direction, tenant, category, account, subject) - } func RatingSubjectAliasKey(tenant, subject string) string {