Add Type in AttributeProfile

This commit is contained in:
TeoV
2019-04-03 18:22:16 +03:00
committed by Dan Christian Bogos
parent 6b79c01287
commit ff49c8997e
15 changed files with 95 additions and 64 deletions

View File

@@ -169,16 +169,34 @@ func (alS *AttributeService) processEvent(args *AttrArgsProcessEvent) (
continue
}
}
substitute, err := attribute.Substitute.ParseEvent(args.Event)
var substitute string
var err error
switch attribute.Type {
case utils.META_CONSTANT:
substitute, err = attribute.Substitute.ParseValue(utils.EmptyString)
case utils.MetaVariable, utils.META_COMPOSED:
substitute, err = attribute.Substitute.ParseEvent(args.Event)
default: // backwards compatible in case that Type is empty
substitute, err = attribute.Substitute.ParseEvent(args.Event)
}
if err != nil {
return nil, err
}
rply.AlteredFields = append(rply.AlteredFields, attribute.FieldName)
if substitute == utils.META_NONE {
delete(rply.CGREvent.Event, attribute.FieldName)
} else {
rply.CGREvent.Event[attribute.FieldName] = substitute
continue
}
rply.AlteredFields = append(rply.AlteredFields, attribute.FieldName)
if attribute.Type == utils.META_COMPOSED {
evStrVal, err := utils.IfaceAsString(rply.CGREvent.Event[attribute.FieldName])
if err != nil {
return nil, err
}
substitute = evStrVal + substitute
}
rply.CGREvent.Event[attribute.FieldName] = substitute
}
return
}

View File

@@ -28,6 +28,7 @@ import (
type Attribute struct {
FilterIDs []string
FieldName string
Type string
Substitute config.RSRParsers
}

View File

@@ -257,9 +257,9 @@ cgrates.org,SPP_1,,,,,supplier1,FLTR_DST_DE,Account2,RPL_3,ResGroup3,Stat2,10,,,
cgrates.org,SPP_1,,,,,supplier1,,,,ResGroup4,Stat3,10,,,
`
attributeProfiles = `
#Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,FieldName,Substitute,Blocker,Weight
cgrates.org,ALS1,con1,FLTR_1,2014-07-29T15:00:00Z,*string:Field1:Initial,Field1,Sub1,true,20
cgrates.org,ALS1,con2;con3,,,,Field2,Sub2,true,20
#Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,FieldName,Type,Substitute,Blocker,Weight
cgrates.org,ALS1,con1,FLTR_1,2014-07-29T15:00:00Z,*string:Field1:Initial,Field1,*variable,Sub1,true,20
cgrates.org,ALS1,con2;con3,,,,Field2,*variable,Sub2,true,20
`
chargerProfiles = `
#Tenant,ID,FilterIDs,ActivationInterval,RunID,AttributeIDs,Weight
@@ -1513,11 +1513,13 @@ func TestLoadAttributeProfiles(t *testing.T) {
&utils.TPAttribute{
FilterIDs: []string{"*string:Field1:Initial"},
FieldName: "Field1",
Type: utils.MetaVariable,
Substitute: "Sub1",
},
&utils.TPAttribute{
FilterIDs: []string{},
FieldName: "Field2",
Type: utils.MetaVariable,
Substitute: "Sub2",
},
},

View File

@@ -2070,6 +2070,7 @@ func (tps TPAttributes) AsTPAttributes() (result []*utils.TPAttributeProfile) {
}
th.Attributes = append(th.Attributes, &utils.TPAttribute{
FilterIDs: filterIDs,
Type: tp.Type,
FieldName: tp.FieldName,
Substitute: tp.Substitute,
})
@@ -2135,6 +2136,7 @@ func APItoModelTPAttribute(th *utils.TPAttributeProfile) (mdls TPAttributes) {
}
mdl.FieldName = reqAttribute.FieldName
mdl.Substitute = reqAttribute.Substitute
mdl.Type = reqAttribute.Type
mdls = append(mdls, mdl)
}
return
@@ -2164,6 +2166,7 @@ func APItoAttributeProfile(tpAttr *utils.TPAttributeProfile, timezone string) (a
attrPrf.Attributes[i] = &Attribute{
FilterIDs: reqAttr.FilterIDs,
FieldName: reqAttr.FieldName,
Type: reqAttr.Type,
Substitute: sbstPrsr,
}
}

View File

@@ -367,9 +367,10 @@ type TPAttribute struct {
ActivationInterval string `index:"4" re:""`
AttributeFilterIDs string `index:"5" re:""`
FieldName string `index:"6" re:""`
Substitute string `index:"7" re:""`
Blocker bool `index:"8" re:""`
Weight float64 `index:"9" re:"\d+\.?\d*"`
Type string `index:"7" re:""`
Substitute string `index:"8" re:""`
Blocker bool `index:"9" re:""`
Weight float64 `index:"10" re:"\d+\.?\d*"`
CreatedAt time.Time
}