mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-14 20:59:53 +05:00
@@ -54,10 +54,19 @@ type Action struct {
|
||||
balanceValue float64 // balance value after action execution, used with cdrlog
|
||||
}
|
||||
|
||||
func (a *Action) Clone() *Action {
|
||||
var clonedAction Action
|
||||
utils.Clone(a, &clonedAction)
|
||||
return &clonedAction
|
||||
func (a *Action) Clone() (cln *Action) {
|
||||
if a == nil {
|
||||
return
|
||||
}
|
||||
return &Action{
|
||||
Id: a.Id,
|
||||
ActionType: a.ActionType,
|
||||
ExtraParameters: a.ExtraParameters,
|
||||
Filter: a.Filter,
|
||||
ExpirationString: a.ExpirationString,
|
||||
Weight: a.Weight,
|
||||
Balance: a.Balance.Clone(),
|
||||
}
|
||||
}
|
||||
|
||||
type actionTypeFunc func(*Account, *Action, Actions, interface{}) error
|
||||
@@ -868,19 +877,12 @@ func (apl Actions) Sort() {
|
||||
}
|
||||
|
||||
func (apl Actions) Clone() (interface{}, error) {
|
||||
var cln Actions
|
||||
if err := utils.Clone(apl, &cln); err != nil {
|
||||
return nil, err
|
||||
if apl == nil {
|
||||
return nil, nil
|
||||
}
|
||||
for i, act := range apl { // Fix issues with gob cloning nil pointer towards false value
|
||||
if act.Balance != nil {
|
||||
if act.Balance.Disabled != nil && !*act.Balance.Disabled {
|
||||
cln[i].Balance.Disabled = utils.BoolPointer(*act.Balance.Disabled)
|
||||
}
|
||||
if act.Balance.Blocker != nil && !*act.Balance.Blocker {
|
||||
cln[i].Balance.Blocker = utils.BoolPointer(*act.Balance.Blocker)
|
||||
}
|
||||
}
|
||||
cln := make(Actions, len(apl))
|
||||
for i, action := range apl {
|
||||
cln[i] = action.Clone()
|
||||
}
|
||||
return cln, nil
|
||||
}
|
||||
|
||||
@@ -142,18 +142,14 @@ func (bf *BalanceFilter) Clone() *BalanceFilter {
|
||||
result.ID = new(string)
|
||||
*result.ID = *bf.ID
|
||||
}
|
||||
if bf.Value != nil {
|
||||
result.Value = new(utils.ValueFormula)
|
||||
*result.Value = *bf.Value
|
||||
}
|
||||
if bf.RatingSubject != nil {
|
||||
result.RatingSubject = new(string)
|
||||
*result.RatingSubject = *bf.RatingSubject
|
||||
}
|
||||
if bf.Type != nil {
|
||||
result.Type = new(string)
|
||||
*result.Type = *bf.Type
|
||||
}
|
||||
if bf.Value != nil {
|
||||
result.Value = new(utils.ValueFormula)
|
||||
*result.Value = *bf.Value
|
||||
}
|
||||
if bf.ExpirationDate != nil {
|
||||
result.ExpirationDate = new(time.Time)
|
||||
*result.ExpirationDate = *bf.ExpirationDate
|
||||
@@ -162,21 +158,13 @@ func (bf *BalanceFilter) Clone() *BalanceFilter {
|
||||
result.Weight = new(float64)
|
||||
*result.Weight = *bf.Weight
|
||||
}
|
||||
if bf.Disabled != nil {
|
||||
result.Disabled = new(bool)
|
||||
*result.Disabled = *bf.Disabled
|
||||
}
|
||||
if bf.Blocker != nil {
|
||||
result.Blocker = new(bool)
|
||||
*result.Blocker = *bf.Blocker
|
||||
}
|
||||
if bf.Factor != nil {
|
||||
result.Factor = new(ValueFactor)
|
||||
*result.Factor = *bf.Factor
|
||||
}
|
||||
if bf.DestinationIDs != nil {
|
||||
result.DestinationIDs = utils.StringMapPointer(bf.DestinationIDs.Clone())
|
||||
}
|
||||
if bf.RatingSubject != nil {
|
||||
result.RatingSubject = new(string)
|
||||
*result.RatingSubject = *bf.RatingSubject
|
||||
}
|
||||
if bf.Categories != nil {
|
||||
result.Categories = utils.StringMapPointer(bf.Categories.Clone())
|
||||
}
|
||||
@@ -186,7 +174,24 @@ func (bf *BalanceFilter) Clone() *BalanceFilter {
|
||||
if bf.TimingIDs != nil {
|
||||
result.TimingIDs = utils.StringMapPointer(bf.TimingIDs.Clone())
|
||||
}
|
||||
|
||||
if bf.Timings != nil {
|
||||
result.Timings = make([]*RITiming, len(bf.Timings))
|
||||
for i, rit := range bf.Timings {
|
||||
result.Timings[i] = rit.Clone()
|
||||
}
|
||||
}
|
||||
if bf.Disabled != nil {
|
||||
result.Disabled = new(bool)
|
||||
*result.Disabled = *bf.Disabled
|
||||
}
|
||||
if bf.Factor != nil {
|
||||
result.Factor = new(ValueFactor)
|
||||
*result.Factor = *bf.Factor
|
||||
}
|
||||
if bf.Blocker != nil {
|
||||
result.Blocker = new(bool)
|
||||
*result.Blocker = *bf.Blocker
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
@@ -222,9 +222,42 @@ func (cdr *CDR) ParseFieldValue(fieldId, fieldVal, timezone string) error {
|
||||
}
|
||||
|
||||
func (cdr *CDR) Clone() *CDR {
|
||||
var clnedCDR CDR
|
||||
utils.Clone(cdr, &clnedCDR)
|
||||
return &clnedCDR
|
||||
if cdr == nil {
|
||||
return nil
|
||||
}
|
||||
cln := &CDR{
|
||||
CGRID: cdr.CGRID,
|
||||
RunID: cdr.RunID,
|
||||
OrderID: cdr.OrderID,
|
||||
OriginHost: cdr.OriginHost,
|
||||
Source: cdr.Source,
|
||||
OriginID: cdr.OriginID,
|
||||
ToR: cdr.ToR,
|
||||
RequestType: cdr.RequestType,
|
||||
Tenant: cdr.Tenant,
|
||||
Category: cdr.Category,
|
||||
Account: cdr.Account,
|
||||
Subject: cdr.Subject,
|
||||
Destination: cdr.Destination,
|
||||
SetupTime: cdr.SetupTime,
|
||||
AnswerTime: cdr.AnswerTime,
|
||||
Usage: cdr.Usage,
|
||||
ExtraFields: cdr.ExtraFields,
|
||||
ExtraInfo: cdr.ExtraInfo,
|
||||
Partial: cdr.Partial,
|
||||
PreRated: cdr.PreRated,
|
||||
CostSource: cdr.CostSource,
|
||||
Cost: cdr.Cost,
|
||||
CostDetails: cdr.CostDetails.Clone(),
|
||||
}
|
||||
if cdr.ExtraFields != nil {
|
||||
cln.ExtraFields = make(map[string]string, len(cdr.ExtraFields))
|
||||
for key, val := range cdr.ExtraFields {
|
||||
cln.ExtraFields[key] = val
|
||||
}
|
||||
}
|
||||
|
||||
return cln
|
||||
}
|
||||
|
||||
func (cdr *CDR) AsMapStringIface() (mp map[string]interface{}) {
|
||||
|
||||
@@ -473,6 +473,49 @@ func TestCDRParseFieldValue(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCdrClone(t * testing.T){
|
||||
cdr := &CDR{}
|
||||
eOut := &CDR{}
|
||||
if rcv := cdr.Clone(); !reflect.DeepEqual(rcv,eOut) {
|
||||
t.Errorf("Expecting: %+v, received: %+v",eOut,rcv)
|
||||
}
|
||||
cdr = &CDR{
|
||||
CGRID: "CGRID_test",
|
||||
OrderID: 18,
|
||||
SetupTime: time.Date(2020, time.April, 18, 23, 0, 4, 0, time.UTC),
|
||||
Usage: time.Duration(10),
|
||||
ExtraFields: map[string]string{
|
||||
"test1":"_test1_",
|
||||
"test2":"_test2_",
|
||||
},
|
||||
Partial: true,
|
||||
Cost: 0.74,
|
||||
CostDetails: &EventCost{
|
||||
CGRID: "EventCost_CGRID",
|
||||
Cost: utils.Float64Pointer(0.74),
|
||||
},
|
||||
}
|
||||
eOut = &CDR{
|
||||
CGRID: "CGRID_test",
|
||||
OrderID: 18,
|
||||
SetupTime: time.Date(2020, time.April, 18, 23, 0, 4, 0, time.UTC),
|
||||
Usage: time.Duration(10),
|
||||
ExtraFields: map[string]string{
|
||||
"test1":"_test1_",
|
||||
"test2":"_test2_",
|
||||
},
|
||||
Partial: true,
|
||||
Cost: 0.74,
|
||||
CostDetails: &EventCost{
|
||||
CGRID: "EventCost_CGRID",
|
||||
Cost: utils.Float64Pointer(0.74),
|
||||
},
|
||||
}
|
||||
if rcv := cdr.Clone(); !reflect.DeepEqual(rcv,eOut) {
|
||||
t.Errorf("Expecting: %+v,\n received: %+v",eOut,rcv)
|
||||
}
|
||||
|
||||
}
|
||||
func TestCDRAsMapStringIface(t *testing.T) {
|
||||
cdr := &CDR{
|
||||
CGRID: utils.Sha1("dsafdsaf", time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String()),
|
||||
|
||||
@@ -192,11 +192,21 @@ func (ec *EventCost) Clone() (cln *EventCost) {
|
||||
if ec.AccountSummary != nil {
|
||||
cln.AccountSummary = ec.AccountSummary.Clone()
|
||||
}
|
||||
cln.Rating = ec.Rating.Clone()
|
||||
cln.Accounting = ec.Accounting.Clone()
|
||||
cln.RatingFilters = ec.RatingFilters.Clone()
|
||||
cln.Rates = ec.Rates.Clone()
|
||||
cln.Timings = ec.Timings.Clone()
|
||||
if ec.Rating != nil {
|
||||
cln.Rating = ec.Rating.Clone()
|
||||
}
|
||||
if ec.Accounting != nil {
|
||||
cln.Accounting = ec.Accounting.Clone()
|
||||
}
|
||||
if ec.RatingFilters != nil {
|
||||
cln.RatingFilters = ec.RatingFilters.Clone()
|
||||
}
|
||||
if ec.Rates != nil {
|
||||
cln.Rates = ec.Rates.Clone()
|
||||
}
|
||||
if ec.Timings != nil {
|
||||
cln.Timings = ec.Timings.Clone()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user