mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 13:49:53 +05:00
local engine tests passing
This commit is contained in:
@@ -25,6 +25,12 @@ func APItoModelDestination(dest *utils.TPDestination) (result []TpDestination) {
|
||||
Prefix: p,
|
||||
})
|
||||
}
|
||||
if len(dest.Prefixes) == 0 {
|
||||
result = append(result, TpDestination{
|
||||
Tpid: dest.TPid,
|
||||
Tag: dest.DestinationId,
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -40,6 +46,12 @@ func APItoModelRate(r *utils.TPRate) (result []TpRate) {
|
||||
GroupIntervalStart: rs.GroupIntervalStart,
|
||||
})
|
||||
}
|
||||
if len(r.RateSlots) == 0 {
|
||||
result = append(result, TpRate{
|
||||
Tpid: r.TPid,
|
||||
Tag: r.RateId,
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -56,6 +68,12 @@ func APItoModelDestinationRate(drs *utils.TPDestinationRate) (result []TpDestina
|
||||
MaxCostStrategy: dr.MaxCostStrategy,
|
||||
})
|
||||
}
|
||||
if len(drs.DestinationRates) == 0 {
|
||||
result = append(result, TpDestinationRate{
|
||||
Tpid: drs.TPid,
|
||||
Tag: drs.DestinationRateId,
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -69,6 +87,12 @@ func APItoModelRatingPlan(rps *utils.TPRatingPlan) (result []TpRatingPlan) {
|
||||
Weight: rp.Weight,
|
||||
})
|
||||
}
|
||||
if len(rps.RatingPlanBindings) == 0 {
|
||||
result = append(result, TpRatingPlan{
|
||||
Tpid: rps.TPid,
|
||||
Tag: rps.RatingPlanId,
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -87,6 +111,16 @@ func APItoModelRatingProfile(rpf *utils.TPRatingProfile) (result []TpRatingProfi
|
||||
CdrStatQueueIds: ra.CdrStatQueueIds,
|
||||
})
|
||||
}
|
||||
if len(rpf.RatingPlanActivations) == 0 {
|
||||
result = append(result, TpRatingProfile{
|
||||
Tpid: rpf.TPid,
|
||||
Loadid: rpf.LoadId,
|
||||
Direction: rpf.Direction,
|
||||
Tenant: rpf.Tenant,
|
||||
Category: rpf.Category,
|
||||
Subject: rpf.Subject,
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -106,6 +140,11 @@ func APItoModelLcrRule(lcrs *utils.TPLcrRules) (result []TpLcrRule) {
|
||||
ActivationTime: lcr.ActivationTime,
|
||||
})
|
||||
}
|
||||
if len(lcrs.LcrRules) == 0 {
|
||||
result = append(result, TpLcrRule{
|
||||
Tpid: lcrs.TPid,
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -130,6 +169,12 @@ func APItoModelAction(as *utils.TPActions) (result []TpAction) {
|
||||
Weight: a.Weight,
|
||||
})
|
||||
}
|
||||
if len(as.Actions) == 0 {
|
||||
result = append(result, TpAction{
|
||||
Tpid: as.TPid,
|
||||
Tag: as.ActionsId,
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -143,6 +188,12 @@ func APItoModelActionPlan(aps *utils.TPActionPlan) (result []TpActionPlan) {
|
||||
Weight: ap.Weight,
|
||||
})
|
||||
}
|
||||
if len(aps.ActionPlan) == 0 {
|
||||
result = append(result, TpActionPlan{
|
||||
Tpid: aps.TPid,
|
||||
Tag: aps.Id,
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -171,6 +222,12 @@ func APItoModelActionTrigger(ats *utils.TPActionTriggers) (result []TpActionTrig
|
||||
Weight: at.Weight,
|
||||
})
|
||||
}
|
||||
if len(ats.ActionTriggers) == 0 {
|
||||
result = append(result, TpActionTrigger{
|
||||
Tpid: ats.TPid,
|
||||
Tag: ats.ActionTriggersId,
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -196,6 +253,12 @@ func APItoModelSharedGroup(sgs *utils.TPSharedGroups) (result []TpSharedGroup) {
|
||||
RatingSubject: sg.RatingSubject,
|
||||
})
|
||||
}
|
||||
if len(sgs.SharedGroups) == 0 {
|
||||
result = append(result, TpSharedGroup{
|
||||
Tpid: sgs.TPid,
|
||||
Tag: sgs.SharedGroupsId,
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -225,6 +288,17 @@ func APItoModelDerivedCharger(dcs *utils.TPDerivedChargers) (result []TpDerivedC
|
||||
DisconnectCauseField: dc.DisconnectCauseField,
|
||||
})
|
||||
}
|
||||
if len(dcs.DerivedChargers) == 0 {
|
||||
result = append(result, TpDerivedCharger{
|
||||
Tpid: dcs.TPid,
|
||||
Loadid: dcs.Loadid,
|
||||
Direction: dcs.Direction,
|
||||
Tenant: dcs.Tenant,
|
||||
Category: dcs.Category,
|
||||
Account: dcs.Account,
|
||||
Subject: dcs.Subject,
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -258,5 +332,11 @@ func APItoModelCdrStat(stats *utils.TPCdrStats) (result []TpCdrStat) {
|
||||
ActionTriggers: st.ActionTriggers,
|
||||
})
|
||||
}
|
||||
if len(stats.CdrStats) == 0 {
|
||||
result = append(result, TpCdrStat{
|
||||
Tpid: stats.TPid,
|
||||
Tag: stats.CdrStatsId,
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -99,6 +99,33 @@ func csvDump(s interface{}) ([]string, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func modelEqual(this interface{}, other interface{}) bool {
|
||||
var fieldNames []string
|
||||
st := reflect.TypeOf(this)
|
||||
stO := reflect.TypeOf(other)
|
||||
if st != stO {
|
||||
return false
|
||||
}
|
||||
numFields := st.NumField()
|
||||
for i := 0; i < numFields; i++ {
|
||||
field := st.Field(i)
|
||||
index := field.Tag.Get("index")
|
||||
if index != "" {
|
||||
fieldNames = append(fieldNames, field.Name)
|
||||
}
|
||||
}
|
||||
thisElem := reflect.ValueOf(this)
|
||||
otherElem := reflect.ValueOf(other)
|
||||
for _, fieldName := range fieldNames {
|
||||
thisField := thisElem.FieldByName(fieldName)
|
||||
otherField := otherElem.FieldByName(fieldName)
|
||||
if thisField.String() != otherField.String() {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func getColumnCount(s interface{}) int {
|
||||
st := reflect.TypeOf(s)
|
||||
numFields := st.NumField()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Real-time Charging System for Telecom & ISP environments
|
||||
Copyright (C) ITsysCOM GmbH
|
||||
Rating system designed to be used in VoIP Carriers World
|
||||
Copyright (C) 2012-2015 ITsysCOM
|
||||
|
||||
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
|
||||
@@ -66,7 +66,7 @@ func TestMySQLSetGetTPTiming(t *testing.T) {
|
||||
}
|
||||
if tmgs, err := mysqlDb.GetTpTimings(TEST_SQL, tm.Tag); err != nil {
|
||||
t.Error(err.Error())
|
||||
} else if !reflect.DeepEqual(tm, tmgs[0]) {
|
||||
} else if !modelEqual(tm, tmgs[0]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", tm, tmgs[0])
|
||||
}
|
||||
// Update
|
||||
@@ -76,7 +76,7 @@ func TestMySQLSetGetTPTiming(t *testing.T) {
|
||||
}
|
||||
if tmgs, err := mysqlDb.GetTpTimings(TEST_SQL, tm.Tag); err != nil {
|
||||
t.Error(err.Error())
|
||||
} else if !reflect.DeepEqual(tm, tmgs[0]) {
|
||||
} else if !modelEqual(tm, tmgs[0]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", tm, tmgs[0])
|
||||
}
|
||||
}
|
||||
@@ -86,9 +86,9 @@ func TestMySQLSetGetTPDestination(t *testing.T) {
|
||||
return
|
||||
}
|
||||
dst := []TpDestination{
|
||||
TpDestination{Tag: TEST_SQL, Prefix: "+49"},
|
||||
TpDestination{Tag: TEST_SQL, Prefix: "+49151"},
|
||||
TpDestination{Tag: TEST_SQL, Prefix: "+49176"},
|
||||
TpDestination{Tpid: TEST_SQL, Tag: TEST_SQL, Prefix: "+49"},
|
||||
TpDestination{Tpid: TEST_SQL, Tag: TEST_SQL, Prefix: "+49151"},
|
||||
TpDestination{Tpid: TEST_SQL, Tag: TEST_SQL, Prefix: "+49176"},
|
||||
}
|
||||
if err := mysqlDb.SetTpDestinations(dst); err != nil {
|
||||
t.Error(err.Error())
|
||||
@@ -98,8 +98,8 @@ func TestMySQLSetGetTPDestination(t *testing.T) {
|
||||
expected := &Destination{Id: TEST_SQL, Prefixes: []string{"+49", "+49151", "+49176"}}
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
} else if !reflect.DeepEqual(expected, dsts[TEST_SQL]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", dst, dsts[TEST_SQL])
|
||||
} else if !modelEqual(*expected, *dsts[TEST_SQL]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected, dsts[TEST_SQL])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ func TestMySQLSetGetTPRates(t *testing.T) {
|
||||
}
|
||||
if rts, err := mysqlDb.GetTpRates(TEST_SQL, RT_ID); err != nil {
|
||||
t.Error(err.Error())
|
||||
} else if !reflect.DeepEqual(mRates, rts) {
|
||||
} else if !modelEqual(mRates[0], rts[0]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", mRates, rts)
|
||||
}
|
||||
}
|
||||
@@ -145,7 +145,7 @@ func TestMySQLSetGetTPDestinationRates(t *testing.T) {
|
||||
}
|
||||
if drs, err := mysqlDb.GetTpDestinationRates(TEST_SQL, DR_ID, nil); err != nil {
|
||||
t.Error(err.Error())
|
||||
} else if !reflect.DeepEqual(mdrs, drs) {
|
||||
} else if !modelEqual(mdrs[0], drs[0]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", mdrs, drs)
|
||||
}
|
||||
}
|
||||
@@ -167,7 +167,7 @@ func TestMySQLSetGetTPRatingPlans(t *testing.T) {
|
||||
}
|
||||
if drps, err := mysqlDb.GetTpRatingPlans(TEST_SQL, RP_ID, nil); err != nil {
|
||||
t.Error(err.Error())
|
||||
} else if !reflect.DeepEqual(mrp, drps) {
|
||||
} else if !modelEqual(mrp[0], drps[0]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", mrp, drps)
|
||||
}
|
||||
}
|
||||
@@ -184,7 +184,7 @@ func TestMySQLSetGetTPRatingProfiles(t *testing.T) {
|
||||
}
|
||||
if rps, err := mysqlDb.GetTpRatingProfiles(&mrp[0]); err != nil {
|
||||
t.Error(err.Error())
|
||||
} else if !reflect.DeepEqual(mrp, rps) {
|
||||
} else if !modelEqual(mrp[0], rps[0]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", mrp, rps)
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ func TestMySQLSetGetTPSharedGroups(t *testing.T) {
|
||||
}
|
||||
if sgs, err := mysqlDb.GetTpSharedGroups(TEST_SQL, SG_ID); err != nil {
|
||||
t.Error(err.Error())
|
||||
} else if !reflect.DeepEqual(mSgs, sgs) {
|
||||
} else if !modelEqual(mSgs[0], sgs[0]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", mSgs, sgs)
|
||||
}
|
||||
}
|
||||
@@ -231,7 +231,7 @@ func TestMySQLSetGetTPCdrStats(t *testing.T) {
|
||||
}
|
||||
if cs, err := mysqlDb.GetTpCdrStats(TEST_SQL, CS_ID); err != nil {
|
||||
t.Error(err.Error())
|
||||
} else if !reflect.DeepEqual(mcs, cs) {
|
||||
} else if !modelEqual(mcs[0], cs[0]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", mcs, cs)
|
||||
}
|
||||
}
|
||||
@@ -250,7 +250,7 @@ func TestMySQLSetGetTPDerivedChargers(t *testing.T) {
|
||||
}
|
||||
if rDCs, err := mysqlDb.GetTpDerivedChargers(&mdcs[0]); err != nil {
|
||||
t.Error(err.Error())
|
||||
} else if !reflect.DeepEqual(mdcs, rDCs) {
|
||||
} else if !modelEqual(mdcs[0], rDCs[0]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", mdcs, rDCs)
|
||||
}
|
||||
}
|
||||
@@ -270,7 +270,7 @@ func TestMySQLSetGetTPActions(t *testing.T) {
|
||||
}
|
||||
if rTpActs, err := mysqlDb.GetTpActions(TEST_SQL, ACTS_ID); err != nil {
|
||||
t.Error(err.Error())
|
||||
} else if !reflect.DeepEqual(mas, rTpActs) {
|
||||
} else if !modelEqual(mas[0], rTpActs[0]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", mas, rTpActs)
|
||||
}
|
||||
}
|
||||
@@ -291,7 +291,7 @@ func TestMySQLTPActionTimings(t *testing.T) {
|
||||
}
|
||||
if rAP, err := mysqlDb.GetTpActionPlans(TEST_SQL, AP_ID); err != nil {
|
||||
t.Error(err.Error())
|
||||
} else if !reflect.DeepEqual(maps, rAP) {
|
||||
} else if !modelEqual(maps[0], rAP[0]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", maps, rAP)
|
||||
}
|
||||
}
|
||||
@@ -322,7 +322,7 @@ func TestMySQLSetGetTPActionTriggers(t *testing.T) {
|
||||
}
|
||||
if rcvMpAtrgs, err := mysqlDb.GetTpActionTriggers(TEST_SQL, TEST_SQL); err != nil {
|
||||
t.Error("Unexpected error: ", err.Error())
|
||||
} else if !reflect.DeepEqual(matrg, rcvMpAtrgs) {
|
||||
} else if !modelEqual(matrg[0], rcvMpAtrgs[0]) {
|
||||
t.Errorf("Expecting: %v, received: %v", matrg, rcvMpAtrgs)
|
||||
}
|
||||
}
|
||||
@@ -339,7 +339,7 @@ func TestMySQLSetGetTpAccountActions(t *testing.T) {
|
||||
}
|
||||
if aas, err := mysqlDb.GetTpAccountActions(maa); err != nil {
|
||||
t.Error(err.Error())
|
||||
} else if !reflect.DeepEqual(maa, aas) {
|
||||
} else if !modelEqual(*maa, aas[0]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", maa, aas)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Real-time Charging System for Telecom & ISP environments
|
||||
Copyright (C) ITsysCOM GmbH
|
||||
Rating system designed to be used in VoIP Carriers World
|
||||
Copyright (C) 2012-2015 ITsysCOM
|
||||
|
||||
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
|
||||
@@ -68,7 +68,7 @@ func TestPSQLSetGetTPTiming(t *testing.T) {
|
||||
}
|
||||
if tmgs, err := psqlDb.GetTpTimings(TEST_SQL, tm.TimingId); err != nil {
|
||||
t.Error(err.Error())
|
||||
} else if !reflect.DeepEqual(mtms, tmgs) {
|
||||
} else if !modelEqual(mtms[0], tmgs[0]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", mtms, tmgs)
|
||||
}
|
||||
// Update
|
||||
@@ -78,7 +78,7 @@ func TestPSQLSetGetTPTiming(t *testing.T) {
|
||||
}
|
||||
if tmgs, err := psqlDb.GetTpTimings(TEST_SQL, tm.TimingId); err != nil {
|
||||
t.Error(err.Error())
|
||||
} else if !reflect.DeepEqual(mtms, tmgs) {
|
||||
} else if !modelEqual(mtms[0], tmgs[0]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", mtms, tmgs)
|
||||
}
|
||||
}
|
||||
@@ -140,7 +140,7 @@ func TestPSQLSetGetTPDestinationRates(t *testing.T) {
|
||||
}
|
||||
if drs, err := psqlDb.GetTpDestinationRates(TEST_SQL, DR_ID, nil); err != nil {
|
||||
t.Error(err.Error())
|
||||
} else if !reflect.DeepEqual(mdrs, drs) {
|
||||
} else if !modelEqual(mdrs[0], drs[0]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", mdrs, drs)
|
||||
}
|
||||
}
|
||||
@@ -163,7 +163,7 @@ func TestPSQLSetGetTPRatingPlans(t *testing.T) {
|
||||
}
|
||||
if drps, err := psqlDb.GetTpRatingPlans(TEST_SQL, RP_ID, nil); err != nil {
|
||||
t.Error(err.Error())
|
||||
} else if !reflect.DeepEqual(mrp, drps) {
|
||||
} else if !modelEqual(mrp[0], drps[0]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", mrp, drps)
|
||||
}
|
||||
}
|
||||
@@ -181,7 +181,7 @@ func TestPSQLSetGetTPRatingProfiles(t *testing.T) {
|
||||
}
|
||||
if rps, err := psqlDb.GetTpRatingProfiles(&mrp[0]); err != nil {
|
||||
t.Error(err.Error())
|
||||
} else if !reflect.DeepEqual(mrp, rps) {
|
||||
} else if !modelEqual(mrp[0], rps[0]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", mrp, rps)
|
||||
}
|
||||
}
|
||||
@@ -204,7 +204,7 @@ func TestPSQLSetGetTPSharedGroups(t *testing.T) {
|
||||
}
|
||||
if sgs, err := psqlDb.GetTpSharedGroups(TEST_SQL, SG_ID); err != nil {
|
||||
t.Error(err.Error())
|
||||
} else if !reflect.DeepEqual(mSgs, sgs) {
|
||||
} else if !modelEqual(mSgs[0], sgs[0]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", mSgs, sgs)
|
||||
}
|
||||
}
|
||||
@@ -227,7 +227,7 @@ func TestPSQLSetGetTPCdrStats(t *testing.T) {
|
||||
}
|
||||
if cs, err := psqlDb.GetTpCdrStats(TEST_SQL, CS_ID); err != nil {
|
||||
t.Error(err.Error())
|
||||
} else if !reflect.DeepEqual(mcs, cs) {
|
||||
} else if !modelEqual(mcs[0], cs[0]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", mcs, cs)
|
||||
}
|
||||
}
|
||||
@@ -245,7 +245,7 @@ func TestPSQLSetGetTPDerivedChargers(t *testing.T) {
|
||||
}
|
||||
if rDCs, err := psqlDb.GetTpDerivedChargers(&mdcs[0]); err != nil {
|
||||
t.Error(err.Error())
|
||||
} else if !reflect.DeepEqual(mdcs, rDCs) {
|
||||
} else if !modelEqual(mdcs[0], rDCs[0]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", mdcs, rDCs)
|
||||
}
|
||||
}
|
||||
@@ -265,7 +265,7 @@ func TestPSQLSetGetTPActions(t *testing.T) {
|
||||
}
|
||||
if rTpActs, err := psqlDb.GetTpActions(TEST_SQL, ACTS_ID); err != nil {
|
||||
t.Error(err.Error())
|
||||
} else if !reflect.DeepEqual(mas, rTpActs) {
|
||||
} else if !modelEqual(mas[0], rTpActs[0]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", mas, rTpActs)
|
||||
}
|
||||
}
|
||||
@@ -286,7 +286,7 @@ func TestPSQLTPActionTimings(t *testing.T) {
|
||||
}
|
||||
if rAP, err := psqlDb.GetTpActionPlans(TEST_SQL, AP_ID); err != nil {
|
||||
t.Error(err.Error())
|
||||
} else if !reflect.DeepEqual(maps, rAP) {
|
||||
} else if !modelEqual(maps[0], rAP[0]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", maps, rAP)
|
||||
}
|
||||
}
|
||||
@@ -317,7 +317,7 @@ func TestPSQLSetGetTPActionTriggers(t *testing.T) {
|
||||
}
|
||||
if rcvMpAtrgs, err := psqlDb.GetTpActionTriggers(TEST_SQL, TEST_SQL); err != nil {
|
||||
t.Error("Unexpected error: ", err.Error())
|
||||
} else if !reflect.DeepEqual(matrg, rcvMpAtrgs) {
|
||||
} else if !modelEqual(matrg[0], rcvMpAtrgs[0]) {
|
||||
t.Errorf("Expecting: %v, received: %v", matrg, rcvMpAtrgs)
|
||||
}
|
||||
}
|
||||
@@ -334,7 +334,7 @@ func TestPSQLSetGetTpAccountActions(t *testing.T) {
|
||||
}
|
||||
if aas, err := psqlDb.GetTpAccountActions(maa); err != nil {
|
||||
t.Error(err.Error())
|
||||
} else if !reflect.DeepEqual(maa, aas) {
|
||||
} else if !modelEqual(*maa, aas[0]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", maa, aas)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ func (self *SQLStorage) SetTpTimings(timings []TpTiming) error {
|
||||
for _, timing := range timings {
|
||||
if found, _ := m[timing.Tag]; !found {
|
||||
m[timing.Tag] = true
|
||||
if err := tx.Where(&TpTiming{Tpid: timing.Tpid, Tag: timing.Tag}).Delete(TpDestination{}).Error; err != nil {
|
||||
if err := tx.Where(&TpTiming{Tpid: timing.Tpid, Tag: timing.Tag}).Delete(TpTiming{}).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ func (tpr *TpReader) LoadDestinationsFiltered(tag string) (bool, error) {
|
||||
for _, tpDest := range tpDests {
|
||||
dest.AddPrefix(tpDest.Prefix)
|
||||
}
|
||||
dataStorage.SetDestination(dest)
|
||||
tpr.ratingStorage.SetDestination(dest)
|
||||
return len(tpDests) > 0, err
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ func (tpr *TpReader) LoadRatingPlansFiltered(tag string) (bool, error) {
|
||||
if err != nil {
|
||||
return false, err
|
||||
} else if len(dms) == 0 {
|
||||
if dbExists, err := dataStorage.HasData(DESTINATION_PREFIX, drate.DestinationId); err != nil {
|
||||
if dbExists, err := tpr.ratingStorage.HasData(DESTINATION_PREFIX, drate.DestinationId); err != nil {
|
||||
return false, err
|
||||
} else if !dbExists {
|
||||
return false, fmt.Errorf("could not get destination for tag %v", drate.DestinationId)
|
||||
@@ -194,11 +194,11 @@ func (tpr *TpReader) LoadRatingPlansFiltered(tag string) (bool, error) {
|
||||
continue
|
||||
}
|
||||
for _, destination := range dms {
|
||||
dataStorage.SetDestination(destination)
|
||||
tpr.ratingStorage.SetDestination(destination)
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := dataStorage.SetRatingPlan(ratingPlan); err != nil {
|
||||
if err := tpr.ratingStorage.SetRatingPlan(ratingPlan); err != nil {
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
@@ -260,7 +260,7 @@ func (tpr *TpReader) LoadRatingProfilesFiltered(qriedRpf *TpRatingProfile) error
|
||||
}
|
||||
_, exists := tpr.ratingPlans[tpRa.RatingPlanId]
|
||||
if !exists {
|
||||
if dbExists, err := dataStorage.HasData(RATING_PLAN_PREFIX, tpRa.RatingPlanId); err != nil {
|
||||
if dbExists, err := tpr.ratingStorage.HasData(RATING_PLAN_PREFIX, tpRa.RatingPlanId); err != nil {
|
||||
return err
|
||||
} else if !dbExists {
|
||||
return fmt.Errorf("could not load rating plans for tag: %v", tpRa.RatingPlanId)
|
||||
@@ -274,7 +274,7 @@ func (tpr *TpReader) LoadRatingProfilesFiltered(qriedRpf *TpRatingProfile) error
|
||||
CdrStatQueueIds: strings.Split(tpRa.CdrStatQueueIds, utils.INFIELD_SEP),
|
||||
})
|
||||
}
|
||||
if err := dataStorage.SetRatingProfile(resultRatingProfile); err != nil {
|
||||
if err := tpr.ratingStorage.SetRatingProfile(resultRatingProfile); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -945,17 +945,17 @@ func (tpr *TpReader) IsValid() bool {
|
||||
}
|
||||
|
||||
func (tpr *TpReader) WriteToDatabase(flush, verbose bool) (err error) {
|
||||
if dataStorage == nil {
|
||||
if tpr.ratingStorage == nil || tpr.accountingStorage == nil {
|
||||
return errors.New("no database connection")
|
||||
}
|
||||
if flush {
|
||||
dataStorage.Flush("")
|
||||
tpr.ratingStorage.Flush("")
|
||||
}
|
||||
if verbose {
|
||||
log.Print("Destinations:")
|
||||
}
|
||||
for _, d := range tpr.destinations {
|
||||
err = dataStorage.SetDestination(d)
|
||||
err = tpr.ratingStorage.SetDestination(d)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -94,6 +94,9 @@ func (self *TPCSVImporter) importTimings(fn string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for i := 0; i < len(tps); i++ {
|
||||
tps[i].Tpid = self.TPid
|
||||
}
|
||||
|
||||
return self.StorDb.SetTpTimings(tps)
|
||||
}
|
||||
@@ -106,6 +109,9 @@ func (self *TPCSVImporter) importDestinations(fn string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for i := 0; i < len(tps); i++ {
|
||||
tps[i].Tpid = self.TPid
|
||||
}
|
||||
|
||||
return self.StorDb.SetTpDestinations(tps)
|
||||
}
|
||||
@@ -118,6 +124,9 @@ func (self *TPCSVImporter) importRates(fn string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for i := 0; i < len(tps); i++ {
|
||||
tps[i].Tpid = self.TPid
|
||||
}
|
||||
|
||||
return self.StorDb.SetTpRates(tps)
|
||||
}
|
||||
@@ -131,6 +140,10 @@ func (self *TPCSVImporter) importDestinationRates(fn string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
for i := 0; i < len(tps); i++ {
|
||||
tps[i].Tpid = self.TPid
|
||||
}
|
||||
|
||||
return self.StorDb.SetTpDestinationRates(tps)
|
||||
}
|
||||
|
||||
@@ -142,6 +155,9 @@ func (self *TPCSVImporter) importRatingPlans(fn string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for i := 0; i < len(tps); i++ {
|
||||
tps[i].Tpid = self.TPid
|
||||
}
|
||||
|
||||
return self.StorDb.SetTpRatingPlans(tps)
|
||||
}
|
||||
@@ -154,7 +170,16 @@ func (self *TPCSVImporter) importRatingProfiles(fn string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
loadId := utils.CSV_LOAD //Autogenerate rating profile id
|
||||
if self.ImportId != "" {
|
||||
loadId += "_" + self.ImportId
|
||||
}
|
||||
|
||||
for i := 0; i < len(tps); i++ {
|
||||
tps[i].Tpid = self.TPid
|
||||
tps[i].Loadid = loadId
|
||||
|
||||
}
|
||||
return self.StorDb.SetTpRatingProfiles(tps)
|
||||
}
|
||||
|
||||
@@ -166,10 +191,10 @@ func (self *TPCSVImporter) importSharedGroups(fn string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
loadId := utils.CSV_LOAD //Autogenerate rating profile id
|
||||
if self.ImportId != "" {
|
||||
loadId += "_" + self.ImportId
|
||||
for i := 0; i < len(tps); i++ {
|
||||
tps[i].Tpid = self.TPid
|
||||
}
|
||||
|
||||
return self.StorDb.SetTpSharedGroups(tps)
|
||||
}
|
||||
|
||||
@@ -181,6 +206,9 @@ func (self *TPCSVImporter) importActions(fn string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for i := 0; i < len(tps); i++ {
|
||||
tps[i].Tpid = self.TPid
|
||||
}
|
||||
|
||||
return self.StorDb.SetTpActions(tps)
|
||||
}
|
||||
@@ -193,6 +221,9 @@ func (self *TPCSVImporter) importActionTimings(fn string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for i := 0; i < len(tps); i++ {
|
||||
tps[i].Tpid = self.TPid
|
||||
}
|
||||
|
||||
return self.StorDb.SetTpActionPlans(tps)
|
||||
}
|
||||
@@ -205,6 +236,9 @@ func (self *TPCSVImporter) importActionTriggers(fn string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for i := 0; i < len(tps); i++ {
|
||||
tps[i].Tpid = self.TPid
|
||||
}
|
||||
|
||||
return self.StorDb.SetTpActionTriggers(tps)
|
||||
}
|
||||
@@ -217,7 +251,14 @@ func (self *TPCSVImporter) importAccountActions(fn string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
loadId := utils.CSV_LOAD //Autogenerate rating profile id
|
||||
if self.ImportId != "" {
|
||||
loadId += "_" + self.ImportId
|
||||
}
|
||||
for i := 0; i < len(tps); i++ {
|
||||
tps[i].Tpid = self.TPid
|
||||
tps[i].Loadid = loadId
|
||||
}
|
||||
return self.StorDb.SetTpAccountActions(tps)
|
||||
}
|
||||
|
||||
@@ -229,7 +270,14 @@ func (self *TPCSVImporter) importDerivedChargers(fn string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
loadId := utils.CSV_LOAD //Autogenerate rating profile id
|
||||
if self.ImportId != "" {
|
||||
loadId += "_" + self.ImportId
|
||||
}
|
||||
for i := 0; i < len(tps); i++ {
|
||||
tps[i].Tpid = self.TPid
|
||||
tps[i].Loadid = loadId
|
||||
}
|
||||
return self.StorDb.SetTpDerivedChargers(tps)
|
||||
}
|
||||
|
||||
@@ -241,6 +289,9 @@ func (self *TPCSVImporter) importCdrStats(fn string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for i := 0; i < len(tps); i++ {
|
||||
tps[i].Tpid = self.TPid
|
||||
}
|
||||
|
||||
return self.StorDb.SetTpCdrStats(tps)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user