mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-21 07:08:45 +05:00
finshed mongo tp methods
test pending
This commit is contained in:
@@ -157,7 +157,7 @@ func (self *ApierV1) RemTPAccountActions(attrs AttrGetTPAccountActions, reply *s
|
||||
if err := aa.SetAccountActionId(attrs.AccountActionsId); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := self.StorDb.RemTpData(utils.TBL_TP_ACCOUNT_ACTIONS, aa.Tpid, aa.Loadid, aa.Direction, aa.Tenant, aa.Account); err != nil {
|
||||
if err := self.StorDb.RemTpData(utils.TBL_TP_ACCOUNT_ACTIONS, aa.Tpid, map[string]string{"loadid": aa.Loadid, "direction": aa.Direction, "tenant": aa.Tenant, "account": aa.Account}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
} else {
|
||||
*reply = "OK"
|
||||
|
||||
@@ -98,7 +98,7 @@ func (self *ApierV1) RemTPActionPlan(attrs AttrGetTPActionPlan, reply *string) e
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "Id"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := self.StorDb.RemTpData(utils.TBL_TP_ACTION_PLANS, attrs.TPid, attrs.Id); err != nil {
|
||||
if err := self.StorDb.RemTpData(utils.TBL_TP_ACTION_PLANS, attrs.TPid, map[string]string{"tag": attrs.Id}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
} else {
|
||||
*reply = "OK"
|
||||
|
||||
@@ -96,7 +96,7 @@ func (self *ApierV1) RemTPActions(attrs AttrGetTPActions, reply *string) error {
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ActionsId"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := self.StorDb.RemTpData(utils.TBL_TP_ACTIONS, attrs.TPid, attrs.ActionsId); err != nil {
|
||||
if err := self.StorDb.RemTpData(utils.TBL_TP_ACTIONS, attrs.TPid, map[string]string{"tag": attrs.ActionsId}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
} else {
|
||||
*reply = "OK"
|
||||
|
||||
@@ -92,7 +92,7 @@ func (self *ApierV1) RemTPActionTriggers(attrs AttrGetTPActionTriggers, reply *s
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ActionTriggersId"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := self.StorDb.RemTpData(utils.TBL_TP_ACTION_TRIGGERS, attrs.TPid, attrs.ActionTriggersId); err != nil {
|
||||
if err := self.StorDb.RemTpData(utils.TBL_TP_ACTION_TRIGGERS, attrs.TPid, map[string]string{"tag": attrs.ActionTriggersId}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
} else {
|
||||
*reply = "OK"
|
||||
|
||||
@@ -87,7 +87,7 @@ func (self *ApierV1) RemTPAlias(attrs AttrGetTPAlias, reply *string) error {
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "AliasId"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := self.StorDb.RemTpData(utils.TBL_TP_ALIASES, attrs.TPid); err != nil {
|
||||
if err := self.StorDb.RemTpData(utils.TBL_TP_ALIASES, attrs.TPid, map[string]string{"tag": attrs.AliasId}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
} else {
|
||||
*reply = "OK"
|
||||
|
||||
@@ -94,7 +94,7 @@ func (self *ApierV1) RemTPCdrStats(attrs AttrGetTPCdrStats, reply *string) error
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "CdrStatsId"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := self.StorDb.RemTpData(utils.TBL_TP_SHARED_GROUPS, attrs.TPid, attrs.CdrStatsId); err != nil {
|
||||
if err := self.StorDb.RemTpData(utils.TBL_TP_SHARED_GROUPS, attrs.TPid, map[string]string{"tag": attrs.CdrStatsId}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
} else {
|
||||
*reply = "OK"
|
||||
|
||||
@@ -103,7 +103,7 @@ func (self *ApierV1) RemTPDerivedChargers(attrs AttrGetTPDerivedChargers, reply
|
||||
if err := tmpDc.SetDerivedChargersId(attrs.DerivedChargersId); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := self.StorDb.RemTpData(utils.TBL_TP_DERIVED_CHARGERS, attrs.TPid, tmpDc.Loadid, tmpDc.Direction, tmpDc.Tenant, tmpDc.Category, tmpDc.Account, tmpDc.Subject); err != nil {
|
||||
if err := self.StorDb.RemTpData(utils.TBL_TP_DERIVED_CHARGERS, attrs.TPid, map[string]string{"loadid": tmpDc.Loadid, "direction": tmpDc.Direction, "tenant": tmpDc.Tenant, "category": tmpDc.Category, "account": tmpDc.Account, "subject": tmpDc.Subject}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
} else {
|
||||
*reply = "OK"
|
||||
|
||||
@@ -88,7 +88,7 @@ func (self *ApierV1) RemTPDestinationRate(attrs AttrGetTPDestinationRate, reply
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "DestinationRateId"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := self.StorDb.RemTpData(utils.TBL_TP_DESTINATION_RATES, attrs.TPid, attrs.DestinationRateId); err != nil {
|
||||
if err := self.StorDb.RemTpData(utils.TBL_TP_DESTINATION_RATES, attrs.TPid, map[string]string{"tag": attrs.DestinationRateId}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
} else {
|
||||
*reply = "OK"
|
||||
|
||||
@@ -88,7 +88,7 @@ func (self *ApierV1) RemTPDestination(attrs AttrGetTPDestination, reply *string)
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "DestinationId"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := self.StorDb.RemTpData(utils.TBL_TP_DESTINATIONS, attrs.TPid, attrs.DestinationId); err != nil {
|
||||
if err := self.StorDb.RemTpData(utils.TBL_TP_DESTINATIONS, attrs.TPid, map[string]string{"tag": attrs.DestinationId}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
} else {
|
||||
*reply = "OK"
|
||||
|
||||
@@ -89,7 +89,7 @@ func (self *ApierV1) RemTPLcrRule(attrs AttrGetTPLcrRules, reply *string) error
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "LcrRulesId"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := self.StorDb.RemTpData(utils.TBL_TP_LCRS, attrs.TPid, attrs.LcrRuleId); err != nil {
|
||||
if err := self.StorDb.RemTpData(utils.TBL_TP_LCRS, attrs.TPid, map[string]string{"tag": attrs.LcrRuleId}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
} else {
|
||||
*reply = "OK"
|
||||
|
||||
@@ -87,7 +87,7 @@ func (self *ApierV1) RemTPRate(attrs AttrGetTPRate, reply *string) error {
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "RateId"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := self.StorDb.RemTpData(utils.TBL_TP_RATES, attrs.TPid, attrs.RateId); err != nil {
|
||||
if err := self.StorDb.RemTpData(utils.TBL_TP_RATES, attrs.TPid, map[string]string{"tag": attrs.RateId}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
} else {
|
||||
*reply = "OK"
|
||||
|
||||
@@ -88,7 +88,7 @@ func (self *ApierV1) RemTPRatingPlan(attrs AttrGetTPRatingPlan, reply *string) e
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "RatingPlanId"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := self.StorDb.RemTpData(utils.TBL_TP_RATING_PLANS, attrs.TPid, attrs.RatingPlanId); err != nil {
|
||||
if err := self.StorDb.RemTpData(utils.TBL_TP_RATING_PLANS, attrs.TPid, map[string]string{"tag": attrs.RatingPlanId}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
} else {
|
||||
*reply = "OK"
|
||||
|
||||
@@ -161,7 +161,7 @@ func (self *ApierV1) RemTPRatingProfile(attrs AttrGetTPRatingProfile, reply *str
|
||||
if err := tmpRpf.SetRatingProfileId(attrs.RatingProfileId); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := self.StorDb.RemTpData(utils.TBL_TP_RATE_PROFILES, attrs.TPid, tmpRpf.Loadid, tmpRpf.Direction, tmpRpf.Tenant, tmpRpf.Category, tmpRpf.Subject); err != nil {
|
||||
if err := self.StorDb.RemTpData(utils.TBL_TP_RATE_PROFILES, attrs.TPid, map[string]string{"loadid": tmpRpf.Loadid, "direction": tmpRpf.Direction, "tenant": tmpRpf.Tenant, "category": tmpRpf.Category, "subject": tmpRpf.Subject}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
} else {
|
||||
*reply = "OK"
|
||||
|
||||
@@ -94,7 +94,7 @@ func (self *ApierV1) RemTPSharedGroups(attrs AttrGetTPSharedGroups, reply *strin
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "SharedGroupsId"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := self.StorDb.RemTpData(utils.TBL_TP_SHARED_GROUPS, attrs.TPid, attrs.SharedGroupsId); err != nil {
|
||||
if err := self.StorDb.RemTpData(utils.TBL_TP_SHARED_GROUPS, attrs.TPid, map[string]string{"tag": attrs.SharedGroupsId}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
} else {
|
||||
*reply = "OK"
|
||||
|
||||
@@ -85,7 +85,7 @@ func (self *ApierV1) RemTPTiming(attrs AttrGetTPTiming, reply *string) error {
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "TimingId"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := self.StorDb.RemTpData(utils.TBL_TP_TIMINGS, attrs.TPid, attrs.TimingId); err != nil {
|
||||
if err := self.StorDb.RemTpData(utils.TBL_TP_TIMINGS, attrs.TPid, map[string]string{"tag": attrs.TimingId}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
} else {
|
||||
*reply = "OK"
|
||||
|
||||
@@ -90,7 +90,7 @@ func (self *ApierV1) RemTPUser(attrs AttrGetTPUser, reply *string) error {
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "UserId"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := self.StorDb.RemTpData(utils.TBL_TP_USERS, attrs.TPid); err != nil {
|
||||
if err := self.StorDb.RemTpData(utils.TBL_TP_USERS, attrs.TPid, map[string]string{"tag": attrs.UserId}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
} else {
|
||||
*reply = "OK"
|
||||
|
||||
@@ -33,7 +33,7 @@ func (self *ApierV2) RemTP(attrs AttrRemTp, reply *string) error {
|
||||
if len(attrs.TPid) == 0 {
|
||||
return utils.NewErrMandatoryIeMissing("TPid")
|
||||
}
|
||||
if err := self.StorDb.RemTpData("", attrs.TPid); err != nil {
|
||||
if err := self.StorDb.RemTpData("", attrs.TPid, nil); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
} else {
|
||||
*reply = "OK"
|
||||
|
||||
@@ -37,7 +37,7 @@ const (
|
||||
RECURSION_MAX_DEPTH = 3
|
||||
MIN_PREFIX_MATCH = 1
|
||||
FALLBACK_SUBJECT = utils.ANY
|
||||
DEBUG = true
|
||||
DEBUG = false
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -137,7 +137,7 @@ type LoadReader interface {
|
||||
}
|
||||
|
||||
type LoadWriter interface {
|
||||
RemTpData(string, string, ...string) error
|
||||
RemTpData(string, string, map[string]string) error
|
||||
SetTpTimings([]TpTiming) error
|
||||
SetTpDestinations([]TpDestination) error
|
||||
SetTpRates([]TpRate) error
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package engine
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"gopkg.in/mgo.v2/bson"
|
||||
)
|
||||
@@ -26,10 +28,71 @@ const (
|
||||
colTpCrs = "tp_cdrstats"
|
||||
)
|
||||
|
||||
func (ms *MongoStorage) GetTpIds() ([]string, error) { return nil, nil }
|
||||
func (ms *MongoStorage) GetTpTableIds(string, string, utils.TPDistinctIds, map[string]string, *utils.Paginator) ([]string, error) {
|
||||
return nil, nil
|
||||
func (ms *MongoStorage) GetTpIds() ([]string, error) {
|
||||
tpidMap := make(map[string]bool)
|
||||
cols, err := ms.db.CollectionNames()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, col := range cols {
|
||||
if strings.HasPrefix(col, "tp_") {
|
||||
tpids := make([]string, 0)
|
||||
if err := ms.db.C(col).Find(nil).Select(bson.M{"tpid": 1}).Distinct("tpid", &tpids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, tpid := range tpids {
|
||||
tpidMap[tpid] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
var tpids []string
|
||||
for tpid := range tpidMap {
|
||||
tpids = append(tpids, tpid)
|
||||
}
|
||||
return tpids, nil
|
||||
}
|
||||
func (ms *MongoStorage) GetTpTableIds(tpid, table string, distinct utils.TPDistinctIds, filter map[string]string, pag *utils.Paginator) ([]string, error) {
|
||||
selectors := bson.M{}
|
||||
for _, d := range distinct {
|
||||
selectors[d] = 1
|
||||
}
|
||||
filter["tpid"] = tpid
|
||||
q := ms.db.C(table).Find(filter)
|
||||
if pag != nil {
|
||||
if pag.Limit != nil {
|
||||
q = q.Limit(*pag.Limit)
|
||||
}
|
||||
if pag.Offset != nil {
|
||||
q = q.Skip(*pag.Offset)
|
||||
}
|
||||
}
|
||||
|
||||
iter := q.Select(selectors).Iter()
|
||||
distinctIds := make(map[string]bool)
|
||||
item := make(map[string]string)
|
||||
for iter.Next(item) {
|
||||
id := ""
|
||||
last := len(distinct) - 1
|
||||
for i, d := range distinct {
|
||||
if distinctValue, ok := item[d]; ok {
|
||||
id += distinctValue
|
||||
}
|
||||
if i < last {
|
||||
id += utils.CONCATENATED_KEY_SEP
|
||||
}
|
||||
}
|
||||
distinctIds[id] = true
|
||||
}
|
||||
if err := iter.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var results []string
|
||||
for id := range distinctIds {
|
||||
results = append(results, id)
|
||||
}
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) GetTpTimings(tpid, tag string) ([]TpTiming, error) {
|
||||
filter := bson.M{
|
||||
"tpid": tpid,
|
||||
@@ -41,6 +104,7 @@ func (ms *MongoStorage) GetTpTimings(tpid, tag string) ([]TpTiming, error) {
|
||||
err := ms.db.C(colTpTmg).Find(filter).All(&results)
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) GetTpDestinations(tpid, tag string) ([]TpDestination, error) {
|
||||
filter := bson.M{
|
||||
"tpid": tpid,
|
||||
@@ -52,6 +116,7 @@ func (ms *MongoStorage) GetTpDestinations(tpid, tag string) ([]TpDestination, er
|
||||
err := ms.db.C(colTpDst).Find(filter).All(&results)
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) GetTpRates(tpid, tag string) ([]TpRate, error) {
|
||||
filter := bson.M{
|
||||
"tpid": tpid,
|
||||
@@ -63,6 +128,7 @@ func (ms *MongoStorage) GetTpRates(tpid, tag string) ([]TpRate, error) {
|
||||
err := ms.db.C(colTpRts).Find(filter).All(&results)
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) GetTpDestinationRates(tpid, tag string, pag *utils.Paginator) ([]TpDestinationRate, error) {
|
||||
filter := bson.M{
|
||||
"tpid": tpid,
|
||||
@@ -290,9 +356,23 @@ func (ms *MongoStorage) GetTpAccountActions(tp *TpAccountAction) ([]TpAccountAct
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) RemTpData(string, string, ...string) error {
|
||||
|
||||
return nil
|
||||
func (ms *MongoStorage) RemTpData(table, tpid string, args map[string]string) error {
|
||||
if len(table) == 0 { // Remove tpid out of all tables
|
||||
cols, err := ms.db.CollectionNames()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, col := range cols {
|
||||
if strings.HasPrefix(col, "tp_") {
|
||||
if err := ms.db.C(col).Remove(bson.M{"tpid": tpid}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Remove from a single table
|
||||
args["tpid"] = tpid
|
||||
return ms.db.C(table).Remove(args)
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) SetTpTimings(tps []TpTiming) error {
|
||||
|
||||
@@ -372,7 +372,7 @@ func TestMySQLRemoveTPData(t *testing.T) {
|
||||
t.Error("Could not store TPTiming")
|
||||
}
|
||||
// Remove Timings
|
||||
if err := mysqlDb.RemTpData(utils.TBL_TP_TIMINGS, utils.TEST_SQL, tm.TimingId); err != nil {
|
||||
if err := mysqlDb.RemTpData(utils.TBL_TP_TIMINGS, utils.TEST_SQL, map[string]string{"tag": tm.TimingId}); err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if tmgs, err := mysqlDb.GetTpTimings(utils.TEST_SQL, tm.TimingId); err != nil {
|
||||
@@ -393,7 +393,7 @@ func TestMySQLRemoveTPData(t *testing.T) {
|
||||
t.Error("Could not store TPRatingProfile")
|
||||
}
|
||||
// Remove RatingProfile
|
||||
if err := mysqlDb.RemTpData(utils.TBL_TP_RATE_PROFILES, rp.TPid, rp.LoadId, rp.Direction, rp.Tenant, rp.Category, rp.Subject); err != nil {
|
||||
if err := mysqlDb.RemTpData(utils.TBL_TP_RATE_PROFILES, rp.TPid, map[string]string{"loadid": rp.LoadId, "direction": rp.Direction, "tenant": rp.Tenant, "category": rp.Category, "subject": rp.Subject}); err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if rps, err := mysqlDb.GetTpRatingProfiles(&mrp[0]); err != nil {
|
||||
@@ -414,7 +414,7 @@ func TestMySQLRemoveTPData(t *testing.T) {
|
||||
t.Error("Could not create TPAccountActions")
|
||||
}
|
||||
// Remove AccountActions
|
||||
if err := mysqlDb.RemTpData(utils.TBL_TP_ACCOUNT_ACTIONS, aa.TPid, aa.LoadId, aa.Direction, aa.Tenant, aa.Account); err != nil {
|
||||
if err := mysqlDb.RemTpData(utils.TBL_TP_ACCOUNT_ACTIONS, aa.TPid, map[string]string{"loadis": aa.LoadId, "direction": aa.Direction, "tenant": aa.Tenant, "account": aa.Account}); err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if aas, err := mysqlDb.GetTpAccountActions(maa); err != nil {
|
||||
@@ -450,7 +450,7 @@ func TestMySQLRemoveTPData(t *testing.T) {
|
||||
t.Error("Could not create TPAccountActions")
|
||||
}
|
||||
// Remove TariffPlan completely
|
||||
if err := mysqlDb.RemTpData("", utils.TEST_SQL); err != nil {
|
||||
if err := mysqlDb.RemTpData("", utils.TEST_SQL, nil); err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
// Make sure we have removed it
|
||||
|
||||
@@ -367,7 +367,7 @@ func TestPSQLRemoveTPData(t *testing.T) {
|
||||
t.Error("Could not store TPTiming")
|
||||
}
|
||||
// Remove Timings
|
||||
if err := psqlDb.RemTpData(utils.TBL_TP_TIMINGS, utils.TEST_SQL, tm.TimingId); err != nil {
|
||||
if err := psqlDb.RemTpData(utils.TBL_TP_TIMINGS, utils.TEST_SQL, map[string]string{"tag": tm.TimingId}); err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if tmgs, err := psqlDb.GetTpTimings(utils.TEST_SQL, tm.TimingId); err != nil {
|
||||
@@ -388,7 +388,7 @@ func TestPSQLRemoveTPData(t *testing.T) {
|
||||
t.Error("Could not store TPRatingProfile")
|
||||
}
|
||||
// Remove RatingProfile
|
||||
if err := psqlDb.RemTpData(utils.TBL_TP_RATE_PROFILES, rp.TPid, rp.LoadId, rp.Direction, rp.Tenant, rp.Category, rp.Subject); err != nil {
|
||||
if err := psqlDb.RemTpData(utils.TBL_TP_RATE_PROFILES, rp.TPid, map[string]string{"loadid": rp.LoadId, "direction": rp.Direction, "tenant": rp.Tenant, "category": rp.Category, "subject": rp.Subject}); err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if rps, err := psqlDb.GetTpRatingProfiles(&mrp[0]); err != nil {
|
||||
@@ -409,7 +409,7 @@ func TestPSQLRemoveTPData(t *testing.T) {
|
||||
t.Error("Could not create TPAccountActions")
|
||||
}
|
||||
// Remove AccountActions
|
||||
if err := psqlDb.RemTpData(utils.TBL_TP_ACCOUNT_ACTIONS, aa.TPid, aa.LoadId, aa.Direction, aa.Tenant, aa.Account); err != nil {
|
||||
if err := psqlDb.RemTpData(utils.TBL_TP_ACCOUNT_ACTIONS, aa.TPid, map[string]string{"loadid": aa.LoadId, "direction": aa.Direction, "tenant": aa.Tenant, "account": aa.Account}); err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if aas, err := psqlDb.GetTpAccountActions(maa); err != nil {
|
||||
@@ -445,7 +445,7 @@ func TestPSQLRemoveTPData(t *testing.T) {
|
||||
t.Error("Could not create TPAccountActions")
|
||||
}
|
||||
// Remove TariffPlan completely
|
||||
if err := psqlDb.RemTpData("", utils.TEST_SQL); err != nil {
|
||||
if err := psqlDb.RemTpData("", utils.TEST_SQL, nil); err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
// Make sure we have removed it
|
||||
|
||||
@@ -158,7 +158,7 @@ func (self *SQLStorage) GetTpTableIds(tpid, table string, distinct utils.TPDisti
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
func (self *SQLStorage) RemTpData(table, tpid string, args ...string) error {
|
||||
func (self *SQLStorage) RemTpData(table, tpid string, args map[string]string) error {
|
||||
tx := self.db.Begin()
|
||||
if len(table) == 0 { // Remove tpid out of all tables
|
||||
for _, tblName := range []string{utils.TBL_TP_TIMINGS, utils.TBL_TP_DESTINATIONS, utils.TBL_TP_RATES, utils.TBL_TP_DESTINATION_RATES, utils.TBL_TP_RATING_PLANS, utils.TBL_TP_RATE_PROFILES,
|
||||
@@ -173,15 +173,9 @@ func (self *SQLStorage) RemTpData(table, tpid string, args ...string) error {
|
||||
}
|
||||
// Remove from a single table
|
||||
tx = tx.Table(table).Where("tpid = ?", tpid)
|
||||
switch table {
|
||||
default:
|
||||
tx = tx.Where("tag = ?", args[0])
|
||||
case utils.TBL_TP_RATE_PROFILES:
|
||||
tx = tx.Where("loadid = ?", args[0]).Where("direction = ?", args[1]).Where("tenant = ?", args[2]).Where("category = ?", args[3]).Where("subject = ?", args[4])
|
||||
case utils.TBL_TP_ACCOUNT_ACTIONS:
|
||||
tx = tx.Where("loadid = ?", args[0]).Where("direction = ?", args[1]).Where("tenant = ?", args[2]).Where("account = ?", args[3])
|
||||
case utils.TBL_TP_DERIVED_CHARGERS:
|
||||
tx = tx.Where("loadid = ?", args[0]).Where("direction = ?", args[1]).Where("tenant = ?", args[2]).Where("category = ?", args[3]).Where("account = ?", args[4]).Where("subject = ?", args[5])
|
||||
// Compose filters
|
||||
for key, value := range args {
|
||||
tx = tx.Where(key+" = ?", value)
|
||||
}
|
||||
if err := tx.Delete(nil).Error; err != nil {
|
||||
tx.Rollback()
|
||||
|
||||
Reference in New Issue
Block a user