Updated GetChargerProfileIDs

This commit is contained in:
Tripon Alexandru-Ionut
2019-04-17 16:18:53 +03:00
committed by Dan Christian Bogos
parent fbc1fad902
commit 35d675b840
8 changed files with 92 additions and 10 deletions

View File

@@ -39,8 +39,11 @@ func (apierV1 *ApierV1) GetChargerProfile(arg utils.TenantID, reply *engine.Char
}
// GetChargerProfileIDs returns list of chargerProfile IDs registered for a tenant
func (apierV1 *ApierV1) GetChargerProfileIDs(tenant string, chPrfIDs *[]string) error {
prfx := utils.ChargerProfilePrefix + tenant + ":"
func (apierV1 *ApierV1) GetChargerProfileIDs(args utils.TenantArgWithPaginator, chPrfIDs *[]string) error {
if missing := utils.MissingStructFields(&args, []string{utils.Tenant}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
prfx := utils.ChargerProfilePrefix + args.Tenant + ":"
keys, err := apierV1.DataManager.DataDB().GetKeysForPrefix(prfx)
if err != nil {
return err
@@ -52,7 +55,7 @@ func (apierV1 *ApierV1) GetChargerProfileIDs(tenant string, chPrfIDs *[]string)
for i, key := range keys {
retIDs[i] = key[len(prfx):]
}
*chPrfIDs = retIDs
*chPrfIDs = args.PaginateStringSlice(retIDs)
return nil
}

View File

@@ -267,11 +267,19 @@ func testChargerSSetChargerProfile(t *testing.T) {
func testChargerSGetChargerProfileIDs(t *testing.T) {
expected := []string{"Charger1", "ApierTest"}
var result []string
if err := chargerRPC.Call("ApierV1.GetChargerProfileIDs", "cgrates.org", &result); err != nil {
if err := chargerRPC.Call(utils.ApierV1GetChargerProfileIDs, utils.TenantArgWithPaginator{TenantArg: utils.TenantArg{Tenant: "cgrates.org"}}, &result); err != nil {
t.Error(err)
} else if len(expected) != len(result) {
t.Errorf("Expecting : %+v, received: %+v", expected, result)
}
if err := chargerRPC.Call(utils.ApierV1GetChargerProfileIDs, utils.TenantArgWithPaginator{
TenantArg: utils.TenantArg{Tenant: "cgrates.org"},
Paginator: utils.Paginator{Limit: utils.IntPointer(1)},
}, &result); err != nil {
t.Error(err)
} else if 1 != len(result) {
t.Errorf("Expecting : %+v, received: %+v", expected, result)
}
}
func testChargerSUpdateChargerProfile(t *testing.T) {

View File

@@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package console
import (
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
@@ -61,6 +60,6 @@ func (self *CmdGetAttributeIDs) PostprocessRpcParams() error {
}
func (self *CmdGetAttributeIDs) RpcResult() interface{} {
atr := engine.AttributeProfile{}
atr := []string{}
return &atr
}

65
console/charger_ids.go Normal file
View File

@@ -0,0 +1,65 @@
/*
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 <http://www.gnu.org/licenses/>
*/
package console
import (
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdGetChargerIDs{
name: "chargers_ids",
rpcMethod: utils.ApierV1GetChargerProfileIDs,
rpcParams: &utils.TenantArgWithPaginator{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdGetChargerIDs struct {
name string
rpcMethod string
rpcParams *utils.TenantArgWithPaginator
*CommandExecuter
}
func (self *CmdGetChargerIDs) Name() string {
return self.name
}
func (self *CmdGetChargerIDs) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdGetChargerIDs) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &utils.TenantArgWithPaginator{}
}
return self.rpcParams
}
func (self *CmdGetChargerIDs) PostprocessRpcParams() error {
return nil
}
func (self *CmdGetChargerIDs) RpcResult() interface{} {
atr := []string{}
return &atr
}

View File

@@ -26,7 +26,7 @@ import (
func init() {
c := &CmdGetChargers{
name: "chargers",
rpcMethod: "ApierV1.GetChargerProfile",
rpcMethod: utils.ApierV1GetChargerProfile,
rpcParams: &utils.TenantID{},
}
commands[c.Name()] = c

View File

@@ -23,7 +23,7 @@ import "github.com/cgrates/cgrates/utils"
func init() {
c := &CmdRemoveChargers{
name: "chargers_remove",
rpcMethod: "ApierV1.RemoveChargerProfile",
rpcMethod: utils.ApierV1RemoveChargerProfile,
rpcParams: &utils.TenantID{},
}
commands[c.Name()] = c

View File

@@ -18,12 +18,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package console
import "github.com/cgrates/cgrates/apier/v1"
import (
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdSetChargers{
name: "chargers_set",
rpcMethod: "ApierV1.SetChargerProfile",
rpcMethod: utils.ApierV1SetChargerProfile,
rpcParams: &v1.ChargerWithCache{},
}
commands[c.Name()] = c

View File

@@ -767,6 +767,10 @@ const (
ChargerSv1Ping = "ChargerSv1.Ping"
ChargerSv1GetChargersForEvent = "ChargerSv1.GetChargersForEvent"
ChargerSv1ProcessEvent = "ChargerSv1.ProcessEvent"
ApierV1GetChargerProfile = "ApierV1.GetChargerProfile"
ApierV1RemoveChargerProfile = "ApierV1.RemoveChargerProfile"
ApierV1SetChargerProfile = "ApierV1.SetChargerProfile"
ApierV1GetChargerProfileIDs = "ApierV1.GetChargerProfileIDs"
)
// ThresholdS APIs