mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Migrator improvements for aliases and users
This commit is contained in:
@@ -103,17 +103,34 @@ func alias2AtttributeProfile(alias *v1Alias, defaultTenant string) *engine.Attri
|
||||
if len(destination) == 0 || destination == utils.META_ANY {
|
||||
destination = av.DestinationId
|
||||
}
|
||||
for fieldname, vals := range av.Pairs {
|
||||
for fieldName, vals := range av.Pairs {
|
||||
for initial, substitute := range vals {
|
||||
filterIDs := make([]string, 0)
|
||||
if initial != utils.META_ANY {
|
||||
filterIDs = append(filterIDs, utils.MetaString+":"+fieldname+":"+initial)
|
||||
if fieldName == utils.Tenant {
|
||||
fieldName = utils.MetaTenant
|
||||
}
|
||||
out.Attributes = append(out.Attributes, &engine.Attribute{
|
||||
FilterIDs: filterIDs,
|
||||
FieldName: fieldname,
|
||||
attr := &engine.Attribute{
|
||||
FieldName: fieldName,
|
||||
Substitute: config.NewRSRParsersMustCompile(substitute, true, utils.INFIELD_SEP),
|
||||
})
|
||||
}
|
||||
out.Attributes = append(out.Attributes, attr)
|
||||
// Add attribute filters if needed
|
||||
if initial == "" || initial == utils.META_ANY {
|
||||
continue
|
||||
}
|
||||
if fieldName == utils.MetaTenant { // no filter for tenant
|
||||
continue
|
||||
}
|
||||
if fieldName == utils.Category && alias.Category == initial {
|
||||
continue
|
||||
}
|
||||
if fieldName == utils.Account && alias.Account == initial {
|
||||
continue
|
||||
}
|
||||
if fieldName == utils.Subject && alias.Subject == initial {
|
||||
continue
|
||||
}
|
||||
attr.FilterIDs = append(attr.FilterIDs,
|
||||
fmt.Sprintf("%s:~%s:%s", utils.MetaString, fieldName, initial))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,10 +112,10 @@ func TestAlias2AtttributeProfile(t *testing.T) {
|
||||
DestinationId: "DST_1003",
|
||||
Pairs: map[string]map[string]string{
|
||||
"Account": map[string]string{
|
||||
"1001": "1002",
|
||||
"": "1002",
|
||||
},
|
||||
"Subject": map[string]string{
|
||||
"1001": "call_1001",
|
||||
"": "call_1001",
|
||||
},
|
||||
},
|
||||
Weight: 10,
|
||||
@@ -144,6 +144,22 @@ func TestAlias2AtttributeProfile(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
6: {
|
||||
Tenant: utils.META_ANY,
|
||||
Category: "somecateg_5141",
|
||||
Account: utils.META_ANY,
|
||||
Subject: utils.META_ANY,
|
||||
Context: "*rated",
|
||||
Values: v1AliasValues{
|
||||
&v1AliasValue{
|
||||
Pairs: map[string]map[string]string{
|
||||
utils.Category: map[string]string{
|
||||
"somecateg_5141": "somecateg_roam_fromz4",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
expected := map[int]*engine.AttributeProfile{
|
||||
0: {
|
||||
@@ -164,7 +180,7 @@ func TestAlias2AtttributeProfile(t *testing.T) {
|
||||
ActivationInterval: nil,
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
FilterIDs: []string{"*string:Account:1001"},
|
||||
FilterIDs: []string{"*string:~Account:1001"},
|
||||
FieldName: "Account",
|
||||
Substitute: config.NewRSRParsersMustCompile("1002", true, utils.INFIELD_SEP),
|
||||
},
|
||||
@@ -180,12 +196,12 @@ func TestAlias2AtttributeProfile(t *testing.T) {
|
||||
ActivationInterval: nil,
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
FilterIDs: []string{"*string:Account:1001"},
|
||||
FilterIDs: []string{"*string:~Account:1001"},
|
||||
FieldName: "Account",
|
||||
Substitute: config.NewRSRParsersMustCompile("1002", true, utils.INFIELD_SEP),
|
||||
},
|
||||
{
|
||||
FilterIDs: []string{"*string:Account:1003"},
|
||||
FilterIDs: []string{"*string:~Account:1003"},
|
||||
FieldName: "Account",
|
||||
Substitute: config.NewRSRParsersMustCompile("1004", true, utils.INFIELD_SEP),
|
||||
},
|
||||
@@ -201,12 +217,12 @@ func TestAlias2AtttributeProfile(t *testing.T) {
|
||||
ActivationInterval: nil,
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
FilterIDs: []string{"*string:Account:1001"},
|
||||
FilterIDs: []string{"*string:~Account:1001"},
|
||||
FieldName: "Account",
|
||||
Substitute: config.NewRSRParsersMustCompile("1002", true, utils.INFIELD_SEP),
|
||||
},
|
||||
{
|
||||
FilterIDs: []string{"*string:Account:1003"},
|
||||
FilterIDs: []string{"*string:~Account:1003"},
|
||||
FieldName: "Account",
|
||||
Substitute: config.NewRSRParsersMustCompile("1004", true, utils.INFIELD_SEP),
|
||||
},
|
||||
@@ -226,12 +242,10 @@ func TestAlias2AtttributeProfile(t *testing.T) {
|
||||
ActivationInterval: nil,
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
FilterIDs: []string{"*string:Account:1001"},
|
||||
FieldName: "Account",
|
||||
Substitute: config.NewRSRParsersMustCompile("1002", true, utils.INFIELD_SEP),
|
||||
},
|
||||
{
|
||||
FilterIDs: []string{"*string:Subject:1001"},
|
||||
FieldName: "Subject",
|
||||
Substitute: config.NewRSRParsersMustCompile("call_1001", true, utils.INFIELD_SEP),
|
||||
},
|
||||
@@ -251,19 +265,33 @@ func TestAlias2AtttributeProfile(t *testing.T) {
|
||||
ActivationInterval: nil,
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
FilterIDs: []string{"*string:Account:1001"},
|
||||
FieldName: "Account",
|
||||
Substitute: config.NewRSRParsersMustCompile("1002", true, utils.INFIELD_SEP),
|
||||
},
|
||||
{
|
||||
FilterIDs: []string{"*string:Category:call_1001"},
|
||||
FieldName: "Category",
|
||||
FilterIDs: []string{"*string:~Category:call_1001"},
|
||||
Substitute: config.NewRSRParsersMustCompile("call_1002", true, utils.INFIELD_SEP),
|
||||
},
|
||||
},
|
||||
Blocker: false,
|
||||
Weight: 20,
|
||||
},
|
||||
6: {
|
||||
Tenant: "cgrates.org",
|
||||
ID: aliases[6].GetId(),
|
||||
Contexts: []string{utils.META_ANY},
|
||||
FilterIDs: []string{
|
||||
"*string:~Category:somecateg_5141",
|
||||
},
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
FieldName: utils.Category,
|
||||
Substitute: config.NewRSRParsersMustCompile("somecateg_roam_fromz4", true, utils.INFIELD_SEP),
|
||||
},
|
||||
},
|
||||
Weight: 20,
|
||||
},
|
||||
}
|
||||
for i := range expected {
|
||||
rply := alias2AtttributeProfile(aliases[i], defaultTenant)
|
||||
|
||||
@@ -72,6 +72,18 @@ func TestUserProfile2attributeProfile(t *testing.T) {
|
||||
},
|
||||
Weight: 10,
|
||||
},
|
||||
4: &v1UserProfile{
|
||||
Tenant: usrTenant,
|
||||
UserName: "acstmusername",
|
||||
Profile: map[string]string{
|
||||
"Account": "acnt63",
|
||||
"Subject": "acnt63",
|
||||
"ReqType": "*prepaid",
|
||||
"msisdn": "12345",
|
||||
"imsi": "12345",
|
||||
},
|
||||
Weight: 10,
|
||||
},
|
||||
}
|
||||
expected := map[int]*engine.AttributeProfile{
|
||||
0: {
|
||||
@@ -104,10 +116,12 @@ func TestUserProfile2attributeProfile(t *testing.T) {
|
||||
Weight: 10,
|
||||
},
|
||||
2: {
|
||||
Tenant: defaultTenant,
|
||||
ID: "1001",
|
||||
Contexts: []string{utils.META_ANY},
|
||||
FilterIDs: []string{"*string:~Account:1002"},
|
||||
Tenant: defaultTenant,
|
||||
ID: "1001",
|
||||
Contexts: []string{utils.META_ANY},
|
||||
FilterIDs: []string{
|
||||
"*string:~Account:1002",
|
||||
},
|
||||
ActivationInterval: nil,
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
@@ -141,6 +155,39 @@ func TestUserProfile2attributeProfile(t *testing.T) {
|
||||
Blocker: false,
|
||||
Weight: 10,
|
||||
},
|
||||
4: {
|
||||
Tenant: defaultTenant,
|
||||
ID: "acstmusername",
|
||||
Contexts: []string{utils.META_ANY},
|
||||
FilterIDs: []string{
|
||||
"*string:~Account:acnt63",
|
||||
},
|
||||
ActivationInterval: nil,
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
FieldName: utils.MetaTenant,
|
||||
Substitute: config.NewRSRParsersMustCompile(usrTenant, true, utils.INFIELD_SEP),
|
||||
},
|
||||
{
|
||||
FieldName: utils.RequestType,
|
||||
Substitute: config.NewRSRParsersMustCompile("*prepaid", true, utils.INFIELD_SEP),
|
||||
},
|
||||
{
|
||||
FieldName: utils.Subject,
|
||||
Substitute: config.NewRSRParsersMustCompile("acnt63", true, utils.INFIELD_SEP),
|
||||
},
|
||||
{
|
||||
FieldName: "imsi",
|
||||
Substitute: config.NewRSRParsersMustCompile("12345", true, utils.INFIELD_SEP),
|
||||
},
|
||||
{
|
||||
FieldName: "msisdn",
|
||||
Substitute: config.NewRSRParsersMustCompile("12345", true, utils.INFIELD_SEP),
|
||||
},
|
||||
},
|
||||
Blocker: false,
|
||||
Weight: 10,
|
||||
},
|
||||
}
|
||||
for i := range expected {
|
||||
rply := userProfile2attributeProfile(users[i])
|
||||
@@ -151,7 +198,7 @@ func TestUserProfile2attributeProfile(t *testing.T) {
|
||||
return rply.Attributes[i].FieldName < rply.Attributes[j].FieldName
|
||||
}) // only for test; map returns random keys
|
||||
if !reflect.DeepEqual(expected[i], rply) {
|
||||
t.Errorf("For %v expected: %s ,received: %s ", i, utils.ToJSON(expected[i]), utils.ToJSON(rply))
|
||||
t.Errorf("For %v expected: %s ,\nreceived: %s ", i, utils.ToIJSON(expected[i]), utils.ToIJSON(rply))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user