From 78c458bc701ff05a3874e425f0a5ae4d6fdb9cd8 Mon Sep 17 00:00:00 2001 From: TeoV Date: Mon, 11 Dec 2017 10:58:36 +0200 Subject: [PATCH] Attribute.Alias -> Attribute.Substitute --- apier/v1/attributes_it_test.go | 30 +++++++++++++++--------------- engine/attributes.go | 2 +- engine/attributes_it_test.go | 32 ++++++++++++++++---------------- engine/libattributes.go | 22 +++++++++++----------- engine/loader_csv_test.go | 6 +++--- engine/model_helpers.go | 26 +++++++++++++------------- engine/model_helpers_test.go | 24 ++++++++++++------------ engine/onstor_it_test.go | 24 ++++++++++++------------ utils/apitpdata.go | 4 ++-- 9 files changed, 85 insertions(+), 85 deletions(-) diff --git a/apier/v1/attributes_it_test.go b/apier/v1/attributes_it_test.go index 0682e7e2e..8a4374c56 100644 --- a/apier/v1/attributes_it_test.go +++ b/apier/v1/attributes_it_test.go @@ -152,14 +152,14 @@ func testAttributeSGetAttributeForEvent(t *testing.T) { Context: utils.ALIAS_CONTEXT_RATING, ActivationInterval: &utils.ActivationInterval{ ActivationTime: time.Date(2014, 1, 14, 0, 0, 0, 0, time.UTC)}, - Attributes: []*engine.Attribute{ - &engine.Attribute{ + Substitute: []*engine.Substitute{ + &engine.Substitute{ FieldName: utils.ACCOUNT, Initial: utils.ANY, Alias: "1001", Append: false, }, - &engine.Attribute{ + &engine.Substitute{ FieldName: utils.SUBJECT, Initial: utils.ANY, Alias: "1001", @@ -175,14 +175,14 @@ func testAttributeSGetAttributeForEvent(t *testing.T) { Context: utils.ALIAS_CONTEXT_RATING, ActivationInterval: &utils.ActivationInterval{ ActivationTime: time.Date(2014, 1, 14, 0, 0, 0, 0, time.UTC)}, - Attributes: []*engine.Attribute{ - &engine.Attribute{ + Substitute: []*engine.Substitute{ + &engine.Substitute{ FieldName: utils.SUBJECT, Initial: utils.ANY, Alias: "1001", Append: true, }, - &engine.Attribute{ + &engine.Substitute{ FieldName: utils.ACCOUNT, Initial: utils.ANY, Alias: "1001", @@ -260,8 +260,8 @@ func testAttributeSSetAlsPrf(t *testing.T) { ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC).Local(), ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC).Local(), }, - Attributes: []*engine.Attribute{ - &engine.Attribute{ + Substitute: []*engine.Substitute{ + &engine.Substitute{ FieldName: "FL1", Initial: "In1", Alias: "Al1", @@ -283,22 +283,22 @@ func testAttributeSSetAlsPrf(t *testing.T) { t.Errorf("Expecting : %+v, received: %+v", alsPrf.FilterIDs, reply.FilterIDs) } else if !reflect.DeepEqual(alsPrf.ActivationInterval, reply.ActivationInterval) { t.Errorf("Expecting : %+v, received: %+v", alsPrf.ActivationInterval, reply.ActivationInterval) - } else if !reflect.DeepEqual(len(alsPrf.Attributes), len(reply.Attributes)) { - t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(alsPrf.Attributes), utils.ToJSON(reply.Attributes)) + } else if !reflect.DeepEqual(len(alsPrf.Substitute), len(reply.Substitute)) { + t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(alsPrf.Substitute), utils.ToJSON(reply.Substitute)) } else if !reflect.DeepEqual(alsPrf.ID, reply.ID) { t.Errorf("Expecting : %+v, received: %+v", alsPrf.ID, reply.ID) } } func testAttributeSUpdateAlsPrf(t *testing.T) { - alsPrf.Attributes = []*engine.Attribute{ - &engine.Attribute{ + alsPrf.Substitute = []*engine.Substitute{ + &engine.Substitute{ FieldName: "FL1", Initial: "In1", Alias: "Al1", Append: true, }, - &engine.Attribute{ + &engine.Substitute{ FieldName: "FL2", Initial: "In2", Alias: "Al2", @@ -318,8 +318,8 @@ func testAttributeSUpdateAlsPrf(t *testing.T) { t.Errorf("Expecting : %+v, received: %+v", alsPrf.FilterIDs, reply.FilterIDs) } else if !reflect.DeepEqual(alsPrf.ActivationInterval, reply.ActivationInterval) { t.Errorf("Expecting : %+v, received: %+v", alsPrf.ActivationInterval, reply.ActivationInterval) - } else if !reflect.DeepEqual(len(alsPrf.Attributes), len(reply.Attributes)) { - t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(alsPrf.Attributes), utils.ToJSON(reply.Attributes)) + } else if !reflect.DeepEqual(len(alsPrf.Substitute), len(reply.Substitute)) { + t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(alsPrf.Substitute), utils.ToJSON(reply.Substitute)) } else if !reflect.DeepEqual(alsPrf.ID, reply.ID) { t.Errorf("Expecting : %+v, received: %+v", alsPrf.ID, reply.ID) } diff --git a/engine/attributes.go b/engine/attributes.go index 8a344e69c..8a579b8b5 100644 --- a/engine/attributes.go +++ b/engine/attributes.go @@ -121,7 +121,7 @@ func (alS *AttributeService) processEvent(ev *utils.CGREvent) (rply *AttrSProces return nil, err } rply = &AttrSProcessEventReply{MatchedProfile: attrPrf.ID, CGREvent: ev.Clone()} - for fldName, intialMp := range attrPrf.Attributes { + for fldName, intialMp := range attrPrf.Substitutes { initEvValIf, has := ev.Event[fldName] if !has { // we don't have initial in event, try append if anyInitial, has := intialMp[utils.ANY]; has && anyInitial.Append { diff --git a/engine/attributes_it_test.go b/engine/attributes_it_test.go index c03347aa9..ab3e8a97a 100644 --- a/engine/attributes_it_test.go +++ b/engine/attributes_it_test.go @@ -36,8 +36,8 @@ func TestExternalAttributeProfileAsAttributeProfile(t *testing.T) { ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC).Local(), }, Context: "con1", - Attributes: []*Attribute{ - &Attribute{ + Substitute: []*Substitute{ + &Substitute{ FieldName: "FL1", Initial: "In1", Alias: "Al1", @@ -46,9 +46,9 @@ func TestExternalAttributeProfileAsAttributeProfile(t *testing.T) { }, Weight: 20, } - attrMap := make(map[string]map[string]*Attribute) - attrMap["FL1"] = make(map[string]*Attribute) - attrMap["FL1"]["In1"] = &Attribute{ + attrMap := make(map[string]map[string]*Substitute) + attrMap["FL1"] = make(map[string]*Substitute) + attrMap["FL1"]["In1"] = &Substitute{ FieldName: "FL1", Initial: "In1", Alias: "Al1", @@ -62,9 +62,9 @@ func TestExternalAttributeProfileAsAttributeProfile(t *testing.T) { ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC).Local(), ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC).Local(), }, - Context: "con1", - Attributes: attrMap, - Weight: 20, + Context: "con1", + Substitutes: attrMap, + Weight: 20, } rcv := extAttr.AsAttributeProfile() @@ -74,9 +74,9 @@ func TestExternalAttributeProfileAsAttributeProfile(t *testing.T) { } func TestNewExternalAttributeProfileFromAttributeProfile(t *testing.T) { - attrMap := make(map[string]map[string]*Attribute) - attrMap["FL1"] = make(map[string]*Attribute) - attrMap["FL1"]["In1"] = &Attribute{ + attrMap := make(map[string]map[string]*Substitute) + attrMap["FL1"] = make(map[string]*Substitute) + attrMap["FL1"]["In1"] = &Substitute{ FieldName: "FL1", Initial: "In1", Alias: "Al1", @@ -90,9 +90,9 @@ func TestNewExternalAttributeProfileFromAttributeProfile(t *testing.T) { ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC).Local(), ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC).Local(), }, - Context: "con1", - Attributes: attrMap, - Weight: 20, + Context: "con1", + Substitutes: attrMap, + Weight: 20, } expected := &ExternalAttributeProfile{ @@ -104,8 +104,8 @@ func TestNewExternalAttributeProfileFromAttributeProfile(t *testing.T) { ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC).Local(), }, Context: "con1", - Attributes: []*Attribute{ - &Attribute{ + Substitute: []*Substitute{ + &Substitute{ FieldName: "FL1", Initial: "In1", Alias: "Al1", diff --git a/engine/libattributes.go b/engine/libattributes.go index 52a508d24..f2e57dbb8 100644 --- a/engine/libattributes.go +++ b/engine/libattributes.go @@ -24,7 +24,7 @@ import ( "github.com/cgrates/cgrates/utils" ) -type Attribute struct { +type Substitute struct { FieldName string Initial string Alias string @@ -35,9 +35,9 @@ type AttributeProfile struct { Tenant string ID string FilterIDs []string - ActivationInterval *utils.ActivationInterval // Activation interval - Context string // bind this AttributeProfile to specific context - Attributes map[string]map[string]*Attribute // map[FieldName][InitialValue]*Attribute + ActivationInterval *utils.ActivationInterval // Activation interval + Context string // bind this AttributeProfile to specific context + Substitutes map[string]map[string]*Substitute // map[FieldName][InitialValue]*Attribute Weight float64 } @@ -59,7 +59,7 @@ type ExternalAttributeProfile struct { FilterIDs []string ActivationInterval *utils.ActivationInterval // Activation interval Context string // bind this AttributeProfile to specific context - Attributes []*Attribute + Substitute []*Substitute Weight float64 } @@ -72,12 +72,12 @@ func (eap *ExternalAttributeProfile) AsAttributeProfile() *AttributeProfile { ActivationInterval: eap.ActivationInterval, Context: eap.Context, } - alsMap := make(map[string]map[string]*Attribute) - for _, als := range eap.Attributes { - alsMap[als.FieldName] = make(map[string]*Attribute) + alsMap := make(map[string]map[string]*Substitute) + for _, als := range eap.Substitute { + alsMap[als.FieldName] = make(map[string]*Substitute) alsMap[als.FieldName][als.Initial] = als } - alsPrf.Attributes = alsMap + alsPrf.Substitutes = alsMap return alsPrf } @@ -90,9 +90,9 @@ func NewExternalAttributeProfileFromAttributeProfile(alsPrf *AttributeProfile) * Context: alsPrf.Context, FilterIDs: alsPrf.FilterIDs, } - for key, val := range alsPrf.Attributes { + for key, val := range alsPrf.Substitutes { for key2, val2 := range val { - extals.Attributes = append(extals.Attributes, &Attribute{ + extals.Substitute = append(extals.Substitute, &Substitute{ FieldName: key, Initial: key2, Alias: val2.Alias, diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index 312b83e6e..02834ae7b 100755 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -1676,14 +1676,14 @@ func TestLoadAttributeProfiles(t *testing.T) { ActivationTime: "2014-07-29T15:00:00Z", }, Context: "con1", - Attributes: []*utils.TPRequestAttribute{ - &utils.TPRequestAttribute{ + Substitutes: []*utils.TPRequestSubstitute{ + &utils.TPRequestSubstitute{ FieldName: "Field1", Initial: "Initial1", Alias: "Alias1", Append: true, }, - &utils.TPRequestAttribute{ + &utils.TPRequestSubstitute{ FieldName: "Field2", Initial: "Initial2", Alias: "Alias2", diff --git a/engine/model_helpers.go b/engine/model_helpers.go index ed5258ab0..585c3c0b6 100755 --- a/engine/model_helpers.go +++ b/engine/model_helpers.go @@ -2670,7 +2670,7 @@ func (tps TPAttributes) AsTPAttributes() (result []*utils.TPAttribute) { th.Context = tp.Context } if tp.FieldName != "" { - th.Attributes = append(th.Attributes, &utils.TPRequestAttribute{ + th.Substitutes = append(th.Substitutes, &utils.TPRequestSubstitute{ FieldName: tp.FieldName, Initial: tp.Initial, Alias: tp.Alias, @@ -2689,10 +2689,10 @@ func (tps TPAttributes) AsTPAttributes() (result []*utils.TPAttribute) { } func APItoModelTPAttribute(th *utils.TPAttribute) (mdls TPAttributes) { - if len(th.Attributes) == 0 { + if len(th.Substitutes) == 0 { return } - for i, reqAttribute := range th.Attributes { + for i, reqAttribute := range th.Substitutes { mdl := &TPAttribute{ Tpid: th.TPid, Tenant: th.Tenant, @@ -2731,21 +2731,21 @@ func APItoModelTPAttribute(th *utils.TPAttribute) (mdls TPAttributes) { func APItoAttributeProfile(tpTH *utils.TPAttribute, timezone string) (th *AttributeProfile, err error) { th = &AttributeProfile{ - Tenant: tpTH.Tenant, - ID: tpTH.ID, - Weight: tpTH.Weight, - FilterIDs: []string{}, - Context: tpTH.Context, - Attributes: make(map[string]map[string]*Attribute, len(tpTH.Attributes)), + Tenant: tpTH.Tenant, + ID: tpTH.ID, + Weight: tpTH.Weight, + FilterIDs: []string{}, + Context: tpTH.Context, + Substitutes: make(map[string]map[string]*Substitute, len(tpTH.Substitutes)), } for _, fli := range tpTH.FilterIDs { th.FilterIDs = append(th.FilterIDs, fli) } - for _, reqAttr := range tpTH.Attributes { - if _, has := th.Attributes[reqAttr.FieldName]; !has { - th.Attributes[reqAttr.FieldName] = make(map[string]*Attribute) + for _, reqAttr := range tpTH.Substitutes { + if _, has := th.Substitutes[reqAttr.FieldName]; !has { + th.Substitutes[reqAttr.FieldName] = make(map[string]*Substitute) } - th.Attributes[reqAttr.FieldName][reqAttr.Initial] = &Attribute{ + th.Substitutes[reqAttr.FieldName][reqAttr.Initial] = &Substitute{ FieldName: reqAttr.FieldName, Initial: reqAttr.Initial, Alias: reqAttr.Alias, diff --git a/engine/model_helpers_test.go b/engine/model_helpers_test.go index 393adfe13..5a0fff3c7 100755 --- a/engine/model_helpers_test.go +++ b/engine/model_helpers_test.go @@ -1071,8 +1071,8 @@ func TestAPItoAttributeProfile(t *testing.T) { ExpiryTime: "", }, Context: "con1", - Attributes: []*utils.TPRequestAttribute{ - &utils.TPRequestAttribute{ + Substitutes: []*utils.TPRequestSubstitute{ + &utils.TPRequestSubstitute{ FieldName: "FL1", Initial: "In1", Alias: "Al1", @@ -1081,9 +1081,9 @@ func TestAPItoAttributeProfile(t *testing.T) { }, Weight: 20, } - attrMap := make(map[string]map[string]*Attribute) - attrMap["FL1"] = make(map[string]*Attribute) - attrMap["FL1"]["In1"] = &Attribute{ + attrMap := make(map[string]map[string]*Substitute) + attrMap["FL1"] = make(map[string]*Substitute) + attrMap["FL1"]["In1"] = &Substitute{ FieldName: "FL1", Initial: "In1", Alias: "Al1", @@ -1096,9 +1096,9 @@ func TestAPItoAttributeProfile(t *testing.T) { ActivationInterval: &utils.ActivationInterval{ ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC), }, - Context: "con1", - Attributes: attrMap, - Weight: 20, + Context: "con1", + Substitutes: attrMap, + Weight: 20, } if rcv, err := APItoAttributeProfile(tpAlsPrf, "UTC"); err != nil { t.Error(err) @@ -1118,8 +1118,8 @@ func TestAPItoModelTPAttribute(t *testing.T) { ExpiryTime: "", }, Context: "con1", - Attributes: []*utils.TPRequestAttribute{ - &utils.TPRequestAttribute{ + Substitutes: []*utils.TPRequestSubstitute{ + &utils.TPRequestSubstitute{ FieldName: "FL1", Initial: "In1", Alias: "Al1", @@ -1175,8 +1175,8 @@ func TestModelAsTPAttribute(t *testing.T) { ExpiryTime: "", }, Context: "con1", - Attributes: []*utils.TPRequestAttribute{ - &utils.TPRequestAttribute{ + Substitutes: []*utils.TPRequestSubstitute{ + &utils.TPRequestSubstitute{ FieldName: "FL1", Initial: "In1", Alias: "Al1", diff --git a/engine/onstor_it_test.go b/engine/onstor_it_test.go index 83023bee3..d32b5ef6e 100644 --- a/engine/onstor_it_test.go +++ b/engine/onstor_it_test.go @@ -1148,9 +1148,9 @@ func testOnStorITCacheSupplierProfile(t *testing.T) { } func testOnStorITCacheAttributeProfile(t *testing.T) { - mapAttributes := make(map[string]map[string]*Attribute) - mapAttributes["FN1"] = make(map[string]*Attribute) - mapAttributes["FN1"]["Init1"] = &Attribute{ + mapSubstitutes := make(map[string]map[string]*Substitute) + mapSubstitutes["FN1"] = make(map[string]*Substitute) + mapSubstitutes["FN1"]["Init1"] = &Substitute{ FieldName: "FN1", Initial: "Init1", Alias: "Val1", @@ -1163,9 +1163,9 @@ func testOnStorITCacheAttributeProfile(t *testing.T) { ActivationInterval: &utils.ActivationInterval{ ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC).Local(), }, - Context: "con1", - Attributes: mapAttributes, - Weight: 20, + Context: "con1", + Substitutes: mapSubstitutes, + Weight: 20, } if err := onStor.SetAttributeProfile(attrProfile); err != nil { t.Error(err) @@ -2493,9 +2493,9 @@ func testOnStorITCRUDSupplierProfile(t *testing.T) { } func testOnStorITCRUDAttributeProfile(t *testing.T) { - mapAttributes := make(map[string]map[string]*Attribute) - mapAttributes["FN1"] = make(map[string]*Attribute) - mapAttributes["FN1"]["Init1"] = &Attribute{ + mapSubstitutes := make(map[string]map[string]*Substitute) + mapSubstitutes["FN1"] = make(map[string]*Substitute) + mapSubstitutes["FN1"]["Init1"] = &Substitute{ FieldName: "FN1", Initial: "Init1", Alias: "Val1", @@ -2508,9 +2508,9 @@ func testOnStorITCRUDAttributeProfile(t *testing.T) { ActivationInterval: &utils.ActivationInterval{ ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC).Local(), }, - Context: "con1", - Attributes: mapAttributes, - Weight: 20, + Context: "con1", + Substitutes: mapSubstitutes, + Weight: 20, } if _, rcvErr := onStor.GetAttributeProfile("cgrates.org", "AttrPrf1", true, utils.NonTransactional); rcvErr != nil && rcvErr != utils.ErrNotFound { t.Error(rcvErr) diff --git a/utils/apitpdata.go b/utils/apitpdata.go index e139b0d4c..91665727c 100755 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -1382,7 +1382,7 @@ type TPSupplier struct { Weight float64 } -type TPRequestAttribute struct { +type TPRequestSubstitute struct { FieldName string Initial string Alias string @@ -1396,6 +1396,6 @@ type TPAttribute struct { FilterIDs []string ActivationInterval *TPActivationInterval // Time when this limit becomes active and expires Context string // bind this TPAttribute to specific context - Attributes []*TPRequestAttribute + Substitutes []*TPRequestSubstitute Weight float64 }