Updated GetAttributeProfileIDs

This commit is contained in:
Tripon Alexandru-Ionut
2019-04-17 15:58:37 +03:00
committed by Dan Christian Bogos
parent 87d5f6dd15
commit fbc1fad902
8 changed files with 102 additions and 16 deletions

View File

@@ -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
}

View File

@@ -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)

View File

@@ -26,7 +26,7 @@ import (
func init() {
c := &CmdGetAttributes{
name: "attributes",
rpcMethod: "ApierV1.GetAttributeProfile",
rpcMethod: utils.ApierV1GetAttributeProfile,
rpcParams: &utils.TenantID{},
}
commands[c.Name()] = c

66
console/attributes_ids.go Normal file
View File

@@ -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 <http://www.gnu.org/licenses/>
*/
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
}

View File

@@ -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

View File

@@ -18,12 +18,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
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

View File

@@ -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"
)

View File

@@ -792,6 +792,11 @@ type TenantArg struct {
Tenant string
}
type TenantArgWithPaginator struct {
TenantArg
Paginator
}
type TenantWithArgDispatcher struct {
*TenantArg
*ArgDispatcher