Add in remaing places infrastructure for ActionProfile

This commit is contained in:
TeoV
2020-12-04 13:36:57 +02:00
committed by Dan Christian Bogos
parent 77712ef776
commit f19a78538a
4 changed files with 101 additions and 0 deletions

View File

@@ -0,0 +1,86 @@
/*
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 <http://www.gnu.org/licenses/>
*/
package v1
import (
"github.com/cgrates/cgrates/utils"
)
// SetTPActionProfile creates a new TPActionProfile within a tariff plan
func (apierSv1 *APIerSv1) SetTPActionProfile(attrs *utils.TPActionProfile, reply *string) error {
if missing := utils.MissingStructFields(attrs, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
if err := apierSv1.StorDb.SetTPActionProfiles([]*utils.TPActionProfile{attrs}); err != nil {
return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
}
// GetTPActionProfile queries specific TPActionProfile on tariff plan
func (apierSv1 *APIerSv1) GetTPActionProfile(attr *utils.TPTntID, reply *utils.TPActionProfile) error {
if missing := utils.MissingStructFields(attr, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
spp, err := apierSv1.StorDb.GetTPActionProfiles(attr.TPid, attr.Tenant, attr.ID)
if err != nil {
if err.Error() != utils.ErrNotFound.Error() {
err = utils.NewErrServerError(err)
}
return err
}
*reply = *spp[0]
return nil
}
type AttrGetTPActionProfileIDs struct {
TPid string // Tariff plan id
utils.PaginatorWithSearch
}
// GetTPRouteProfileIDs queries TPActionProfiles identities on specific tariff plan.
func (apierSv1 *APIerSv1) GetTPActionProfileIDs(attrs *AttrGetTPActionProfileIDs, reply *[]string) error {
if missing := utils.MissingStructFields(attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPActionProfiles,
utils.TPDistinctIds{"tenant", "id"}, nil, &attrs.PaginatorWithSearch)
if err != nil {
if err.Error() != utils.ErrNotFound.Error() {
err = utils.NewErrServerError(err)
}
return err
}
*reply = ids
return nil
}
// RemoveTPActionProfile removes specific TPActionProfile on Tariff plan
func (apierSv1 *APIerSv1) RemoveTPActionProfile(attrs *utils.TPTntID, reply *string) error {
if missing := utils.MissingStructFields(attrs, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
if err := apierSv1.StorDb.RemTpData(utils.TBLTPActionProfiles, attrs.TPid,
map[string]string{"tenant": attrs.Tenant, "id": attrs.ID}); err != nil {
return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
}

View File

@@ -698,6 +698,8 @@ func (ms *MongoStorage) GetKeysForPrefix(prefix string) (result []string, err er
result, err = ms.getField3(sctx, ColIndx, utils.ActionPlanIndexes, "key")
case utils.ActionProfilesFilterIndexPrfx:
result, err = ms.getField3(sctx, ColIndx, utils.ActionProfilesFilterIndexPrfx, "key")
case utils.RateProfilesFilterIndexPrfx:
result, err = ms.getField3(sctx, ColIndx, utils.RateProfilesFilterIndexPrfx, "key")
case utils.RateFilterIndexPrfx:
result, err = ms.getField3(sctx, ColIndx, utils.RateFilterIndexPrfx, "key")
case utils.FilterIndexPrfx:

View File

@@ -332,6 +332,18 @@ func (self *TPExporter) Run() error {
}
}
storDataActionProfiles, err := self.storDb.GetTPActionProfiles(self.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.TpRateProfiles))
withError = true
}
for _, sd := range storDataActionProfiles {
sdModels := APItoModelTPActionProfile(sd)
for _, sdModel := range sdModels {
toExportMap[utils.ActionProfilesCsv] = append(toExportMap[utils.ActionProfilesCsv], sdModel)
}
}
if len(toExportMap) == 0 { // if we don't have anything to export we return not found error
return utils.ErrNotFound
}

View File

@@ -2563,6 +2563,7 @@ func (tpr *TpReader) ReloadCache(caching string, verbose bool, opts map[string]i
utils.ChargerProfileIDs: chargerIDs,
utils.DispatcherProfileIDs: dppIDs,
utils.DispatcherHostIDs: dphIDs,
utils.RateProfileIDs: ratePrfIDs,
utils.ActionProfileIDs: actionPrfIDs,
},
}