mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Correctly migrate Value for Attributes ( v4 to current ) in case of dynamic prefix fixes #2029
This commit is contained in:
committed by
Dan Christian Bogos
parent
2497d0dd4e
commit
1f684b5d1a
@@ -425,10 +425,21 @@ func (v4AttrPrf v4AttributeProfile) AsAttributeProfile() (attrPrf *engine.Attrib
|
||||
ActivationInterval: v4AttrPrf.ActivationInterval,
|
||||
}
|
||||
for _, attr := range v4AttrPrf.Attributes {
|
||||
val := attr.Value.GetRule()
|
||||
rsrVal := attr.Value
|
||||
if strings.HasPrefix(val, utils.DynamicDataPrefix) {
|
||||
val = val[1:] // remove the DynamicDataPrefix
|
||||
val = utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + val
|
||||
rsrVal, err = config.NewRSRParsers(val, true, config.CgrConfig().GeneralCfg().RSRSep)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
attrPrf.Attributes = append(attrPrf.Attributes, &engine.Attribute{
|
||||
FilterIDs: attr.FilterIDs,
|
||||
Path: utils.MetaReq + utils.NestingSep + attr.FieldName,
|
||||
Value: attr.Value,
|
||||
Value: rsrVal,
|
||||
Type: attr.Type,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -592,16 +592,16 @@ func testAttrITMigrateV4(t *testing.T) {
|
||||
Tenant: "cgrates.org",
|
||||
ID: "ATTR_1",
|
||||
Contexts: []string{utils.MetaSessionS},
|
||||
FilterIDs: []string{"*string:Accont:1001"},
|
||||
FilterIDs: []string{"*string:~*req.Accont:1001"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
},
|
||||
Attributes: []*v4Attribute{
|
||||
&v4Attribute{
|
||||
FilterIDs: []string{"*string:FL1:In1"},
|
||||
FilterIDs: []string{"*string:~*req.FL1:In1"},
|
||||
FieldName: "FL1",
|
||||
Value: config.NewRSRParsersMustCompile("Al1", true, utils.INFIELD_SEP),
|
||||
Value: config.NewRSRParsersMustCompile("~Category:s/(.*)/${1}_UK_Mobile_Vodafone_GBRVF/", true, utils.INFIELD_SEP),
|
||||
Type: utils.MetaVariable,
|
||||
},
|
||||
},
|
||||
@@ -612,17 +612,17 @@ func testAttrITMigrateV4(t *testing.T) {
|
||||
Tenant: "cgrates.org",
|
||||
ID: "ATTR_1",
|
||||
Contexts: []string{utils.MetaSessionS},
|
||||
FilterIDs: []string{"*string:Accont:1001"},
|
||||
FilterIDs: []string{"*string:~*req.Accont:1001"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
},
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
FilterIDs: []string{"*string:FL1:In1"},
|
||||
FilterIDs: []string{"*string:~*req.FL1:In1"},
|
||||
Path: utils.MetaReq + utils.NestingSep + "FL1",
|
||||
Type: utils.MetaVariable,
|
||||
Value: config.NewRSRParsersMustCompile("Al1", true, utils.INFIELD_SEP),
|
||||
Value: config.NewRSRParsersMustCompile("~*req.Category:s/(.*)/${1}_UK_Mobile_Vodafone_GBRVF/", true, utils.INFIELD_SEP),
|
||||
},
|
||||
},
|
||||
Weight: 20,
|
||||
|
||||
@@ -214,3 +214,48 @@ func TestV3AttributeProfileAsAttributeProfile(t *testing.T) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(attrPrf), utils.ToJSON(ap))
|
||||
}
|
||||
}
|
||||
|
||||
func TestV4AttributeProfileAsAttributeProfile(t *testing.T) {
|
||||
cloneExpTime := time.Now().Add(time.Duration(20 * time.Minute))
|
||||
v4Attribute := v4AttributeProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "attributeprofile1",
|
||||
Contexts: []string{utils.MetaSessionS},
|
||||
FilterIDs: []string{"filter1"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
ExpiryTime: cloneExpTime,
|
||||
},
|
||||
Attributes: []*v4Attribute{
|
||||
&v4Attribute{
|
||||
FieldName: "FL1",
|
||||
Type: utils.MetaVariable,
|
||||
Value: config.NewRSRParsersMustCompile("~Category:s/(.*)/${1}_UK_Mobile_Vodafone_GBRVF/", true, utils.INFIELD_SEP),
|
||||
},
|
||||
},
|
||||
Weight: 20,
|
||||
}
|
||||
attrPrf := &engine.AttributeProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "attributeprofile1",
|
||||
Contexts: []string{utils.MetaSessionS},
|
||||
FilterIDs: []string{"filter1"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
ExpiryTime: cloneExpTime,
|
||||
},
|
||||
Attributes: []*engine.Attribute{
|
||||
&engine.Attribute{
|
||||
Path: utils.MetaReq + utils.NestingSep + "FL1",
|
||||
Type: utils.MetaVariable,
|
||||
Value: config.NewRSRParsersMustCompile("~*req.Category:s/(.*)/${1}_UK_Mobile_Vodafone_GBRVF/", true, utils.INFIELD_SEP),
|
||||
},
|
||||
},
|
||||
Weight: 20,
|
||||
}
|
||||
if ap, err := v4Attribute.AsAttributeProfile(); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(attrPrf, ap) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(attrPrf), utils.ToJSON(ap))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user