diff --git a/accounts/accounts.go b/accounts/accounts.go index 771be945b..946e71f31 100644 --- a/accounts/accounts.go +++ b/accounts/accounts.go @@ -68,7 +68,7 @@ func (aS *AccountS) Call(serviceMethod string, args interface{}, reply interface // if lked option is passed, each AccountProfile will be also locked // so it becomes responsibility of upper layers to release the lock func (aS *AccountS) matchingAccountsForEvent(tnt string, cgrEv *utils.CGREvent, - acntIDs []string, lked bool) (acnts utils.AccountProfilesWithWeight, err error) { + acntIDs []string, lked bool) (acnts utils.AccountsWithWeight, err error) { evNm := utils.MapStorage{ utils.MetaReq: cgrEv.Event, utils.MetaOpts: cgrEv.APIOpts, @@ -97,7 +97,7 @@ func (aS *AccountS) matchingAccountsForEvent(tnt string, cgrEv *utils.CGREvent, refID = guardian.Guardian.GuardIDs("", aS.cfg.GeneralCfg().LockingTimeout, cacheKey) // RPC caching needs to be atomic } - var qAcnt *utils.AccountProfile + var qAcnt *utils.Account if qAcnt, err = aS.dm.GetAccountProfile(tnt, acntID); err != nil { guardian.Guardian.UnguardIDs(refID) if err == utils.ErrNotFound { @@ -129,7 +129,7 @@ func (aS *AccountS) matchingAccountsForEvent(tnt string, cgrEv *utils.CGREvent, unlockAccountProfiles(acnts) return } - acnts = append(acnts, &utils.AccountProfileWithWeight{qAcnt, weight, refID}) + acnts = append(acnts, &utils.AccountWithWeight{qAcnt, weight, refID}) } if len(acnts) == 0 { return nil, utils.ErrNotFound @@ -139,7 +139,7 @@ func (aS *AccountS) matchingAccountsForEvent(tnt string, cgrEv *utils.CGREvent, } // accountsDebit will debit an usage out of multiple accounts -func (aS *AccountS) accountsDebit(acnts []*utils.AccountProfileWithWeight, +func (aS *AccountS) accountsDebit(acnts []*utils.AccountWithWeight, cgrEv *utils.CGREvent, concretes, store bool) (ec *utils.EventCharges, err error) { usage := decimal.New(int64(72*time.Hour), 0) var usgEv time.Duration @@ -164,9 +164,9 @@ func (aS *AccountS) accountsDebit(acnts []*utils.AccountProfileWithWeight, if usage.Cmp(decimal.New(0, 0)) == 0 { return // no more debits } - acntBkps[i] = acnt.AccountProfile.AccountBalancesBackup() + acntBkps[i] = acnt.Account.AccountBalancesBackup() var ecDbt *utils.EventCharges - if ecDbt, err = aS.accountDebit(acnt.AccountProfile, + if ecDbt, err = aS.accountDebit(acnt.Account, new(decimal.Big).Copy(usage), cgrEv, concretes); err != nil { if store { restoreAccounts(aS.dm, acnts, acntBkps) @@ -179,8 +179,8 @@ func (aS *AccountS) accountsDebit(acnts []*utils.AccountProfileWithWeight, if ec == nil { // no debit performed yet ec = utils.NewEventCharges() } - if store && acnt.AccountProfile.BalancesAltered(acntBkps[i]) { - if err = aS.dm.SetAccountProfile(acnt.AccountProfile, false); err != nil { + if store && acnt.Account.BalancesAltered(acntBkps[i]) { + if err = aS.dm.SetAccountProfile(acnt.Account, false); err != nil { restoreAccounts(aS.dm, acnts, acntBkps) return } @@ -198,7 +198,7 @@ func (aS *AccountS) accountsDebit(acnts []*utils.AccountProfileWithWeight, } // accountDebit will debit the usage out of an Account -func (aS *AccountS) accountDebit(acnt *utils.AccountProfile, usage *decimal.Big, +func (aS *AccountS) accountDebit(acnt *utils.Account, usage *decimal.Big, cgrEv *utils.CGREvent, concretes bool) (ec *utils.EventCharges, err error) { // Find balances matching event @@ -254,8 +254,8 @@ func (aS *AccountS) accountDebit(acnt *utils.AccountProfile, usage *decimal.Big, } // V1AccountProfilesForEvent returns the matching AccountProfiles for Event -func (aS *AccountS) V1AccountProfilesForEvent(args *utils.ArgsAccountsForEvent, aps *[]*utils.AccountProfile) (err error) { - var acnts utils.AccountProfilesWithWeight +func (aS *AccountS) V1AccountProfilesForEvent(args *utils.ArgsAccountsForEvent, aps *[]*utils.Account) (err error) { + var acnts utils.AccountsWithWeight if acnts, err = aS.matchingAccountsForEvent(args.CGREvent.Tenant, args.CGREvent, args.AccountIDs, false); err != nil { if err != utils.ErrNotFound { @@ -269,7 +269,7 @@ func (aS *AccountS) V1AccountProfilesForEvent(args *utils.ArgsAccountsForEvent, // V1MaxAbstracts returns the maximum abstract units for the event, based on matching Accounts func (aS *AccountS) V1MaxAbstracts(args *utils.ArgsAccountsForEvent, eEc *utils.ExtEventCharges) (err error) { - var acnts utils.AccountProfilesWithWeight + var acnts utils.AccountsWithWeight if acnts, err = aS.matchingAccountsForEvent(args.CGREvent.Tenant, args.CGREvent, args.AccountIDs, true); err != nil { if err != utils.ErrNotFound { @@ -293,7 +293,7 @@ func (aS *AccountS) V1MaxAbstracts(args *utils.ArgsAccountsForEvent, eEc *utils. // V1DebitAbstracts performs debit for the provided event func (aS *AccountS) V1DebitAbstracts(args *utils.ArgsAccountsForEvent, eEc *utils.ExtEventCharges) (err error) { - var acnts utils.AccountProfilesWithWeight + var acnts utils.AccountsWithWeight if acnts, err = aS.matchingAccountsForEvent(args.CGREvent.Tenant, args.CGREvent, args.AccountIDs, true); err != nil { if err != utils.ErrNotFound { @@ -319,7 +319,7 @@ func (aS *AccountS) V1DebitAbstracts(args *utils.ArgsAccountsForEvent, eEc *util // V1MaxConcretes returns the maximum concrete units for the event, based on matching Accounts func (aS *AccountS) V1MaxConcretes(args *utils.ArgsAccountsForEvent, eEc *utils.ExtEventCharges) (err error) { - var acnts utils.AccountProfilesWithWeight + var acnts utils.AccountsWithWeight if acnts, err = aS.matchingAccountsForEvent(args.CGREvent.Tenant, args.CGREvent, args.AccountIDs, true); err != nil { if err != utils.ErrNotFound { @@ -343,7 +343,7 @@ func (aS *AccountS) V1MaxConcretes(args *utils.ArgsAccountsForEvent, eEc *utils. // V1DebitConcretes performs debit of concrete units for the provided event func (aS *AccountS) V1DebitConcretes(args *utils.ArgsAccountsForEvent, eEc *utils.ExtEventCharges) (err error) { - var acnts utils.AccountProfilesWithWeight + var acnts utils.AccountsWithWeight if acnts, err = aS.matchingAccountsForEvent(args.CGREvent.Tenant, args.CGREvent, args.AccountIDs, true); err != nil { if err != utils.ErrNotFound { diff --git a/accounts/accounts_test.go b/accounts/accounts_test.go index a7a3a73de..3aade20bd 100644 --- a/accounts/accounts_test.go +++ b/accounts/accounts_test.go @@ -83,7 +83,7 @@ type dataDBMockErrorNotFound struct { *engine.DataDBMock } -func (dB *dataDBMockErrorNotFound) GetAccountProfileDrv(string, string) (*utils.AccountProfile, error) { +func (dB *dataDBMockErrorNotFound) GetAccountProfileDrv(string, string) (*utils.Account, error) { return nil, utils.ErrNotFound } @@ -92,7 +92,7 @@ func TestMatchingAccountsForEventMockingErrors(t *testing.T) { cfg := config.NewDefaultCGRConfig() fltr := engine.NewFilterS(cfg, nil, nil) - accPrf := &utils.AccountProfile{ + accPrf := &utils.Account{ Tenant: "cgrates.org", ID: "1004", FilterIDs: []string{"*string:~*req.Account:1004"}, @@ -161,7 +161,7 @@ func TestMatchingAccountsForEvent(t *testing.T) { fltr := engine.NewFilterS(cfg, nil, dm) accnts := NewAccountS(cfg, fltr, nil, dm) - accPrf := &utils.AccountProfile{ + accPrf := &utils.Account{ Tenant: "cgrates.org", ID: "1004", ActivationInterval: &utils.ActivationInterval{ @@ -233,10 +233,10 @@ func TestMatchingAccountsForEvent(t *testing.T) { } accPrf.Weights[0].FilterIDs = []string{} - expectedAccPrfWeght := utils.AccountProfilesWithWeight{ + expectedAccPrfWeght := utils.AccountsWithWeight{ { - AccountProfile: accPrf, - Weight: 20, + Account: accPrf, + Weight: 20, }, } if rcv, err := accnts.matchingAccountsForEvent("cgrates.org", cgrEvent, @@ -255,7 +255,7 @@ func TestAccountDebit(t *testing.T) { fltr := engine.NewFilterS(cfg, nil, dm) accnts := NewAccountS(cfg, fltr, nil, dm) - accPrf := &utils.AccountProfile{ + accPrf := &utils.Account{ Tenant: "cgrates.org", ID: "TestAccountDebit", FilterIDs: []string{"*string:~*req.Account:1004"}, @@ -348,9 +348,9 @@ func TestAccountsDebit(t *testing.T) { fltr := engine.NewFilterS(cfg, nil, dm) accnts := NewAccountS(cfg, fltr, nil, dm) - accntsPrf := []*utils.AccountProfileWithWeight{ + accntsPrf := []*utils.AccountWithWeight{ { - AccountProfile: &utils.AccountProfile{ + Account: &utils.Account{ Tenant: "cgrates.org", ID: "TestAccountsDebit", FilterIDs: []string{"*string:~*req.Account:1004"}, @@ -467,7 +467,7 @@ func TestV1AccountProfilesForEvent(t *testing.T) { fltr := engine.NewFilterS(cfg, nil, dm) accnts := NewAccountS(cfg, fltr, nil, dm) - accPrf := &utils.AccountProfile{ + accPrf := &utils.Account{ Tenant: "cgrates.org", ID: "1004", ActivationInterval: &utils.ActivationInterval{ @@ -504,7 +504,7 @@ func TestV1AccountProfilesForEvent(t *testing.T) { }, }, } - rply := make([]*utils.AccountProfile, 0) + rply := make([]*utils.Account, 0) expected := "SERVER_ERROR: NOT_FOUND:invalid_filter_format" if err := accnts.V1AccountProfilesForEvent(args, &rply); err == nil || err.Error() != expected { @@ -529,7 +529,7 @@ func TestV1MaxAbstracts(t *testing.T) { fltr := engine.NewFilterS(cfg, nil, dm) accnts := NewAccountS(cfg, fltr, nil, dm) - accPrf := &utils.AccountProfile{ + accPrf := &utils.Account{ Tenant: "cgrates.org", ID: "TestV1MaxAbstracts", Weights: []*utils.DynamicWeight{ @@ -616,7 +616,7 @@ func TestV1DebitAbstracts(t *testing.T) { fltr := engine.NewFilterS(cfg, nil, dm) accnts := NewAccountS(cfg, fltr, nil, dm) - accPrf := &utils.AccountProfile{ + accPrf := &utils.Account{ Tenant: "cgrates.org", ID: "TestV1DebitAbstracts", Weights: []*utils.DynamicWeight{ @@ -703,7 +703,7 @@ func TestV1MaxConcretes(t *testing.T) { fltr := engine.NewFilterS(cfg, nil, dm) accnts := NewAccountS(cfg, fltr, nil, dm) - accPrf := &utils.AccountProfile{ + accPrf := &utils.Account{ Tenant: "cgrates.org", ID: "TestV1DebitAbstracts", Weights: []*utils.DynamicWeight{ @@ -814,7 +814,7 @@ func TestV1DebitConcretes(t *testing.T) { fltr := engine.NewFilterS(cfg, nil, dm) accnts := NewAccountS(cfg, fltr, nil, dm) - accPrf := &utils.AccountProfile{ + accPrf := &utils.Account{ Tenant: "cgrates.org", ID: "TestV1DebitAbstracts", Weights: []*utils.DynamicWeight{ @@ -937,7 +937,7 @@ func TestMultipleAccountsFail(t *testing.T) { fltr := engine.NewFilterS(cfg, nil, dm) accnts := NewAccountS(cfg, fltr, nil, dm) - accPrf := []*utils.AccountProfile{ + accPrf := []*utils.Account{ { Tenant: "cgrates.org", ID: "TestV1MaxAbstracts", @@ -1109,7 +1109,7 @@ func TestV1ActionSetBalance(t *testing.T) { t.Error("Unexpected status reply", reply) } - expectedAcc := &utils.AccountProfile{ + expectedAcc := &utils.Account{ Tenant: "cgrates.org", ID: "TestV1ActionSetBalance", Balances: map[string]*utils.Balance{ diff --git a/accounts/actsetbalance.go b/accounts/actsetbalance.go index b15bc4783..cf0ccf0c1 100644 --- a/accounts/actsetbalance.go +++ b/accounts/actsetbalance.go @@ -29,13 +29,13 @@ import ( // actSetAccount updates the balances base on the diktat func actSetAccount(dm *engine.DataManager, tnt, acntID string, diktats []*utils.BalDiktat, reset bool) (err error) { - var qAcnt *utils.AccountProfile + var qAcnt *utils.Account if qAcnt, err = dm.GetAccountProfile(tnt, acntID); err != nil { if err != utils.ErrNotFound { return } // in case the account doesn't exist create it with minimal information - qAcnt = &utils.AccountProfile{ + qAcnt = &utils.Account{ Tenant: tnt, ID: acntID, } @@ -79,7 +79,7 @@ func actSetAccount(dm *engine.DataManager, tnt, acntID string, diktats []*utils. } // actSetAccountFields sets the fields inside the account -func actSetAccountFields(ac *utils.AccountProfile, path []string, value string) (err error) { +func actSetAccountFields(ac *utils.Account, path []string, value string) (err error) { switch path[0] { // the tenant and ID should come from user and should not change case utils.FilterIDs: diff --git a/accounts/actsetbalance_test.go b/accounts/actsetbalance_test.go index 0ef86d3cd..ce0e00770 100644 --- a/accounts/actsetbalance_test.go +++ b/accounts/actsetbalance_test.go @@ -60,7 +60,7 @@ func TestActSetAccountBalance(t *testing.T) { } diktats[0].Path = "*balance.Concrete1.Weights" - expectedAcc := &utils.AccountProfile{ + expectedAcc := &utils.Account{ Tenant: "cgrates.org", ID: acntID, Balances: map[string]*utils.Balance{ @@ -133,7 +133,7 @@ func TestActSetAccount(t *testing.T) { } diktats[0].Value = ";10" - expectedAcc := &utils.AccountProfile{ + expectedAcc := &utils.Account{ Tenant: "cgrates.org", ID: acntID, Weights: []*utils.DynamicWeight{ @@ -152,9 +152,9 @@ func TestActSetAccount(t *testing.T) { } func TestActSetAccountFields(t *testing.T) { - accPrf := &utils.AccountProfile{} + accPrf := &utils.Account{} - expectedAccprf := &utils.AccountProfile{ + expectedAccprf := &utils.Account{ FilterIDs: []string{"*string:~*req.ToR:*sms"}, ActivationInterval: &utils.ActivationInterval{ ActivationTime: time.Date(2014, 7, 29, 15, 0, 0, 0, time.UTC), diff --git a/accounts/libaccounts.go b/accounts/libaccounts.go index c581e7de5..c26d895e4 100644 --- a/accounts/libaccounts.go +++ b/accounts/libaccounts.go @@ -331,22 +331,22 @@ func maxDebitAbstractsFromConcretes(aUnits *decimal.Big, // restoreAccounts will restore the accounts in DataDB out of their backups if present func restoreAccounts(dm *engine.DataManager, - acnts []*utils.AccountProfileWithWeight, bkps []utils.AccountBalancesBackup) { + acnts []*utils.AccountWithWeight, bkps []utils.AccountBalancesBackup) { for i, bkp := range bkps { if bkp == nil || - !acnts[i].AccountProfile.BalancesAltered(bkp) { + !acnts[i].Account.BalancesAltered(bkp) { continue } - acnts[i].AccountProfile.RestoreFromBackup(bkp) - if err := dm.SetAccountProfile(acnts[i].AccountProfile, false); err != nil { + acnts[i].Account.RestoreFromBackup(bkp) + if err := dm.SetAccountProfile(acnts[i].Account, false); err != nil { utils.Logger.Warning(fmt.Sprintf("<%s> error <%s> restoring account <%s>", - utils.AccountS, err, acnts[i].AccountProfile.TenantID())) + utils.AccountS, err, acnts[i].Account.TenantID())) } } } // unlockAccountProfiles is used to unlock the accounts based on their lock identifiers -func unlockAccountProfiles(acnts utils.AccountProfilesWithWeight) { +func unlockAccountProfiles(acnts utils.AccountsWithWeight) { for _, lkID := range acnts.LockIDs() { guardian.Guardian.UnguardIDs(lkID) } diff --git a/accounts/libaccounts_test.go b/accounts/libaccounts_test.go index 7dd96b971..6a4f33637 100644 --- a/accounts/libaccounts_test.go +++ b/accounts/libaccounts_test.go @@ -39,7 +39,7 @@ import ( ) func TestNewAccountBalanceOperators(t *testing.T) { - acntPrf := &utils.AccountProfile{ + acntPrf := &utils.Account{ ID: "TEST_ID", Tenant: "cgrates.org", Balances: map[string]*utils.Balance{ @@ -450,7 +450,7 @@ func TestRestoreAccount(t *testing.T) { //coverage purpose data := engine.NewInternalDB(nil, nil, true) dm := engine.NewDataManager(data, config.CgrConfig().CacheCfg(), nil) - acntPrf := &utils.AccountProfile{ + acntPrf := &utils.Account{ Tenant: "cgrates.org", ID: "1001", Balances: map[string]*utils.Balance{ @@ -470,7 +470,7 @@ func TestRestoreAccount(t *testing.T) { //coverage purpose t.Error(err) } - restoreAccounts(dm, []*utils.AccountProfileWithWeight{ + restoreAccounts(dm, []*utils.AccountWithWeight{ {acntPrf, 0, utils.EmptyString}, }, []utils.AccountBalancesBackup{ map[string]*decimal.Big{"CB2": decimal.New(100, 0)}, @@ -493,7 +493,7 @@ func TestRestoreAccount2(t *testing.T) { //coverage purpose engine.Cache.Clear(nil) dm := engine.NewDataManager(&dataDBMockError{}, config.CgrConfig().CacheCfg(), nil) - acntPrf := &utils.AccountProfile{ + acntPrf := &utils.Account{ Tenant: "cgrates.org", ID: "1001", Balances: map[string]*utils.Balance{ @@ -518,7 +518,7 @@ func TestRestoreAccount2(t *testing.T) { //coverage purpose buff := new(bytes.Buffer) log.SetOutput(buff) - restoreAccounts(dm, []*utils.AccountProfileWithWeight{ + restoreAccounts(dm, []*utils.AccountWithWeight{ {acntPrf, 0, utils.EmptyString}, }, []utils.AccountBalancesBackup{ map[string]*decimal.Big{"CB1": decimal.New(100, 0)}, @@ -537,7 +537,7 @@ func TestRestoreAccount3(t *testing.T) { //coverage purpose data := engine.NewInternalDB(nil, nil, true) dm := engine.NewDataManager(data, config.CgrConfig().CacheCfg(), nil) - acntPrf := &utils.AccountProfile{ + acntPrf := &utils.Account{ Tenant: "cgrates.org", ID: "1001", Balances: map[string]*utils.Balance{ @@ -557,7 +557,7 @@ func TestRestoreAccount3(t *testing.T) { //coverage purpose t.Error(err) } - restoreAccounts(dm, []*utils.AccountProfileWithWeight{ + restoreAccounts(dm, []*utils.AccountWithWeight{ {acntPrf, 0, utils.EmptyString}, }, []utils.AccountBalancesBackup{ nil, diff --git a/apier/v1/accountprofiles.go b/apier/v1/accountprofiles.go index a1db781ed..b908bd85b 100644 --- a/apier/v1/accountprofiles.go +++ b/apier/v1/accountprofiles.go @@ -27,7 +27,7 @@ import ( ) // GetAccountProfile returns an Account Profile -func (apierSv1 *APIerSv1) GetAccountProfile(arg *utils.TenantIDWithAPIOpts, reply *utils.AccountProfile) error { +func (apierSv1 *APIerSv1) GetAccountProfile(arg *utils.TenantIDWithAPIOpts, reply *utils.Account) error { if missing := utils.MissingStructFields(arg, []string{utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -88,14 +88,14 @@ func (apierSv1 *APIerSv1) GetAccountProfileIDsCount(args *utils.TenantWithAPIOpt } //SetAccountProfile add/update a new Account Profile -func (apierSv1 *APIerSv1) SetAccountProfile(extAp *utils.APIAccountProfileWithOpts, reply *string) error { - if missing := utils.MissingStructFields(extAp.APIAccountProfile, []string{utils.ID}); len(missing) != 0 { +func (apierSv1 *APIerSv1) SetAccountProfile(extAp *utils.APIAccountWithOpts, reply *string) error { + if missing := utils.MissingStructFields(extAp.APIAccount, []string{utils.ID}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } if extAp.Tenant == utils.EmptyString { extAp.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant } - ap, err := extAp.AsAccountProfile() + ap, err := extAp.AsAccount() if err != nil { return err } @@ -155,7 +155,7 @@ func (aSv1 *AccountSv1) Ping(ign *utils.CGREvent, reply *string) error { // AccountProfilesForEvent returns the matching AccountProfile for Event func (aSv1 *AccountSv1) AccountProfilesForEvent(args *utils.ArgsAccountsForEvent, - aps *[]*utils.AccountProfile) (err error) { + aps *[]*utils.Account) (err error) { return aSv1.aS.V1AccountProfilesForEvent(args, aps) } diff --git a/apier/v1/api_interfaces.go b/apier/v1/api_interfaces.go index f258903ca..a1f89b4a5 100644 --- a/apier/v1/api_interfaces.go +++ b/apier/v1/api_interfaces.go @@ -219,8 +219,8 @@ type ReplicatorSv1Interface interface { SetIndexes(args *utils.SetIndexesArg, reply *string) error RemoveIndexes(args *utils.GetIndexesArg, reply *string) error - GetAccountProfile(tntID *utils.TenantIDWithAPIOpts, reply *utils.AccountProfile) error - SetAccountProfile(args *utils.AccountProfileWithAPIOpts, reply *string) error + GetAccountProfile(tntID *utils.TenantIDWithAPIOpts, reply *utils.Account) error + SetAccountProfile(args *utils.AccountWithAPIOpts, reply *string) error RemoveAccountProfile(args *utils.TenantIDWithAPIOpts, reply *string) error GetActionProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.ActionProfile) error @@ -236,7 +236,7 @@ type ActionSv1Interface interface { type AccountSv1Interface interface { Ping(ign *utils.CGREvent, reply *string) error - AccountProfilesForEvent(args *utils.ArgsAccountsForEvent, aps *[]*utils.AccountProfile) error + AccountProfilesForEvent(args *utils.ArgsAccountsForEvent, aps *[]*utils.Account) error MaxAbstracts(args *utils.ArgsAccountsForEvent, eEc *utils.ExtEventCharges) error DebitAbstracts(args *utils.ArgsAccountsForEvent, eEc *utils.ExtEventCharges) error ActionSetBalance(args *utils.ArgsActSetBalance, eEc *string) (err error) diff --git a/apier/v1/dispatcher.go b/apier/v1/dispatcher.go index 34dbe0c24..9777ee081 100755 --- a/apier/v1/dispatcher.go +++ b/apier/v1/dispatcher.go @@ -1059,12 +1059,12 @@ func (dS *DispatcherReplicatorSv1) RemoveIndexes(args *utils.GetIndexesArg, repl } // GetAccountProfile . -func (dS *DispatcherReplicatorSv1) GetAccountProfile(tntID *utils.TenantIDWithAPIOpts, reply *utils.AccountProfile) error { +func (dS *DispatcherReplicatorSv1) GetAccountProfile(tntID *utils.TenantIDWithAPIOpts, reply *utils.Account) error { return dS.dS.ReplicatorSv1GetAccountProfile(tntID, reply) } // SetAccountProfile . -func (dS *DispatcherReplicatorSv1) SetAccountProfile(args *utils.AccountProfileWithAPIOpts, reply *string) error { +func (dS *DispatcherReplicatorSv1) SetAccountProfile(args *utils.AccountWithAPIOpts, reply *string) error { return dS.dS.ReplicatorSv1SetAccountProfile(args, reply) } @@ -1141,7 +1141,7 @@ func (dR *DispatcherAccountSv1) Ping(args *utils.CGREvent, reply *string) error return dR.dR.AccountSv1Ping(args, reply) } -func (dR *DispatcherAccountSv1) AccountProfilesForEvent(args *utils.ArgsAccountsForEvent, aps *[]*utils.AccountProfile) error { +func (dR *DispatcherAccountSv1) AccountProfilesForEvent(args *utils.ArgsAccountsForEvent, aps *[]*utils.Account) error { return dR.dR.AccountProfilesForEvent(args, aps) } diff --git a/apier/v1/replicator.go b/apier/v1/replicator.go index 9abf25cca..6ea0f8b01 100644 --- a/apier/v1/replicator.go +++ b/apier/v1/replicator.go @@ -232,7 +232,7 @@ func (rplSv1 *ReplicatorSv1) GetActionProfile(tntID *utils.TenantIDWithAPIOpts, } // GetAccountProfile is the remote method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) GetAccountProfile(tntID *utils.TenantIDWithAPIOpts, reply *utils.AccountProfile) error { +func (rplSv1 *ReplicatorSv1) GetAccountProfile(tntID *utils.TenantIDWithAPIOpts, reply *utils.Account) error { engine.UpdateReplicationFilters(utils.AccountProfilePrefix, tntID.TenantID.TenantID(), utils.IfaceAsString(tntID.APIOpts[utils.RemoteHostOpt])) rcv, err := rplSv1.dm.DataDB().GetAccountProfileDrv(tntID.Tenant, tntID.ID) if err != nil { @@ -486,8 +486,8 @@ func (rplSv1 *ReplicatorSv1) SetActionProfile(acp *engine.ActionProfileWithAPIOp } // SetAccountProfile is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) SetAccountProfile(acp *utils.AccountProfileWithAPIOpts, reply *string) (err error) { - if err = rplSv1.dm.DataDB().SetAccountProfileDrv(acp.AccountProfile); err != nil { +func (rplSv1 *ReplicatorSv1) SetAccountProfile(acp *utils.AccountWithAPIOpts, reply *string) (err error) { + if err = rplSv1.dm.DataDB().SetAccountProfileDrv(acp.Account); err != nil { return } if err = rplSv1.v1.CallCache(utils.IfaceAsString(acp.APIOpts[utils.CacheOpt]), diff --git a/console/accounts_profile.go b/console/accounts_profile.go index f0b24e91f..0294c21f5 100644 --- a/console/accounts_profile.go +++ b/console/accounts_profile.go @@ -60,6 +60,6 @@ func (self *CmdGetAccountsProfile) PostprocessRpcParams() error { } func (self *CmdGetAccountsProfile) RpcResult() interface{} { - var atr utils.AccountProfile + var atr utils.Account return &atr } diff --git a/console/accounts_profile_set.go b/console/accounts_profile_set.go index 42d85d3e2..68eef8b97 100644 --- a/console/accounts_profile_set.go +++ b/console/accounts_profile_set.go @@ -26,7 +26,7 @@ func init() { c := &CmdSetAccountProfile{ name: "accounts_profile_set", rpcMethod: utils.APIerSv1SetAccountProfile, - rpcParams: &utils.APIAccountProfileWithOpts{}, + rpcParams: &utils.APIAccountWithOpts{}, } commands[c.Name()] = c c.CommandExecuter = &CommandExecuter{c} @@ -35,7 +35,7 @@ func init() { type CmdSetAccountProfile struct { name string rpcMethod string - rpcParams *utils.APIAccountProfileWithOpts + rpcParams *utils.APIAccountWithOpts *CommandExecuter } @@ -49,7 +49,7 @@ func (self *CmdSetAccountProfile) RpcMethod() string { func (self *CmdSetAccountProfile) RpcParams(reset bool) interface{} { if reset || self.rpcParams == nil { - self.rpcParams = &utils.APIAccountProfileWithOpts{APIAccountProfile: new(utils.APIAccountProfile)} + self.rpcParams = &utils.APIAccountWithOpts{APIAccount: new(utils.APIAccount)} } return self.rpcParams } diff --git a/dispatchers/accounts.go b/dispatchers/accounts.go index 15526aa71..a932e4552 100644 --- a/dispatchers/accounts.go +++ b/dispatchers/accounts.go @@ -38,7 +38,7 @@ func (dS *DispatcherService) AccountSv1Ping(args *utils.CGREvent, rpl *string) ( return dS.Dispatch(args, utils.MetaAccounts, utils.AccountSv1Ping, args, rpl) } -func (dS *DispatcherService) AccountProfilesForEvent(args *utils.ArgsAccountsForEvent, reply *[]*utils.AccountProfile) (err error) { +func (dS *DispatcherService) AccountProfilesForEvent(args *utils.ArgsAccountsForEvent, reply *[]*utils.Account) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.CGREvent != nil && args.CGREvent.Tenant != utils.EmptyString { tnt = args.CGREvent.Tenant diff --git a/dispatchers/replicator.go b/dispatchers/replicator.go index 31fc04063..235ece26a 100644 --- a/dispatchers/replicator.go +++ b/dispatchers/replicator.go @@ -1008,7 +1008,7 @@ func (dS *DispatcherService) ReplicatorSv1RemoveIndexes(args *utils.GetIndexesAr }, utils.MetaReplicator, utils.ReplicatorSv1RemoveIndexes, args, reply) } -func (dS *DispatcherService) ReplicatorSv1GetAccountProfile(args *utils.TenantIDWithAPIOpts, reply *utils.AccountProfile) (err error) { +func (dS *DispatcherService) ReplicatorSv1GetAccountProfile(args *utils.TenantIDWithAPIOpts, reply *utils.Account) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.TenantID != nil && args.TenantID.Tenant != utils.EmptyString { tnt = args.TenantID.Tenant @@ -1026,9 +1026,9 @@ func (dS *DispatcherService) ReplicatorSv1GetAccountProfile(args *utils.TenantID }, utils.MetaReplicator, utils.ReplicatorSv1GetAccountProfile, args, reply) } -func (dS *DispatcherService) ReplicatorSv1SetAccountProfile(args *utils.AccountProfileWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1SetAccountProfile(args *utils.AccountWithAPIOpts, rpl *string) (err error) { if args == nil { - args = &utils.AccountProfileWithAPIOpts{} + args = &utils.AccountWithAPIOpts{} } args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { diff --git a/engine/datadbmock.go b/engine/datadbmock.go index 040ba83e3..0a594cf12 100644 --- a/engine/datadbmock.go +++ b/engine/datadbmock.go @@ -301,11 +301,11 @@ func (dbM *DataDBMock) RemoveActionProfileDrv(string, string) error { return utils.ErrNotImplemented } -func (dbM *DataDBMock) GetAccountProfileDrv(string, string) (*utils.AccountProfile, error) { +func (dbM *DataDBMock) GetAccountProfileDrv(string, string) (*utils.Account, error) { return nil, utils.ErrNotImplemented } -func (dbM *DataDBMock) SetAccountProfileDrv(profile *utils.AccountProfile) error { +func (dbM *DataDBMock) SetAccountProfileDrv(profile *utils.Account) error { return utils.ErrNotImplemented } diff --git a/engine/datamanager.go b/engine/datamanager.go index d08a982b3..788d91ace 100644 --- a/engine/datamanager.go +++ b/engine/datamanager.go @@ -2831,7 +2831,7 @@ func (dm *DataManager) checkFilters(tenant string, ids []string) (brokenReferenc return } -func (dm *DataManager) GetAccountProfile(tenant, id string) (ap *utils.AccountProfile, err error) { +func (dm *DataManager) GetAccountProfile(tenant, id string) (ap *utils.Account, err error) { if dm == nil { err = utils.ErrNoDatabaseConn return @@ -2857,7 +2857,7 @@ func (dm *DataManager) GetAccountProfile(tenant, id string) (ap *utils.AccountPr return } -func (dm *DataManager) SetAccountProfile(ap *utils.AccountProfile, withIndex bool) (err error) { +func (dm *DataManager) SetAccountProfile(ap *utils.Account, withIndex bool) (err error) { if dm == nil { return utils.ErrNoDatabaseConn } @@ -2890,8 +2890,8 @@ func (dm *DataManager) SetAccountProfile(ap *utils.AccountProfile, withIndex boo config.CgrConfig().DataDbCfg().RplFiltered, utils.AccountProfilePrefix, ap.TenantID(), // this are used to get the host IDs from cache utils.ReplicatorSv1SetAccountProfile, - &utils.AccountProfileWithAPIOpts{ - AccountProfile: ap, + &utils.AccountWithAPIOpts{ + Account: ap, APIOpts: utils.GenerateDBItemOpts(itm.APIKey, itm.RouteID, config.CgrConfig().DataDbCfg().RplCache, utils.EmptyString)}) } diff --git a/engine/dynamicdp.go b/engine/dynamicdp.go index 46fa36caf..91815fb09 100644 --- a/engine/dynamicdp.go +++ b/engine/dynamicdp.go @@ -90,7 +90,7 @@ func (dDP *dynamicDP) fieldAsInterface(fldPath []string) (val interface{}, err e // split the field name in 3 parts // fieldNameType (~*accounts), accountID(1001) and queried part (BalanceMap.*monetary[0].Value) - var account utils.AccountProfile + var account utils.Account if err = connMgr.Call(dDP.apiConns, nil, utils.APIerSv1GetAccountProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: dDP.tenant, ID: fldPath[1]}}, &account); err != nil { return diff --git a/engine/model_helpers.go b/engine/model_helpers.go index c848a58d2..f6ff1d582 100644 --- a/engine/model_helpers.go +++ b/engine/model_helpers.go @@ -2845,8 +2845,8 @@ func APItoModelTPAccountProfile(tPrf *utils.TPAccountProfile) (mdls AccountProfi return } -func APItoAccountProfile(tpAp *utils.TPAccountProfile, timezone string) (ap *utils.AccountProfile, err error) { - ap = &utils.AccountProfile{ +func APItoAccountProfile(tpAp *utils.TPAccountProfile, timezone string) (ap *utils.Account, err error) { + ap = &utils.Account{ Tenant: tpAp.Tenant, ID: tpAp.ID, FilterIDs: make([]string, len(tpAp.FilterIDs)), @@ -2939,7 +2939,7 @@ func APItoAccountProfile(tpAp *utils.TPAccountProfile, timezone string) (ap *uti return } -func AccountProfileToAPI(ap *utils.AccountProfile) (tpAp *utils.TPAccountProfile) { +func AccountProfileToAPI(ap *utils.Account) (tpAp *utils.TPAccountProfile) { tpAp = &utils.TPAccountProfile{ Tenant: ap.Tenant, ID: ap.ID, diff --git a/engine/model_helpers_test.go b/engine/model_helpers_test.go index 972d28879..54b1e8138 100644 --- a/engine/model_helpers_test.go +++ b/engine/model_helpers_test.go @@ -5617,7 +5617,7 @@ func TestApitoAccountProfileCase2(t *testing.T) { }, ThresholdIDs: []string{"WARN_RES1"}, } - exp := &utils.AccountProfile{ + exp := &utils.Account{ Tenant: "cgrates.org", ID: "ResGroup1", FilterIDs: []string{"FLTR_RES_GR1"}, @@ -5809,7 +5809,7 @@ func TestModelHelpersActionProfileToAPICase2(t *testing.T) { } func TestModelHelpersAccountProfileToAPI(t *testing.T) { - testStruct := &utils.AccountProfile{ + testStruct := &utils.Account{ Tenant: "cgrates.org", ID: "RP1", FilterIDs: []string{"test_filterId"}, diff --git a/engine/storage_interface.go b/engine/storage_interface.go index 5ac51624b..b16110991 100644 --- a/engine/storage_interface.go +++ b/engine/storage_interface.go @@ -107,8 +107,8 @@ type DataDB interface { GetActionProfileDrv(string, string) (*ActionProfile, error) SetActionProfileDrv(*ActionProfile) error RemoveActionProfileDrv(string, string) error - GetAccountProfileDrv(string, string) (*utils.AccountProfile, error) - SetAccountProfileDrv(profile *utils.AccountProfile) error + GetAccountProfileDrv(string, string) (*utils.Account, error) + SetAccountProfileDrv(profile *utils.Account) error RemoveAccountProfileDrv(string, string) error } diff --git a/engine/storage_internal_datadb.go b/engine/storage_internal_datadb.go index ddb36df52..dc9abe2d7 100644 --- a/engine/storage_internal_datadb.go +++ b/engine/storage_internal_datadb.go @@ -677,15 +677,15 @@ func (iDB *InternalDB) RemoveIndexesDrv(idxItmType, tntCtx, idxKey string) (err return } -func (iDB *InternalDB) GetAccountProfileDrv(tenant, id string) (ap *utils.AccountProfile, err error) { +func (iDB *InternalDB) GetAccountProfileDrv(tenant, id string) (ap *utils.Account, err error) { x, ok := Cache.Get(utils.CacheAccountProfiles, utils.ConcatenatedKey(tenant, id)) if !ok || x == nil { return nil, utils.ErrNotFound } - return x.(*utils.AccountProfile).Clone(), nil + return x.(*utils.Account).Clone(), nil } -func (iDB *InternalDB) SetAccountProfileDrv(ap *utils.AccountProfile) (err error) { +func (iDB *InternalDB) SetAccountProfileDrv(ap *utils.Account) (err error) { Cache.SetWithoutReplicate(utils.CacheAccountProfiles, ap.TenantID(), ap, nil, cacheCommit(utils.NonTransactional), utils.NonTransactional) return diff --git a/engine/storage_mongo_datadb.go b/engine/storage_mongo_datadb.go index ac88db3e2..70fd1924e 100644 --- a/engine/storage_mongo_datadb.go +++ b/engine/storage_mongo_datadb.go @@ -1612,8 +1612,8 @@ func (ms *MongoStorage) RemoveIndexesDrv(idxItmType, tntCtx, idxKey string) (err }) } -func (ms *MongoStorage) GetAccountProfileDrv(tenant, id string) (ap *utils.AccountProfile, err error) { - ap = new(utils.AccountProfile) +func (ms *MongoStorage) GetAccountProfileDrv(tenant, id string) (ap *utils.Account, err error) { + ap = new(utils.Account) err = ms.query(func(sctx mongo.SessionContext) (err error) { cur := ms.getCol(ColAnp).FindOne(sctx, bson.M{"tenant": tenant, "id": id}) if err := cur.Decode(ap); err != nil { @@ -1628,7 +1628,7 @@ func (ms *MongoStorage) GetAccountProfileDrv(tenant, id string) (ap *utils.Accou return } -func (ms *MongoStorage) SetAccountProfileDrv(ap *utils.AccountProfile) (err error) { +func (ms *MongoStorage) SetAccountProfileDrv(ap *utils.Account) (err error) { return ms.query(func(sctx mongo.SessionContext) (err error) { _, err = ms.getCol(ColAnp).UpdateOne(sctx, bson.M{"tenant": ap.Tenant, "id": ap.ID}, bson.M{"$set": ap}, diff --git a/engine/storage_redis.go b/engine/storage_redis.go index 7d1998fbb..60d74a1a5 100644 --- a/engine/storage_redis.go +++ b/engine/storage_redis.go @@ -937,7 +937,7 @@ func (rs *RedisStorage) RemoveIndexesDrv(idxItmType, tntCtx, idxKey string) (err return rs.Cmd(nil, redisHDEL, utils.CacheInstanceToPrefix[idxItmType]+tntCtx, idxKey) } -func (rs *RedisStorage) GetAccountProfileDrv(tenant, id string) (ap *utils.AccountProfile, err error) { +func (rs *RedisStorage) GetAccountProfileDrv(tenant, id string) (ap *utils.Account, err error) { var values []byte if err = rs.Cmd(&values, redisGET, utils.AccountProfilePrefix+utils.ConcatenatedKey(tenant, id)); err != nil { return @@ -949,7 +949,7 @@ func (rs *RedisStorage) GetAccountProfileDrv(tenant, id string) (ap *utils.Accou return } -func (rs *RedisStorage) SetAccountProfileDrv(ap *utils.AccountProfile) (err error) { +func (rs *RedisStorage) SetAccountProfileDrv(ap *utils.Account) (err error) { var result []byte if result, err = rs.ms.Marshal(ap); err != nil { return diff --git a/engine/tpreader.go b/engine/tpreader.go index d7d42e4f9..16b0c7b77 100644 --- a/engine/tpreader.go +++ b/engine/tpreader.go @@ -763,7 +763,7 @@ func (tpr *TpReader) WriteToDatabase(verbose, disableReverse bool) (err error) { log.Print("AccountProfiles:") } for _, tpAP := range tpr.accountProfiles { - var ap *utils.AccountProfile + var ap *utils.Account if ap, err = APItoAccountProfile(tpAP, tpr.timezone); err != nil { return } diff --git a/loaders/loader_test.go b/loaders/loader_test.go index e5a69be12..1514c4ee6 100644 --- a/loaders/loader_test.go +++ b/loaders/loader_test.go @@ -4716,7 +4716,7 @@ cgrates.org,REM_ACTPROFILE_1 //set dataManager ldr.dm = engine.NewDataManager(data, config.CgrConfig().CacheCfg(), nil) - acntPrf := &utils.AccountProfile{ + acntPrf := &utils.Account{ Tenant: "cgrates.org", ID: "REM_ACTPROFILE_1", } diff --git a/utils/accountprofile.go b/utils/accountprofile.go index 8a2dec267..c96fccf79 100644 --- a/utils/accountprofile.go +++ b/utils/accountprofile.go @@ -26,7 +26,7 @@ import ( ) // AccountProfile represents one Account on a Tenant -type AccountProfile struct { +type Account struct { Tenant string ID string // Account identificator, unique within the tenant FilterIDs []string @@ -38,7 +38,7 @@ type AccountProfile struct { } // BalancesAltered detects altering of the Balances by comparing the Balance values with the ones from backup -func (ap *AccountProfile) BalancesAltered(abb AccountBalancesBackup) (altred bool) { +func (ap *Account) BalancesAltered(abb AccountBalancesBackup) (altred bool) { if len(ap.Balances) != len(abb) { return true } @@ -51,14 +51,14 @@ func (ap *AccountProfile) BalancesAltered(abb AccountBalancesBackup) (altred boo return } -func (ap *AccountProfile) RestoreFromBackup(abb AccountBalancesBackup) { +func (ap *Account) RestoreFromBackup(abb AccountBalancesBackup) { for blncID, val := range abb { ap.Balances[blncID].Units.Big = val } } // AccountBalancesBackup returns a backup of all balance values -func (ap *AccountProfile) AccountBalancesBackup() (abb AccountBalancesBackup) { +func (ap *Account) AccountBalancesBackup() (abb AccountBalancesBackup) { if ap.Balances != nil { abb = make(AccountBalancesBackup) for blncID, blnc := range ap.Balances { @@ -185,13 +185,13 @@ func (uF *UnitFactor) Equals(nUf *UnitFactor) (eq bool) { } // TenantID returns the combined Tenant:ID -func (aP *AccountProfile) TenantID() string { +func (aP *Account) TenantID() string { return ConcatenatedKey(aP.Tenant, aP.ID) } // Clone returns a clone of the Account -func (aP *AccountProfile) Clone() (acnt *AccountProfile) { - acnt = &AccountProfile{ +func (aP *Account) Clone() (acnt *Account) { + acnt = &Account{ Tenant: aP.Tenant, ID: aP.ID, ActivationInterval: aP.ActivationInterval.Clone(), @@ -285,33 +285,33 @@ func (bL *Balance) Clone() (blnc *Balance) { } // AccountProfileWithWeight attaches static weight to AccountProfile -type AccountProfileWithWeight struct { - *AccountProfile +type AccountWithWeight struct { + *Account Weight float64 LockID string } // AccountProfilesWithWeight is a sortable list of AccountProfileWithWeight -type AccountProfilesWithWeight []*AccountProfileWithWeight +type AccountsWithWeight []*AccountWithWeight // Sort is part of sort interface, sort based on Weight -func (aps AccountProfilesWithWeight) Sort() { +func (aps AccountsWithWeight) Sort() { sort.Slice(aps, func(i, j int) bool { return aps[i].Weight > aps[j].Weight }) } // AccountProfiles returns the list of AccountProfiles -func (apWws AccountProfilesWithWeight) AccountProfiles() (aps []*AccountProfile) { +func (apWws AccountsWithWeight) AccountProfiles() (aps []*Account) { if apWws != nil { - aps = make([]*AccountProfile, len(apWws)) + aps = make([]*Account, len(apWws)) for i, apWw := range apWws { - aps[i] = apWw.AccountProfile + aps[i] = apWw.Account } } return } // LockIDs returns the list of LockIDs -func (apWws AccountProfilesWithWeight) LockIDs() (lkIDs []string) { +func (apWws AccountsWithWeight) LockIDs() (lkIDs []string) { if apWws != nil { lkIDs = make([]string, len(apWws)) for i, apWw := range apWws { @@ -347,13 +347,13 @@ func (bWws BalancesWithWeight) Balances() (blncs []*Balance) { } // APIAccountProfileWithOpts is used in API calls -type APIAccountProfileWithOpts struct { - *APIAccountProfile +type APIAccountWithOpts struct { + *APIAccount APIOpts map[string]interface{} } -type AccountProfileWithAPIOpts struct { - *AccountProfile +type AccountWithAPIOpts struct { + *Account APIOpts map[string]interface{} } @@ -364,7 +364,7 @@ type ArgsAccountsForEvent struct { } // APIAccountProfile represents one APIAccount on a Tenant -type APIAccountProfile struct { +type APIAccount struct { Tenant string ID string FilterIDs []string @@ -375,9 +375,9 @@ type APIAccountProfile struct { ThresholdIDs []string } -// AsAccountProfile convert APIAccountProfile struct to AccountProfile struct -func (ext *APIAccountProfile) AsAccountProfile() (profile *AccountProfile, err error) { - profile = &AccountProfile{ +// AsAccount convert APIAccount struct to AccountProfile struct +func (ext *APIAccount) AsAccount() (profile *Account, err error) { + profile = &Account{ Tenant: ext.Tenant, ID: ext.ID, FilterIDs: ext.FilterIDs, diff --git a/utils/accountprofile_test.go b/utils/accountprofile_test.go index 88e77f2f2..f51c2b204 100644 --- a/utils/accountprofile_test.go +++ b/utils/accountprofile_test.go @@ -68,7 +68,7 @@ func TestCloneBalance(t *testing.T) { } func TestCloneAccountProfile(t *testing.T) { - actPrf := &AccountProfile{ + actPrf := &Account{ Tenant: "cgrates.org", ID: "Profile_id1", FilterIDs: []string{"*string:~*req.Account:1001"}, @@ -129,7 +129,7 @@ func TestCloneAccountProfile(t *testing.T) { } func TestTenantIDAccountProfile(t *testing.T) { - actPrf := &AccountProfile{ + actPrf := &Account{ Tenant: "cgrates.org", ID: "test_ID1", } @@ -140,7 +140,7 @@ func TestTenantIDAccountProfile(t *testing.T) { } func TestAccountProfileAsAccountProfile(t *testing.T) { - apiAccPrf := &APIAccountProfile{ + apiAccPrf := &APIAccount{ Tenant: "cgrates.org", ID: "test_ID1", Opts: map[string]interface{}{}, @@ -158,7 +158,7 @@ func TestAccountProfileAsAccountProfile(t *testing.T) { }, Weights: ";10", } - expected := &AccountProfile{ + expected := &Account{ Tenant: "cgrates.org", ID: "test_ID1", Opts: map[string]interface{}{}, @@ -184,7 +184,7 @@ func TestAccountProfileAsAccountProfile(t *testing.T) { }, }, } - if rcv, err := apiAccPrf.AsAccountProfile(); err != nil { + if rcv, err := apiAccPrf.AsAccount(); err != nil { t.Error(err) } else if !reflect.DeepEqual(expected, rcv) { t.Errorf("Expected %+v, received %+v", ToJSON(expected), ToJSON(rcv)) @@ -192,7 +192,7 @@ func TestAccountProfileAsAccountProfile(t *testing.T) { } func TestAsAccountProfileError(t *testing.T) { - apiAccPrf := &APIAccountProfile{ + apiAccPrf := &APIAccount{ Tenant: "cgrates.org", ID: "test_ID1", Opts: map[string]interface{}{}, @@ -204,14 +204,14 @@ func TestAsAccountProfileError(t *testing.T) { Weights: "10", } expectedErr := "invalid DynamicWeight format for string <10>" - if _, err := apiAccPrf.AsAccountProfile(); err == nil || err.Error() != expectedErr { + if _, err := apiAccPrf.AsAccount(); err == nil || err.Error() != expectedErr { t.Errorf("Expected %+v, received %+v", expectedErr, err) } apiAccPrf.Weights = ";10" apiAccPrf.Balances["MonetaryBalance"].Weights = "10" expectedErr = "invalid DynamicWeight format for string <10>" - if _, err := apiAccPrf.AsAccountProfile(); err == nil || err.Error() != expectedErr { + if _, err := apiAccPrf.AsAccount(); err == nil || err.Error() != expectedErr { t.Errorf("Expected %+v, received %+v", expectedErr, err) } } @@ -267,7 +267,7 @@ func TestAPIBalanceAsBalance(t *testing.T) { } func TestAccountProfileBalancesAlteredCompareLength(t *testing.T) { - actPrf := &AccountProfile{ + actPrf := &Account{ Balances: map[string]*Balance{ "testString": {}, "testString2": {}, @@ -286,7 +286,7 @@ func TestAccountProfileBalancesAlteredCompareLength(t *testing.T) { } func TestAccountProfileBalancesAlteredCheckKeys(t *testing.T) { - actPrf := &AccountProfile{ + actPrf := &Account{ Balances: map[string]*Balance{ "testString": {}, }, @@ -304,7 +304,7 @@ func TestAccountProfileBalancesAlteredCheckKeys(t *testing.T) { } func TestAccountProfileBalancesAlteredCompareValues(t *testing.T) { - actPrf := &AccountProfile{ + actPrf := &Account{ Balances: map[string]*Balance{ "testString": { Units: &Decimal{decimal.New(1, 1)}, @@ -324,7 +324,7 @@ func TestAccountProfileBalancesAlteredCompareValues(t *testing.T) { } func TestAccountProfileBalancesAlteredFalse(t *testing.T) { - actPrf := &AccountProfile{} + actPrf := &Account{} actBk := AccountBalancesBackup{} @@ -336,7 +336,7 @@ func TestAccountProfileBalancesAlteredFalse(t *testing.T) { } func TestAPRestoreFromBackup(t *testing.T) { - actPrf := &AccountProfile{ + actPrf := &Account{ Balances: map[string]*Balance{ "testString": { Units: &Decimal{}, @@ -357,7 +357,7 @@ func TestAPRestoreFromBackup(t *testing.T) { } func TestAPAccountBalancesBackup(t *testing.T) { - actPrf := &AccountProfile{ + actPrf := &Account{ Balances: map[string]*Balance{ "testKey": { Units: &Decimal{decimal.New(1234, 3)}, @@ -410,7 +410,7 @@ func TestAPNewDefaultBalance(t *testing.T) { func TestAPApsSort(t *testing.T) { - apS := AccountProfilesWithWeight{ + apS := AccountsWithWeight{ { Weight: 2, }, @@ -421,7 +421,7 @@ func TestAPApsSort(t *testing.T) { Weight: 3, }, } - expected := AccountProfilesWithWeight{ + expected := AccountsWithWeight{ { Weight: 3, }, @@ -441,9 +441,9 @@ func TestAPApsSort(t *testing.T) { func TestAPAccountProfiles(t *testing.T) { - apS := AccountProfilesWithWeight{ + apS := AccountsWithWeight{ { - AccountProfile: &AccountProfile{ + Account: &Account{ Tenant: "testTenant1", ID: "testID1", FilterIDs: []string{"testFID1", "testFID2"}, @@ -464,7 +464,7 @@ func TestAPAccountProfiles(t *testing.T) { LockID: "testString1", }, { - AccountProfile: &AccountProfile{ + Account: &Account{ Tenant: "testTenant2", ID: "testID2", FilterIDs: []string{"testFID1", "testFID2"}, @@ -486,9 +486,9 @@ func TestAPAccountProfiles(t *testing.T) { }, } - expected := make([]*AccountProfile, 0) + expected := make([]*Account, 0) for i := range apS { - expected = append(expected, apS[i].AccountProfile) + expected = append(expected, apS[i].Account) } received := apS.AccountProfiles() @@ -498,9 +498,9 @@ func TestAPAccountProfiles(t *testing.T) { } func TestAPLockIDs(t *testing.T) { - apS := AccountProfilesWithWeight{ + apS := AccountsWithWeight{ { - AccountProfile: &AccountProfile{ + Account: &Account{ Tenant: "testTenant1", ID: "testID1", FilterIDs: []string{"testFID1", "testFID2"}, @@ -521,7 +521,7 @@ func TestAPLockIDs(t *testing.T) { LockID: "testString1", }, { - AccountProfile: &AccountProfile{ + Account: &Account{ Tenant: "testTenant2", ID: "testID2", FilterIDs: []string{"testFID1", "testFID2"}, diff --git a/utils/eventcharges.go b/utils/eventcharges.go index 4626d5d64..0d5c5f481 100644 --- a/utils/eventcharges.go +++ b/utils/eventcharges.go @@ -38,7 +38,7 @@ type EventCharges struct { Concretes *Decimal // total concrete units charged ChargingIntervals []*ChargingInterval - Accounts []*AccountProfile + Accounts []*Account Accounting map[string]*AccountCharge UnitFactors map[string]*UnitFactor