mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Merge branch 'master' of https://github.com/cgrates/cgrates
This commit is contained in:
@@ -1086,8 +1086,16 @@ func TestLoadCdrStats(t *testing.T) {
|
||||
RatedSubject: []string{"rif"},
|
||||
CostInterval: []float64{0, 2},
|
||||
}
|
||||
cdrStats1.Triggers = append(cdrStats1.Triggers, csvr.actionsTriggers["STANDARD_TRIGGERS"]...)
|
||||
cdrStats1.Triggers = append(cdrStats1.Triggers, csvr.actionsTriggers["STANDARD_TRIGGER"]...)
|
||||
for _, triggerKey := range []string{"STANDARD_TRIGGER", "STANDARD_TRIGGERS"} {
|
||||
cdrStats1.Triggers = append(cdrStats1.Triggers, csvr.actionsTriggers[triggerKey]...)
|
||||
}
|
||||
// compare trigger lengths
|
||||
if len(csvr.cdrStats[cdrStats1.Id].Triggers) != len(cdrStats1.Triggers) {
|
||||
t.Error("Wrong trigger length: ", len(csvr.cdrStats[cdrStats1.Id].Triggers), len(cdrStats1.Triggers))
|
||||
}
|
||||
// cannot deepequal triggers
|
||||
csvr.cdrStats[cdrStats1.Id].Triggers = nil
|
||||
cdrStats1.Triggers = nil
|
||||
if !reflect.DeepEqual(csvr.cdrStats[cdrStats1.Id], cdrStats1) {
|
||||
t.Errorf("Unexpected stats %+v", csvr.cdrStats[cdrStats1.Id])
|
||||
}
|
||||
|
||||
@@ -295,6 +295,23 @@ func TestLoadIndividualProfiles(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Load cdr stats
|
||||
//loadId = utils.CSV_LOAD + "_" + utils.TEST_SQL
|
||||
if cdrStats, err := storDb.GetTpCdrStats(utils.TEST_SQL, ""); err != nil {
|
||||
t.Fatal("Could not retrieve cdr stats, error: ", err.Error())
|
||||
} else if len(cdrStats) == 0 {
|
||||
t.Fatal("Could not retrieve cdr stats")
|
||||
} else {
|
||||
cds, err := TpCdrStats(cdrStats).GetCdrStats()
|
||||
if err != nil {
|
||||
t.Fatal("Could not convert cdr stats")
|
||||
}
|
||||
for id := range cds {
|
||||
if err := loader.LoadCdrStatsFiltered(id, true); err != nil {
|
||||
t.Fatalf("Could not load cdr stats with id: %s, error: %s", id, err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
// Load account actions
|
||||
if accountActions, err := storDb.GetTpAccountActions(&TpAccountAction{Tpid: utils.TEST_SQL, Loadid: loadId}); err != nil {
|
||||
t.Fatal("Could not retrieve account action profiles, error: ", err.Error())
|
||||
|
||||
@@ -808,6 +808,7 @@ func (tpr *TpReader) LoadAccountActionsFiltered(qriedAA *TpAccountAction) error
|
||||
Weight: tpact.BalanceWeight,
|
||||
RatingSubject: tpact.RatingSubject,
|
||||
DestinationIds: tpact.DestinationIds,
|
||||
SharedGroup: tpact.SharedGroup,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -931,6 +932,7 @@ func (tpr *TpReader) LoadCdrStatsFiltered(tag string, save bool) (err error) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var actionsIds []string // collect action ids
|
||||
for tag, tpStats := range storStats {
|
||||
for _, tpStat := range tpStats {
|
||||
var cs *CdrStats
|
||||
@@ -938,7 +940,48 @@ func (tpr *TpReader) LoadCdrStatsFiltered(tag string, save bool) (err error) {
|
||||
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 {
|
||||
expTime, _ := utils.ParseDate(apiAtr.BalanceExpirationDate)
|
||||
atrs[idx] = &ActionTrigger{Id: utils.GenUUID(),
|
||||
ThresholdType: apiAtr.ThresholdType,
|
||||
ThresholdValue: apiAtr.ThresholdValue,
|
||||
BalanceId: apiAtr.BalanceId,
|
||||
BalanceType: apiAtr.BalanceType,
|
||||
BalanceDirection: apiAtr.BalanceDirection,
|
||||
BalanceDestinationIds: apiAtr.BalanceDestinationIds,
|
||||
BalanceWeight: apiAtr.BalanceWeight,
|
||||
BalanceExpirationDate: expTime,
|
||||
BalanceRatingSubject: apiAtr.BalanceRatingSubject,
|
||||
BalanceCategory: apiAtr.BalanceCategory,
|
||||
BalanceSharedGroup: apiAtr.BalanceSharedGroup,
|
||||
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
|
||||
@@ -948,7 +991,52 @@ func (tpr *TpReader) LoadCdrStatsFiltered(tag string, save bool) (err error) {
|
||||
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,
|
||||
Direction: tpact.Direction,
|
||||
Weight: tpact.Weight,
|
||||
ExtraParameters: tpact.ExtraParameters,
|
||||
ExpirationString: tpact.ExpiryTime,
|
||||
Balance: &Balance{
|
||||
Uuid: utils.GenUUID(),
|
||||
Value: tpact.Units,
|
||||
Weight: tpact.BalanceWeight,
|
||||
RatingSubject: tpact.RatingSubject,
|
||||
DestinationIds: tpact.DestinationIds,
|
||||
SharedGroup: tpact.SharedGroup,
|
||||
},
|
||||
}
|
||||
}
|
||||
tpr.actions[tag] = enacts
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if save {
|
||||
// write actions
|
||||
for k, as := range tpr.actions {
|
||||
err = tpr.ratingStorage.SetActions(k, as)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, stat := range tpr.cdrStats {
|
||||
if err := tpr.ratingStorage.SetCdrStats(stat); err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user