func (self *ApierV1) SetActionTrigger(attr AttrSetActionTrigger, reply *string) error { if missing := utils.MissingStructFields(&attr, []string{"GroupID"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } atrs, _ := self.RatingDb.GetActionTriggers(attr.GroupID, false, utils.NonTransactional) var newAtr *engine.ActionTrigger if attr.UniqueID != "" { //search for exiting one for _, atr := range atrs { if atr.UniqueID == attr.UniqueID { newAtr = atr break } } } if newAtr == nil { newAtr = &engine.ActionTrigger{} atrs = append(atrs, newAtr) } newAtr.ID = attr.GroupID if attr.UniqueID != "" { newAtr.UniqueID = attr.UniqueID } else { newAtr.UniqueID = utils.GenUUID() } if attr.ThresholdType != nil { newAtr.ThresholdType = *attr.ThresholdType } if attr.ThresholdValue != nil { newAtr.ThresholdValue = *attr.ThresholdValue } if attr.Recurrent != nil { newAtr.Recurrent = *attr.Recurrent } if attr.MinSleep != nil { minSleep, err := utils.ParseDurationWithSecs(*attr.MinSleep) if err != nil { *reply = err.Error() return err } newAtr.MinSleep = minSleep } if attr.ExpirationDate != nil { expTime, err := utils.ParseTimeDetectLayout(*attr.ExpirationDate, self.Config.DefaultTimezone) if err != nil { *reply = err.Error() return err } newAtr.ExpirationDate = expTime } if attr.ActivationDate != nil { actTime, err := utils.ParseTimeDetectLayout(*attr.ActivationDate, self.Config.DefaultTimezone) if err != nil { *reply = err.Error() return err } newAtr.ActivationDate = actTime } newAtr.Balance = &engine.BalanceFilter{} if attr.BalanceID != nil { newAtr.Balance.ID = attr.BalanceID } if attr.BalanceType != nil { newAtr.Balance.Type = attr.BalanceType } if attr.BalanceDirections != nil { newAtr.Balance.Directions = utils.StringMapPointer(utils.NewStringMap(*attr.BalanceDirections...)) } if attr.BalanceDestinationIds != nil { newAtr.Balance.DestinationIDs = utils.StringMapPointer(utils.NewStringMap(*attr.BalanceDestinationIds...)) } if attr.BalanceWeight != nil { newAtr.Balance.Weight = attr.BalanceWeight } if attr.BalanceExpirationDate != nil { balanceExpTime, err := utils.ParseDate(*attr.BalanceExpirationDate) if err != nil { *reply = err.Error() return err } newAtr.Balance.ExpirationDate = &balanceExpTime } if attr.BalanceTimingTags != nil { newAtr.Balance.TimingIDs = utils.StringMapPointer(utils.NewStringMap(*attr.BalanceTimingTags...)) } if attr.BalanceRatingSubject != nil { newAtr.Balance.RatingSubject = attr.BalanceRatingSubject } if attr.BalanceCategories != nil { newAtr.Balance.Categories = utils.StringMapPointer(utils.NewStringMap(*attr.BalanceCategories...)) } if attr.BalanceSharedGroups != nil { newAtr.Balance.SharedGroups = utils.StringMapPointer(utils.NewStringMap(*attr.BalanceSharedGroups...)) } if attr.BalanceBlocker != nil { newAtr.Balance.Blocker = attr.BalanceBlocker } if attr.BalanceDisabled != nil { newAtr.Balance.Disabled = attr.BalanceDisabled } if attr.MinQueuedItems != nil { newAtr.MinQueuedItems = *attr.MinQueuedItems } if attr.ActionsID != nil { newAtr.ActionsID = *attr.ActionsID } if err := self.RatingDb.SetActionTriggers(attr.GroupID, atrs, utils.NonTransactional); err != nil { *reply = err.Error() return err } //no cache for action triggers *reply = utils.OK return nil }
func (attr *AttrSetAccountActionTriggers) UpdateActionTrigger(at *engine.ActionTrigger, timezone string) (updated bool, err error) { if at == nil { return false, errors.New("Empty ActionTrigger") } if at.ID == "" { // New AT, update it's data if missing := utils.MissingStructFields(attr, []string{"GroupID", "ThresholdType", "ThresholdValue"}); len(missing) != 0 { return false, utils.NewErrMandatoryIeMissing(missing...) } at.ID = *attr.GroupID if attr.UniqueID != nil { at.UniqueID = *attr.UniqueID } } if attr.GroupID != nil && *attr.GroupID != at.ID { return } if attr.UniqueID != nil && *attr.UniqueID != at.UniqueID { return } // at matches updated = true if attr.ThresholdType != nil { at.ThresholdType = *attr.ThresholdType } if attr.ThresholdValue != nil { at.ThresholdValue = *attr.ThresholdValue } if attr.Recurrent != nil { at.Recurrent = *attr.Recurrent } if attr.Executed != nil { at.Executed = *attr.Executed } if attr.MinSleep != nil { if at.MinSleep, err = utils.ParseDurationWithSecs(*attr.MinSleep); err != nil { return } } if attr.ExpirationDate != nil { if at.ExpirationDate, err = utils.ParseTimeDetectLayout(*attr.ExpirationDate, timezone); err != nil { return } } if attr.ActivationDate != nil { if at.ActivationDate, err = utils.ParseTimeDetectLayout(*attr.ActivationDate, timezone); err != nil { return } } if at.Balance == nil { at.Balance = &engine.BalanceFilter{} } if attr.BalanceID != nil { at.Balance.ID = attr.BalanceID } if attr.BalanceType != nil { at.Balance.Type = attr.BalanceType } if attr.BalanceDirections != nil { at.Balance.Directions = utils.StringMapPointer(utils.NewStringMap(*attr.BalanceDirections...)) } if attr.BalanceDestinationIds != nil { at.Balance.DestinationIDs = utils.StringMapPointer(utils.NewStringMap(*attr.BalanceDestinationIds...)) } if attr.BalanceWeight != nil { at.Balance.Weight = attr.BalanceWeight } if attr.BalanceExpirationDate != nil { balanceExpTime, err := utils.ParseDate(*attr.BalanceExpirationDate) if err != nil { return false, err } at.Balance.ExpirationDate = &balanceExpTime } if attr.BalanceTimingTags != nil { at.Balance.TimingIDs = utils.StringMapPointer(utils.NewStringMap(*attr.BalanceTimingTags...)) } if attr.BalanceRatingSubject != nil { at.Balance.RatingSubject = attr.BalanceRatingSubject } if attr.BalanceCategories != nil { at.Balance.Categories = utils.StringMapPointer(utils.NewStringMap(*attr.BalanceCategories...)) } if attr.BalanceSharedGroups != nil { at.Balance.SharedGroups = utils.StringMapPointer(utils.NewStringMap(*attr.BalanceSharedGroups...)) } if attr.BalanceBlocker != nil { at.Balance.Blocker = attr.BalanceBlocker } if attr.BalanceDisabled != nil { at.Balance.Disabled = attr.BalanceDisabled } if attr.MinQueuedItems != nil { at.MinQueuedItems = *attr.MinQueuedItems } if attr.ActionsID != nil { at.ActionsID = *attr.ActionsID } return }