Change name from ExternalAttributeProfile to APIAttributeProfile

This commit is contained in:
porosnicuadrian
2021-01-12 16:34:54 +02:00
committed by Dan Christian Bogos
parent 0f71856262
commit 594f7bb557
8 changed files with 51 additions and 21 deletions

View File

@@ -26,20 +26,20 @@ import (
)
type AttributeWithCache struct {
*engine.ExternalAttributeProfile
*engine.APIAttributeProfile
Cache *string
Opts map[string]interface{}
}
//SetAttributeProfile add/update a new Attribute Profile
func (APIerSv2 *APIerSv2) SetAttributeProfile(arg *AttributeWithCache, reply *string) error {
if missing := utils.MissingStructFields(arg.ExternalAttributeProfile, []string{utils.ID}); len(missing) != 0 {
if missing := utils.MissingStructFields(arg.APIAttributeProfile, []string{utils.ID}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
if arg.Tenant == utils.EmptyString {
arg.Tenant = APIerSv2.Config.GeneralCfg().DefaultTenant
}
alsPrf, err := arg.ExternalAttributeProfile.AsAttributeProfile()
alsPrf, err := arg.APIAttributeProfile.AsAttributeProfile()
if err != nil {
return utils.APIErrorHandler(err)
}

View File

@@ -115,7 +115,7 @@ func testAttributeSRPCConn(t *testing.T) {
func testAttributeSSetAlsPrf(t *testing.T) {
extAlsPrf := &AttributeWithCache{
ExternalAttributeProfile: &engine.ExternalAttributeProfile{
APIAttributeProfile: &engine.APIAttributeProfile{
Tenant: "cgrates.org",
ID: "ExternalAttribute",
Contexts: []string{utils.MetaSessionS, utils.MetaCDRs},
@@ -173,7 +173,7 @@ func testAttributeSSetAlsPrf(t *testing.T) {
func testAttributeSUpdateAlsPrf(t *testing.T) {
extAlsPrf := &AttributeWithCache{
ExternalAttributeProfile: &engine.ExternalAttributeProfile{
APIAttributeProfile: &engine.APIAttributeProfile{
Tenant: "cgrates.org",
ID: "ExternalAttribute",
Contexts: []string{utils.MetaSessionS, utils.MetaCDRs},
@@ -247,7 +247,7 @@ func testAttributeSKillEngine(t *testing.T) {
func testAttributeSSetAlsPrfWithoutTenant(t *testing.T) {
extAlsPrf := &AttributeWithCache{
ExternalAttributeProfile: &engine.ExternalAttributeProfile{
APIAttributeProfile: &engine.APIAttributeProfile{
ID: "ExternalAttribute",
Contexts: []string{utils.MetaSessionS, utils.MetaCDRs},
FilterIDs: []string{"*string:~*req.Account:1001"},

View File

@@ -51,7 +51,7 @@ func (self *CmdSetAttributes) RpcMethod() string {
func (self *CmdSetAttributes) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &v2.AttributeWithCache{ExternalAttributeProfile: new(engine.ExternalAttributeProfile)}
self.rpcParams = &v2.AttributeWithCache{APIAttributeProfile: new(engine.APIAttributeProfile)}
}
return self.rpcParams
}

View File

@@ -88,8 +88,8 @@ type ExternalAttribute struct {
Value string
}
// ExternalAttributeProfile used by APIs
type ExternalAttributeProfile struct {
// APIAttributeProfile used by APIs
type APIAttributeProfile struct {
Tenant string
ID string
Contexts []string // bind this AttributeProfile to multiple contexts
@@ -101,7 +101,7 @@ type ExternalAttributeProfile struct {
}
// AsAttributeProfile converts the external attribute format to the actual AttributeProfile
func (ext *ExternalAttributeProfile) AsAttributeProfile() (attr *AttributeProfile, err error) {
func (ext *APIAttributeProfile) AsAttributeProfile() (attr *AttributeProfile, err error) {
attr = new(AttributeProfile)
if len(ext.Attributes) == 0 {
return nil, utils.NewErrMandatoryIeMissing("Attributes")

View File

@@ -29,7 +29,7 @@ import (
)
func TestConvertExternalToProfile(t *testing.T) {
external := &ExternalAttributeProfile{
external := &APIAttributeProfile{
Tenant: "cgrates.org",
ID: "ATTR_ID",
Contexts: []string{utils.MetaSessionS, utils.MetaCDRs},
@@ -77,7 +77,7 @@ func TestConvertExternalToProfile(t *testing.T) {
}
func TestConvertExternalToProfileMissing(t *testing.T) {
external := &ExternalAttributeProfile{
external := &APIAttributeProfile{
Tenant: "cgrates.org",
ID: "ATTR_ID",
Contexts: []string{utils.MetaSessionS, utils.MetaCDRs},
@@ -98,7 +98,7 @@ func TestConvertExternalToProfileMissing(t *testing.T) {
}
func TestConvertExternalToProfileMissing2(t *testing.T) {
external := &ExternalAttributeProfile{
external := &APIAttributeProfile{
Tenant: "cgrates.org",
ID: "ATTR_ID",
Contexts: []string{utils.MetaSessionS, utils.MetaCDRs},

View File

@@ -364,6 +364,14 @@ func testExpVerifyRoutes(t *testing.T) {
}
func testExpVerifyRateProfiles(t *testing.T) {
minDec, err := utils.NewDecimalFromUnit("1m")
if err != nil {
t.Error(err)
}
secDec, err := utils.NewDecimalFromUnit("1s")
if err != nil {
t.Error(err)
}
var reply *engine.RateProfile
minDecimal, err := utils.NewDecimalFromUnit("1m")
if err != nil {
@@ -393,10 +401,9 @@ func testExpVerifyRateProfiles(t *testing.T) {
IntervalRates: []*engine.IntervalRate{
{
IntervalStart: 0 * time.Second,
FixedFee: utils.NewDecimal(0, 0),
RecurrentFee: utils.NewDecimal(1, 2),
Unit: minDecimal,
Increment: secDecimal,
Unit: minDec,
Increment: secDec,
},
},
},

View File

@@ -866,12 +866,12 @@ cgrates.org,NewRes1
{Tag: "Tenant",
Path: "Tenant",
Type: utils.MetaComposed,
Value: config.NewRSRParsersMustCompile("~*req.0", utils.InfieldSep),
Value: config.NewRSRParsersMustCompile("~*req.0", utils.FieldsSep),
Mandatory: true},
{Tag: "ID",
Path: "ID",
Type: utils.MetaComposed,
Value: config.NewRSRParsersMustCompile("~*req.1", utils.InfieldSep),
Value: config.NewRSRParsersMustCompile("~*req.1", utils.FieldsSep),
Mandatory: true},
},
}

View File

@@ -177,6 +177,14 @@ func testRatePrfITFlush(t *testing.T) {
}
func testRatePrfITMigrateAndMove(t *testing.T) {
minDec, err := utils.NewDecimalFromUnit("1m")
if err != nil {
t.Error(err)
}
secDec, err := utils.NewDecimalFromUnit("1s")
if err != nil {
t.Error(err)
}
rPrf := &engine.RateProfile{
Tenant: "cgrates.org",
ID: "RP1",
@@ -184,21 +192,36 @@ func testRatePrfITMigrateAndMove(t *testing.T) {
Weight: 0,
RoundingMethod: "*up",
RoundingDecimals: 4,
MaxCostStrategy: "*free",
MinCost: utils.NewDecimal(1, 1),
MaxCost: utils.NewDecimal(6, 1),
MaxCostStrategy: "*free",
Rates: map[string]*engine.Rate{
"FIRST_GI": {
ID: "FIRST_GI",
FilterIDs: []string{"*gi:~*req.Usage:0"},
Weight: 0,
IntervalRates: []*engine.IntervalRate{
{
RecurrentFee: utils.NewDecimal(12, 2),
Unit: minDec,
Increment: minDec,
},
},
Blocker: false,
},
"SECOND_GI": {
ID: "SECOND_GI",
FilterIDs: []string{"*gi:~*req.Usage:1m"},
Weight: 10,
Blocker: false,
IntervalRates: []*engine.IntervalRate{
{
RecurrentFee: utils.NewDecimal(6, 2),
Unit: minDec,
Increment: secDec,
},
},
Blocker: false,
},
},
}