From 11bd70735af3106237d0787fbe7855d919f150c8 Mon Sep 17 00:00:00 2001 From: Tripon Alexandru-Ionut Date: Fri, 21 Jun 2019 15:22:47 +0300 Subject: [PATCH] Added RemoveActionPlans.Fixes#1517 --- apier/v1/apier.go | 33 ++++++++++++++++++ console/actionplan_remove.go | 65 ++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 console/actionplan_remove.go diff --git a/apier/v1/apier.go b/apier/v1/apier.go index c07d5296b..b8be8dbe0 100644 --- a/apier/v1/apier.go +++ b/apier/v1/apier.go @@ -722,6 +722,39 @@ func (self *ApierV1) GetActionPlan(attr AttrGetActionPlan, reply *[]*engine.Acti return nil } +func (self *ApierV1) RemoveActionPlan(attr AttrGetActionPlan, reply *string) (err error) { + if missing := utils.MissingStructFields(&attr, []string{"ID"}); len(missing) != 0 { + return utils.NewErrMandatoryIeMissing(missing...) + } + if _, err = guardian.Guardian.Guard(func() (interface{}, error) { + var prevAccountIDs utils.StringMap + if prevAP, err := self.DataManager.DataDB().GetActionPlan(attr.ID, false, utils.NonTransactional); err != nil && err != utils.ErrNotFound { + return 0, err + } else if prevAP != nil { + prevAccountIDs = prevAP.AccountIDs + } + if err := self.DataManager.DataDB().RemoveActionPlan(attr.ID, utils.NonTransactional); err != nil { + return 0, err + } + for acntID := range prevAccountIDs { + if err := self.DataManager.DataDB().RemAccountActionPlans(acntID, []string{attr.ID}); err != nil { + return 0, utils.NewErrServerError(err) + } + } + if len(prevAccountIDs) != 0 { + if err = self.DataManager.CacheDataFromDB(utils.AccountActionPlansPrefix, prevAccountIDs.Slice(), true); err != nil && + err.Error() != utils.ErrNotFound.Error() { + return 0, utils.NewErrServerError(err) + } + } + return 0, nil + }, config.CgrConfig().GeneralCfg().LockingTimeout, utils.ACTION_PLAN_PREFIX); err != nil { + return err + } + *reply = OK + return nil +} + // Process dependencies and load a specific AccountActions profile from storDb into dataDb. func (self *ApierV1) LoadAccountActions(attrs utils.TPAccountActions, reply *string) error { if len(attrs.TPid) == 0 { diff --git a/console/actionplan_remove.go b/console/actionplan_remove.go new file mode 100644 index 000000000..67bb1da86 --- /dev/null +++ b/console/actionplan_remove.go @@ -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 +*/ + +package console + +import ( + v1 "github.com/cgrates/cgrates/apier/v1" +) + +func init() { + c := &CmdRemoveActionPlan{ + name: "actionplan_remove", + rpcMethod: "ApierV1.RemoveActionPlan", + rpcParams: &v1.AttrGetActionPlan{}, + } + commands[c.Name()] = c + c.CommandExecuter = &CommandExecuter{c} +} + +// Commander implementation +type CmdRemoveActionPlan struct { + name string + rpcMethod string + rpcParams *v1.AttrGetActionPlan + *CommandExecuter +} + +func (self *CmdRemoveActionPlan) Name() string { + return self.name +} + +func (self *CmdRemoveActionPlan) RpcMethod() string { + return self.rpcMethod +} + +func (self *CmdRemoveActionPlan) RpcParams(reset bool) interface{} { + if reset || self.rpcParams == nil { + self.rpcParams = &v1.AttrGetActionPlan{} + } + return self.rpcParams +} + +func (self *CmdRemoveActionPlan) PostprocessRpcParams() error { + return nil +} + +func (self *CmdRemoveActionPlan) RpcResult() interface{} { + var s string + return &s +}