mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
added reset filters for action trigger reset
+test
This commit is contained in:
@@ -477,12 +477,16 @@ func (self *ApierV1) AddTriggeredAction(attr AttrAddActionTrigger, reply *string
|
||||
}
|
||||
|
||||
type AttrResetTriggeredAction struct {
|
||||
Tenant string
|
||||
Account string
|
||||
Direction string
|
||||
BalanceType string
|
||||
ThresholdType string
|
||||
ThresholdValue float64
|
||||
Tenant string
|
||||
Account string
|
||||
Direction string
|
||||
BalanceType string
|
||||
ThresholdType string
|
||||
ThresholdValue float64
|
||||
DestinationId string
|
||||
BalanceWeight float64
|
||||
BalanceRatingSubject string
|
||||
BalanceSharedGroup string
|
||||
}
|
||||
|
||||
func (self *ApierV1) ResetTriggeredActions(attr AttrResetTriggeredAction, reply *string) error {
|
||||
@@ -490,9 +494,20 @@ func (self *ApierV1) ResetTriggeredActions(attr AttrResetTriggeredAction, reply
|
||||
attr.Direction = engine.OUTBOUND
|
||||
}
|
||||
extraParameters, err := json.Marshal(struct {
|
||||
ThresholdType string
|
||||
ThresholdValue float64
|
||||
}{attr.ThresholdType, attr.ThresholdValue})
|
||||
ThresholdType string
|
||||
ThresholdValue float64
|
||||
DestinationId string
|
||||
BalanceWeight float64
|
||||
BalanceRatingSubject string
|
||||
BalanceSharedGroup string
|
||||
}{
|
||||
attr.ThresholdType,
|
||||
attr.ThresholdValue,
|
||||
attr.DestinationId,
|
||||
attr.BalanceWeight,
|
||||
attr.BalanceRatingSubject,
|
||||
attr.BalanceSharedGroup,
|
||||
})
|
||||
if err != nil {
|
||||
*reply = err.Error()
|
||||
return err
|
||||
|
||||
@@ -90,17 +90,25 @@ func (at *ActionTrigger) Match(a *Action) bool {
|
||||
}
|
||||
id := a.BalanceType == "" || at.BalanceType == a.BalanceType
|
||||
direction := a.Direction == "" || at.Direction == a.Direction
|
||||
thresholdType, thresholdValue := true, true
|
||||
thresholdType, thresholdValue, destinationId, weight, ratingSubject, sharedGroup := true, true, true, true, true, true
|
||||
if a.ExtraParameters != "" {
|
||||
t := struct {
|
||||
ThresholdType string
|
||||
ThresholdValue float64
|
||||
ThresholdType string
|
||||
ThresholdValue float64
|
||||
DestinationId string
|
||||
BalanceWeight float64
|
||||
BalanceRatingSubject string
|
||||
BalanceSharedGroup string
|
||||
}{}
|
||||
json.Unmarshal([]byte(a.ExtraParameters), &t)
|
||||
thresholdType = t.ThresholdType == "" || at.ThresholdType == t.ThresholdType
|
||||
thresholdValue = t.ThresholdValue == 0 || at.ThresholdValue == t.ThresholdValue
|
||||
destinationId = t.DestinationId == "" || at.DestinationId == t.DestinationId
|
||||
weight = t.BalanceWeight == 0 || at.BalanceWeight == t.BalanceWeight
|
||||
ratingSubject = t.BalanceRatingSubject == "" || at.BalanceRatingSubject == t.BalanceRatingSubject
|
||||
sharedGroup = t.BalanceSharedGroup == "" || at.BalanceSharedGroup == t.BalanceSharedGroup
|
||||
}
|
||||
return id && direction && thresholdType && thresholdValue
|
||||
return id && direction && thresholdType && thresholdValue && destinationId && weight && ratingSubject && sharedGroup
|
||||
}
|
||||
|
||||
// Structure to store actions according to weight
|
||||
|
||||
@@ -563,6 +563,23 @@ func TestActionTriggerMatcAllFalse(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTriggerMatchAll(t *testing.T) {
|
||||
at := &ActionTrigger{
|
||||
Direction: OUTBOUND,
|
||||
BalanceType: CREDIT,
|
||||
ThresholdType: TRIGGER_MAX_BALANCE,
|
||||
ThresholdValue: 2,
|
||||
DestinationId: "NAT",
|
||||
BalanceWeight: 1.0,
|
||||
BalanceRatingSubject: "test1",
|
||||
BalanceSharedGroup: "test2",
|
||||
}
|
||||
a := &Action{Direction: OUTBOUND, BalanceType: CREDIT, ExtraParameters: fmt.Sprintf(`{"ThresholdType":"%v", "ThresholdValue": %v, "DestinationId": "%v", "BalanceWeight": %v, "BalanceRatingSubject": "%v", "BalanceSharedGroup": "%v"}`, TRIGGER_MAX_BALANCE, 2, "NAT", 1.0, "test1", "test2")}
|
||||
if !at.Match(a) {
|
||||
t.Errorf("Action trigger [%v] does not match action [%v]", at, a)
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTriggerPriotityList(t *testing.T) {
|
||||
at1 := &ActionTrigger{Weight: 10}
|
||||
at2 := &ActionTrigger{Weight: 20}
|
||||
|
||||
Reference in New Issue
Block a user