diff --git a/apier/v1/attributes.go b/apier/v1/attributes.go
index a8cef3c5e..f979c5e30 100644
--- a/apier/v1/attributes.go
+++ b/apier/v1/attributes.go
@@ -42,11 +42,11 @@ func (apierV1 *ApierV1) GetAttributeProfile(arg utils.TenantID, reply *engine.At
}
// GetAttributeProfileIDs returns list of attributeProfile IDs registered for a tenant
-func (apierV1 *ApierV1) GetAttributeProfileIDs(tenant string, attrPrfIDs *[]string) error {
- if tenant == "" {
- return utils.NewErrMandatoryIeMissing("Tenant")
+func (apierV1 *ApierV1) GetAttributeProfileIDs(args utils.TenantArgWithPaginator, attrPrfIDs *[]string) error {
+ if missing := utils.MissingStructFields(&args, []string{utils.Tenant}); len(missing) != 0 { //Params missing
+ return utils.NewErrMandatoryIeMissing(missing...)
}
- prfx := utils.AttributeProfilePrefix + tenant + ":"
+ prfx := utils.AttributeProfilePrefix + args.Tenant + ":"
keys, err := apierV1.DataManager.DataDB().GetKeysForPrefix(prfx)
if err != nil {
return err
@@ -58,7 +58,7 @@ func (apierV1 *ApierV1) GetAttributeProfileIDs(tenant string, attrPrfIDs *[]stri
for i, key := range keys {
retIDs[i] = key[len(prfx):]
}
- *attrPrfIDs = retIDs
+ *attrPrfIDs = args.PaginateStringSlice(retIDs)
return nil
}
diff --git a/apier/v1/attributes_it_test.go b/apier/v1/attributes_it_test.go
index e92a961bd..b09eabc4e 100644
--- a/apier/v1/attributes_it_test.go
+++ b/apier/v1/attributes_it_test.go
@@ -683,15 +683,23 @@ func testAttributeSProcessEventWithHeader(t *testing.T) {
func testAttributeSGetAttPrfIDs(t *testing.T) {
expected := []string{"ATTR_2", "ATTR_1", "ATTR_3", "ATTR_Header", "AttributeWithNonSubstitute"}
var result []string
- if err := attrSRPC.Call("ApierV1.GetAttributeProfileIDs", "", &result); err == nil ||
+ if err := attrSRPC.Call(utils.ApierV1GetAttributeProfileIDs, utils.TenantArgWithPaginator{}, &result); err == nil ||
err.Error() != utils.NewErrMandatoryIeMissing("Tenant").Error() {
t.Errorf("Expected error recived reply %+v with err=%v", result, err)
}
- if err := attrSRPC.Call("ApierV1.GetAttributeProfileIDs", "cgrates.org", &result); err != nil {
+ if err := attrSRPC.Call(utils.ApierV1GetAttributeProfileIDs, 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 := attrSRPC.Call(utils.ApierV1GetAttributeProfileIDs, utils.TenantArgWithPaginator{
+ TenantArg: utils.TenantArg{Tenant: "cgrates.org"},
+ Paginator: utils.Paginator{Limit: utils.IntPointer(10)},
+ }, &result); err != nil {
+ t.Error(err)
+ } else if 10 < len(result) {
+ t.Errorf("Expecting : %+v, received: %+v", expected, result)
+ }
}
func testAttributeSSetAlsPrf(t *testing.T) {
@@ -1234,7 +1242,7 @@ func testAttributeSCachingMetaNone(t *testing.T) {
//check in dataManager
expected := []string{"ATTR_1"}
var rcvIDs []string
- if err := attrSRPC.Call("ApierV1.GetAttributeProfileIDs", "cgrates.org", &rcvIDs); err != nil {
+ if err := attrSRPC.Call(utils.ApierV1GetAttributeProfileIDs, utils.TenantArgWithPaginator{TenantArg: utils.TenantArg{Tenant: "cgrates.org"}}, &rcvIDs); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expected, rcvIDs) {
t.Errorf("Expecting : %+v, received: %+v", expected, rcvIDs)
@@ -1294,7 +1302,7 @@ func testAttributeSCachingMetaLoad(t *testing.T) {
//check in dataManager
expected := []string{"ATTR_1"}
var rcvIDs []string
- if err := attrSRPC.Call("ApierV1.GetAttributeProfileIDs", "cgrates.org", &rcvIDs); err != nil {
+ if err := attrSRPC.Call(utils.ApierV1GetAttributeProfileIDs, utils.TenantArgWithPaginator{TenantArg: utils.TenantArg{Tenant: "cgrates.org"}}, &rcvIDs); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expected, rcvIDs) {
t.Errorf("Expecting : %+v, received: %+v", expected, rcvIDs)
@@ -1326,7 +1334,7 @@ func testAttributeSCachingMetaLoad(t *testing.T) {
}
//check in dataManager
- if err := attrSRPC.Call("ApierV1.GetAttributeProfileIDs", "cgrates.org", &rcvIDs); err == nil ||
+ if err := attrSRPC.Call(utils.ApierV1GetAttributeProfileIDs, utils.TenantArgWithPaginator{TenantArg: utils.TenantArg{Tenant: "cgrates.org"}}, &rcvIDs); err == nil ||
err.Error() != utils.ErrNotFound.Error() {
t.Fatalf("Expected error: %s received error: %s and reply: %v ",
utils.ErrNotFound, err, rcvIDs)
@@ -1385,7 +1393,7 @@ func testAttributeSCachingMetaReload1(t *testing.T) {
//check in dataManager
expected := []string{"ATTR_1"}
var rcvIDs []string
- if err := attrSRPC.Call("ApierV1.GetAttributeProfileIDs", "cgrates.org", &rcvIDs); err != nil {
+ if err := attrSRPC.Call(utils.ApierV1GetAttributeProfileIDs, utils.TenantArgWithPaginator{TenantArg: utils.TenantArg{Tenant: "cgrates.org"}}, &rcvIDs); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expected, rcvIDs) {
t.Errorf("Expecting : %+v, received: %+v", expected, rcvIDs)
@@ -1564,7 +1572,7 @@ func testAttributeSCachingMetaRemove(t *testing.T) {
//check in dataManager
expected := []string{"ATTR_1"}
var rcvIDs []string
- if err := attrSRPC.Call("ApierV1.GetAttributeProfileIDs", "cgrates.org", &rcvIDs); err != nil {
+ if err := attrSRPC.Call(utils.ApierV1GetAttributeProfileIDs, utils.TenantArgWithPaginator{TenantArg: utils.TenantArg{Tenant: "cgrates.org"}}, &rcvIDs); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expected, rcvIDs) {
t.Errorf("Expecting : %+v, received: %+v", expected, rcvIDs)
diff --git a/console/attributes.go b/console/attributes.go
index 7da05e28b..806d52b08 100644
--- a/console/attributes.go
+++ b/console/attributes.go
@@ -26,7 +26,7 @@ import (
func init() {
c := &CmdGetAttributes{
name: "attributes",
- rpcMethod: "ApierV1.GetAttributeProfile",
+ rpcMethod: utils.ApierV1GetAttributeProfile,
rpcParams: &utils.TenantID{},
}
commands[c.Name()] = c
diff --git a/console/attributes_ids.go b/console/attributes_ids.go
new file mode 100644
index 000000000..59371787b
--- /dev/null
+++ b/console/attributes_ids.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 := &CmdGetAttributeIDs{
+ name: "attribute_ids",
+ rpcMethod: utils.ApierV1GetAttributeProfileIDs,
+ rpcParams: &utils.TenantArgWithPaginator{},
+ }
+ commands[c.Name()] = c
+ c.CommandExecuter = &CommandExecuter{c}
+}
+
+// Commander implementation
+type CmdGetAttributeIDs struct {
+ name string
+ rpcMethod string
+ rpcParams *utils.TenantArgWithPaginator
+ *CommandExecuter
+}
+
+func (self *CmdGetAttributeIDs) Name() string {
+ return self.name
+}
+
+func (self *CmdGetAttributeIDs) RpcMethod() string {
+ return self.rpcMethod
+}
+
+func (self *CmdGetAttributeIDs) RpcParams(reset bool) interface{} {
+ if reset || self.rpcParams == nil {
+ self.rpcParams = &utils.TenantArgWithPaginator{}
+ }
+ return self.rpcParams
+}
+
+func (self *CmdGetAttributeIDs) PostprocessRpcParams() error {
+ return nil
+}
+
+func (self *CmdGetAttributeIDs) RpcResult() interface{} {
+ atr := engine.AttributeProfile{}
+ return &atr
+}
diff --git a/console/attributes_remove.go b/console/attributes_remove.go
index 44d8acbca..e1114e3b1 100644
--- a/console/attributes_remove.go
+++ b/console/attributes_remove.go
@@ -23,7 +23,7 @@ import "github.com/cgrates/cgrates/utils"
func init() {
c := &CmdRemoveAttributes{
name: "attributes_remove",
- rpcMethod: "ApierV1.RemoveAttributeProfile",
+ rpcMethod: utils.ApierV1RemoveAttributeProfile,
rpcParams: &utils.TenantIDWithCache{},
}
commands[c.Name()] = c
diff --git a/console/attributes_set.go b/console/attributes_set.go
index 4f6f82201..c504dbccb 100644
--- a/console/attributes_set.go
+++ b/console/attributes_set.go
@@ -18,12 +18,15 @@ along with this program. If not, see
package console
-import v2 "github.com/cgrates/cgrates/apier/v2"
+import (
+ v2 "github.com/cgrates/cgrates/apier/v2"
+ "github.com/cgrates/cgrates/utils"
+)
func init() {
c := &CmdSetAttributes{
name: "attributes_set",
- rpcMethod: "ApierV2.SetAttributeProfile",
+ rpcMethod: utils.ApierV2SetAttributeProfile,
rpcParams: &v2.AttributeWithCache{},
}
commands[c.Name()] = c
diff --git a/utils/consts.go b/utils/consts.go
index 45d190db2..589cc1003 100755
--- a/utils/consts.go
+++ b/utils/consts.go
@@ -753,8 +753,12 @@ const (
// AttributeS APIs
const (
+ ApierV1GetAttributeProfile = "ApierV1.GetAttributeProfile"
+ ApierV1GetAttributeProfileIDs = "ApierV1.GetAttributeProfileIDs"
AttributeSv1GetAttributeForEvent = "AttributeSv1.GetAttributeForEvent"
AttributeSv1ProcessEvent = "AttributeSv1.ProcessEvent"
+ ApierV1RemoveAttributeProfile = "ApierV1.RemoveAttributeProfile"
+ ApierV2SetAttributeProfile = "ApierV2.SetAttributeProfile"
AttributeSv1Ping = "AttributeSv1.Ping"
)
diff --git a/utils/coreutils.go b/utils/coreutils.go
index 6002109e1..2d655075a 100644
--- a/utils/coreutils.go
+++ b/utils/coreutils.go
@@ -792,6 +792,11 @@ type TenantArg struct {
Tenant string
}
+type TenantArgWithPaginator struct {
+ TenantArg
+ Paginator
+}
+
type TenantWithArgDispatcher struct {
*TenantArg
*ArgDispatcher