Updated GetFilterIDs

This commit is contained in:
Tripon Alexandru-Ionut
2019-04-17 16:58:16 +03:00
committed by Dan Christian Bogos
parent 717a801648
commit 9c379a969a
9 changed files with 99 additions and 20 deletions

View File

@@ -68,8 +68,11 @@ func (apierV1 *ApierV1) GetFilter(arg utils.TenantID, reply *engine.Filter) erro
}
// GetFilterIDs returns list of Filter IDs registered for a tenant
func (apierV1 *ApierV1) GetFilterIDs(tenant string, fltrIDs *[]string) error {
prfx := utils.FilterPrefix + tenant + ":"
func (apierV1 *ApierV1) GetFilterIDs(args utils.TenantArgWithPaginator, fltrIDs *[]string) error {
if missing := utils.MissingStructFields(&args, []string{utils.Tenant}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
prfx := utils.FilterPrefix + args.Tenant + ":"
keys, err := apierV1.DataManager.DataDB().GetKeysForPrefix(prfx)
if err != nil {
return err
@@ -81,7 +84,7 @@ func (apierV1 *ApierV1) GetFilterIDs(tenant string, fltrIDs *[]string) error {
for i, key := range keys {
retIDs[i] = key[len(prfx):]
}
*fltrIDs = retIDs
*fltrIDs = args.PaginateStringSlice(retIDs)
return nil
}

View File

@@ -145,7 +145,7 @@ func testFilterSetFilter(t *testing.T) {
func testFilterGetFilterIDs(t *testing.T) {
expected := []string{"Filter1"}
var result []string
if err := filterRPC.Call("ApierV1.GetFilterIDs", "cgrates.org", &result); err != nil {
if err := filterRPC.Call(utils.ApierV1GetFilterIDs, 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)

View File

@@ -26,7 +26,7 @@ import (
func init() {
c := &CmdGetFilter{
name: "filter",
rpcMethod: "ApierV1.GetFilter",
rpcMethod: utils.ApierV1GetFilter,
rpcParams: &utils.TenantID{},
}
commands[c.Name()] = c

65
console/filter_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 := &CmdGetFilterIDs{
name: "filter_ids",
rpcMethod: utils.ApierV1GetFilterIDs,
rpcParams: &utils.TenantArgWithPaginator{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdGetFilterIDs struct {
name string
rpcMethod string
rpcParams *utils.TenantArgWithPaginator
*CommandExecuter
}
func (self *CmdGetFilterIDs) Name() string {
return self.name
}
func (self *CmdGetFilterIDs) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdGetFilterIDs) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &utils.TenantArgWithPaginator{}
}
return self.rpcParams
}
func (self *CmdGetFilterIDs) PostprocessRpcParams() error {
return nil
}
func (self *CmdGetFilterIDs) RpcResult() interface{} {
atr := []string{}
return &atr
}

View File

@@ -19,13 +19,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package console
import (
"github.com/cgrates/cgrates/apier/v1"
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdGetFilterIndexes{
name: "filter_indexes",
rpcMethod: "ApierV1.GetFilterIndexes",
rpcMethod: utils.ApierV1GetFilterIndexes,
rpcParams: &v1.AttrGetFilterIndexes{},
}
commands[c.Name()] = c

View File

@@ -19,13 +19,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package console
import (
"github.com/cgrates/cgrates/apier/v1"
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdRemoveFilterIndexes{
name: "filter_indexes_remove",
rpcMethod: "ApierV1.RemoveFilterIndexes",
rpcMethod: utils.ApierV1RemoveFilterIndexes,
rpcParams: &v1.AttrRemFilterIndexes{},
}
commands[c.Name()] = c

View File

@@ -23,7 +23,7 @@ import "github.com/cgrates/cgrates/utils"
func init() {
c := &CmdRemoveFilter{
name: "filter_remove",
rpcMethod: "ApierV1.RemoveFilter",
rpcMethod: utils.ApierV1RemoveFilter,
rpcParams: &utils.TenantIDWithCache{},
}
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 v1 "github.com/cgrates/cgrates/apier/v1"
import (
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdSetFilter{
name: "filter_set",
rpcMethod: "ApierV1.SetFilter",
rpcMethod: utils.ApierV1SetFilter,
rpcParams: &v1.FilterWithCache{},
}
commands[c.Name()] = c

View File

@@ -722,10 +722,12 @@ const (
ApierV1LoadTariffPlanFromFolder = "ApierV1.LoadTariffPlanFromFolder"
ApierV1GetCost = "ApierV1.GetCost"
ApierV1SetBalance = "ApierV1.SetBalance"
ApierV1GetSupplierProfile = "ApierV1.GetSupplierProfile"
ApierV1GetSupplierProfileIDs = "ApierV1.GetSupplierProfileIDs"
ApierV1RemoveSupplierProfile = "ApierV1.RemoveSupplierProfile"
ApierV1SetSupplierProfile = "ApierV1.SetSupplierProfile"
ApierV1GetFilter = "ApierV1.GetFilter"
ApierV1GetFilterIndexes = "ApierV1.GetFilterIndexes"
ApierV1RemoveFilterIndexes = "ApierV1.RemoveFilterIndexes"
ApierV1RemoveFilter = "ApierV1.RemoveFilter"
ApierV1SetFilter = "ApierV1.SetFilter"
ApierV1GetFilterIDs = "ApierV1.GetFilterIDs"
)
const (
@@ -747,18 +749,22 @@ const (
// SupplierS APIs
const (
SupplierSv1GetSuppliers = "SupplierSv1.GetSuppliers"
SupplierSv1Ping = "SupplierSv1.Ping"
SupplierSv1GetSuppliers = "SupplierSv1.GetSuppliers"
SupplierSv1Ping = "SupplierSv1.Ping"
ApierV1GetSupplierProfile = "ApierV1.GetSupplierProfile"
ApierV1GetSupplierProfileIDs = "ApierV1.GetSupplierProfileIDs"
ApierV1RemoveSupplierProfile = "ApierV1.RemoveSupplierProfile"
ApierV1SetSupplierProfile = "ApierV1.SetSupplierProfile"
)
// AttributeS APIs
const (
ApierV1GetAttributeProfile = "ApierV1.GetAttributeProfile"
ApierV1GetAttributeProfileIDs = "ApierV1.GetAttributeProfileIDs"
AttributeSv1GetAttributeForEvent = "AttributeSv1.GetAttributeForEvent"
AttributeSv1ProcessEvent = "AttributeSv1.ProcessEvent"
ApierV1RemoveAttributeProfile = "ApierV1.RemoveAttributeProfile"
ApierV2SetAttributeProfile = "ApierV2.SetAttributeProfile"
AttributeSv1GetAttributeForEvent = "AttributeSv1.GetAttributeForEvent"
AttributeSv1ProcessEvent = "AttributeSv1.ProcessEvent"
AttributeSv1Ping = "AttributeSv1.Ping"
)