mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 13:49:53 +05:00
Updated Clone function in action plan
This commit is contained in:
@@ -80,14 +80,36 @@ func (apl *ActionPlan) RemoveAccountID(accID string) (found bool) {
|
||||
return
|
||||
}
|
||||
|
||||
// Clone clones *ActionPlan
|
||||
func (apl *ActionPlan) Clone() (interface{}, error) {
|
||||
cln := new(ActionPlan)
|
||||
if err := utils.Clone(*apl, cln); err != nil {
|
||||
return nil, err
|
||||
cln := &ActionPlan{
|
||||
Id: apl.Id,
|
||||
AccountIDs: apl.AccountIDs.Clone(),
|
||||
}
|
||||
if apl.ActionTimings != nil {
|
||||
cln.ActionTimings = make([]*ActionTiming, len(apl.ActionTimings))
|
||||
for i, act := range apl.ActionTimings {
|
||||
cln.ActionTimings[i] = act.Clone()
|
||||
}
|
||||
}
|
||||
return cln, nil
|
||||
}
|
||||
|
||||
// Clone clones ActionTiming
|
||||
func (at *ActionTiming) Clone() (cln *ActionTiming) {
|
||||
if at == nil {
|
||||
return
|
||||
}
|
||||
cln = &ActionTiming{
|
||||
Uuid: at.Uuid,
|
||||
ActionsID: at.ActionsID,
|
||||
Weight: at.Weight,
|
||||
ExtraData: at.ExtraData,
|
||||
Timing: at.Timing.Clone(),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (at *ActionTiming) GetNextStartTime(now time.Time) (t time.Time) {
|
||||
if !at.stCache.IsZero() {
|
||||
return at.stCache
|
||||
|
||||
@@ -91,7 +91,16 @@ func TestActionPlanClone(t *testing.T) {
|
||||
at1 := &ActionPlan{
|
||||
Id: "test",
|
||||
AccountIDs: utils.StringMap{"one": true, "two": true, "three": true},
|
||||
//ActionTimings: []*ActionTiming{},
|
||||
ActionTimings: []*ActionTiming{
|
||||
&ActionTiming{
|
||||
Uuid: "Uuid_test1",
|
||||
ActionsID: "ActionsID_test1",
|
||||
Weight: 0.8,
|
||||
Timing: &RateInterval{
|
||||
Weight: 0.7,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
clned, err := at1.Clone()
|
||||
if err != nil {
|
||||
@@ -99,7 +108,7 @@ func TestActionPlanClone(t *testing.T) {
|
||||
}
|
||||
at1Cloned := clned.(*ActionPlan)
|
||||
if !reflect.DeepEqual(at1, at1Cloned) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", at1, at1Cloned)
|
||||
t.Errorf("\nExpecting: %+v,\n received: %+v", at1, at1Cloned)
|
||||
}
|
||||
}
|
||||
func TestActionTimindSetActions(t *testing.T) {
|
||||
|
||||
@@ -425,3 +425,48 @@ func (il *RateIntervalTimeSorter) Sort() []*RateInterval {
|
||||
sort.Sort(il)
|
||||
return il.ris
|
||||
}
|
||||
|
||||
// Clone clones RateInterval
|
||||
func (i *RateInterval) Clone() (cln *RateInterval) {
|
||||
if i == nil {
|
||||
return
|
||||
}
|
||||
cln = &RateInterval{
|
||||
Timing: i.Timing.Clone(),
|
||||
Rating: i.Rating.Clone(),
|
||||
Weight: i.Weight,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Clone clones RITiming
|
||||
func (rit *RITiming) Clone() (cln *RITiming) {
|
||||
if rit == nil {
|
||||
return
|
||||
}
|
||||
cln = &RITiming{
|
||||
Years: rit.Years,
|
||||
Months: rit.Months,
|
||||
MonthDays: rit.MonthDays,
|
||||
WeekDays: rit.WeekDays,
|
||||
StartTime: rit.StartTime,
|
||||
EndTime: rit.EndTime,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Clone clones RIRate
|
||||
func (rit *RIRate) Clone() (cln *RIRate) {
|
||||
if rit == nil {
|
||||
return
|
||||
}
|
||||
cln = &RIRate{
|
||||
ConnectFee: rit.ConnectFee,
|
||||
RoundingMethod: rit.RoundingMethod,
|
||||
RoundingDecimals: rit.RoundingDecimals,
|
||||
MaxCost: rit.MaxCost,
|
||||
MaxCostStrategy: rit.MaxCostStrategy,
|
||||
Rates: rit.Rates,
|
||||
}
|
||||
return cln
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user