From 850a43433b8f8785708a15216ff96e7326c4d196 Mon Sep 17 00:00:00 2001 From: porosnicuadrian Date: Wed, 7 Apr 2021 17:17:09 +0300 Subject: [PATCH] Renamed AccountProfile in Accounts from all packages --- accounts/accounts.go | 20 ++++++++++---------- accounts/actsetbalance.go | 2 +- accounts/libaccounts.go | 2 +- apier/v1/accountprofiles.go | 4 ++-- apier/v1/apier.go | 6 +++--- apier/v1/filter_indexes.go | 10 +++++----- apier/v1/tpaccountprofiles.go | 12 ++++++------ engine/datamanager.go | 8 ++++---- engine/libindex.go | 2 +- engine/model_helpers.go | 22 +++++++++++----------- engine/models.go | 4 ++-- engine/storage_csv.go | 10 +++++----- engine/storage_interface.go | 4 ++-- engine/storage_internal_stordb.go | 6 +++--- engine/storage_mongo_stordb.go | 8 ++++---- engine/storage_sql.go | 12 ++++++------ engine/tpexporter.go | 4 ++-- engine/tpimporter_csv.go | 4 ++-- engine/tpreader.go | 20 ++++++++++---------- loaders/loader.go | 10 +++++----- utils/accountprofile.go | 4 ++-- utils/apitpdata.go | 2 +- 22 files changed, 88 insertions(+), 88 deletions(-) diff --git a/accounts/accounts.go b/accounts/accounts.go index d25af37ac..3e4ae0dd8 100644 --- a/accounts/accounts.go +++ b/accounts/accounts.go @@ -98,13 +98,13 @@ func (aS *AccountS) matchingAccountsForEvent(tnt string, cgrEv *utils.CGREvent, aS.cfg.GeneralCfg().LockingTimeout, cacheKey) // RPC caching needs to be atomic } var qAcnt *utils.Account - if qAcnt, err = aS.dm.GetAccountProfile(tnt, acntID); err != nil { + if qAcnt, err = aS.dm.GetAccount(tnt, acntID); err != nil { guardian.Guardian.UnguardIDs(refID) if err == utils.ErrNotFound { err = nil continue } - unlockAccountProfiles(acnts) // in case of errors will not have unlocks in upper layers + unlockAccounts(acnts) // in case of errors will not have unlocks in upper layers return } if _, isDisabled := qAcnt.Opts[utils.Disabled]; isDisabled || @@ -116,7 +116,7 @@ func (aS *AccountS) matchingAccountsForEvent(tnt string, cgrEv *utils.CGREvent, var pass bool if pass, err = aS.fltrS.Pass(tnt, qAcnt.FilterIDs, evNm); err != nil { guardian.Guardian.UnguardIDs(refID) - unlockAccountProfiles(acnts) + unlockAccounts(acnts) return } else if !pass { guardian.Guardian.UnguardIDs(refID) @@ -126,7 +126,7 @@ func (aS *AccountS) matchingAccountsForEvent(tnt string, cgrEv *utils.CGREvent, if weight, err = engine.WeightFromDynamics(qAcnt.Weights, aS.fltrS, cgrEv.Tenant, evNm); err != nil { guardian.Guardian.UnguardIDs(refID) - unlockAccountProfiles(acnts) + unlockAccounts(acnts) return } acnts = append(acnts, &utils.AccountWithWeight{qAcnt, weight, refID}) @@ -263,7 +263,7 @@ func (aS *AccountS) V1AccountProfilesForEvent(args *utils.ArgsAccountsForEvent, } return } - *aps = acnts.AccountProfiles() + *aps = acnts.Accounts() return } @@ -277,7 +277,7 @@ func (aS *AccountS) V1MaxAbstracts(args *utils.ArgsAccountsForEvent, eEc *utils. } return } - defer unlockAccountProfiles(acnts) + defer unlockAccounts(acnts) var procEC *utils.EventCharges if procEC, err = aS.accountsDebit(acnts, args.CGREvent, false, false); err != nil { @@ -301,7 +301,7 @@ func (aS *AccountS) V1DebitAbstracts(args *utils.ArgsAccountsForEvent, eEc *util } return } - defer unlockAccountProfiles(acnts) + defer unlockAccounts(acnts) var procEC *utils.EventCharges if procEC, err = aS.accountsDebit(acnts, args.CGREvent, false, true); err != nil { @@ -327,7 +327,7 @@ func (aS *AccountS) V1MaxConcretes(args *utils.ArgsAccountsForEvent, eEc *utils. } return } - defer unlockAccountProfiles(acnts) + defer unlockAccounts(acnts) var procEC *utils.EventCharges if procEC, err = aS.accountsDebit(acnts, args.CGREvent, true, false); err != nil { @@ -351,7 +351,7 @@ func (aS *AccountS) V1DebitConcretes(args *utils.ArgsAccountsForEvent, eEc *util } return } - defer unlockAccountProfiles(acnts) + defer unlockAccounts(acnts) var procEC *utils.EventCharges if procEC, err = aS.accountsDebit(acnts, args.CGREvent, true, true); err != nil { @@ -403,7 +403,7 @@ func (aS *AccountS) V1ActionRemoveBalance(args *utils.ArgsActRemoveBalances, rpl tnt = aS.cfg.GeneralCfg().DefaultTenant } if _, err = guardian.Guardian.Guard(func() (interface{}, error) { - qAcnt, err := aS.dm.GetAccountProfile(tnt, args.AccountID) + qAcnt, err := aS.dm.GetAccount(tnt, args.AccountID) if err != nil { return nil, err } diff --git a/accounts/actsetbalance.go b/accounts/actsetbalance.go index 98dc79d30..8ffc6603c 100644 --- a/accounts/actsetbalance.go +++ b/accounts/actsetbalance.go @@ -30,7 +30,7 @@ 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.Account - if qAcnt, err = dm.GetAccountProfile(tnt, acntID); err != nil { + if qAcnt, err = dm.GetAccount(tnt, acntID); err != nil { if err != utils.ErrNotFound { return } diff --git a/accounts/libaccounts.go b/accounts/libaccounts.go index 192b5d0f7..205e2b600 100644 --- a/accounts/libaccounts.go +++ b/accounts/libaccounts.go @@ -346,7 +346,7 @@ func restoreAccounts(dm *engine.DataManager, } // unlockAccountProfiles is used to unlock the accounts based on their lock identifiers -func unlockAccountProfiles(acnts utils.AccountsWithWeight) { +func unlockAccounts(acnts utils.AccountsWithWeight) { for _, lkID := range acnts.LockIDs() { guardian.Guardian.UnguardIDs(lkID) } diff --git a/apier/v1/accountprofiles.go b/apier/v1/accountprofiles.go index ca0a3009e..dd7042cff 100644 --- a/apier/v1/accountprofiles.go +++ b/apier/v1/accountprofiles.go @@ -35,7 +35,7 @@ func (apierSv1 *APIerSv1) GetAccountProfile(arg *utils.TenantIDWithAPIOpts, repl if tnt == utils.EmptyString { tnt = apierSv1.Config.GeneralCfg().DefaultTenant } - ap, err := apierSv1.DataManager.GetAccountProfile(tnt, arg.ID) + ap, err := apierSv1.DataManager.GetAccount(tnt, arg.ID) if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) @@ -119,7 +119,7 @@ func (apierSv1 *APIerSv1) RemoveAccountProfile(arg *utils.TenantIDWithAPIOpts, r if tnt == utils.EmptyString { tnt = apierSv1.Config.GeneralCfg().DefaultTenant } - if err := apierSv1.DataManager.RemoveAccountProfile(tnt, arg.ID, + if err := apierSv1.DataManager.RemoveAccount(tnt, arg.ID, utils.NonTransactional, true); err != nil { return utils.APIErrorHandler(err) } diff --git a/apier/v1/apier.go b/apier/v1/apier.go index a78123ae5..98f99bcca 100644 --- a/apier/v1/apier.go +++ b/apier/v1/apier.go @@ -1106,16 +1106,16 @@ func (apierSv1 *APIerSv1) ExportToFolder(arg *utils.ArgExportToFolder, reply *st csvWriter := csv.NewWriter(f) csvWriter.Comma = utils.CSVSep //write the header of the file - if err := csvWriter.Write(engine.AccountProfileMdls{}.CSVHeader()); err != nil { + if err := csvWriter.Write(engine.AccountMdls{}.CSVHeader()); err != nil { return err } for _, key := range keys { tntID := strings.SplitN(key[len(prfx):], utils.InInFieldSep, 2) - accPrf, err := apierSv1.DataManager.GetAccountProfile(tntID[0], tntID[1]) + accPrf, err := apierSv1.DataManager.GetAccount(tntID[0], tntID[1]) if err != nil { return err } - for _, model := range engine.APItoModelTPAccountProfile(engine.AccountProfileToAPI(accPrf)) { + for _, model := range engine.APItoModelTPAccount(engine.AccountToAPI(accPrf)) { if record, err := engine.CsvDump(model); err != nil { return err } else if err := csvWriter.Write(record); err != nil { diff --git a/apier/v1/filter_indexes.go b/apier/v1/filter_indexes.go index 9575696f0..6f4232b97 100644 --- a/apier/v1/filter_indexes.go +++ b/apier/v1/filter_indexes.go @@ -326,11 +326,11 @@ func (apierSv1 *APIerSv1) ComputeFilterIndexes(args *utils.ArgsComputeFilterInde return utils.APIErrorHandler(err) } } - //AccountProfile Indexes + //Account Indexes if args.AccountS { if args.AccountS, err = engine.ComputeIndexes(apierSv1.DataManager, tnt, args.Context, utils.CacheAccountProfilesFilterIndexes, nil, transactionID, func(tnt, id, ctx string) (*[]string, error) { - acp, e := apierSv1.DataManager.GetAccountProfile(tnt, id) + acp, e := apierSv1.DataManager.GetAccount(tnt, id) if e != nil { return nil, e } @@ -465,7 +465,7 @@ func (apierSv1 *APIerSv1) ComputeFilterIndexes(args *utils.ArgsComputeFilterInde return } } - //AccountProfile Indexes + //Account Indexes if args.AccountS { if err = apierSv1.DataManager.SetIndexes(utils.CacheAccountProfilesFilterIndexes, tnt, nil, true, transactionID); err != nil { return @@ -577,10 +577,10 @@ func (apierSv1 *APIerSv1) ComputeFilterIndexIDs(args *utils.ArgsComputeFilterInd }); err != nil && err != utils.ErrNotFound { return utils.APIErrorHandler(err) } - //AccountProfile Indexes + //Account Indexes if _, err = engine.ComputeIndexes(apierSv1.DataManager, tnt, args.Context, utils.CacheAccountProfilesFilterIndexes, &args.AccountProfileIDs, transactionID, func(tnt, id, ctx string) (*[]string, error) { - acp, e := apierSv1.DataManager.GetAccountProfile(tnt, id) + acp, e := apierSv1.DataManager.GetAccount(tnt, id) if e != nil { return nil, e } diff --git a/apier/v1/tpaccountprofiles.go b/apier/v1/tpaccountprofiles.go index b24efd62a..778cf575e 100644 --- a/apier/v1/tpaccountprofiles.go +++ b/apier/v1/tpaccountprofiles.go @@ -23,14 +23,14 @@ import ( ) // SetTPAccountProfile creates a new TPAccountProfile within a tariff plan -func (apierSv1 *APIerSv1) SetTPAccountProfile(attrs *utils.TPAccountProfile, reply *string) error { +func (apierSv1 *APIerSv1) SetTPAccountProfile(attrs *utils.TPAccount, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } if attrs.Tenant == utils.EmptyString { attrs.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant } - if err := apierSv1.StorDb.SetTPAccountProfiles([]*utils.TPAccountProfile{attrs}); err != nil { + if err := apierSv1.StorDb.SetTPAccounts([]*utils.TPAccount{attrs}); err != nil { return utils.NewErrServerError(err) } *reply = utils.OK @@ -38,14 +38,14 @@ func (apierSv1 *APIerSv1) SetTPAccountProfile(attrs *utils.TPAccountProfile, rep } // GetTPAccountProfile queries specific TPAccountProfile on tariff plan -func (apierSv1 *APIerSv1) GetTPAccountProfile(attr *utils.TPTntID, reply *utils.TPAccountProfile) error { +func (apierSv1 *APIerSv1) GetTPAccountProfile(attr *utils.TPTntID, reply *utils.TPAccount) error { if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } if attr.Tenant == utils.EmptyString { attr.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant } - spp, err := apierSv1.StorDb.GetTPAccountProfiles(attr.TPid, attr.Tenant, attr.ID) + spp, err := apierSv1.StorDb.GetTPAccounts(attr.TPid, attr.Tenant, attr.ID) if err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) @@ -56,13 +56,13 @@ func (apierSv1 *APIerSv1) GetTPAccountProfile(attr *utils.TPTntID, reply *utils. return nil } -type AttrGetTPAccountProfileIDs struct { +type AttrGetTPAccountIDs struct { TPid string // Tariff plan id utils.PaginatorWithSearch } // GetTPRouteProfileIDs queries TPAccountProfiles identities on specific tariff plan. -func (apierSv1 *APIerSv1) GetTPAccountProfileIDs(attrs *AttrGetTPAccountProfileIDs, reply *[]string) error { +func (apierSv1 *APIerSv1) GetTPAccountProfileIDs(attrs *AttrGetTPAccountIDs, reply *[]string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } diff --git a/engine/datamanager.go b/engine/datamanager.go index 159dc5b97..f8e40530f 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.Account, err error) { +func (dm *DataManager) GetAccount(tenant, id string) (ap *utils.Account, err error) { if dm == nil { err = utils.ErrNoDatabaseConn return @@ -2868,7 +2868,7 @@ func (dm *DataManager) SetAccount(ap *utils.Account, withIndex bool) (err error) brokenReference, ap.TenantID()) } } - oldRpp, err := dm.GetAccountProfile(ap.Tenant, ap.ID) + oldRpp, err := dm.GetAccount(ap.Tenant, ap.ID) if err != nil && err != utils.ErrNotFound { return err } @@ -2898,12 +2898,12 @@ func (dm *DataManager) SetAccount(ap *utils.Account, withIndex bool) (err error) return } -func (dm *DataManager) RemoveAccountProfile(tenant, id string, +func (dm *DataManager) RemoveAccount(tenant, id string, transactionID string, withIndex bool) (err error) { if dm == nil { return utils.ErrNoDatabaseConn } - oldRpp, err := dm.GetAccountProfile(tenant, id) + oldRpp, err := dm.GetAccount(tenant, id) if err != nil && err != utils.ErrNotFound { return err } diff --git a/engine/libindex.go b/engine/libindex.go index 3c4d55d64..57c2efceb 100644 --- a/engine/libindex.go +++ b/engine/libindex.go @@ -701,7 +701,7 @@ func UpdateFilterIndex(dm *DataManager, oldFlt, newFlt *Filter) (err error) { idxSlice := indx.AsSlice() if _, err = ComputeIndexes(dm, newFlt.Tenant, utils.EmptyString, idxItmType, // compute all the indexes for afected items &idxSlice, utils.NonTransactional, func(tnt, id, ctx string) (*[]string, error) { - ap, e := dm.GetAccountProfile(tnt, id) + ap, e := dm.GetAccount(tnt, id) if e != nil { return nil, e } diff --git a/engine/model_helpers.go b/engine/model_helpers.go index f6ff1d582..a18251b8e 100644 --- a/engine/model_helpers.go +++ b/engine/model_helpers.go @@ -2653,10 +2653,10 @@ func ActionProfileToAPI(ap *ActionProfile) (tpAp *utils.TPActionProfile) { return } -type AccountProfileMdls []*AccountProfileMdl +type AccountMdls []*AccountMdl // CSVHeader return the header for csv fields as a slice of string -func (apm AccountProfileMdls) CSVHeader() (result []string) { +func (apm AccountMdls) CSVHeader() (result []string) { return []string{"#" + utils.Tenant, utils.ID, utils.FilterIDs, utils.ActivationIntervalString, utils.Weight, utils.BalanceID, utils.BalanceFilterIDs, utils.BalanceWeight, utils.BalanceBlocker, @@ -2664,15 +2664,15 @@ func (apm AccountProfileMdls) CSVHeader() (result []string) { } } -func (apm AccountProfileMdls) AsTPAccountProfile() (result []*utils.TPAccountProfile, err error) { +func (apm AccountMdls) AsTPAccount() (result []*utils.TPAccount, err error) { filterIDsMap := make(map[string]utils.StringSet) thresholdIDsMap := make(map[string]utils.StringSet) - actPrfMap := make(map[string]*utils.TPAccountProfile) + actPrfMap := make(map[string]*utils.TPAccount) for _, tp := range apm { tenID := (&utils.TenantID{Tenant: tp.Tenant, ID: tp.ID}).TenantID() aPrf, found := actPrfMap[tenID] if !found { - aPrf = &utils.TPAccountProfile{ + aPrf = &utils.TPAccount{ TPid: tp.Tpid, Tenant: tp.Tenant, ID: tp.ID, @@ -2759,7 +2759,7 @@ func (apm AccountProfileMdls) AsTPAccountProfile() (result []*utils.TPAccountPro } actPrfMap[tenID] = aPrf } - result = make([]*utils.TPAccountProfile, len(actPrfMap)) + result = make([]*utils.TPAccount, len(actPrfMap)) i := 0 for tntID, th := range actPrfMap { result[i] = th @@ -2770,13 +2770,13 @@ func (apm AccountProfileMdls) AsTPAccountProfile() (result []*utils.TPAccountPro return } -func APItoModelTPAccountProfile(tPrf *utils.TPAccountProfile) (mdls AccountProfileMdls) { +func APItoModelTPAccount(tPrf *utils.TPAccount) (mdls AccountMdls) { if len(tPrf.Balances) == 0 { return } i := 0 for _, balance := range tPrf.Balances { - mdl := &AccountProfileMdl{ + mdl := &AccountMdl{ Tenant: tPrf.Tenant, Tpid: tPrf.TPid, ID: tPrf.ID, @@ -2845,7 +2845,7 @@ func APItoModelTPAccountProfile(tPrf *utils.TPAccountProfile) (mdls AccountProfi return } -func APItoAccountProfile(tpAp *utils.TPAccountProfile, timezone string) (ap *utils.Account, err error) { +func APItoAccount(tpAp *utils.TPAccount, timezone string) (ap *utils.Account, err error) { ap = &utils.Account{ Tenant: tpAp.Tenant, ID: tpAp.ID, @@ -2939,8 +2939,8 @@ func APItoAccountProfile(tpAp *utils.TPAccountProfile, timezone string) (ap *uti return } -func AccountProfileToAPI(ap *utils.Account) (tpAp *utils.TPAccountProfile) { - tpAp = &utils.TPAccountProfile{ +func AccountToAPI(ap *utils.Account) (tpAp *utils.TPAccount) { + tpAp = &utils.TPAccount{ Tenant: ap.Tenant, ID: ap.ID, Weights: ap.Weights.String(";", "&"), diff --git a/engine/models.go b/engine/models.go index 1c4ae08db..99e68c7ad 100644 --- a/engine/models.go +++ b/engine/models.go @@ -382,7 +382,7 @@ func (ActionProfileMdl) TableName() string { return utils.TBLTPActionProfiles } -type AccountProfileMdl struct { +type AccountMdl struct { PK uint `gorm:"primary_key"` Tpid string Tenant string `index:"0" re:""` @@ -405,6 +405,6 @@ type AccountProfileMdl struct { CreatedAt time.Time } -func (AccountProfileMdl) TableName() string { +func (AccountMdl) TableName() string { return utils.TBLTPAccountProfiles } diff --git a/engine/storage_csv.go b/engine/storage_csv.go index 8d8acfbe2..14b1748ba 100644 --- a/engine/storage_csv.go +++ b/engine/storage_csv.go @@ -486,16 +486,16 @@ func (csvs *CSVStorage) GetTPActionProfiles(tpid, tenant, id string) ([]*utils.T return tpDPPs.AsTPActionProfile(), nil } -func (csvs *CSVStorage) GetTPAccountProfiles(tpid, tenant, id string) ([]*utils.TPAccountProfile, error) { - var tpDPPs AccountProfileMdls - if err := csvs.proccesData(AccountProfileMdl{}, csvs.accountProfilesFn, func(tp interface{}) { - dpp := tp.(AccountProfileMdl) +func (csvs *CSVStorage) GetTPAccounts(tpid, tenant, id string) ([]*utils.TPAccount, error) { + var tpDPPs AccountMdls + if err := csvs.proccesData(AccountMdl{}, csvs.accountProfilesFn, func(tp interface{}) { + dpp := tp.(AccountMdl) dpp.Tpid = tpid tpDPPs = append(tpDPPs, &dpp) }); err != nil { return nil, err } - return tpDPPs.AsTPAccountProfile() + return tpDPPs.AsTPAccount() } func (csvs *CSVStorage) GetTpIds(colName string) ([]string, error) { diff --git a/engine/storage_interface.go b/engine/storage_interface.go index b16110991..9be826bd2 100644 --- a/engine/storage_interface.go +++ b/engine/storage_interface.go @@ -148,7 +148,7 @@ type LoadReader interface { GetTPDispatcherHosts(string, string, string) ([]*utils.TPDispatcherHost, error) GetTPRateProfiles(string, string, string) ([]*utils.TPRateProfile, error) GetTPActionProfiles(string, string, string) ([]*utils.TPActionProfile, error) - GetTPAccountProfiles(string, string, string) ([]*utils.TPAccountProfile, error) + GetTPAccounts(string, string, string) ([]*utils.TPAccount, error) } type LoadWriter interface { @@ -166,7 +166,7 @@ type LoadWriter interface { SetTPDispatcherHosts([]*utils.TPDispatcherHost) error SetTPRateProfiles([]*utils.TPRateProfile) error SetTPActionProfiles([]*utils.TPActionProfile) error - SetTPAccountProfiles([]*utils.TPAccountProfile) error + SetTPAccounts([]*utils.TPAccount) error } // NewMarshaler returns the marshaler type selected by mrshlerStr diff --git a/engine/storage_internal_stordb.go b/engine/storage_internal_stordb.go index 368b1d67f..a9d6a0333 100644 --- a/engine/storage_internal_stordb.go +++ b/engine/storage_internal_stordb.go @@ -346,7 +346,7 @@ func (iDB *InternalDB) GetTPActionProfiles(tpid, tenant, id string) (tpPrfs []*u return } -func (iDB *InternalDB) GetTPAccountProfiles(tpid, tenant, id string) (tpPrfs []*utils.TPAccountProfile, err error) { +func (iDB *InternalDB) GetTPAccounts(tpid, tenant, id string) (tpPrfs []*utils.TPAccount, err error) { key := tpid if tenant != utils.EmptyString { key += utils.ConcatenatedKeySep + tenant @@ -360,7 +360,7 @@ func (iDB *InternalDB) GetTPAccountProfiles(tpid, tenant, id string) (tpPrfs []* if !ok || x == nil { return nil, utils.ErrNotFound } - tpPrfs = append(tpPrfs, x.(*utils.TPAccountProfile)) + tpPrfs = append(tpPrfs, x.(*utils.TPAccount)) } if len(tpPrfs) == 0 { return nil, utils.ErrNotFound @@ -531,7 +531,7 @@ func (iDB *InternalDB) SetTPActionProfiles(tpPrfs []*utils.TPActionProfile) (err return } -func (iDB *InternalDB) SetTPAccountProfiles(tpPrfs []*utils.TPAccountProfile) (err error) { +func (iDB *InternalDB) SetTPAccounts(tpPrfs []*utils.TPAccount) (err error) { if len(tpPrfs) == 0 { return nil } diff --git a/engine/storage_mongo_stordb.go b/engine/storage_mongo_stordb.go index fdca19bf6..8b7d66862 100644 --- a/engine/storage_mongo_stordb.go +++ b/engine/storage_mongo_stordb.go @@ -1055,7 +1055,7 @@ func (ms *MongoStorage) GetTPActionProfiles(tpid, tenant, id string) ([]*utils.T return results, err } -func (ms *MongoStorage) GetTPAccountProfiles(tpid, tenant, id string) ([]*utils.TPAccountProfile, error) { +func (ms *MongoStorage) GetTPAccounts(tpid, tenant, id string) ([]*utils.TPAccount, error) { filter := bson.M{"tpid": tpid} if id != "" { filter["id"] = id @@ -1063,14 +1063,14 @@ func (ms *MongoStorage) GetTPAccountProfiles(tpid, tenant, id string) ([]*utils. if tenant != "" { filter["tenant"] = tenant } - var results []*utils.TPAccountProfile + var results []*utils.TPAccount err := ms.query(func(sctx mongo.SessionContext) (err error) { cur, err := ms.getCol(utils.TBLTPAccountProfiles).Find(sctx, filter) if err != nil { return err } for cur.Next(sctx) { - var tp utils.TPAccountProfile + var tp utils.TPAccount err := cur.Decode(&tp) if err != nil { return err @@ -1103,7 +1103,7 @@ func (ms *MongoStorage) SetTPActionProfiles(tpAps []*utils.TPActionProfile) (err }) } -func (ms *MongoStorage) SetTPAccountProfiles(tpAps []*utils.TPAccountProfile) (err error) { +func (ms *MongoStorage) SetTPAccounts(tpAps []*utils.TPAccount) (err error) { if len(tpAps) == 0 { return } diff --git a/engine/storage_sql.go b/engine/storage_sql.go index a66464784..43f6bc4c4 100644 --- a/engine/storage_sql.go +++ b/engine/storage_sql.go @@ -538,18 +538,18 @@ func (sqls *SQLStorage) SetTPActionProfiles(tpAps []*utils.TPActionProfile) erro return nil } -func (sqls *SQLStorage) SetTPAccountProfiles(tpAps []*utils.TPAccountProfile) error { +func (sqls *SQLStorage) SetTPAccounts(tpAps []*utils.TPAccount) error { if len(tpAps) == 0 { return nil } tx := sqls.db.Begin() for _, tpAp := range tpAps { // Remove previous - if err := tx.Where(&AccountProfileMdl{Tpid: tpAp.TPid, Tenant: tpAp.Tenant, ID: tpAp.ID}).Delete(AccountProfileMdl{}).Error; err != nil { + if err := tx.Where(&AccountMdl{Tpid: tpAp.TPid, Tenant: tpAp.Tenant, ID: tpAp.ID}).Delete(AccountMdl{}).Error; err != nil { tx.Rollback() return err } - for _, mst := range APItoModelTPAccountProfile(tpAp) { + for _, mst := range APItoModelTPAccount(tpAp) { if err := tx.Create(&mst).Error; err != nil { tx.Rollback() return err @@ -1097,8 +1097,8 @@ func (sqls *SQLStorage) GetTPActionProfiles(tpid, tenant, id string) ([]*utils.T return arls, nil } -func (sqls *SQLStorage) GetTPAccountProfiles(tpid, tenant, id string) ([]*utils.TPAccountProfile, error) { - var dpps AccountProfileMdls +func (sqls *SQLStorage) GetTPAccounts(tpid, tenant, id string) ([]*utils.TPAccount, error) { + var dpps AccountMdls q := sqls.db.Where("tpid = ?", tpid) if len(id) != 0 { q = q.Where("id = ?", id) @@ -1109,7 +1109,7 @@ func (sqls *SQLStorage) GetTPAccountProfiles(tpid, tenant, id string) ([]*utils. if err := q.Find(&dpps).Error; err != nil { return nil, err } - arls, err := dpps.AsTPAccountProfile() + arls, err := dpps.AsTPAccount() if err != nil { return nil, err } else if len(arls) == 0 { diff --git a/engine/tpexporter.go b/engine/tpexporter.go index 354bcd358..0cc455201 100644 --- a/engine/tpexporter.go +++ b/engine/tpexporter.go @@ -237,13 +237,13 @@ func (tpExp *TPExporter) Run() error { } } - storDataAccountProfiles, err := tpExp.storDB.GetTPAccountProfiles(tpExp.tpID, "", "") + storDataAccountProfiles, err := tpExp.storDB.GetTPAccounts(tpExp.tpID, "", "") if err != nil && err.Error() != utils.ErrNotFound.Error() { utils.Logger.Warning(fmt.Sprintf("<%s> error: %s, when getting %s from stordb for export", utils.ApierS, err, utils.TpAccountProfiles)) withError = true } for _, sd := range storDataAccountProfiles { - sdModels := APItoModelTPAccountProfile(sd) + sdModels := APItoModelTPAccount(sd) for _, sdModel := range sdModels { toExportMap[utils.AccountProfilesCsv] = append(toExportMap[utils.AccountProfilesCsv], sdModel) } diff --git a/engine/tpimporter_csv.go b/engine/tpimporter_csv.go index 703a26925..29e2f8f61 100644 --- a/engine/tpimporter_csv.go +++ b/engine/tpimporter_csv.go @@ -232,9 +232,9 @@ func (tpImp *TPCSVImporter) importAccountProfiles(fn string) error { if tpImp.Verbose { log.Printf("Processing file: <%s> ", fn) } - rpps, err := tpImp.csvr.GetTPAccountProfiles(tpImp.TPid, "", "") + rpps, err := tpImp.csvr.GetTPAccounts(tpImp.TPid, "", "") if err != nil { return err } - return tpImp.StorDB.SetTPAccountProfiles(rpps) + return tpImp.StorDB.SetTPAccounts(rpps) } diff --git a/engine/tpreader.go b/engine/tpreader.go index dbe1e814a..b3d2227bc 100644 --- a/engine/tpreader.go +++ b/engine/tpreader.go @@ -47,7 +47,7 @@ type TpReader struct { dispatcherHosts map[utils.TenantID]*utils.TPDispatcherHost rateProfiles map[utils.TenantID]*utils.TPRateProfile actionProfiles map[utils.TenantID]*utils.TPActionProfile - accountProfiles map[utils.TenantID]*utils.TPAccountProfile + accountProfiles map[utils.TenantID]*utils.TPAccount resources []*utils.TenantID // IDs of resources which need creation based on resourceProfiles statQueues []*utils.TenantID // IDs of statQueues which need creation based on statQueueProfiles thresholds []*utils.TenantID // IDs of thresholds which need creation based on thresholdProfiles @@ -89,7 +89,7 @@ func (tpr *TpReader) Init() { tpr.dispatcherHosts = make(map[utils.TenantID]*utils.TPDispatcherHost) tpr.rateProfiles = make(map[utils.TenantID]*utils.TPRateProfile) tpr.actionProfiles = make(map[utils.TenantID]*utils.TPActionProfile) - tpr.accountProfiles = make(map[utils.TenantID]*utils.TPAccountProfile) + tpr.accountProfiles = make(map[utils.TenantID]*utils.TPAccount) tpr.filters = make(map[utils.TenantID]*utils.TPFilterProfile) tpr.acntActionPlans = make(map[string][]string) } @@ -367,16 +367,16 @@ func (tpr *TpReader) LoadActionProfilesFiltered(tag string) (err error) { return nil } -func (tpr *TpReader) LoadAccountProfiles() error { - return tpr.LoadAccountProfilesFiltered("") +func (tpr *TpReader) LoadAccounts() error { + return tpr.LoadAccountsFiltered("") } -func (tpr *TpReader) LoadAccountProfilesFiltered(tag string) (err error) { - aps, err := tpr.lr.GetTPAccountProfiles(tpr.tpid, "", tag) +func (tpr *TpReader) LoadAccountsFiltered(tag string) (err error) { + aps, err := tpr.lr.GetTPAccounts(tpr.tpid, "", tag) if err != nil { return err } - mapAccountProfiles := make(map[utils.TenantID]*utils.TPAccountProfile) + mapAccountProfiles := make(map[utils.TenantID]*utils.TPAccount) for _, ap := range aps { if err = verifyInlineFilterS(ap.FilterIDs); err != nil { return @@ -431,7 +431,7 @@ func (tpr *TpReader) LoadAll() (err error) { if err = tpr.LoadActionProfiles(); err != nil && err.Error() != utils.NotFoundCaps { return } - if err = tpr.LoadAccountProfiles(); err != nil && err.Error() != utils.NotFoundCaps { + if err = tpr.LoadAccounts(); err != nil && err.Error() != utils.NotFoundCaps { return } return nil @@ -764,7 +764,7 @@ func (tpr *TpReader) WriteToDatabase(verbose, disableReverse bool) (err error) { } for _, tpAP := range tpr.accountProfiles { var ap *utils.Account - if ap, err = APItoAccountProfile(tpAP, tpr.timezone); err != nil { + if ap, err = APItoAccount(tpAP, tpr.timezone); err != nil { return } if err = tpr.dm.SetAccount(ap, true); err != nil { @@ -1121,7 +1121,7 @@ func (tpr *TpReader) RemoveFromDatabase(verbose, disableReverse bool) (err error log.Print("AccountProfiles:") } for _, tpAp := range tpr.accountProfiles { - if err = tpr.dm.RemoveAccountProfile(tpAp.Tenant, tpAp.ID, + if err = tpr.dm.RemoveAccount(tpAp.Tenant, tpAp.ID, utils.NonTransactional, true); err != nil { return } diff --git a/loaders/loader.go b/loaders/loader.go index d75ac840a..456f23a75 100644 --- a/loaders/loader.go +++ b/loaders/loader.go @@ -642,19 +642,19 @@ func (ldr *Loader) storeLoadedData(loaderType string, case utils.MetaAccountProfiles: cacheIDs = []string{utils.CacheAccountProfilesFilterIndexes} for _, lDataSet := range lds { - acpsModels := make(engine.AccountProfileMdls, len(lDataSet)) + acpsModels := make(engine.AccountMdls, len(lDataSet)) for i, ld := range lDataSet { - acpsModels[i] = new(engine.AccountProfileMdl) + acpsModels[i] = new(engine.AccountMdl) if err = utils.UpdateStructWithIfaceMap(acpsModels[i], ld); err != nil { return } } - accountTPModels, err := acpsModels.AsTPAccountProfile() + accountTPModels, err := acpsModels.AsTPAccount() if err != nil { return err } for _, tpAcp := range accountTPModels { - acp, err := engine.APItoAccountProfile(tpAcp, ldr.timezone) + acp, err := engine.APItoAccount(tpAcp, ldr.timezone) if err != nil { return err } @@ -1021,7 +1021,7 @@ func (ldr *Loader) removeLoadedData(loaderType string, lds map[string][]LoaderDa tntIDStruct := utils.NewTenantID(tntID) // get IDs so we can reload in cache ids = append(ids, tntID) - if err := ldr.dm.RemoveAccountProfile(tntIDStruct.Tenant, + if err := ldr.dm.RemoveAccount(tntIDStruct.Tenant, tntIDStruct.ID, utils.NonTransactional, true); err != nil { return err } diff --git a/utils/accountprofile.go b/utils/accountprofile.go index c96fccf79..185a0e546 100644 --- a/utils/accountprofile.go +++ b/utils/accountprofile.go @@ -299,8 +299,8 @@ 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 AccountsWithWeight) AccountProfiles() (aps []*Account) { +// Accounts returns the list of Account +func (apWws AccountsWithWeight) Accounts() (aps []*Account) { if apWws != nil { aps = make([]*Account, len(apWws)) for i, apWw := range apWws { diff --git a/utils/apitpdata.go b/utils/apitpdata.go index e9dba6140..3cf8b906d 100755 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -995,7 +995,7 @@ type TPAPDiktat struct { Value string } -type TPAccountProfile struct { +type TPAccount struct { TPid string Tenant string ID string