mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Attribute.Alias -> Attribute.Substitute
This commit is contained in:
committed by
Dan Christian Bogos
parent
175767f6d5
commit
78c458bc70
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user