mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-20 14:48:43 +05:00
Removed external structs for event charges
This commit is contained in:
committed by
Dan Christian Bogos
parent
ee4a0ad36e
commit
b6b39b0e7d
@@ -51,7 +51,7 @@ func (dS *DispatcherService) AccountsForEvent(args *utils.CGREvent, reply *[]*ut
|
||||
return dS.Dispatch(context.TODO(), args, utils.MetaAccounts, utils.AccountSv1AccountsForEvent, args, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) MaxAbstracts(args *utils.CGREvent, reply *utils.ExtEventCharges) (err error) {
|
||||
func (dS *DispatcherService) MaxAbstracts(args *utils.CGREvent, reply *utils.EventCharges) (err error) {
|
||||
tnt := dS.cfg.GeneralCfg().DefaultTenant
|
||||
if args != nil && args.Tenant != utils.EmptyString {
|
||||
tnt = args.Tenant
|
||||
@@ -65,7 +65,7 @@ func (dS *DispatcherService) MaxAbstracts(args *utils.CGREvent, reply *utils.Ext
|
||||
return dS.Dispatch(context.TODO(), args, utils.MetaAccounts, utils.AccountSv1MaxAbstracts, args, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) DebitAbstracts(args *utils.CGREvent, reply *utils.ExtEventCharges) (err error) {
|
||||
func (dS *DispatcherService) DebitAbstracts(args *utils.CGREvent, reply *utils.EventCharges) (err error) {
|
||||
tnt := dS.cfg.GeneralCfg().DefaultTenant
|
||||
if args != nil && args.Tenant != utils.EmptyString {
|
||||
tnt = args.Tenant
|
||||
@@ -79,7 +79,7 @@ func (dS *DispatcherService) DebitAbstracts(args *utils.CGREvent, reply *utils.E
|
||||
return dS.Dispatch(context.TODO(), args, utils.MetaAccounts, utils.AccountSv1DebitAbstracts, args, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) MaxConcretes(args *utils.CGREvent, reply *utils.ExtEventCharges) (err error) {
|
||||
func (dS *DispatcherService) MaxConcretes(args *utils.CGREvent, reply *utils.EventCharges) (err error) {
|
||||
tnt := dS.cfg.GeneralCfg().DefaultTenant
|
||||
if args != nil && args.Tenant != utils.EmptyString {
|
||||
tnt = args.Tenant
|
||||
@@ -93,7 +93,7 @@ func (dS *DispatcherService) MaxConcretes(args *utils.CGREvent, reply *utils.Ext
|
||||
return dS.Dispatch(context.TODO(), args, utils.MetaAccounts, utils.AccountSv1MaxConcretes, args, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) DebitConcretes(args *utils.CGREvent, reply *utils.ExtEventCharges) (err error) {
|
||||
func (dS *DispatcherService) DebitConcretes(args *utils.CGREvent, reply *utils.EventCharges) (err error) {
|
||||
tnt := dS.cfg.GeneralCfg().DefaultTenant
|
||||
if args != nil && args.Tenant != utils.EmptyString {
|
||||
tnt = args.Tenant
|
||||
|
||||
344
utils/account.go
344
utils/account.go
@@ -19,8 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package utils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
@@ -99,104 +97,6 @@ func NewDefaultBalance(id string) *Balance {
|
||||
}
|
||||
}
|
||||
|
||||
type ExtAccount struct {
|
||||
Tenant string
|
||||
ID string // Account identificator, unique within the tenant
|
||||
FilterIDs []string
|
||||
Weights DynamicWeights
|
||||
Opts map[string]interface{}
|
||||
Balances map[string]*ExtBalance
|
||||
ThresholdIDs []string
|
||||
}
|
||||
|
||||
// AsExtAccount converts Account to ExtAccount
|
||||
func (aC *Account) AsExtAccount() (eAc *ExtAccount, err error) {
|
||||
eAc = &ExtAccount{
|
||||
Tenant: aC.Tenant,
|
||||
ID: aC.ID,
|
||||
}
|
||||
if aC.FilterIDs != nil {
|
||||
eAc.FilterIDs = make([]string, len(aC.FilterIDs))
|
||||
for idx, val := range aC.FilterIDs {
|
||||
eAc.FilterIDs[idx] = val
|
||||
}
|
||||
}
|
||||
if aC.Weights != nil {
|
||||
eAc.Weights = aC.Weights
|
||||
}
|
||||
if aC.Opts != nil {
|
||||
eAc.Opts = make(map[string]interface{}, len(aC.Opts))
|
||||
for key, val := range aC.Opts {
|
||||
eAc.Opts[key] = val
|
||||
}
|
||||
}
|
||||
if aC.Balances != nil {
|
||||
eAc.Balances = make(map[string]*ExtBalance, len(aC.Balances))
|
||||
for key, val := range aC.Balances {
|
||||
if bal, err := val.AsExtBalance(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
eAc.Balances[key] = bal
|
||||
}
|
||||
}
|
||||
}
|
||||
if aC.ThresholdIDs != nil {
|
||||
eAc.ThresholdIDs = make([]string, len(aC.ThresholdIDs))
|
||||
for idx, val := range aC.ThresholdIDs {
|
||||
eAc.ThresholdIDs[idx] = val
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Equals returns the equality between two ExtAccount
|
||||
func (eAc *ExtAccount) Equals(extAc *ExtAccount) (eq bool) {
|
||||
if (eAc.ID != extAc.ID || eAc.Tenant != extAc.Tenant) ||
|
||||
(eAc.FilterIDs == nil && extAc.FilterIDs != nil ||
|
||||
eAc.FilterIDs != nil && extAc.FilterIDs == nil ||
|
||||
len(eAc.FilterIDs) != len(extAc.FilterIDs)) ||
|
||||
(eAc.Weights == nil && extAc.Weights != nil ||
|
||||
eAc.Weights != nil && extAc.Weights == nil ||
|
||||
len(eAc.Weights) != len(extAc.Weights)) ||
|
||||
(eAc.Opts == nil && extAc.Opts != nil ||
|
||||
eAc.Opts != nil && extAc.Opts == nil ||
|
||||
len(eAc.Opts) != len(extAc.Opts)) ||
|
||||
(eAc.Balances == nil && extAc.Balances != nil ||
|
||||
eAc.Balances != nil && extAc.Balances == nil ||
|
||||
len(eAc.Balances) != len(extAc.Balances)) ||
|
||||
(eAc.ThresholdIDs == nil && extAc.ThresholdIDs != nil ||
|
||||
eAc.ThresholdIDs != nil && extAc.ThresholdIDs == nil ||
|
||||
len(eAc.ThresholdIDs) != len(extAc.ThresholdIDs)) {
|
||||
return
|
||||
}
|
||||
for idx, val := range eAc.FilterIDs {
|
||||
if val != extAc.FilterIDs[idx] {
|
||||
return
|
||||
}
|
||||
}
|
||||
for idx, val := range eAc.Weights {
|
||||
if ok := val.Equals(extAc.Weights[idx]); !ok {
|
||||
return
|
||||
}
|
||||
}
|
||||
for key, val := range eAc.Opts {
|
||||
if val != extAc.Opts[key] {
|
||||
return
|
||||
}
|
||||
}
|
||||
for key, val := range eAc.Balances {
|
||||
if ok := val.Equals(extAc.Balances[key]); !ok {
|
||||
return
|
||||
}
|
||||
}
|
||||
for idx, val := range eAc.ThresholdIDs {
|
||||
if val != extAc.ThresholdIDs[idx] {
|
||||
return
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Balance represents one Balance inside an Account
|
||||
type Balance struct {
|
||||
ID string // Balance identificator, unique within an Account
|
||||
@@ -211,148 +111,6 @@ type Balance struct {
|
||||
RateProfileIDs []string
|
||||
}
|
||||
|
||||
type ExtBalance struct {
|
||||
ID string // Balance identificator, unique within an Account
|
||||
FilterIDs []string
|
||||
Weights DynamicWeights
|
||||
Type string
|
||||
Units *float64
|
||||
UnitFactors []*ExtUnitFactor
|
||||
Opts map[string]interface{}
|
||||
CostIncrements []*ExtCostIncrement
|
||||
AttributeIDs []string
|
||||
RateProfileIDs []string
|
||||
}
|
||||
|
||||
// AsExtBalance converts Balance to ExtBalance
|
||||
func (bL *Balance) AsExtBalance() (eBl *ExtBalance, err error) {
|
||||
eBl = &ExtBalance{
|
||||
ID: bL.ID,
|
||||
Type: bL.Type,
|
||||
}
|
||||
if bL.FilterIDs != nil {
|
||||
eBl.FilterIDs = make([]string, len(bL.FilterIDs))
|
||||
for idx, val := range bL.FilterIDs {
|
||||
eBl.FilterIDs[idx] = val
|
||||
}
|
||||
}
|
||||
if bL.Weights != nil {
|
||||
eBl.Weights = bL.Weights
|
||||
}
|
||||
if bL.Units != nil {
|
||||
fltUnits, ok := bL.Units.Big.Float64()
|
||||
if !ok {
|
||||
Logger.Warning(fmt.Sprintf("Units Balance: %v from ID: %v cannot fit into a float64 without truncation, overflow, or underflow", bL.Units, bL.ID))
|
||||
}
|
||||
eBl.Units = &fltUnits
|
||||
}
|
||||
if bL.UnitFactors != nil {
|
||||
eBl.UnitFactors = make([]*ExtUnitFactor, len(bL.UnitFactors))
|
||||
for idx, val := range bL.UnitFactors {
|
||||
if uFctr, err := val.AsExtUnitFactor(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
eBl.UnitFactors[idx] = uFctr
|
||||
}
|
||||
}
|
||||
}
|
||||
if bL.Opts != nil {
|
||||
eBl.Opts = make(map[string]interface{}, len(bL.Opts))
|
||||
for key, val := range bL.Opts {
|
||||
eBl.Opts[key] = val
|
||||
}
|
||||
}
|
||||
if bL.CostIncrements != nil {
|
||||
eBl.CostIncrements = make([]*ExtCostIncrement, len(bL.CostIncrements))
|
||||
for idx, val := range bL.CostIncrements {
|
||||
if extCstIncr, err := val.AsExtCostIncrement(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
eBl.CostIncrements[idx] = extCstIncr
|
||||
}
|
||||
}
|
||||
}
|
||||
if bL.AttributeIDs != nil {
|
||||
eBl.AttributeIDs = make([]string, len(bL.AttributeIDs))
|
||||
for idx, val := range bL.AttributeIDs {
|
||||
eBl.AttributeIDs[idx] = val
|
||||
}
|
||||
}
|
||||
if bL.RateProfileIDs != nil {
|
||||
eBl.RateProfileIDs = make([]string, len(bL.RateProfileIDs))
|
||||
for idx, val := range bL.RateProfileIDs {
|
||||
eBl.RateProfileIDs[idx] = val
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Equals returns the equality between two ExtBalance
|
||||
func (eBL *ExtBalance) Equals(extBl *ExtBalance) (eq bool) {
|
||||
if (eBL.ID != extBl.ID || eBL.Type != extBl.Type) ||
|
||||
(eBL.FilterIDs == nil && extBl.FilterIDs != nil ||
|
||||
eBL.FilterIDs != nil && extBl.FilterIDs == nil ||
|
||||
len(eBL.FilterIDs) != len(extBl.FilterIDs)) ||
|
||||
(eBL.Weights == nil && extBl.Weights != nil ||
|
||||
eBL.Weights != nil && extBl.Weights == nil ||
|
||||
len(eBL.Weights) != len(extBl.Weights)) ||
|
||||
!((eBL.Units == nil && extBl.Units == nil) ||
|
||||
(eBL.Units != nil && extBl.Units != nil && *eBL.Units == *extBl.Units)) ||
|
||||
(eBL.UnitFactors == nil && extBl.UnitFactors != nil ||
|
||||
eBL.UnitFactors != nil && extBl.UnitFactors == nil ||
|
||||
len(eBL.UnitFactors) != len(extBl.UnitFactors)) ||
|
||||
(eBL.Opts == nil && extBl.Opts != nil ||
|
||||
eBL.Opts != nil && extBl.Opts == nil ||
|
||||
len(eBL.Opts) != len(extBl.Opts)) ||
|
||||
(eBL.CostIncrements == nil && extBl.CostIncrements != nil ||
|
||||
eBL.CostIncrements != nil && extBl.CostIncrements == nil ||
|
||||
len(eBL.CostIncrements) != len(extBl.CostIncrements)) ||
|
||||
(eBL.AttributeIDs == nil && extBl.AttributeIDs != nil ||
|
||||
eBL.AttributeIDs != nil && extBl.AttributeIDs == nil ||
|
||||
len(eBL.AttributeIDs) != len(extBl.AttributeIDs)) ||
|
||||
(eBL.RateProfileIDs == nil && extBl.RateProfileIDs != nil ||
|
||||
eBL.RateProfileIDs != nil && extBl.RateProfileIDs == nil ||
|
||||
len(eBL.RateProfileIDs) != len(extBl.RateProfileIDs)) {
|
||||
return
|
||||
}
|
||||
for i, val := range eBL.FilterIDs {
|
||||
if val != extBl.FilterIDs[i] {
|
||||
return
|
||||
}
|
||||
}
|
||||
for idx, val := range eBL.Weights {
|
||||
if ok := val.Equals(extBl.Weights[idx]); !ok {
|
||||
return
|
||||
}
|
||||
}
|
||||
for idx, val := range eBL.UnitFactors {
|
||||
if ok := val.Equals(extBl.UnitFactors[idx]); !ok {
|
||||
return
|
||||
}
|
||||
}
|
||||
for key, val := range eBL.Opts {
|
||||
if val != extBl.Opts[key] {
|
||||
return
|
||||
}
|
||||
}
|
||||
for idx, val := range eBL.CostIncrements {
|
||||
if ok := val.Equals(extBl.CostIncrements[idx]); !ok {
|
||||
return
|
||||
}
|
||||
}
|
||||
for i, val := range eBL.AttributeIDs {
|
||||
if val != extBl.AttributeIDs[i] {
|
||||
return
|
||||
}
|
||||
}
|
||||
for i, val := range eBL.RateProfileIDs {
|
||||
if val != extBl.RateProfileIDs[i] {
|
||||
return
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Equals returns the equality between two Balance
|
||||
func (bL *Balance) Equals(bal *Balance) (eq bool) {
|
||||
if (bL.ID != bal.ID || bL.Type != bal.Type) ||
|
||||
@@ -428,67 +186,6 @@ type CostIncrement struct {
|
||||
RecurrentFee *Decimal
|
||||
}
|
||||
|
||||
type ExtCostIncrement struct {
|
||||
FilterIDs []string
|
||||
Increment *float64
|
||||
FixedFee *float64
|
||||
RecurrentFee *float64
|
||||
}
|
||||
|
||||
// Equals returns the equality between two ExtCostIncrement
|
||||
func (eCi *ExtCostIncrement) Equals(extCi *ExtCostIncrement) (eq bool) {
|
||||
if (eCi.FilterIDs == nil && extCi.FilterIDs != nil ||
|
||||
eCi.FilterIDs != nil && extCi.FilterIDs == nil ||
|
||||
len(eCi.FilterIDs) != len(extCi.FilterIDs)) ||
|
||||
!((eCi.Increment == nil && extCi.Increment == nil) ||
|
||||
(eCi.Increment != nil && extCi.Increment != nil && *eCi.Increment == *extCi.Increment)) ||
|
||||
!((eCi.FixedFee == nil && extCi.FixedFee == nil) ||
|
||||
(eCi.FixedFee != nil && extCi.FixedFee != nil && *eCi.FixedFee == *extCi.FixedFee)) ||
|
||||
!((eCi.RecurrentFee == nil && extCi.RecurrentFee == nil) ||
|
||||
(eCi.RecurrentFee != nil && extCi.RecurrentFee != nil && *eCi.RecurrentFee == *extCi.RecurrentFee)) {
|
||||
return
|
||||
}
|
||||
for idx, val := range eCi.FilterIDs {
|
||||
if val != extCi.FilterIDs[idx] {
|
||||
return
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// AsExtCostIncrement converts CostIncrement to ExtCostIncrement
|
||||
func (cI *CostIncrement) AsExtCostIncrement() (eCi *ExtCostIncrement, err error) {
|
||||
eCi = new(ExtCostIncrement)
|
||||
if cI.FilterIDs != nil {
|
||||
eCi.FilterIDs = make([]string, len(cI.FilterIDs))
|
||||
for idx, val := range cI.FilterIDs {
|
||||
eCi.FilterIDs[idx] = val
|
||||
}
|
||||
}
|
||||
if cI.Increment != nil {
|
||||
if fltIncr, ok := cI.Increment.Big.Float64(); !ok {
|
||||
return nil, errors.New("cannot convert decimal Increment to float64 ")
|
||||
} else {
|
||||
eCi.Increment = &fltIncr
|
||||
}
|
||||
}
|
||||
if cI.FixedFee != nil {
|
||||
if fltFxdFee, ok := cI.FixedFee.Big.Float64(); !ok {
|
||||
return nil, errors.New("cannot convert decimal FixedFee to float64 ")
|
||||
} else {
|
||||
eCi.FixedFee = &fltFxdFee
|
||||
}
|
||||
}
|
||||
if cI.RecurrentFee != nil {
|
||||
if fltRecFee, ok := cI.RecurrentFee.Big.Float64(); !ok {
|
||||
return nil, errors.New("cannot convert decimal RecurrentFee to float64 ")
|
||||
} else {
|
||||
eCi.RecurrentFee = &fltRecFee
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Equals returns the equality between two CostIncrement
|
||||
func (cI *CostIncrement) Equals(ctIn *CostIncrement) (eq bool) {
|
||||
if (cI.FilterIDs == nil && ctIn.FilterIDs != nil ||
|
||||
@@ -537,47 +234,6 @@ func (cI *CostIncrement) Clone() (cIcln *CostIncrement) {
|
||||
return
|
||||
}
|
||||
|
||||
type ExtUnitFactor struct {
|
||||
FilterIDs []string
|
||||
Factor *float64
|
||||
}
|
||||
|
||||
// AsExtUnitFactor converts UnitFactor to ExtUnitFactor
|
||||
func (uF *UnitFactor) AsExtUnitFactor() (eUf *ExtUnitFactor, err error) {
|
||||
eUf = new(ExtUnitFactor)
|
||||
if uF.FilterIDs != nil {
|
||||
eUf.FilterIDs = make([]string, len(uF.FilterIDs))
|
||||
for idx, val := range uF.FilterIDs {
|
||||
eUf.FilterIDs[idx] = val
|
||||
}
|
||||
}
|
||||
if uF.Factor != nil {
|
||||
if fltFct, ok := uF.Factor.Big.Float64(); !ok {
|
||||
return nil, errors.New("cannot convert decimal Factor to float64 ")
|
||||
} else {
|
||||
eUf.Factor = &fltFct
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Equals compares two ExtUnitFactor
|
||||
func (eUf *ExtUnitFactor) Equals(extUf *ExtUnitFactor) (eq bool) {
|
||||
if (eUf.FilterIDs == nil && extUf.FilterIDs != nil ||
|
||||
eUf.FilterIDs != nil && extUf.FilterIDs == nil ||
|
||||
len(eUf.FilterIDs) != len(extUf.FilterIDs)) ||
|
||||
!((eUf.Factor == nil && extUf.Factor == nil) ||
|
||||
(eUf.Factor != nil && extUf.Factor != nil && *eUf.Factor == *extUf.Factor)) {
|
||||
return
|
||||
}
|
||||
for idx, val := range eUf.FilterIDs {
|
||||
if val != extUf.FilterIDs[idx] {
|
||||
return
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Clone return a copy of the UnitFactor
|
||||
func (uF *UnitFactor) Clone() (untFct *UnitFactor) {
|
||||
untFct = new(UnitFactor)
|
||||
|
||||
@@ -18,10 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
// NewEventChargers instantiates the EventChargers in a central place
|
||||
func NewEventCharges() (ec *EventCharges) {
|
||||
ec = &EventCharges{
|
||||
@@ -148,131 +144,6 @@ func (ec *EventCharges) SyncIDs(eCs ...*EventCharges) {
|
||||
}
|
||||
}
|
||||
|
||||
// AsExtEventCharges converts EventCharges to ExtEventCharges
|
||||
func (ec *EventCharges) AsExtEventCharges() (eEc *ExtEventCharges, err error) {
|
||||
eEc = new(ExtEventCharges)
|
||||
if ec.Abstracts != nil {
|
||||
if flt, ok := ec.Abstracts.Big.Float64(); !ok {
|
||||
return nil, errors.New("cannot convert decimal Abstracts to float64")
|
||||
} else {
|
||||
eEc.Abstracts = &flt
|
||||
}
|
||||
}
|
||||
if ec.Concretes != nil {
|
||||
if flt, ok := ec.Concretes.Big.Float64(); !ok {
|
||||
return nil, errors.New("cannot convert decimal Concretes to float64")
|
||||
} else {
|
||||
eEc.Concretes = &flt
|
||||
}
|
||||
}
|
||||
if ec.Charges != nil {
|
||||
eEc.Charges = make([]*ChargeEntry, len(ec.Charges))
|
||||
for idx, val := range ec.Charges {
|
||||
eEc.Charges[idx] = val
|
||||
}
|
||||
}
|
||||
if ec.Accounting != nil {
|
||||
eEc.Accounting = make(map[string]*ExtAccountCharge, len(eEc.Accounting))
|
||||
for key, val := range ec.Accounting {
|
||||
if eEc.Accounting[key], err = val.AsExtAccountCharge(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
if ec.UnitFactors != nil {
|
||||
eEc.UnitFactors = make(map[string]*ExtUnitFactor, len(ec.UnitFactors))
|
||||
for key, val := range ec.UnitFactors {
|
||||
if eEc.UnitFactors[key], err = val.AsExtUnitFactor(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
if ec.Rating != nil {
|
||||
eEc.Rating = make(map[string]*ExtRateSInterval, len(ec.Rating))
|
||||
for key, val := range ec.Rating {
|
||||
if eEc.Rating[key], err = val.AsExtRateSInterval(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
if ec.Rates != nil {
|
||||
eEc.Rates = make(map[string]*ExtIntervalRate, len(ec.Rates))
|
||||
for key, val := range ec.Rates {
|
||||
if eEc.Rates[key], err = val.AsExtIntervalRate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
if ec.Accounts != nil {
|
||||
eEc.Accounts = make(map[string]*ExtAccount, len(ec.Accounts))
|
||||
for acntID, acnt := range ec.Accounts {
|
||||
if eEc.Accounts[acntID], err = acnt.AsExtAccount(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Equals returns the equality between two ExtEventCharges
|
||||
func (eEc *ExtEventCharges) Equals(exCh *ExtEventCharges) (eq bool) {
|
||||
if !((eEc.Abstracts == nil && exCh.Abstracts == nil) ||
|
||||
(eEc.Abstracts != nil && exCh.Abstracts != nil &&
|
||||
*eEc.Abstracts == *exCh.Abstracts)) ||
|
||||
!((eEc.Concretes == nil && exCh.Concretes == nil) ||
|
||||
(eEc.Concretes != nil && exCh.Concretes != nil &&
|
||||
*eEc.Concretes == *exCh.Concretes)) ||
|
||||
(eEc.Charges == nil && exCh.Charges != nil ||
|
||||
eEc.Charges != nil && exCh.Charges == nil ||
|
||||
len(eEc.Charges) != len(exCh.Charges)) ||
|
||||
(eEc.Accounting == nil && exCh.Accounting != nil ||
|
||||
eEc.Accounting != nil && exCh.Accounting == nil ||
|
||||
len(eEc.Accounting) != len(exCh.Accounting)) ||
|
||||
(eEc.UnitFactors == nil && exCh.UnitFactors != nil ||
|
||||
eEc.UnitFactors != nil && exCh.UnitFactors == nil ||
|
||||
len(eEc.UnitFactors) != len(exCh.UnitFactors)) ||
|
||||
(eEc.Rating == nil && exCh.Rating != nil ||
|
||||
eEc.Rating != nil && exCh.Rating == nil ||
|
||||
len(eEc.Rating) != len(exCh.Rating)) ||
|
||||
(eEc.Rates == nil && exCh.Rates != nil ||
|
||||
eEc.Rates != nil && exCh.Rates == nil ||
|
||||
len(eEc.Rates) != len(exCh.Rates)) ||
|
||||
(eEc.Accounts == nil && exCh.Accounts != nil ||
|
||||
eEc.Accounts != nil && exCh.Accounts == nil ||
|
||||
len(eEc.Accounts) != len(exCh.Accounts)) {
|
||||
return
|
||||
}
|
||||
/*
|
||||
for idx, val := range exCh.Charges {
|
||||
if ok := val.Equals(exCh.Charges[idx], eEc.Accounting, exCh.Accounting); !ok {
|
||||
return
|
||||
}
|
||||
}
|
||||
for key, val := range eEc.Accounting {
|
||||
if ok := val.Equals(exCh.Accounting[key]); !ok {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
for key, val := range eEc.UnitFactors {
|
||||
if ok := val.Equals(exCh.UnitFactors[key]); !ok {
|
||||
return
|
||||
}
|
||||
}
|
||||
for key, val := range eEc.Rating {
|
||||
if ok := val.Equals(exCh.Rating[key], eEc.Rates, exCh.Rates); !ok {
|
||||
return
|
||||
}
|
||||
}
|
||||
for key, val := range eEc.Accounts {
|
||||
if ok := val.Equals(exCh.Accounts[key]); !ok {
|
||||
return
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Equals returns the equality between two EventCharges
|
||||
func (eC *EventCharges) Equals(evCh *EventCharges) (eq bool) {
|
||||
if eC == nil && evCh == nil {
|
||||
@@ -376,26 +247,6 @@ func (ec *EventCharges) accountChargeID(ac *AccountCharge) (acID string) {
|
||||
return
|
||||
}
|
||||
|
||||
// ExtEventCharges is a generic EventCharges used in APIs
|
||||
type ExtEventCharges struct {
|
||||
Abstracts *float64
|
||||
Concretes *float64
|
||||
|
||||
Charges []*ChargeEntry
|
||||
|
||||
Accounting map[string]*ExtAccountCharge
|
||||
UnitFactors map[string]*ExtUnitFactor
|
||||
Rating map[string]*ExtRateSInterval
|
||||
Rates map[string]*ExtIntervalRate
|
||||
Accounts map[string]*ExtAccount
|
||||
}
|
||||
|
||||
type ExtChargingIncrement struct {
|
||||
Units *float64
|
||||
AccountChargeID string
|
||||
CompressFactor int
|
||||
}
|
||||
|
||||
// AccountCharge represents one Account charge
|
||||
type AccountCharge struct {
|
||||
AccountID string
|
||||
@@ -408,85 +259,6 @@ type AccountCharge struct {
|
||||
JoinedChargeIDs []string // identificator of extra account charges
|
||||
}
|
||||
|
||||
type ExtAccountCharge struct {
|
||||
AccountID string
|
||||
BalanceID string
|
||||
Units *float64
|
||||
BalanceLimit *float64 // the minimum balance value accepted(float64 type)
|
||||
UnitFactorID string // identificator in ChargingUnitFactors
|
||||
AttributeIDs []string // list of attribute profiles matched
|
||||
RatingID string // identificator in cost increments
|
||||
JoinedChargeIDs []string // identificator of extra account charges
|
||||
}
|
||||
|
||||
// AsExtAccountCharge converts AccountCharge to ExtAccountCharge
|
||||
func (aC *AccountCharge) AsExtAccountCharge() (eAc *ExtAccountCharge, err error) {
|
||||
eAc = &ExtAccountCharge{
|
||||
AccountID: aC.AccountID,
|
||||
BalanceID: aC.BalanceID,
|
||||
UnitFactorID: aC.UnitFactorID,
|
||||
RatingID: aC.RatingID,
|
||||
}
|
||||
if aC.Units != nil {
|
||||
if fltUnit, ok := aC.Units.Big.Float64(); !ok {
|
||||
return nil, errors.New("cannot convert decimal Units to float64 ")
|
||||
} else {
|
||||
eAc.Units = &fltUnit
|
||||
}
|
||||
}
|
||||
if aC.BalanceLimit != nil {
|
||||
if fltBlUnit, ok := aC.BalanceLimit.Big.Float64(); !ok {
|
||||
return nil, errors.New("cannot convert decimal BalanceLimit to float64 ")
|
||||
} else {
|
||||
eAc.BalanceLimit = &fltBlUnit
|
||||
}
|
||||
}
|
||||
if aC.AttributeIDs != nil {
|
||||
eAc.AttributeIDs = make([]string, len(aC.AttributeIDs))
|
||||
for idx, val := range aC.AttributeIDs {
|
||||
eAc.AttributeIDs[idx] = val
|
||||
}
|
||||
}
|
||||
if aC.JoinedChargeIDs != nil {
|
||||
eAc.JoinedChargeIDs = make([]string, len(aC.JoinedChargeIDs))
|
||||
for idx, val := range aC.JoinedChargeIDs {
|
||||
eAc.JoinedChargeIDs[idx] = val
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Equals compares two ExtAccountCharge
|
||||
func (eAc *ExtAccountCharge) Equals(extAc *ExtAccountCharge) (eq bool) {
|
||||
if (eAc.AttributeIDs == nil && extAc.AttributeIDs != nil ||
|
||||
eAc.AttributeIDs != nil && extAc.AttributeIDs == nil ||
|
||||
len(eAc.AttributeIDs) != len(extAc.AttributeIDs)) ||
|
||||
(eAc.JoinedChargeIDs == nil && extAc.JoinedChargeIDs != nil ||
|
||||
eAc.JoinedChargeIDs != nil && extAc.JoinedChargeIDs == nil ||
|
||||
len(eAc.JoinedChargeIDs) != len(extAc.JoinedChargeIDs)) ||
|
||||
(eAc.AccountID != extAc.AccountID ||
|
||||
eAc.BalanceID != extAc.BalanceID ||
|
||||
eAc.UnitFactorID != extAc.UnitFactorID ||
|
||||
eAc.RatingID != extAc.RatingID) ||
|
||||
!((eAc.Units == nil && extAc.Units == nil) ||
|
||||
(eAc.Units != nil && extAc.Units != nil && *eAc.Units == *extAc.Units)) ||
|
||||
!((eAc.BalanceLimit == nil && extAc.BalanceLimit == nil) ||
|
||||
(eAc.BalanceLimit != nil && extAc.BalanceLimit != nil && *eAc.BalanceLimit == *extAc.BalanceLimit)) {
|
||||
return
|
||||
}
|
||||
for idx, val := range eAc.AttributeIDs {
|
||||
if val != extAc.AttributeIDs[idx] {
|
||||
return
|
||||
}
|
||||
}
|
||||
for idx, val := range eAc.JoinedChargeIDs {
|
||||
if val != extAc.JoinedChargeIDs[idx] {
|
||||
return
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Equals compares two AccountCharges
|
||||
func (ac *AccountCharge) equals(nAc *AccountCharge) (eq bool) {
|
||||
if ac == nil && nAc == nil {
|
||||
|
||||
@@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package utils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"time"
|
||||
@@ -67,86 +66,6 @@ type Rate struct {
|
||||
uID string
|
||||
}
|
||||
|
||||
type ExtRate struct {
|
||||
ID string // RateID
|
||||
FilterIDs []string // RateFilterIDs
|
||||
ActivationTimes string // ActivationTimes is a cron formatted time interval
|
||||
Weights DynamicWeights // RateWeight will decide the winner per interval start
|
||||
Blocker bool // RateBlocker will make this rate recurrent, deactivating further intervals
|
||||
IntervalRates []*ExtIntervalRate
|
||||
|
||||
sched cron.Schedule // compiled version of activation times as cron.Schedule interface
|
||||
uID string
|
||||
}
|
||||
|
||||
// Equals returns the equality between two ExtRate
|
||||
func (eRt *ExtRate) Equals(extRT *ExtRate) (eq bool) {
|
||||
if (eRt.ID != extRT.ID ||
|
||||
eRt.ActivationTimes != extRT.ActivationTimes ||
|
||||
eRt.Blocker != extRT.Blocker) ||
|
||||
(eRt.FilterIDs == nil && extRT.FilterIDs != nil ||
|
||||
eRt.FilterIDs != nil && extRT.FilterIDs == nil) ||
|
||||
(eRt.Weights == nil && extRT.Weights != nil ||
|
||||
eRt.Weights != nil && extRT.Weights == nil ||
|
||||
len(eRt.Weights) != len(extRT.Weights)) ||
|
||||
(eRt.IntervalRates == nil && extRT.IntervalRates != nil ||
|
||||
eRt.IntervalRates != nil && extRT.IntervalRates == nil ||
|
||||
len(eRt.IntervalRates) != len(extRT.IntervalRates)) {
|
||||
return
|
||||
}
|
||||
for idx, val := range eRt.FilterIDs {
|
||||
if val != extRT.FilterIDs[idx] {
|
||||
return
|
||||
}
|
||||
}
|
||||
if eRt.Weights != nil && extRT.Weights != nil {
|
||||
for idx, val := range eRt.Weights {
|
||||
if ok := val.Equals(extRT.Weights[idx]); !ok {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
if eRt.IntervalRates != nil && extRT.IntervalRates != nil {
|
||||
for idx, val := range eRt.IntervalRates {
|
||||
if ok := val.Equals(extRT.IntervalRates[idx]); !ok {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// AsExtRate converts Rate to ExtRate
|
||||
func (rT *Rate) AsExtRate() (eRt *ExtRate, err error) {
|
||||
eRt = &ExtRate{
|
||||
ID: rT.ID,
|
||||
ActivationTimes: rT.ActivationTimes,
|
||||
sched: rT.sched,
|
||||
uID: rT.uID,
|
||||
Blocker: rT.Blocker,
|
||||
}
|
||||
if rT.FilterIDs != nil {
|
||||
eRt.FilterIDs = make([]string, len(rT.FilterIDs))
|
||||
for idx, val := range rT.FilterIDs {
|
||||
eRt.FilterIDs[idx] = val
|
||||
}
|
||||
}
|
||||
if rT.Weights != nil {
|
||||
eRt.Weights = rT.Weights
|
||||
}
|
||||
if rT.IntervalRates != nil {
|
||||
eRt.IntervalRates = make([]*ExtIntervalRate, len(rT.IntervalRates))
|
||||
for idx, val := range rT.IntervalRates {
|
||||
if rcvIntv, err := val.AsExtIntervalRate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
eRt.IntervalRates[idx] = rcvIntv
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// UID returns system wide unique identifier
|
||||
func (rt *Rate) UID() string {
|
||||
return rt.uID
|
||||
@@ -160,72 +79,6 @@ type IntervalRate struct {
|
||||
Increment *Decimal // RateIncrement
|
||||
}
|
||||
|
||||
type ExtIntervalRate struct {
|
||||
IntervalStart *float64 // Starting point when the Rate kicks in
|
||||
FixedFee *float64
|
||||
RecurrentFee *float64
|
||||
Unit *float64 // RateUnit
|
||||
Increment *float64 // RateIncrement
|
||||
}
|
||||
|
||||
// AsExtIntervalRate converts IntervalRate to ExtIntervalRate
|
||||
func (iR *IntervalRate) AsExtIntervalRate() (eIr *ExtIntervalRate, err error) {
|
||||
eIr = new(ExtIntervalRate)
|
||||
if iR.IntervalStart != nil {
|
||||
if fltIntSt, ok := iR.IntervalStart.Big.Float64(); !ok {
|
||||
return nil, errors.New("cannot convert decimal IntervalStart to float64")
|
||||
} else {
|
||||
eIr.IntervalStart = &fltIntSt
|
||||
}
|
||||
}
|
||||
if iR.FixedFee != nil {
|
||||
if fltFxdFee, ok := iR.FixedFee.Big.Float64(); !ok {
|
||||
return nil, errors.New("cannot convert decimal FixedFee to float64")
|
||||
} else {
|
||||
eIr.FixedFee = &fltFxdFee
|
||||
}
|
||||
}
|
||||
if iR.RecurrentFee != nil {
|
||||
if fltRecFee, ok := iR.RecurrentFee.Big.Float64(); !ok {
|
||||
return nil, errors.New("cannot convert decimal RecurrentFee to float64")
|
||||
} else {
|
||||
eIr.RecurrentFee = &fltRecFee
|
||||
}
|
||||
}
|
||||
if iR.Unit != nil {
|
||||
if fltUnit, ok := iR.Unit.Big.Float64(); !ok {
|
||||
return nil, errors.New("cannot convert decimal Unit to float64")
|
||||
} else {
|
||||
eIr.Unit = &fltUnit
|
||||
}
|
||||
}
|
||||
if iR.Increment != nil {
|
||||
if fltIncr, ok := iR.Increment.Big.Float64(); !ok {
|
||||
return nil, errors.New("cannot convert decimal Increment to float64")
|
||||
} else {
|
||||
eIr.Increment = &fltIncr
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Equals returns the equality between two ExtIntervalRate
|
||||
func (eIr *ExtIntervalRate) Equals(extIr *ExtIntervalRate) (eq bool) {
|
||||
if !((eIr.IntervalStart == nil && extIr.IntervalStart == nil) ||
|
||||
(eIr.IntervalStart != nil && extIr.IntervalStart != nil && *eIr.IntervalStart == *extIr.IntervalStart)) ||
|
||||
!((eIr.FixedFee == nil && extIr.FixedFee == nil) ||
|
||||
(eIr.FixedFee != nil && extIr.FixedFee != nil && *eIr.FixedFee == *extIr.FixedFee)) ||
|
||||
!((eIr.RecurrentFee == nil && extIr.RecurrentFee == nil) ||
|
||||
(eIr.RecurrentFee != nil && extIr.RecurrentFee != nil && *eIr.RecurrentFee == *extIr.RecurrentFee)) ||
|
||||
!((eIr.Unit == nil && extIr.Unit == nil) ||
|
||||
(eIr.Unit != nil && extIr.Unit != nil && *eIr.Unit == *extIr.Unit)) ||
|
||||
!((eIr.Increment == nil && extIr.Increment == nil) ||
|
||||
(eIr.Increment != nil && extIr.Increment != nil && *eIr.Increment == *extIr.Increment)) {
|
||||
return
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Equals returns the equality between two IntervalRate
|
||||
func (iR *IntervalRate) Equals(inRt *IntervalRate) (eq bool) {
|
||||
if iR == nil && inRt == nil {
|
||||
@@ -310,14 +163,6 @@ type RateSInterval struct {
|
||||
cost *decimal.Big // unexported total interval cost
|
||||
}
|
||||
|
||||
type ExtRateSInterval struct {
|
||||
IntervalStart *float64
|
||||
Increments []*ExtRateSIncrement
|
||||
CompressFactor int64
|
||||
|
||||
cost *float64 // unexported total interval cost
|
||||
}
|
||||
|
||||
// AsRatesIntervalsCost converts RateSInterval to RateSIntervalCost
|
||||
// The difference between this 2 is that RateSIntervalCost don't need IntervalStart
|
||||
func (rI *RateSInterval) AsRatesIntervalsCost() (rIc *RateSIntervalCost) {
|
||||
@@ -333,56 +178,6 @@ func (rI *RateSInterval) AsRatesIntervalsCost() (rIc *RateSIntervalCost) {
|
||||
return
|
||||
}
|
||||
|
||||
// AsExtRateSInterval converts RateSInterval to ExtRateSInterval
|
||||
func (rI *RateSInterval) AsExtRateSInterval() (eRi *ExtRateSInterval, err error) {
|
||||
eRi = &ExtRateSInterval{
|
||||
CompressFactor: rI.CompressFactor,
|
||||
}
|
||||
if rI.Increments != nil {
|
||||
eRi.Increments = make([]*ExtRateSIncrement, len(rI.Increments))
|
||||
for idx, val := range rI.Increments {
|
||||
if rcv, err := val.AsExtRateSIncrement(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
eRi.Increments[idx] = rcv
|
||||
}
|
||||
}
|
||||
}
|
||||
if rI.IntervalStart != nil {
|
||||
if fltIntStart, ok := rI.IntervalStart.Big.Float64(); !ok {
|
||||
return nil, errors.New("Cannot convert decimal IntervalStart into float64 ")
|
||||
} else {
|
||||
eRi.IntervalStart = &fltIntStart
|
||||
}
|
||||
}
|
||||
if rI.cost != nil {
|
||||
if fltCost, ok := rI.cost.Float64(); !ok {
|
||||
return nil, errors.New("Cannot convert decimal cost into float64 ")
|
||||
} else {
|
||||
eRi.cost = &fltCost
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Equals compares two ExtRateSInterval
|
||||
func (rIl *ExtRateSInterval) Equals(nRil *ExtRateSInterval, exInRt, exInRtRef map[string]*ExtIntervalRate) (eq bool) {
|
||||
if !((rIl.IntervalStart == nil && nRil.IntervalStart == nil) ||
|
||||
(rIl.IntervalStart != nil && nRil.IntervalStart != nil && *rIl.IntervalStart == *nRil.IntervalStart)) ||
|
||||
(rIl.Increments == nil && nRil.Increments != nil ||
|
||||
rIl.Increments != nil && nRil.Increments == nil ||
|
||||
len(rIl.Increments) != len(nRil.Increments)) ||
|
||||
(rIl.CompressFactor != nRil.CompressFactor) {
|
||||
return
|
||||
}
|
||||
for i, rtIn := range rIl.Increments {
|
||||
if !rtIn.Equals(nRil.Increments[i], exInRt, exInRtRef) {
|
||||
return
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
type RateSIncrement struct {
|
||||
IncrementStart *Decimal
|
||||
RateIntervalIndex int
|
||||
@@ -393,58 +188,6 @@ type RateSIncrement struct {
|
||||
cost *decimal.Big // unexported total increment cost
|
||||
}
|
||||
|
||||
type ExtRateSIncrement struct {
|
||||
IncrementStart *float64
|
||||
IntervalRateIndex int
|
||||
RateID string
|
||||
CompressFactor int64
|
||||
Usage *float64
|
||||
|
||||
cost *float64 // unexported total increment cost
|
||||
}
|
||||
|
||||
//AsExtRateSIncrement converts RateSIncrement to ExtRateSIncrement
|
||||
func (rI *RateSIncrement) AsExtRateSIncrement() (eRi *ExtRateSIncrement, err error) {
|
||||
eRi = &ExtRateSIncrement{
|
||||
IntervalRateIndex: rI.RateIntervalIndex,
|
||||
CompressFactor: rI.CompressFactor,
|
||||
RateID: rI.RateID,
|
||||
}
|
||||
if rI.IncrementStart != nil {
|
||||
if fltIncrStart, ok := rI.IncrementStart.Big.Float64(); !ok {
|
||||
return nil, errors.New("Cannot convert decimal IncrementStart into float64 ")
|
||||
} else {
|
||||
eRi.IncrementStart = &fltIncrStart
|
||||
}
|
||||
}
|
||||
if rI.Usage != nil {
|
||||
if fltUsage, ok := rI.Usage.Big.Float64(); !ok {
|
||||
return nil, errors.New("Cannot convert decimal Usage into float64 ")
|
||||
} else {
|
||||
eRi.Usage = &fltUsage
|
||||
}
|
||||
}
|
||||
if rI.cost != nil {
|
||||
if fltCost, ok := rI.cost.Float64(); !ok {
|
||||
return nil, errors.New("Cannot convert decimal cost into float64 ")
|
||||
} else {
|
||||
eRi.cost = &fltCost
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Equals returns the equality between twoExt RateSIncrement
|
||||
func (eRI *ExtRateSIncrement) Equals(extRI *ExtRateSIncrement, exInRt, exInRtRef map[string]*ExtIntervalRate) (eq bool) {
|
||||
return ((eRI.Usage == nil && extRI.Usage == nil) ||
|
||||
(eRI.Usage != nil && extRI.Usage != nil && *eRI.Usage == *extRI.Usage)) &&
|
||||
((eRI.IncrementStart == nil && extRI.IncrementStart == nil) ||
|
||||
(eRI.IncrementStart != nil && extRI.IncrementStart != nil && *eRI.IncrementStart == *extRI.IncrementStart)) &&
|
||||
(eRI.CompressFactor == extRI.CompressFactor) &&
|
||||
(eRI.IntervalRateIndex == extRI.IntervalRateIndex) &&
|
||||
exInRt[eRI.RateID].Equals(exInRtRef[extRI.RateID])
|
||||
}
|
||||
|
||||
// Equals compares two RateSIntervals
|
||||
func (rIl *RateSInterval) Equals(nRil *RateSInterval, rIlRef, nRilRef map[string]*IntervalRate) (eq bool) {
|
||||
if rIl == nil && nRil == nil {
|
||||
@@ -559,7 +302,7 @@ func (rIncrC *RateSIncrementCost) Equals(nRi *RateSIncrementCost, rIRef, rtInRef
|
||||
!rIRef[rIncrC.RateID].Equals(rtInRef[nRi.RateID])))
|
||||
}
|
||||
|
||||
/*rIncrC
|
||||
/*
|
||||
func (rpC *RateProfileCost) SynchronizeRateKeys(nRpCt *RateProfileCost) {
|
||||
rts := make(map[string]*IntervalRate)
|
||||
reverse := make(map[string]string)
|
||||
|
||||
Reference in New Issue
Block a user