From fd658aeb01fe9f72a22d7733ecd026de5aee9d98 Mon Sep 17 00:00:00 2001 From: TeoV Date: Tue, 9 Feb 2021 10:28:18 +0200 Subject: [PATCH] Update ActionS loding from CSV --- engine/loader_csv_test.go | 55 ++++++++++++++++++--------------------- engine/model_helpers.go | 30 ++++++++++----------- loaders/loader_test.go | 45 ++++++++++++++------------------ 3 files changed, 59 insertions(+), 71 deletions(-) diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index 587bb03b8..7743a48b4 100644 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -1491,44 +1491,39 @@ func TestLoadActionProfiles(t *testing.T) { }, Actions: []*utils.TPAPAction{ { - ID: "TOPUP", - FilterIDs: []string{}, - TTL: "0s", - Type: "*topup", - Path: "~*balance.TestBalance.Value", - Value: "10", + ID: "TOPUP", + TTL: "0s", + Type: "*topup", + Path: "~*balance.TestBalance.Value", + Value: "10", }, { - ID: "SET_BALANCE_TEST_DATA", - FilterIDs: []string{}, - TTL: "0s", - Type: "*set_balance", - Path: "~*balance.TestDataBalance.Type", - Value: "*data", + ID: "SET_BALANCE_TEST_DATA", + TTL: "0s", + Type: "*set_balance", + Path: "~*balance.TestDataBalance.Type", + Value: "*data", }, { - ID: "TOPUP_TEST_DATA", - FilterIDs: []string{}, - TTL: "0s", - Type: "*topup", - Path: "~*balance.TestDataBalance.Value", - Value: "1024", + ID: "TOPUP_TEST_DATA", + TTL: "0s", + Type: "*topup", + Path: "~*balance.TestDataBalance.Value", + Value: "1024", }, { - ID: "SET_BALANCE_TEST_VOICE", - FilterIDs: []string{}, - TTL: "0s", - Type: "*set_balance", - Path: "~*balance.TestVoiceBalance.Type", - Value: "*voice", + ID: "SET_BALANCE_TEST_VOICE", + TTL: "0s", + Type: "*set_balance", + Path: "~*balance.TestVoiceBalance.Type", + Value: "*voice", }, { - ID: "TOPUP_TEST_VOICE", - FilterIDs: []string{}, - TTL: "0s", - Type: "*topup", - Path: "~*balance.TestVoiceBalance.Value", - Value: "15m15s", + ID: "TOPUP_TEST_VOICE", + TTL: "0s", + Type: "*topup", + Path: "~*balance.TestVoiceBalance.Value", + Value: "15m15s", }, }, } diff --git a/engine/model_helpers.go b/engine/model_helpers.go index 5ee90f0c9..f8ed469db 100644 --- a/engine/model_helpers.go +++ b/engine/model_helpers.go @@ -3221,23 +3221,21 @@ func (tps ActionProfileMdls) AsTPActionProfile() (result []*utils.TPActionProfil } if tp.ActionID != utils.EmptyString { - filterIDs := make([]string, 0) - if tp.ActionFilterIDs != utils.EmptyString { - filterAttrSplit := strings.Split(tp.ActionFilterIDs, utils.InfieldSep) - for _, filterAttr := range filterAttrSplit { - filterIDs = append(filterIDs, filterAttr) - } + tpAAction := &utils.TPAPAction{ + ID: tp.ActionID, + Blocker: tp.ActionBlocker, + TTL: tp.ActionTTL, + Type: tp.ActionType, + Opts: tp.ActionOpts, + Path: tp.ActionPath, + Value: tp.ActionValue, } - aPrf.Actions = append(aPrf.Actions, &utils.TPAPAction{ - ID: tp.ActionID, - FilterIDs: filterIDs, - Blocker: tp.ActionBlocker, - TTL: tp.ActionTTL, - Type: tp.ActionType, - Opts: tp.ActionOpts, - Path: tp.ActionPath, - Value: tp.ActionValue, - }) + if tp.ActionFilterIDs != utils.EmptyString { + filterIDs := make(utils.StringSet) + filterIDs.AddSlice(strings.Split(tp.ActionFilterIDs, utils.InfieldSep)) + tpAAction.FilterIDs = filterIDs.AsSlice() + } + aPrf.Actions = append(aPrf.Actions, tpAAction) } actPrfMap[tenID] = aPrf } diff --git a/loaders/loader_test.go b/loaders/loader_test.go index a5c9a7d96..6aa3c8565 100644 --- a/loaders/loader_test.go +++ b/loaders/loader_test.go @@ -2447,39 +2447,34 @@ func TestLoaderActionProfile(t *testing.T) { }, Actions: []*engine.APAction{ &engine.APAction{ - ID: "TOPUP", - FilterIDs: []string{}, - Type: "*topup", - Path: "~*balance.TestBalance.Value", - Value: config.NewRSRParsersMustCompile("10", utils.InfieldSep), + ID: "TOPUP", + Type: "*topup", + Path: "~*balance.TestBalance.Value", + Value: config.NewRSRParsersMustCompile("10", utils.InfieldSep), }, &engine.APAction{ - ID: "SET_BALANCE_TEST_DATA", - FilterIDs: []string{}, - Type: "*set_balance", - Path: "~*balance.TestDataBalance.Type", - Value: config.NewRSRParsersMustCompile("*data", utils.InfieldSep), + ID: "SET_BALANCE_TEST_DATA", + Type: "*set_balance", + Path: "~*balance.TestDataBalance.Type", + Value: config.NewRSRParsersMustCompile("*data", utils.InfieldSep), }, &engine.APAction{ - ID: "TOPUP_TEST_DATA", - FilterIDs: []string{}, - Type: "*topup", - Path: "~*balance.TestDataBalance.Value", - Value: config.NewRSRParsersMustCompile("1024", utils.InfieldSep), + ID: "TOPUP_TEST_DATA", + Type: "*topup", + Path: "~*balance.TestDataBalance.Value", + Value: config.NewRSRParsersMustCompile("1024", utils.InfieldSep), }, &engine.APAction{ - ID: "SET_BALANCE_TEST_VOICE", - FilterIDs: []string{}, - Type: "*set_balance", - Path: "~*balance.TestVoiceBalance.Type", - Value: config.NewRSRParsersMustCompile("*voice", utils.InfieldSep), + ID: "SET_BALANCE_TEST_VOICE", + Type: "*set_balance", + Path: "~*balance.TestVoiceBalance.Type", + Value: config.NewRSRParsersMustCompile("*voice", utils.InfieldSep), }, &engine.APAction{ - ID: "TOPUP_TEST_VOICE", - FilterIDs: []string{}, - Type: "*topup", - Path: "~*balance.TestVoiceBalance.Value", - Value: config.NewRSRParsersMustCompile("15m15s", utils.InfieldSep), + ID: "TOPUP_TEST_VOICE", + Type: "*topup", + Path: "~*balance.TestVoiceBalance.Value", + Value: config.NewRSRParsersMustCompile("15m15s", utils.InfieldSep), }, }, }