diff --git a/dispatchers/accounts.go b/dispatchers/accounts.go new file mode 100644 index 000000000..5d564e22e --- /dev/null +++ b/dispatchers/accounts.go @@ -0,0 +1,19 @@ +/* +Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments +Copyright (C) ITsysCOM GmbH + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see +*/ + +package dispatchers diff --git a/engine/datamanager.go b/engine/datamanager.go index 97c50e0e5..03128ce16 100644 --- a/engine/datamanager.go +++ b/engine/datamanager.go @@ -4027,7 +4027,7 @@ func (dm *DataManager) SetAccount2(ap *utils.Account, withIndex bool) (err error } func (dm *DataManager) RemoveAccount2(tenant, id string, - transactionID string, withIndex bool) (err error) { + transactionID string) (err error) { if dm == nil { err = utils.ErrNoDatabaseConn return diff --git a/loaders/loader.go b/loaders/loader.go index f51ea81d6..cc898b7c7 100644 --- a/loaders/loader.go +++ b/loaders/loader.go @@ -652,6 +652,36 @@ func (ldr *Loader) storeLoadedData(loaderType string, cacheArgs[utils.ActionProfileIDs] = ids } } + case utils.MetaAccountProfiles: + cacheIDs = []string{utils.CacheAccountProfilesFilterIndexes} + for _, lDataSet := range lds { + acpsModels := make(engine.AccountProfileMdls, len(lDataSet)) + for i, ld := range lDataSet { + acpsModels[i] = new(engine.AccountProfileMdl) + if err = utils.UpdateStructWithIfaceMap(acpsModels[i], ld); err != nil { + return + } + } + + for _, tpAcp := range acpsModels.AsTPAccountProfile() { + acp, err := engine.APItoAccountProfile(tpAcp, ldr.timezone) + if err != nil { + return err + } + if ldr.dryRun { + utils.Logger.Info( + fmt.Sprintf("<%s-%s> DRY_RUN: AccountProfiles: %s", + utils.LoaderS, ldr.ldrID, utils.ToJSON(acp))) + continue + } + // get IDs so we can reload in cache + ids = append(ids, acp.TenantID()) + if err := ldr.dm.SetAccountProfile(acp, true); err != nil { + return err + } + cacheArgs[utils.AccountProfileIDs] = ids + } + } } if len(ldr.cacheConns) != 0 { @@ -992,6 +1022,28 @@ func (ldr *Loader) removeLoadedData(loaderType string, lds map[string][]LoaderDa cacheArgs[utils.ActionProfileIDs] = ids } } + case utils.MetaAccountProfiles: + cacheIDs = []string{utils.CacheAccountProfiles, utils.CacheAccounts2, utils.CacheAccountProfilesFilterIndexes} + for tntID := range lds { + if ldr.dryRun { + utils.Logger.Info( + fmt.Sprintf("<%s-%s> DRY_RUN: AccountProfileIDs: %s", + utils.LoaderS, ldr.ldrID, tntID)) + } else { + tntIDStruct := utils.NewTenantID(tntID) + // get IDs so we can reload in cache + ids = append(ids, tntID) + if err := ldr.dm.RemoveAccountProfile(tntIDStruct.Tenant, + tntIDStruct.ID, utils.NonTransactional, true); err != nil { + return err + } + if err := ldr.dm.RemoveAccount2(tntIDStruct.Tenant, tntIDStruct.ID, utils.NonTransactional); err != nil { + return err + } + cacheArgs[utils.AccountProfileIDs] = ids + cacheArgs[utils.Account2IDs] = ids + } + } } if len(ldr.cacheConns) != 0 { diff --git a/utils/consts.go b/utils/consts.go index b545a5926..c95e0a7f3 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -2597,6 +2597,7 @@ const ( ActionProfileIDs = "ActionProfileIDs" TimingIDs = "TimingIDs" AccountProfileIDs = "AccountProfileIDs" + Account2IDs = "Account2IDs" AttributeFilterIndexIDs = "AttributeFilterIndexIDs" ResourceFilterIndexIDs = "ResourceFilterIndexIDs" StatFilterIndexIDs = "StatFilterIndexIDs"