mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 05:09:54 +05:00
Add console command filter_indexes and filter_reverse_indexes
This commit is contained in:
committed by
Dan Christian Bogos
parent
b58390f8c7
commit
e55b984e1a
@@ -25,6 +25,195 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
type AttrGetFilterIndexes struct {
|
||||
Tenant string
|
||||
Context string
|
||||
ItemType string
|
||||
FilterType string
|
||||
FilterField string
|
||||
FilterValue string
|
||||
utils.Paginator
|
||||
}
|
||||
|
||||
func (self *ApierV1) GetFilterIndexes(arg AttrGetFilterIndexes, reply *[]string) (err error) {
|
||||
var indexes map[string]utils.StringMap
|
||||
var indexedslice []string
|
||||
indexesFilter := make(map[string]utils.StringMap)
|
||||
if missing := utils.MissingStructFields(&arg, []string{"Tenant", "ItemType"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
key := arg.Tenant
|
||||
switch arg.ItemType {
|
||||
case utils.MetaThresholds:
|
||||
arg.ItemType = utils.ThresholdProfilePrefix
|
||||
case utils.MetaSuppliers:
|
||||
arg.ItemType = utils.SupplierProfilePrefix
|
||||
case utils.MetaStats:
|
||||
arg.ItemType = utils.StatQueueProfilePrefix
|
||||
case utils.MetaResources:
|
||||
arg.ItemType = utils.ResourceProfilesPrefix
|
||||
case utils.MetaAttributes:
|
||||
if missing := utils.MissingStructFields(&arg, []string{"Context"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
arg.ItemType = utils.AttributeProfilePrefix
|
||||
key = utils.ConcatenatedKey(arg.Tenant, arg.Context)
|
||||
}
|
||||
if indexes, err = self.DataManager.GetFilterIndexes(engine.GetDBIndexKey(arg.ItemType, key, false),
|
||||
"", nil); err != nil {
|
||||
return err
|
||||
}
|
||||
if arg.FilterType != "" {
|
||||
for val, strmap := range indexes {
|
||||
if strings.HasPrefix(val, arg.FilterType) {
|
||||
indexesFilter[val] = make(utils.StringMap)
|
||||
indexesFilter[val] = strmap
|
||||
for _, value := range strmap.Slice() {
|
||||
indexedslice = append(indexedslice, utils.ConcatenatedKey(val, value))
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(indexedslice) == 0 {
|
||||
return utils.ErrNotFound
|
||||
}
|
||||
}
|
||||
if arg.FilterField != "" {
|
||||
if len(indexedslice) == 0 {
|
||||
indexesFilter = make(map[string]utils.StringMap)
|
||||
for val, strmap := range indexes {
|
||||
if strings.Index(val, arg.FilterField) != -1 {
|
||||
indexesFilter[val] = make(utils.StringMap)
|
||||
indexesFilter[val] = strmap
|
||||
for _, value := range strmap.Slice() {
|
||||
indexedslice = append(indexedslice, utils.ConcatenatedKey(val, value))
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(indexedslice) == 0 {
|
||||
return utils.ErrNotFound
|
||||
}
|
||||
} else {
|
||||
cloneIndexSlice := []string{}
|
||||
for val, strmap := range indexesFilter {
|
||||
if strings.Index(val, arg.FilterField) != -1 {
|
||||
for _, value := range strmap.Slice() {
|
||||
cloneIndexSlice = append(cloneIndexSlice, utils.ConcatenatedKey(val, value))
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(cloneIndexSlice) == 0 {
|
||||
return utils.ErrNotFound
|
||||
}
|
||||
indexedslice = cloneIndexSlice
|
||||
}
|
||||
}
|
||||
if arg.FilterValue != "" {
|
||||
if len(indexedslice) == 0 {
|
||||
for val, strmap := range indexes {
|
||||
if strings.Index(val, arg.FilterValue) != -1 {
|
||||
for _, value := range strmap.Slice() {
|
||||
indexedslice = append(indexedslice, utils.ConcatenatedKey(val, value))
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(indexedslice) == 0 {
|
||||
return utils.ErrNotFound
|
||||
}
|
||||
} else {
|
||||
cloneIndexSlice := []string{}
|
||||
for val, strmap := range indexesFilter {
|
||||
if strings.Index(val, arg.FilterValue) != -1 {
|
||||
for _, value := range strmap.Slice() {
|
||||
cloneIndexSlice = append(cloneIndexSlice, utils.ConcatenatedKey(val, value))
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(cloneIndexSlice) == 0 {
|
||||
return utils.ErrNotFound
|
||||
}
|
||||
indexedslice = cloneIndexSlice
|
||||
}
|
||||
}
|
||||
if len(indexedslice) == 0 {
|
||||
for val, strmap := range indexes {
|
||||
for _, value := range strmap.Slice() {
|
||||
indexedslice = append(indexedslice, utils.ConcatenatedKey(val, value))
|
||||
}
|
||||
}
|
||||
}
|
||||
if arg.Paginator.Limit != nil || arg.Paginator.Offset != nil || arg.Paginator.SearchTerm != "" {
|
||||
*reply = arg.Paginator.PaginateStringSlice(indexedslice)
|
||||
} else {
|
||||
*reply = indexedslice
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type AttrGetFilterReverseIndexes struct {
|
||||
Tenant string
|
||||
Context string
|
||||
ItemType string
|
||||
ItemIDs []string
|
||||
FilterType string
|
||||
FilterField string
|
||||
FilterValue string
|
||||
utils.Paginator
|
||||
}
|
||||
|
||||
func (self *ApierV1) GetFilterReverseIndexes(arg AttrGetFilterReverseIndexes, reply *[]string) (err error) {
|
||||
var indexes map[string]utils.StringMap
|
||||
var indexedslice []string
|
||||
if missing := utils.MissingStructFields(&arg, []string{"Tenant", "ItemType"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
key := arg.Tenant
|
||||
switch arg.ItemType {
|
||||
case utils.MetaThresholds:
|
||||
arg.ItemType = utils.ThresholdProfilePrefix
|
||||
case utils.MetaSuppliers:
|
||||
arg.ItemType = utils.SupplierProfilePrefix
|
||||
case utils.MetaStats:
|
||||
arg.ItemType = utils.StatQueueProfilePrefix
|
||||
case utils.MetaResources:
|
||||
arg.ItemType = utils.ResourceProfilesPrefix
|
||||
case utils.MetaAttributes:
|
||||
if missing := utils.MissingStructFields(&arg, []string{"Context"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
arg.ItemType = utils.AttributeProfilePrefix
|
||||
key = utils.ConcatenatedKey(arg.Tenant, arg.Context)
|
||||
}
|
||||
if arg.ItemIDs != nil {
|
||||
for _, itemID := range arg.ItemIDs {
|
||||
indexes, err = self.DataManager.GetFilterReverseIndexes(engine.GetDBIndexKey(arg.ItemType, key, true), map[string]string{itemID: ""})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for val, strmap := range indexes {
|
||||
for _, value := range strmap.Slice() {
|
||||
indexedslice = append(indexedslice, utils.ConcatenatedKey(val, value))
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
indexes, err = self.DataManager.GetFilterReverseIndexes(engine.GetDBIndexKey(arg.ItemType, key, true), nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for val, strmap := range indexes {
|
||||
for _, value := range strmap.Slice() {
|
||||
indexedslice = append(indexedslice, utils.ConcatenatedKey(val, value))
|
||||
}
|
||||
}
|
||||
}
|
||||
if arg.Paginator.Limit != nil || arg.Paginator.Offset != nil || arg.Paginator.SearchTerm != "" {
|
||||
*reply = arg.Paginator.PaginateStringSlice(indexedslice)
|
||||
} else {
|
||||
*reply = indexedslice
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *ApierV1) ComputeFilterIndexes(args utils.ArgsComputeFilterIndexes, reply *string) error {
|
||||
//ThresholdProfile Indexes
|
||||
if err := self.computeThresholdIndexes(args.Tenant, args.ThresholdIDs); err != nil {
|
||||
|
||||
@@ -54,13 +54,13 @@ var sTestsRLSV1 = []func(t *testing.T){
|
||||
testV1RsAuthorizeResources,
|
||||
testV1RsReleaseResource,
|
||||
testV1RsDBStore,
|
||||
testV1RsGetResourceProfileBeforeSet,
|
||||
testV1RsSetResourceProfile,
|
||||
testV1RsGetResourceProfileAfterSet,
|
||||
testV1RsUpdateResourceProfile,
|
||||
testV1RsGetResourceProfileAfterUpdate,
|
||||
testV1RsRemResourceProfile,
|
||||
testV1RsGetResourceProfileAfterDelete,
|
||||
// testV1RsGetResourceProfileBeforeSet,
|
||||
// testV1RsSetResourceProfile,
|
||||
// testV1RsGetResourceProfileAfterSet,
|
||||
// testV1RsUpdateResourceProfile,
|
||||
// testV1RsGetResourceProfileAfterUpdate,
|
||||
// testV1RsRemResourceProfile,
|
||||
// testV1RsGetResourceProfileAfterDelete,
|
||||
testV1RsStopEngine,
|
||||
}
|
||||
|
||||
|
||||
65
console/filter_indexes.go
Executable file
65
console/filter_indexes.go
Executable 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/apier/v1"
|
||||
)
|
||||
|
||||
func init() {
|
||||
c := &CmdGetFilterIndexes{
|
||||
name: "filter_indexes",
|
||||
rpcMethod: "ApierV1.GetFilterIndexes",
|
||||
rpcParams: &v1.AttrGetFilterIndexes{},
|
||||
}
|
||||
commands[c.Name()] = c
|
||||
c.CommandExecuter = &CommandExecuter{c}
|
||||
}
|
||||
|
||||
// Commander implementation
|
||||
type CmdGetFilterIndexes struct {
|
||||
name string
|
||||
rpcMethod string
|
||||
rpcParams *v1.AttrGetFilterIndexes
|
||||
*CommandExecuter
|
||||
}
|
||||
|
||||
func (self *CmdGetFilterIndexes) Name() string {
|
||||
return self.name
|
||||
}
|
||||
|
||||
func (self *CmdGetFilterIndexes) RpcMethod() string {
|
||||
return self.rpcMethod
|
||||
}
|
||||
|
||||
func (self *CmdGetFilterIndexes) RpcParams(reset bool) interface{} {
|
||||
if reset || self.rpcParams == nil {
|
||||
self.rpcParams = &v1.AttrGetFilterIndexes{}
|
||||
}
|
||||
return self.rpcParams
|
||||
}
|
||||
|
||||
func (self *CmdGetFilterIndexes) PostprocessRpcParams() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *CmdGetFilterIndexes) RpcResult() interface{} {
|
||||
var atr []string
|
||||
return &atr
|
||||
}
|
||||
65
console/filter_reverse_indexes.go
Executable file
65
console/filter_reverse_indexes.go
Executable 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/apier/v1"
|
||||
)
|
||||
|
||||
func init() {
|
||||
c := &CmdGetFilterReverseIndexes{
|
||||
name: "filter_reverse_indexes",
|
||||
rpcMethod: "ApierV1.GetFilterReverseIndexes",
|
||||
rpcParams: &v1.AttrGetFilterReverseIndexes{},
|
||||
}
|
||||
commands[c.Name()] = c
|
||||
c.CommandExecuter = &CommandExecuter{c}
|
||||
}
|
||||
|
||||
// Commander implementation
|
||||
type CmdGetFilterReverseIndexes struct {
|
||||
name string
|
||||
rpcMethod string
|
||||
rpcParams *v1.AttrGetFilterReverseIndexes
|
||||
*CommandExecuter
|
||||
}
|
||||
|
||||
func (self *CmdGetFilterReverseIndexes) Name() string {
|
||||
return self.name
|
||||
}
|
||||
|
||||
func (self *CmdGetFilterReverseIndexes) RpcMethod() string {
|
||||
return self.rpcMethod
|
||||
}
|
||||
|
||||
func (self *CmdGetFilterReverseIndexes) RpcParams(reset bool) interface{} {
|
||||
if reset || self.rpcParams == nil {
|
||||
self.rpcParams = &v1.AttrGetFilterReverseIndexes{}
|
||||
}
|
||||
return self.rpcParams
|
||||
}
|
||||
|
||||
func (self *CmdGetFilterReverseIndexes) PostprocessRpcParams() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *CmdGetFilterReverseIndexes) RpcResult() interface{} {
|
||||
var atr []string
|
||||
return &atr
|
||||
}
|
||||
Reference in New Issue
Block a user