mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-24 08:38:45 +05:00
Alias profile context and Append, AliaSv1.GetAliasForEvent with test
This commit is contained in:
@@ -82,13 +82,11 @@ func (alSv1 *AliasSv1) Call(serviceMethod string,
|
||||
return utils.APIerRPCCall(alSv1, serviceMethod, args, reply)
|
||||
}
|
||||
|
||||
/*
|
||||
// GetAliasProfileForEvent returns matching AliasProfile for Event
|
||||
func (alSv1 *AliasSv1) GetAliasProfileForEvent(ev *utils.CGREvent,
|
||||
reply *engine.ApierAliasProfile) error {
|
||||
return alSv1.alS.V1GetSuppliers(args, reply)
|
||||
// GetAliasForEvent returns matching AliasProfile for Event
|
||||
func (alSv1 *AliasSv1) GetAliasForEvent(ev *utils.CGREvent,
|
||||
reply *engine.ExternalAliasProfile) error {
|
||||
return alSv1.alS.V1GetAliasForEvent(ev, reply)
|
||||
}
|
||||
*/
|
||||
|
||||
// ProcessEvent will replace event fields with the ones in maching AliasProfile
|
||||
func (alSv1 *AliasSv1) ProcessEvent(ev *utils.CGREvent,
|
||||
|
||||
@@ -49,6 +49,8 @@ var sTestsAlsPrf = []func(t *testing.T){
|
||||
testAlsPrfResetStorDb,
|
||||
testAlsPrfStartEngine,
|
||||
testAlsPrfRPCConn,
|
||||
testAlsPrfFromFolder,
|
||||
//testAlsPrfGetAliasForEvent,
|
||||
testAlsPrfGetAlsPrfBeforeSet,
|
||||
testAlsPrfSetAlsPrf,
|
||||
testAlsPrfUpdateAlsPrf,
|
||||
@@ -124,6 +126,56 @@ func testAlsPrfGetAlsPrfBeforeSet(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func testAlsPrfFromFolder(t *testing.T) {
|
||||
var reply string
|
||||
attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")}
|
||||
if err := alsPrfRPC.Call("ApierV1.LoadTariffPlanFromFolder", attrs, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
}
|
||||
|
||||
func testAlsPrfGetAliasForEvent(t *testing.T) {
|
||||
ev := &utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "testAlsPrfGetAliasForEvent",
|
||||
Event: map[string]interface{}{
|
||||
"Account": "1007",
|
||||
"Destination": "+491511231234",
|
||||
},
|
||||
}
|
||||
eAlsPrfl := engine.ExternalAliasProfile{
|
||||
Tenant: ev.Tenant,
|
||||
ID: "ALS1",
|
||||
FilterIDs: []string{"FLTR_ACNT_1007"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC).Local()},
|
||||
Aliases: []*engine.AliasEntry{
|
||||
&engine.AliasEntry{
|
||||
FieldName: utils.ACCOUNT,
|
||||
Initial: utils.ANY,
|
||||
Alias: "1001",
|
||||
Append: false,
|
||||
},
|
||||
&engine.AliasEntry{
|
||||
FieldName: utils.SUBJECT,
|
||||
Initial: utils.ANY,
|
||||
Alias: "1001",
|
||||
Append: false,
|
||||
},
|
||||
},
|
||||
Weight: 10.0,
|
||||
}
|
||||
var alsReply engine.ExternalAliasProfile
|
||||
if err := alsPrfRPC.Call(utils.AliasSv1GetAliasForEvent,
|
||||
ev, &alsReply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eAlsPrfl, alsReply) {
|
||||
t.Errorf("Expecting: %s, received: %s",
|
||||
utils.ToJSON(eAlsPrfl), utils.ToJSON(alsReply))
|
||||
}
|
||||
}
|
||||
|
||||
func testAlsPrfSetAlsPrf(t *testing.T) {
|
||||
alsPrf = &engine.ExternalAliasProfile{
|
||||
Tenant: "cgrates.org",
|
||||
|
||||
@@ -116,6 +116,12 @@
|
||||
},
|
||||
|
||||
|
||||
"alias": { // Alias service (*new)
|
||||
"enabled": true, // starts Alias service: <true|false>.
|
||||
"indexed_fields": [], // query indexes based on these fields for faster processing
|
||||
},
|
||||
|
||||
|
||||
"resources": {
|
||||
"enabled": true,
|
||||
"store_interval": "1s",
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#,Tenant,ID,FilterIDs,ActivationInterval,FieldName,Initial,Alias,Weight
|
||||
cgrates.org,ALS1,FLTR_1,2014-01-14T00:00:00Z,Field1,Initial1,Alias1,20
|
||||
cgrates.org,ALS1,,,Field2,Initial2,Alias2,
|
||||
#Tenant,ID,FilterIDs,ActivationInterval,Context,FieldName,Initial,Alias,Append,Weight
|
||||
cgrates.org,ALS1,FLTR_ACNT_1007,2014-01-14T00:00:00Z,Account,*any,1001,10
|
||||
cgrates.org,ALS1,,,Subject,*any,1001,
|
||||
|
||||
|
@@ -98,6 +98,30 @@ func (alS *AliasService) matchingAliasProfilesForEvent(ev *utils.CGREvent) (aPrf
|
||||
return
|
||||
}
|
||||
|
||||
func (alS *AliasService) aliasProfileForEvent(ev *utils.CGREvent) (alsPrfl *AliasProfile, err error) {
|
||||
var alsPrfls AliasProfiles
|
||||
if alsPrfls, err = alS.matchingAliasProfilesForEvent(ev); err != nil {
|
||||
return
|
||||
} else if len(alsPrfls) == 0 {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
return alsPrfls[0], nil
|
||||
}
|
||||
|
||||
func (alS *AliasService) V1GetAliasForEvent(ev *utils.CGREvent,
|
||||
extAlsPrf *ExternalAliasProfile) (err error) {
|
||||
alsPrf, err := alS.aliasProfileForEvent(ev)
|
||||
if err != nil {
|
||||
if err != utils.ErrNotFound {
|
||||
err = utils.NewErrServerError(err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
eAlsPrfl := NewExternalAliasProfileFromAliasProfile(alsPrf)
|
||||
*extAlsPrf = *eAlsPrfl
|
||||
return
|
||||
}
|
||||
|
||||
func (alS *AliasService) V1ProcessEvent(ev *utils.CGREvent,
|
||||
reply *string) (err error) {
|
||||
return
|
||||
|
||||
@@ -28,6 +28,7 @@ type AliasEntry struct {
|
||||
FieldName string
|
||||
Initial string
|
||||
Alias string
|
||||
Append bool
|
||||
}
|
||||
|
||||
type AliasProfile struct {
|
||||
@@ -35,6 +36,7 @@ type AliasProfile struct {
|
||||
ID string
|
||||
FilterIDs []string
|
||||
ActivationInterval *utils.ActivationInterval // Activation interval
|
||||
Context string // bind this AliasProfile to specific context
|
||||
Aliases map[string]map[string]string // map[FieldName][InitialValue]AliasValue
|
||||
Weight float64
|
||||
}
|
||||
|
||||
@@ -27,10 +27,11 @@ import (
|
||||
|
||||
// CGREvent is a generic event processed by CGR services
|
||||
type CGREvent struct {
|
||||
Tenant string
|
||||
ID string
|
||||
Time *time.Time // event time
|
||||
Event map[string]interface{}
|
||||
Tenant string
|
||||
ID string
|
||||
Context string // attach the event to a context
|
||||
Time *time.Time // event time
|
||||
Event map[string]interface{}
|
||||
}
|
||||
|
||||
func (ev *CGREvent) CheckMandatoryFields(fldNames []string) error {
|
||||
|
||||
@@ -622,6 +622,11 @@ const (
|
||||
SupplierSv1GetSuppliers = "SupplierSv1.GetSuppliers"
|
||||
)
|
||||
|
||||
// AliasS APIs
|
||||
const (
|
||||
AliasSv1GetAliasForEvent = "AliasSv1.GetAliasForEvent"
|
||||
)
|
||||
|
||||
func buildCacheInstRevPrefixes() {
|
||||
CachePrefixToInstance = make(map[string]string)
|
||||
for k, v := range CacheInstanceToPrefix {
|
||||
|
||||
Reference in New Issue
Block a user