本文整理匯總了Golang中github.com/cgrates/cgrates/utils.ParseStringMap函數的典型用法代碼示例。如果您正苦於以下問題:Golang ParseStringMap函數的具體用法?Golang ParseStringMap怎麽用?Golang ParseStringMap使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ParseStringMap函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: RemoveBalances
func (self *ApierV1) RemoveBalances(attr *utils.AttrSetBalance, reply *string) error {
if missing := utils.MissingStructFields(attr, []string{"Tenant", "Account", "BalanceType"}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
var expTime *time.Time
if attr.ExpiryTime != nil {
expTimeVal, err := utils.ParseTimeDetectLayout(*attr.ExpiryTime, self.Config.DefaultTimezone)
if err != nil {
*reply = err.Error()
return err
}
expTime = &expTimeVal
}
accID := utils.AccountKey(attr.Tenant, attr.Account)
if _, err := self.AccountDb.GetAccount(accID); err != nil {
return utils.ErrNotFound
}
at := &engine.ActionTiming{}
at.SetAccountIDs(utils.StringMap{accID: true})
a := &engine.Action{
ActionType: engine.REMOVE_BALANCE,
Balance: &engine.BalanceFilter{
Uuid: attr.BalanceUUID,
ID: attr.BalanceID,
Type: utils.StringPointer(attr.BalanceType),
ExpirationDate: expTime,
RatingSubject: attr.RatingSubject,
Weight: attr.Weight,
Blocker: attr.Blocker,
Disabled: attr.Disabled,
},
}
if attr.Value != nil {
a.Balance.Value = &utils.ValueFormula{Static: *attr.Value}
}
if attr.Directions != nil {
a.Balance.Directions = utils.StringMapPointer(utils.ParseStringMap(*attr.Directions))
}
if attr.DestinationIds != nil {
a.Balance.DestinationIDs = utils.StringMapPointer(utils.ParseStringMap(*attr.DestinationIds))
}
if attr.Categories != nil {
a.Balance.Categories = utils.StringMapPointer(utils.ParseStringMap(*attr.Categories))
}
if attr.SharedGroups != nil {
a.Balance.SharedGroups = utils.StringMapPointer(utils.ParseStringMap(*attr.SharedGroups))
}
if attr.TimingIds != nil {
a.Balance.TimingIDs = utils.StringMapPointer(utils.ParseStringMap(*attr.TimingIds))
}
at.SetActions(engine.Actions{a})
if err := at.Execute(); err != nil {
*reply = err.Error()
return err
}
*reply = OK
return nil
}
示例2: LoadActions
func (tpr *TpReader) LoadActions() (err error) {
tps, err := tpr.lr.GetTpActions(tpr.tpid, "")
if err != nil {
return err
}
storActs, err := TpActions(tps).GetActions()
if err != nil {
return err
}
// map[string][]*Action
for tag, tpacts := range storActs {
acts := make([]*Action, len(tpacts))
for idx, tpact := range tpacts {
acts[idx] = &Action{
Id: tag + strconv.Itoa(idx),
ActionType: tpact.Identifier,
BalanceType: tpact.BalanceType,
Weight: tpact.Weight,
ExtraParameters: tpact.ExtraParameters,
ExpirationString: tpact.ExpiryTime,
Balance: &Balance{
Id: tpact.BalanceId,
Value: tpact.Units,
Weight: tpact.BalanceWeight,
RatingSubject: tpact.RatingSubject,
Categories: utils.ParseStringMap(tpact.Categories),
Directions: utils.ParseStringMap(tpact.Directions),
DestinationIds: utils.ParseStringMap(tpact.DestinationIds),
SharedGroups: utils.ParseStringMap(tpact.SharedGroups),
TimingIDs: utils.ParseStringMap(tpact.TimingTags),
},
}
// load action timings from tags
if tpact.TimingTags != "" {
timingIds := strings.Split(tpact.TimingTags, utils.INFIELD_SEP)
for _, timingID := range timingIds {
if timing, found := tpr.timings[timingID]; found {
acts[idx].Balance.Timings = append(acts[idx].Balance.Timings, &RITiming{
Years: timing.Years,
Months: timing.Months,
MonthDays: timing.MonthDays,
WeekDays: timing.WeekDays,
StartTime: timing.StartTime,
EndTime: timing.EndTime,
})
} else {
return fmt.Errorf("could not find timing: %v", timingID)
}
}
}
}
tpr.actions[tag] = acts
}
return nil
}
示例3: modifyBalance
func (self *ApierV1) modifyBalance(aType string, attr *AttrAddBalance, reply *string) error {
if missing := utils.MissingStructFields(attr, []string{"Tenant", "Account", "BalanceType"}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
expTime, err := utils.ParseTimeDetectLayout(attr.ExpiryTime, self.Config.DefaultTimezone)
if err != nil {
*reply = err.Error()
return err
}
accID := utils.AccountKey(attr.Tenant, attr.Account)
if _, err := self.AccountDb.GetAccount(accID); err != nil {
// create account if not exists
account := &engine.Account{
Id: accID,
}
if err := self.AccountDb.SetAccount(account); err != nil {
*reply = err.Error()
return err
}
}
at := &engine.ActionTiming{}
at.SetAccountIDs(utils.StringMap{accID: true})
if attr.Overwrite {
aType += "_reset" // => *topup_reset/*debit_reset
}
at.SetActions(engine.Actions{
&engine.Action{
ActionType: aType,
BalanceType: attr.BalanceType,
Balance: &engine.Balance{
Uuid: attr.BalanceUuid,
Id: attr.BalanceId,
Value: attr.Value,
ExpirationDate: expTime,
RatingSubject: attr.RatingSubject,
Directions: utils.ParseStringMap(attr.Directions),
DestinationIds: utils.ParseStringMap(attr.DestinationIds),
Categories: utils.ParseStringMap(attr.Categories),
Weight: attr.Weight,
SharedGroups: utils.ParseStringMap(attr.SharedGroups),
TimingIDs: utils.ParseStringMap(attr.TimingIds),
Blocker: attr.Blocker,
Disabled: attr.Disabled,
},
},
})
if err := at.Execute(); err != nil {
*reply = err.Error()
return err
}
*reply = OK
return nil
}
示例4: AddBalance
func (self *ApierV1) AddBalance(attr *AttrAddBalance, reply *string) error {
expTime, err := utils.ParseDate(attr.ExpiryTime)
if err != nil {
*reply = err.Error()
return err
}
tag := utils.ConcatenatedKey(attr.Tenant, attr.Account)
if _, err := self.AccountDb.GetAccount(tag); err != nil {
// create user balance if not exists
account := &engine.Account{
Id: tag,
}
if err := self.AccountDb.SetAccount(account); err != nil {
*reply = err.Error()
return err
}
}
at := &engine.ActionPlan{
AccountIds: []string{tag},
}
aType := engine.DEBIT
// reverse the sign as it is a debit
attr.Value = -attr.Value
if attr.Overwrite {
aType = engine.DEBIT_RESET
}
at.SetActions(engine.Actions{
&engine.Action{
ActionType: aType,
BalanceType: attr.BalanceType,
Balance: &engine.Balance{
Uuid: attr.BalanceUuid,
Id: attr.BalanceId,
Value: attr.Value,
ExpirationDate: expTime,
RatingSubject: attr.RatingSubject,
Directions: utils.ParseStringMap(attr.Directions),
DestinationIds: utils.ParseStringMap(attr.DestinationIds),
Weight: attr.Weight,
SharedGroups: utils.ParseStringMap(attr.SharedGroups),
Disabled: attr.Disabled,
},
},
})
if err := at.Execute(); err != nil {
*reply = err.Error()
return err
}
*reply = OK
return nil
}
示例5: SetActions
func (self *ApierV1) SetActions(attrs V1AttrSetActions, reply *string) (err error) {
if missing := utils.MissingStructFields(&attrs, []string{"ActionsId", "Actions"}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
for _, action := range attrs.Actions {
requiredFields := []string{"Identifier", "Weight"}
if action.BalanceType != "" { // Add some inter-dependent parameters - if balanceType then we are not talking about simply calling actions
requiredFields = append(requiredFields, "Direction", "Units")
}
if missing := utils.MissingStructFields(action, requiredFields); len(missing) != 0 {
return fmt.Errorf("%s:Action:%s:%v", utils.ErrMandatoryIeMissing.Error(), action.Identifier, missing)
}
}
if !attrs.Overwrite {
if exists, err := self.RatingDb.HasData(utils.ACTION_PREFIX, attrs.ActionsId); err != nil {
return utils.NewErrServerError(err)
} else if exists {
return utils.ErrExists
}
}
storeActions := make(engine.Actions, len(attrs.Actions))
for idx, apiAct := range attrs.Actions {
a := &engine.Action{
Id: attrs.ActionsId,
ActionType: apiAct.Identifier,
Weight: apiAct.Weight,
ExpirationString: apiAct.ExpiryTime,
ExtraParameters: apiAct.ExtraParameters,
Filter: apiAct.Filter,
Balance: &engine.BalanceFilter{ // TODO: update this part
Uuid: utils.StringPointer(apiAct.BalanceUuid),
ID: utils.StringPointer(apiAct.BalanceId),
Type: utils.StringPointer(apiAct.BalanceType),
Value: &utils.ValueFormula{Static: apiAct.Units},
Weight: apiAct.BalanceWeight,
Directions: utils.StringMapPointer(utils.ParseStringMap(apiAct.Directions)),
DestinationIDs: utils.StringMapPointer(utils.ParseStringMap(apiAct.DestinationIds)),
RatingSubject: utils.StringPointer(apiAct.RatingSubject),
SharedGroups: utils.StringMapPointer(utils.ParseStringMap(apiAct.SharedGroups)),
},
}
storeActions[idx] = a
}
if err := self.RatingDb.SetActions(attrs.ActionsId, storeActions, utils.NonTransactional); err != nil {
return utils.NewErrServerError(err)
}
if err = self.RatingDb.CacheDataFromDB(utils.ACTION_PREFIX, []string{attrs.ActionsId}, true); err != nil {
utils.NewErrServerError(err)
}
*reply = OK
return nil
}
示例6: SetActions
func (self *ApierV1) SetActions(attrs utils.AttrSetActions, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"ActionsId", "Actions"}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
for _, action := range attrs.Actions {
requiredFields := []string{"Identifier", "Weight"}
if action.BalanceType != "" { // Add some inter-dependent parameters - if balanceType then we are not talking about simply calling actions
requiredFields = append(requiredFields, "Direction", "Units")
}
if missing := utils.MissingStructFields(action, requiredFields); len(missing) != 0 {
return fmt.Errorf("%s:Action:%s:%v", utils.ErrMandatoryIeMissing.Error(), action.Identifier, missing)
}
}
if !attrs.Overwrite {
if exists, err := self.RatingDb.HasData(utils.ACTION_PREFIX, attrs.ActionsId); err != nil {
return utils.NewErrServerError(err)
} else if exists {
return utils.ErrExists
}
}
storeActions := make(engine.Actions, len(attrs.Actions))
for idx, apiAct := range attrs.Actions {
a := &engine.Action{
Id: utils.GenUUID(),
ActionType: apiAct.Identifier,
BalanceType: apiAct.BalanceType,
Weight: apiAct.Weight,
ExpirationString: apiAct.ExpiryTime,
ExtraParameters: apiAct.ExtraParameters,
Filter: apiAct.Filter,
Balance: &engine.Balance{
Uuid: utils.GenUUID(),
Id: apiAct.BalanceId,
Value: apiAct.Units,
Weight: apiAct.BalanceWeight,
Directions: utils.ParseStringMap(apiAct.Directions),
DestinationIds: utils.ParseStringMap(apiAct.DestinationIds),
RatingSubject: apiAct.RatingSubject,
SharedGroups: utils.ParseStringMap(apiAct.SharedGroups),
},
}
storeActions[idx] = a
}
if err := self.RatingDb.SetActions(attrs.ActionsId, storeActions); err != nil {
return utils.NewErrServerError(err)
}
self.RatingDb.CacheRatingPrefixValues(map[string][]string{utils.ACTION_PREFIX: []string{utils.ACTION_PREFIX + attrs.ActionsId}})
*reply = OK
return nil
}
示例7: RemoveBalances
func (self *ApierV1) RemoveBalances(attr *AttrAddBalance, reply *string) error {
if missing := utils.MissingStructFields(attr, []string{"Tenant", "Account", "BalanceType"}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
expTime, err := utils.ParseTimeDetectLayout(attr.ExpiryTime, self.Config.DefaultTimezone)
if err != nil {
*reply = err.Error()
return err
}
accID := utils.AccountKey(attr.Tenant, attr.Account)
if _, err := self.AccountDb.GetAccount(accID); err != nil {
return utils.ErrNotFound
}
at := &engine.ActionTiming{}
at.SetAccountIDs(utils.StringMap{accID: true})
at.SetActions(engine.Actions{
&engine.Action{
ActionType: engine.REMOVE_BALANCE,
BalanceType: attr.BalanceType,
Balance: &engine.Balance{
Uuid: attr.BalanceUuid,
Id: attr.BalanceId,
Value: attr.Value,
ExpirationDate: expTime,
RatingSubject: attr.RatingSubject,
Directions: utils.ParseStringMap(attr.Directions),
DestinationIds: utils.ParseStringMap(attr.DestinationIds),
Categories: utils.ParseStringMap(attr.Categories),
Weight: attr.Weight,
SharedGroups: utils.ParseStringMap(attr.SharedGroups),
TimingIDs: utils.ParseStringMap(attr.TimingIds),
Blocker: attr.Blocker,
Disabled: attr.Disabled,
},
},
})
if err := at.Execute(); err != nil {
*reply = err.Error()
return err
}
*reply = OK
return nil
}
示例8: AddTriggeredAction
func (self *ApierV1) AddTriggeredAction(attr AttrAddActionTrigger, reply *string) error {
if attr.BalanceDirection == "" {
attr.BalanceDirection = utils.OUT
}
balExpiryTime, err := utils.ParseTimeDetectLayout(attr.BalanceExpiryTime, self.Config.DefaultTimezone)
if err != nil {
return utils.NewErrServerError(err)
}
at := &engine.ActionTrigger{
Id: attr.ActionTriggersId,
ThresholdType: attr.ThresholdType,
ThresholdValue: attr.ThresholdValue,
BalanceId: attr.BalanceId,
BalanceType: attr.BalanceType,
BalanceDirections: utils.ParseStringMap(attr.BalanceDirection),
BalanceDestinationIds: utils.ParseStringMap(attr.BalanceDestinationIds),
BalanceWeight: attr.BalanceWeight,
BalanceExpirationDate: balExpiryTime,
Weight: attr.Weight,
ActionsId: attr.ActionsId,
Executed: false,
}
tag := utils.AccountKey(attr.Tenant, attr.Account)
_, err = engine.Guardian.Guard(func() (interface{}, error) {
userBalance, err := self.AccountDb.GetAccount(tag)
if err != nil {
return 0, err
}
userBalance.ActionTriggers = append(userBalance.ActionTriggers, at)
if err = self.AccountDb.SetAccount(userBalance); err != nil {
return 0, err
}
return 0, nil
}, 0, tag)
if err != nil {
*reply = err.Error()
return err
}
*reply = OK
return nil
}
示例9: LoadActionTriggers
func (tpr *TpReader) LoadActionTriggers() (err error) {
tps, err := tpr.lr.GetTpActionTriggers(tpr.tpid, "")
if err != nil {
return err
}
storAts, err := TpActionTriggers(tps).GetActionTriggers()
if err != nil {
return err
}
for key, atrsLst := range storAts {
atrs := make([]*ActionTrigger, len(atrsLst))
for idx, atr := range atrsLst {
balanceExpirationDate, _ := utils.ParseTimeDetectLayout(atr.BalanceExpirationDate, tpr.timezone)
minSleep, err := utils.ParseDurationWithSecs(atr.MinSleep)
if err != nil {
return err
}
atrs[idx] = &ActionTrigger{
ThresholdType: atr.ThresholdType,
ThresholdValue: atr.ThresholdValue,
Recurrent: atr.Recurrent,
MinSleep: minSleep,
BalanceId: atr.BalanceId,
BalanceType: atr.BalanceType,
BalanceDirections: utils.ParseStringMap(atr.BalanceDirections),
BalanceDestinationIds: utils.ParseStringMap(atr.BalanceDestinationIds),
BalanceWeight: atr.BalanceWeight,
BalanceExpirationDate: balanceExpirationDate,
BalanceTimingTags: utils.ParseStringMap(atr.BalanceTimingTags),
BalanceRatingSubject: atr.BalanceRatingSubject,
BalanceCategories: utils.ParseStringMap(atr.BalanceCategories),
BalanceSharedGroups: utils.ParseStringMap(atr.BalanceSharedGroups),
Weight: atr.Weight,
ActionsId: atr.ActionsId,
MinQueuedItems: atr.MinQueuedItems,
}
}
tpr.actionsTriggers[key] = atrs
}
return nil
}
示例10: RemoveBalances
func (self *ApierV1) RemoveBalances(attr *AttrAddBalance, reply *string) error {
expTime, err := utils.ParseDate(attr.ExpiryTime)
if err != nil {
*reply = err.Error()
return err
}
accId := utils.ConcatenatedKey(attr.Tenant, attr.Account)
if _, err := self.AccountDb.GetAccount(accId); err != nil {
return utils.ErrNotFound
}
at := &engine.ActionPlan{
AccountIds: []string{accId},
}
at.SetActions(engine.Actions{
&engine.Action{
ActionType: engine.REMOVE_BALANCE,
BalanceType: attr.BalanceType,
Balance: &engine.Balance{
Uuid: attr.BalanceUuid,
Id: attr.BalanceId,
Value: attr.Value,
ExpirationDate: expTime,
RatingSubject: attr.RatingSubject,
Directions: utils.ParseStringMap(attr.Directions),
DestinationIds: utils.ParseStringMap(attr.DestinationIds),
Weight: attr.Weight,
SharedGroups: utils.ParseStringMap(attr.SharedGroups),
Disabled: attr.Disabled,
},
},
})
if err := at.Execute(); err != nil {
*reply = err.Error()
return err
}
*reply = OK
return nil
}
示例11: Match
// returns true if the field of the action timing are equeal to the non empty
// fields of the action
func (at *ActionTrigger) Match(a *Action) bool {
if a == nil {
return true
}
// if we have Id than we can draw an early conclusion
if a.Id != "" {
match, _ := regexp.MatchString(a.Id, at.Id)
return match
}
id := a.BalanceType == "" || at.BalanceType == a.BalanceType
thresholdType, thresholdValue, direction, destinationId, weight, ratingSubject, categories, sharedGroup, timings, disabled := true, true, true, true, true, true, true, true, true, true
if a.ExtraParameters != "" {
t := struct {
ThresholdType string
ThresholdValue float64
DestinationIds string
BalanceDirections string
BalanceWeight float64
BalanceRatingSubject string
BalanceCategories string
BalanceSharedGroups string
BalanceTimingTags string
BalanceDisabled bool
}{}
json.Unmarshal([]byte(a.ExtraParameters), &t)
thresholdType = t.ThresholdType == "" || at.ThresholdType == t.ThresholdType
thresholdValue = t.ThresholdValue == 0 || at.ThresholdValue == t.ThresholdValue
direction = len(t.BalanceDirections) == 0 || at.BalanceDirections.Equal(utils.ParseStringMap(t.BalanceDirections))
destinationId = len(t.DestinationIds) == 0 || at.BalanceDestinationIds.Equal(utils.ParseStringMap(t.DestinationIds))
categories = len(t.BalanceCategories) == 0 || at.BalanceCategories.Equal(utils.ParseStringMap(t.BalanceCategories))
timings = len(t.BalanceTimingTags) == 0 || at.BalanceTimingTags.Equal(utils.ParseStringMap(t.BalanceTimingTags))
sharedGroup = len(t.BalanceSharedGroups) == 0 || at.BalanceSharedGroups.Equal(utils.ParseStringMap(t.BalanceSharedGroups))
weight = t.BalanceWeight == 0 || at.BalanceWeight == t.BalanceWeight
ratingSubject = t.BalanceRatingSubject == "" || at.BalanceRatingSubject == t.BalanceRatingSubject
disabled = at.BalanceDisabled == t.BalanceDisabled
}
return id && direction && thresholdType && thresholdValue && destinationId && weight && ratingSubject && categories && sharedGroup && timings && disabled
}
示例12: LoadDerivedChargersFiltered
func (tpr *TpReader) LoadDerivedChargersFiltered(filter *TpDerivedCharger, save bool) (err error) {
tps, err := tpr.lr.GetTpDerivedChargers(filter)
if err != nil {
return err
}
storDcs, err := TpDerivedChargers(tps).GetDerivedChargers()
if err != nil {
return err
}
for _, tpDcs := range storDcs {
tag := tpDcs.GetDerivedChargersKey()
if _, hasIt := tpr.derivedChargers[tag]; !hasIt {
tpr.derivedChargers[tag] = &utils.DerivedChargers{
DestinationIds: make(utils.StringMap),
Chargers: make([]*utils.DerivedCharger, 0),
} // Load object map since we use this method also from LoadDerivedChargers
}
for _, tpDc := range tpDcs.DerivedChargers {
dc, err := utils.NewDerivedCharger(tpDc.RunId, tpDc.RunFilters, tpDc.ReqTypeField, tpDc.DirectionField, tpDc.TenantField, tpDc.CategoryField,
tpDc.AccountField, tpDc.SubjectField, tpDc.DestinationField, tpDc.SetupTimeField, tpDc.PddField, tpDc.AnswerTimeField, tpDc.UsageField, tpDc.SupplierField,
tpDc.DisconnectCauseField, tpDc.RatedField, tpDc.CostField)
if err != nil {
return err
}
tpr.derivedChargers[tag].DestinationIds.Copy(utils.ParseStringMap(tpDcs.DestinationIds))
tpr.derivedChargers[tag].Chargers = append(tpr.derivedChargers[tag].Chargers, dc)
}
}
if save {
for dcsKey, dcs := range tpr.derivedChargers {
if err := tpr.ratingStorage.SetDerivedChargers(dcsKey, dcs); err != nil {
return err
}
}
}
return nil
}
示例13: LoadCdrStatsFiltered
func (tpr *TpReader) LoadCdrStatsFiltered(tag string, save bool) (err error) {
tps, err := tpr.lr.GetTpCdrStats(tpr.tpid, tag)
if err != nil {
return err
}
storStats, err := TpCdrStats(tps).GetCdrStats()
if err != nil {
return err
}
var actionsIds []string // collect action ids
for tag, tpStats := range storStats {
for _, tpStat := range tpStats {
var cs *CdrStats
var exists bool
if cs, exists = tpr.cdrStats[tag]; !exists {
cs = &CdrStats{Id: tag}
}
// action triggers
triggerTag := tpStat.ActionTriggers
if triggerTag != "" {
_, exists := tpr.actionsTriggers[triggerTag]
if !exists {
tpatrs, err := tpr.lr.GetTpActionTriggers(tpr.tpid, triggerTag)
if err != nil {
return errors.New(err.Error() + " (ActionTriggers): " + triggerTag)
}
atrsM, err := TpActionTriggers(tpatrs).GetActionTriggers()
if err != nil {
return err
}
for _, atrsLst := range atrsM {
atrs := make([]*ActionTrigger, len(atrsLst))
for idx, apiAtr := range atrsLst {
minSleep, _ := utils.ParseDurationWithSecs(apiAtr.MinSleep)
expTime, _ := utils.ParseDate(apiAtr.BalanceExpirationDate)
atrs[idx] = &ActionTrigger{
ThresholdType: apiAtr.ThresholdType,
ThresholdValue: apiAtr.ThresholdValue,
Recurrent: apiAtr.Recurrent,
MinSleep: minSleep,
BalanceId: apiAtr.BalanceId,
BalanceType: apiAtr.BalanceType,
BalanceDirections: utils.ParseStringMap(apiAtr.BalanceDirections),
BalanceDestinationIds: utils.ParseStringMap(apiAtr.BalanceDestinationIds),
BalanceWeight: apiAtr.BalanceWeight,
BalanceExpirationDate: expTime,
BalanceRatingSubject: apiAtr.BalanceRatingSubject,
BalanceCategories: utils.ParseStringMap(apiAtr.BalanceCategories),
BalanceSharedGroups: utils.ParseStringMap(apiAtr.BalanceSharedGroups),
BalanceTimingTags: utils.ParseStringMap(apiAtr.BalanceTimingTags),
Weight: apiAtr.Weight,
ActionsId: apiAtr.ActionsId,
}
}
tpr.actionsTriggers[triggerTag] = atrs
}
}
// collect action ids from triggers
for _, atr := range tpr.actionsTriggers[triggerTag] {
actionsIds = append(actionsIds, atr.ActionsId)
}
}
triggers, exists := tpr.actionsTriggers[triggerTag]
if triggerTag != "" && !exists {
// only return error if there was something there for the tag
return fmt.Errorf("could not get action triggers for cdr stats id %s: %s", cs.Id, triggerTag)
}
// write action triggers
err = tpr.ratingStorage.SetActionTriggers(triggerTag, triggers)
if err != nil {
return errors.New(err.Error() + " (SetActionTriggers): " + triggerTag)
}
UpdateCdrStats(cs, triggers, tpStat, tpr.timezone)
tpr.cdrStats[tag] = cs
}
}
// actions
for _, actId := range actionsIds {
_, exists := tpr.actions[actId]
if !exists {
tpas, err := tpr.lr.GetTpActions(tpr.tpid, actId)
if err != nil {
return err
}
as, err := TpActions(tpas).GetActions()
if err != nil {
return err
}
for tag, tpacts := range as {
enacts := make([]*Action, len(tpacts))
for idx, tpact := range tpacts {
enacts[idx] = &Action{
Id: tag + strconv.Itoa(idx),
ActionType: tpact.Identifier,
BalanceType: tpact.BalanceType,
Weight: tpact.Weight,
ExtraParameters: tpact.ExtraParameters,
ExpirationString: tpact.ExpiryTime,
Balance: &Balance{
//.........這裏部分代碼省略.........
示例14: LoadAccountActionsFiltered
//.........這裏部分代碼省略.........
//ActionTriggerPriotityList []*ActionTrigger
if accountAction.ActionTriggersId != "" {
tpatrs, err := tpr.lr.GetTpActionTriggers(tpr.tpid, accountAction.ActionTriggersId)
if err != nil {
return errors.New(err.Error() + " (ActionTriggers): " + accountAction.ActionTriggersId)
}
atrs, err := TpActionTriggers(tpatrs).GetActionTriggers()
if err != nil {
return err
}
atrsMap := make(map[string][]*ActionTrigger)
for key, atrsLst := range atrs {
atrs := make([]*ActionTrigger, len(atrsLst))
for idx, apiAtr := range atrsLst {
minSleep, _ := utils.ParseDurationWithSecs(apiAtr.MinSleep)
balanceExpTime, _ := utils.ParseDate(apiAtr.BalanceExpirationDate)
expTime, _ := utils.ParseTimeDetectLayout(apiAtr.ExpirationDate, tpr.timezone)
actTime, _ := utils.ParseTimeDetectLayout(apiAtr.ActivationDate, tpr.timezone)
if apiAtr.UniqueID == "" {
apiAtr.UniqueID = utils.GenUUID()
}
atrs[idx] = &ActionTrigger{
ID: key,
UniqueID: apiAtr.UniqueID,
ThresholdType: apiAtr.ThresholdType,
ThresholdValue: apiAtr.ThresholdValue,
Recurrent: apiAtr.Recurrent,
MinSleep: minSleep,
ExpirationDate: expTime,
ActivationDate: actTime,
BalanceId: apiAtr.BalanceId,
BalanceType: apiAtr.BalanceType,
BalanceDirections: utils.ParseStringMap(apiAtr.BalanceDirections),
BalanceDestinationIds: utils.ParseStringMap(apiAtr.BalanceDestinationIds),
BalanceWeight: apiAtr.BalanceWeight,
BalanceExpirationDate: balanceExpTime,
BalanceTimingTags: utils.ParseStringMap(apiAtr.BalanceTimingTags),
BalanceRatingSubject: apiAtr.BalanceRatingSubject,
BalanceCategories: utils.ParseStringMap(apiAtr.BalanceCategories),
BalanceSharedGroups: utils.ParseStringMap(apiAtr.BalanceSharedGroups),
BalanceBlocker: apiAtr.BalanceBlocker,
BalanceDisabled: apiAtr.BalanceDisabled,
Weight: apiAtr.Weight,
ActionsId: apiAtr.ActionsId,
}
}
atrsMap[key] = atrs
}
actionTriggers = atrsMap[accountAction.ActionTriggersId]
// collect action ids from triggers
for _, atr := range actionTriggers {
actionsIds = append(actionsIds, atr.ActionsId)
}
// write action triggers
err = tpr.ratingStorage.SetActionTriggers(accountAction.ActionTriggersId, actionTriggers)
if err != nil {
return errors.New(err.Error() + " (SetActionTriggers): " + accountAction.ActionTriggersId)
}
}
// actions
acts := make(map[string][]*Action)
for _, actId := range actionsIds {
tpas, err := tpr.lr.GetTpActions(tpr.tpid, actId)
if err != nil {
示例15: modifyBalance
func (self *ApierV1) modifyBalance(aType string, attr *AttrAddBalance, reply *string) error {
if missing := utils.MissingStructFields(attr, []string{"Tenant", "Account", "BalanceType", "Value"}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
var expTime *time.Time
if attr.ExpiryTime != nil {
expTimeVal, err := utils.ParseTimeDetectLayout(*attr.ExpiryTime, self.Config.DefaultTimezone)
if err != nil {
*reply = err.Error()
return err
}
expTime = &expTimeVal
}
accID := utils.AccountKey(attr.Tenant, attr.Account)
if _, err := self.AccountDb.GetAccount(accID); err != nil {
// create account if does not exist
account := &engine.Account{
ID: accID,
}
if err := self.AccountDb.SetAccount(account); err != nil {
*reply = err.Error()
return err
}
}
at := &engine.ActionTiming{}
at.SetAccountIDs(utils.StringMap{accID: true})
if attr.Overwrite {
aType += "_reset" // => *topup_reset/*debit_reset
}
a := &engine.Action{
ActionType: aType,
Balance: &engine.BalanceFilter{
Uuid: attr.BalanceUuid,
ID: attr.BalanceId,
Type: utils.StringPointer(attr.BalanceType),
Value: &utils.ValueFormula{Static: attr.Value},
ExpirationDate: expTime,
RatingSubject: attr.RatingSubject,
Weight: attr.Weight,
Blocker: attr.Blocker,
Disabled: attr.Disabled,
},
}
if attr.Directions != nil {
a.Balance.Directions = utils.StringMapPointer(utils.ParseStringMap(*attr.Directions))
}
if attr.DestinationIds != nil {
a.Balance.DestinationIDs = utils.StringMapPointer(utils.ParseStringMap(*attr.DestinationIds))
}
if attr.Categories != nil {
a.Balance.Categories = utils.StringMapPointer(utils.ParseStringMap(*attr.Categories))
}
if attr.SharedGroups != nil {
a.Balance.SharedGroups = utils.StringMapPointer(utils.ParseStringMap(*attr.SharedGroups))
}
if attr.TimingIds != nil {
a.Balance.TimingIDs = utils.StringMapPointer(utils.ParseStringMap(*attr.TimingIds))
}
at.SetActions(engine.Actions{a})
if err := at.Execute(); err != nil {
return err
}
*reply = OK
return nil
}