From 787cc55d15d9c149b887fabb57ec3f05481a48fa Mon Sep 17 00:00:00 2001 From: edwardro22 Date: Fri, 15 Dec 2017 08:54:56 +0200 Subject: [PATCH] Adding cgr-console attributes related APIs --- console/atributes.go | 66 ++++++++++++++++++++++++++ console/atributes_get_for_event.go | 76 ++++++++++++++++++++++++++++++ console/atributes_process_event.go | 76 ++++++++++++++++++++++++++++++ console/atributes_remove.go | 63 +++++++++++++++++++++++++ console/atributes_set.go | 63 +++++++++++++++++++++++++ 5 files changed, 344 insertions(+) create mode 100644 console/atributes.go create mode 100644 console/atributes_get_for_event.go create mode 100644 console/atributes_process_event.go create mode 100644 console/atributes_remove.go create mode 100644 console/atributes_set.go diff --git a/console/atributes.go b/console/atributes.go new file mode 100644 index 000000000..9a1022ee2 --- /dev/null +++ b/console/atributes.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 := &CmdGetAtributes{ + name: "atributes", + rpcMethod: "ApierV1.GetAttributeProfile", + rpcParams: &utils.TenantID{}, + } + commands[c.Name()] = c + c.CommandExecuter = &CommandExecuter{c} +} + +// Commander implementation +type CmdGetAtributes struct { + name string + rpcMethod string + rpcParams *utils.TenantID + *CommandExecuter +} + +func (self *CmdGetAtributes) Name() string { + return self.name +} + +func (self *CmdGetAtributes) RpcMethod() string { + return self.rpcMethod +} + +func (self *CmdGetAtributes) RpcParams(reset bool) interface{} { + if reset || self.rpcParams == nil { + self.rpcParams = &utils.TenantID{} + } + return self.rpcParams +} + +func (self *CmdGetAtributes) PostprocessRpcParams() error { + return nil +} + +func (self *CmdGetAtributes) RpcResult() interface{} { + atr := engine.ExternalAttributeProfile{} + return &atr +} diff --git a/console/atributes_get_for_event.go b/console/atributes_get_for_event.go new file mode 100644 index 000000000..b3817fedb --- /dev/null +++ b/console/atributes_get_for_event.go @@ -0,0 +1,76 @@ +/* +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/config" + "github.com/cgrates/cgrates/utils" +) + +func init() { + c := &CmdAttributesProcessEvent{ + name: "get_attribute_for_event", + rpcMethod: "AttributeSv1.GetAttributeForEvent", + } + commands[c.Name()] = c + c.CommandExecuter = &CommandExecuter{c} +} + +// Commander implementation +type CmdAttributesProcessEvent struct { + name string + rpcMethod string + rpcParams interface{} + *CommandExecuter +} + +func (self *CmdAttributesProcessEvent) Name() string { + return self.name +} + +func (self *CmdAttributesProcessEvent) RpcMethod() string { + return self.rpcMethod +} + +func (self *CmdAttributesProcessEvent) RpcParams(reset bool) interface{} { + if reset || self.rpcParams == nil { + mp := make(map[string]interface{}) + self.rpcParams = &mp + } + return self.rpcParams +} + +func (self *CmdAttributesProcessEvent) PostprocessRpcParams() error { //utils.CGREvent + param := self.rpcParams.(*map[string]interface{}) + cgrev := utils.CGREvent{ + Tenant: config.CgrConfig().DefaultTenant, + ID: utils.UUIDSha1Prefix(), + Event: *param, + } + if (*param)[utils.Tenant] != nil && (*param)[utils.Tenant].(string) != "" { + cgrev.Tenant = (*param)[utils.Tenant].(string) + } + self.rpcParams = cgrev + return nil +} + +func (self *CmdAttributesProcessEvent) RpcResult() interface{} { + atr := engine.ExternalAttributeProfile{} + return &atr +} diff --git a/console/atributes_process_event.go b/console/atributes_process_event.go new file mode 100644 index 000000000..a3840f62c --- /dev/null +++ b/console/atributes_process_event.go @@ -0,0 +1,76 @@ +/* +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/config" + "github.com/cgrates/cgrates/utils" +) + +func init() { + c := &CmdAttributesProcessEvent{ + name: "attributes_process_event", + rpcMethod: "AttributeSv1.ProcessEvent", + } + commands[c.Name()] = c + c.CommandExecuter = &CommandExecuter{c} +} + +// Commander implementation +type CmdAttributesProcessEvent struct { + name string + rpcMethod string + rpcParams interface{} + *CommandExecuter +} + +func (self *CmdAttributesProcessEvent) Name() string { + return self.name +} + +func (self *CmdAttributesProcessEvent) RpcMethod() string { + return self.rpcMethod +} + +func (self *CmdAttributesProcessEvent) RpcParams(reset bool) interface{} { + if reset || self.rpcParams == nil { + mp := make(map[string]interface{}) + self.rpcParams = &mp + } + return self.rpcParams +} + +func (self *CmdAttributesProcessEvent) PostprocessRpcParams() error { //utils.CGREvent + param := self.rpcParams.(*map[string]interface{}) + cgrev := utils.CGREvent{ + Tenant: config.CgrConfig().DefaultTenant, + ID: utils.UUIDSha1Prefix(), + Event: *param, + } + if (*param)[utils.Tenant] != nil && (*param)[utils.Tenant].(string) != "" { + cgrev.Tenant = (*param)[utils.Tenant].(string) + } + self.rpcParams = cgrev + return nil +} + +func (self *CmdAttributesProcessEvent) RpcResult() interface{} { + atr := engine.AttrSProcessEventReply{} + return &atr +} diff --git a/console/atributes_remove.go b/console/atributes_remove.go new file mode 100644 index 000000000..3507283f7 --- /dev/null +++ b/console/atributes_remove.go @@ -0,0 +1,63 @@ +/* +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/utils" + +func init() { + c := &CmdRemoveAtributes{ + name: "atributes_remove", + rpcMethod: "ApierV1.RemAttributeProfile", + rpcParams: &utils.TenantID{}, + } + commands[c.Name()] = c + c.CommandExecuter = &CommandExecuter{c} +} + +// Commander implementation +type CmdRemoveAtributes struct { + name string + rpcMethod string + rpcParams *utils.TenantID + *CommandExecuter +} + +func (self *CmdRemoveAtributes) Name() string { + return self.name +} + +func (self *CmdRemoveAtributes) RpcMethod() string { + return self.rpcMethod +} + +func (self *CmdRemoveAtributes) RpcParams(reset bool) interface{} { + if reset || self.rpcParams == nil { + self.rpcParams = &utils.TenantID{} + } + return self.rpcParams +} + +func (self *CmdRemoveAtributes) PostprocessRpcParams() error { + return nil +} + +func (self *CmdRemoveAtributes) RpcResult() interface{} { + var s string + return &s +} diff --git a/console/atributes_set.go b/console/atributes_set.go new file mode 100644 index 000000000..057d16e62 --- /dev/null +++ b/console/atributes_set.go @@ -0,0 +1,63 @@ +/* +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" + +func init() { + c := &CmdSetResource{ + name: "attributes_set", + rpcMethod: "ApierV1.SetAttributeProfile", + rpcParams: &engine.ExternalAttributeProfile{}, + } + commands[c.Name()] = c + c.CommandExecuter = &CommandExecuter{c} +} + +// Commander implementation +type CmdSetResource struct { + name string + rpcMethod string + rpcParams *engine.ExternalAttributeProfile + *CommandExecuter +} + +func (self *CmdSetResource) Name() string { + return self.name +} + +func (self *CmdSetResource) RpcMethod() string { + return self.rpcMethod +} + +func (self *CmdSetResource) RpcParams(reset bool) interface{} { + if reset || self.rpcParams == nil { + self.rpcParams = &engine.ExternalAttributeProfile{} + } + return self.rpcParams +} + +func (self *CmdSetResource) PostprocessRpcParams() error { + return nil +} + +func (self *CmdSetResource) RpcResult() interface{} { + var s string + return &s +}