ApierV1.GetMaxSessionTime, make direction, tenant, account and subject optional in ApierV1.SetDerivedChargers

This commit is contained in:
DanB
2015-02-18 19:35:12 +01:00
parent 8adc935817
commit 01f1b9aa64
4 changed files with 70 additions and 8 deletions

38
apier/v1/callsetup.go Normal file
View File

@@ -0,0 +1,38 @@
/*
Real-time Charging System 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 v1
import (
"github.com/cgrates/cgrates/utils"
"time"
)
// Returns MaxSessionTime in seconds, -1 for no limit
func (self *ApierV1) GetMaxSessionTime(cdr utils.StoredCdr, maxSessionTime *float64) error {
var maxDur float64
if err := self.Responder.GetDerivedMaxSessionTime(&cdr, &maxDur); err != nil {
return err
}
if maxDur == -1.0 {
*maxSessionTime = -1.0
return nil
}
*maxSessionTime = time.Duration(maxDur).Seconds()
return nil
}

View File

@@ -43,8 +43,20 @@ type AttrSetDerivedChargers struct {
}
func (self *ApierV1) SetDerivedChargers(attrs AttrSetDerivedChargers, reply *string) (err error) {
if missing := utils.MissingStructFields(&attrs, []string{"Tenant", "Category", "Direction", "Account", "Subject", "DerivedChargers"}); len(missing) != 0 {
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
if len(attrs.Direction) == 0 {
attrs.Direction = utils.OUT
}
if len(attrs.Tenant) == 0 {
attrs.Tenant = utils.ANY
}
if len(attrs.Category) == 0 {
attrs.Category = utils.ANY
}
if len(attrs.Account) == 0 {
attrs.Account = utils.ANY
}
if len(attrs.Subject) == 0 {
attrs.Subject = utils.ANY
}
for _, dc := range attrs.DerivedChargers {
if _, err = utils.ParseRSRFields(dc.RunFilters, utils.INFIELD_SEP); err != nil { // Make sure rules are OK before loading in db
@@ -67,8 +79,20 @@ type AttrRemDerivedChargers struct {
}
func (self *ApierV1) RemDerivedChargers(attrs AttrRemDerivedChargers, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"Direction", "Tenant", "Category", "Account", "Subject"}); len(missing) != 0 { //Params missing
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
if len(attrs.Direction) == 0 {
attrs.Direction = utils.OUT
}
if len(attrs.Tenant) == 0 {
attrs.Tenant = utils.ANY
}
if len(attrs.Category) == 0 {
attrs.Category = utils.ANY
}
if len(attrs.Account) == 0 {
attrs.Account = utils.ANY
}
if len(attrs.Subject) == 0 {
attrs.Subject = utils.ANY
}
if err := self.AccountDb.SetDerivedChargers(utils.DerivedChargersKey(attrs.Direction, attrs.Tenant, attrs.Category, attrs.Account, attrs.Subject), nil); err != nil {
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())

View File

@@ -68,7 +68,6 @@ func NewCgrJsonCfgFromFile(fpath string) (*CgrJsonCfg, error) {
return nil, err
}
defer cfgFile.Close()
return NewCgrJsonCfgFromReader(cfgFile)
}

View File

@@ -219,8 +219,9 @@ func (rs *Responder) GetSessionRuns(ev utils.Event, sRuns *[]*SessionRun) error
}
func (rs *Responder) GetDerivedChargers(attrs utils.AttrDerivedChargers, dcs *utils.DerivedChargers) error {
// ToDo: Make it work with balancer if needed
if rs.Bal != nil {
return errors.New("BALANCER_UNSUPPORTED_METHOD")
}
if dcsH, err := HandleGetDerivedChargers(accountingStorage, attrs); err != nil {
return err
} else if dcsH != nil {
@@ -231,7 +232,7 @@ func (rs *Responder) GetDerivedChargers(attrs utils.AttrDerivedChargers, dcs *ut
func (rs *Responder) ProcessCdr(cdr *utils.StoredCdr, reply *string) error {
if rs.CdrSrv == nil {
return errors.New("CdrServerNotRunning")
return errors.New("CDR_SERVER_NOT_RUNNING")
}
if err := rs.CdrSrv.ProcessCdr(cdr); err != nil {
return err