Adding TPTiming APIs together with documentation attached

This commit is contained in:
DanB
2013-07-09 13:15:02 +02:00
parent 7d06363c10
commit 8ecf706086
14 changed files with 736 additions and 170 deletions

View File

@@ -21,56 +21,18 @@ package apier
import (
"errors"
"fmt"
"github.com/cgrates/cgrates/rater"
"github.com/cgrates/cgrates/rater"
"github.com/cgrates/cgrates/utils"
)
type AttrGetTPDestinationIds struct {
TPid string // Tariff plan id
type ApierTPDestination struct {
TPid string // Tariff plan id
DestinationId string // Destination id
Prefixes []string // Prefixes attached to this destination
}
// Return destinations profile for a destination tag received as parameter
func (self *Apier) GetTPDestinationIds(attrs AttrGetTPDestinationIds, reply *[]string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
if ids, err := self.StorDb.GetTPDestinationIds(attrs.TPid); err != nil {
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
} else if ids == nil {
return errors.New(utils.ERR_NOT_FOUND)
} else {
*reply = ids
}
return nil
}
type AttrGetTPDestination struct {
TPid string
DestinationId string
}
// Return destinations profile for a destination tag received as parameter
func (self *Apier) GetTPDestination(attrs AttrGetTPDestination, reply *rater.Destination) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "DestinationId"}); len(missing) != 0 { //Params missing
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
if dst, err := self.StorDb.GetTPDestination(attrs.TPid, attrs.DestinationId); err != nil {
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
} else if dst == nil {
return errors.New(utils.ERR_NOT_FOUND)
} else {
*reply = *dst
}
return nil
}
type AttrSetTPDestination struct {
TPid string
DestinationId string
Prefixes []string
}
func (self *Apier) SetTPDestination(attrs AttrSetTPDestination, reply *string) error {
// Creates a new destination within a tariff plan
func (self *Apier) SetTPDestination(attrs ApierTPDestination, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "DestinationId", "Prefixes"}); len(missing) != 0 { //Params missing
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
@@ -85,3 +47,42 @@ func (self *Apier) SetTPDestination(attrs AttrSetTPDestination, reply *string) e
*reply = "OK"
return nil
}
type AttrGetTPDestination struct {
TPid string // Tariff plan id
DestinationId string // Destination id
}
// Queries a specific destination
func (self *Apier) GetTPDestination(attrs AttrGetTPDestination, reply *ApierTPDestination) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "DestinationId"}); len(missing) != 0 { //Params missing
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
if dst, err := self.StorDb.GetTPDestination(attrs.TPid, attrs.DestinationId); err != nil {
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
} else if dst == nil {
return errors.New(utils.ERR_NOT_FOUND)
} else {
*reply = ApierTPDestination{attrs.TPid, dst.Id, dst.Prefixes}
}
return nil
}
type AttrGetTPDestinationIds struct {
TPid string // Tariff plan id
}
// Queries destination identities on specific tariff plan.
func (self *Apier) GetTPDestinationIds(attrs AttrGetTPDestinationIds, reply *[]string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
if ids, err := self.StorDb.GetTPDestinationIds(attrs.TPid); err != nil {
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
} else if ids == nil {
return errors.New(utils.ERR_NOT_FOUND)
} else {
*reply = ids
}
return nil
}

94
apier/tptimings.go Normal file
View File

@@ -0,0 +1,94 @@
/*
Rating system designed to be used in VoIP Carriers World
Copyright (C) 2013 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
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 apier
import (
"errors"
"fmt"
"github.com/cgrates/cgrates/rater"
"github.com/cgrates/cgrates/utils"
)
type ApierTPTiming struct {
TPid string // Tariff plan id
TimingId string // Timing id
Years string // semicolon separated list of years this timing is valid on, *all supported
Months string // semicolon separated list of months this timing is valid on, *none and *all supported
MonthDays string // semicolon separated list of month's days this timing is valid on, *none and *all supported
WeekDays string // semicolon separated list of week day names this timing is valid on *none and *all supported
Time string // String representing the time this timing starts on
}
// Creates a new timing within a tariff plan
func (self *Apier) SetTPTiming(attrs ApierTPTiming, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "TimingId", "Years","Months","MonthDays", "WeekDays","Time"}); len(missing) != 0 {
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
if exists, err := self.StorDb.ExistsTPTiming(attrs.TPid, attrs.TimingId); err != nil {
return fmt.Errorf("%s:%v", utils.ERR_SERVER_ERROR, err.Error())
} else if exists {
return errors.New(utils.ERR_DUPLICATE)
}
tm := rater.NewTiming( attrs.TimingId, attrs.Years, attrs.Months, attrs.MonthDays, attrs.WeekDays, attrs.Time )
if err := self.StorDb.SetTPTiming(attrs.TPid, tm); err != nil {
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
}
*reply = "OK"
return nil
}
type AttrGetTPTiming struct {
TPid string // Tariff plan id
TimingId string // Timing id
}
// Queries specific Timing on Tariff plan
func (self *Apier) GetTPTiming(attrs AttrGetTPTiming, reply *ApierTPTiming) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "TimingId"}); len(missing) != 0 { //Params missing
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
if tm, err := self.StorDb.GetTPTiming(attrs.TPid, attrs.TimingId); err != nil {
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
} else if tm == nil {
return errors.New(utils.ERR_NOT_FOUND)
} else {
*reply = ApierTPTiming{attrs.TPid, tm.Id, tm.Years.Serialize(";"),
tm.Months.Serialize(";"), tm.MonthDays.Serialize(";"), tm.WeekDays.Serialize(";"), tm.StartTime}
}
return nil
}
type AttrGetTPTimingIds struct {
TPid string // Tariff plan id
}
// Queries timing identities on specific tariff plan.
func (self *Apier) GetTPTimingIds(attrs AttrGetTPTimingIds, reply *[]string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
if ids, err := self.StorDb.GetTPTimingIds(attrs.TPid); err != nil {
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
} else if ids == nil {
return errors.New(utils.ERR_NOT_FOUND)
} else {
*reply = ids
}
return nil
}

View File

@@ -11,7 +11,8 @@ CREATE TABLE `tp_timings` (
`week_days` varchar(255) NOT NULL,
`time` varchar(16) NOT NULL,
PRIMARY KEY (`id`),
KEY `tpid` (`tpid`)
KEY `tpid` (`tpid`),
UNIQUE KEY `tpid_tmid` (`tpid`,`tag`)
);
--
@@ -24,8 +25,8 @@ CREATE TABLE `tp_destinations` (
`tag` varchar(24) NOT NULL,
`prefix` varchar(24) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `tpid_dest_prefix` (`tpid`,`tag`,`prefix`),
KEY `tpid` (`tpid`)
KEY `tpid` (`tpid`),
UNIQUE KEY `tpid_dest_prefix` (`tpid`,`tag`,`prefix`)
);
--

202
docs/api_tptimings.rst Normal file
View File

@@ -0,0 +1,202 @@
Apier.SetTPTiming
+++++++++++++++++
Creates a new timing within a tariff plan.
**Request**:
Data:
::
type ApierTPTiming struct {
TPid string // Tariff plan id
TimingId string // Timing id
Years string // semicolon separated list of years this timing is valid on, \*all supported
Months string // semicolon separated list of months this timing is valid on, \*none and \*all supported
MonthDays string // semicolon separated list of month's days this timing is valid on, \*none and \*all supported
WeekDays string // semicolon separated list of week day names this timing is valid on \*none and \*all supported
Time string // String representing the time this timing starts on
}
Mandatory parameters: ``[]string{"TPid", "TimingId", "Years","Months","MonthDays", "WeekDays","Time"}``
*JSON sample*:
::
{
"id": 3,
"method": "Apier.SetTPTiming",
"params": [
{
"MonthDays": "1;2;3;31",
"Months": "1;3;6",
"TPid": "SAMPLE_TP",
"Time": "13:00:00",
"TimingId": "SAMPLE_TIMING_5",
"WeekDays": "0",
"Years": "2013;2014"
}
]
}
**Reply**:
Data:
::
string
Possible answers:
``OK`` - Success.
*JSON sample*:
::
{
"error": null,
"id": 3,
"result": "OK"
}
**Errors**:
``MANDATORY_IE_MISSING`` - Mandatory parameter missing from request.
``SERVER_ERROR`` - Server error occurred.
``DUPLICATE`` - The specified combination of TPid/DestinationId already exists in StorDb.
Apier.GetTPTiming
+++++++++++++++++
Queries specific Timing on tariff plan.
**Request**:
Data:
::
type AttrGetTPTiming struct {
TPid string // Tariff plan id
TimingId string // Timing id
}
Mandatory parameters: ``[]string{"TPid", "TimingId"}``
*JSON sample*:
::
{
"id": 4,
"method": "Apier.GetTPTiming",
"params": [
{
"TPid": "SAMPLE_TP",
"TimingId": "SAMPLE_TIMING_7"
}
]
}
**Reply**:
Data:
::
type ApierTPTiming struct {
TPid string // Tariff plan id
TimingId string // Timing id
Years string // semicolon separated list of years this timing is valid on, \*all supported
Months string // semicolon separated list of months this timing is valid on, \*none and \*all supported
MonthDays string // semicolon separated list of month's days this timing is valid on, \*none and \*all supported
WeekDays string // semicolon separated list of week day names this timing is valid on \*none and \*all supported
Time string // String representing the time this timing starts on
}
*JSON sample*:
::
{
"error": null,
"id": 4,
"result": {
"MonthDays": "1;2;3;31",
"Months": "1;3;6",
"TPid": "SAMPLE_TP",
"Time": "13:00:00",
"TimingId": "SAMPLE_TIMING_7",
"WeekDays": "*all",
"Years": "2013;2014"
}
}
**Errors**:
``MANDATORY_IE_MISSING`` - Mandatory parameter missing from request.
``SERVER_ERROR`` - Server error occurred.
``NOT_FOUND`` - Requested destination id not found.
Apier.GetTPDestinationIds
+++++++++++++++++++++++++
Queries timing identities on tariff plan.
**Request**:
Data:
::
type AttrGetTPDestinationIds struct {
TPid string // Tariff plan id
}
Required parameters: ``[]string{"TPid"}``
*JSON sample*:
::
{
"id": 5,
"method": "Apier.GetTPTimingIds",
"params": [
{
"TPid": "SAMPLE_TP"
}
]
}
**Reply**:
Data:
::
[]string
*JSON sample*:
::
{
"error": null,
"id": 5,
"result": [
"SAMPLE_TIMING_1",
"SAMPLE_TIMING_2",
"SAMPLE_TIMING_3",
"SAMPLE_TIMING_4",
"SAMPLE_TIMING_5"
]
}
**Errors**:
``MANDATORY_IE_MISSING`` - Mandatory parameter missing from request.
``SERVER_ERROR`` - Server error occurred.
``NOT_FOUND`` - Requested tariff plan not found.

View File

@@ -125,13 +125,6 @@ Destinations
~~~~~~~~~~~~
::
type Destination struct {
Tag string
Prefixes []string
}
Apier.SetTPDestination
++++++++++++++++++++++
@@ -142,12 +135,14 @@ Creates a new destination within a tariff plan id.
Data:
::
type AttrSetTPDestination struct {
TPid string // Tariff plan id
DestinationId string // Unique identity within the tariff plan id
Prefixes []string // Set of prefixes grouped by this destination
type ApierTPDestination struct {
TPid string // Tariff plan id
DestinationId string // Destination id
Prefixes []string // Prefixes attached to this destination
}
Required parameters: ``[]string{"TPid", "DestinationId", "Prefixes"}``
*JSON sample*:
::
@@ -209,6 +204,8 @@ Queries a specific destination.
DestinationId string // Destination id
}
Required parameters: ``[]string{"TPid", "DestinationId"}``
*JSON sample*:
::
@@ -228,9 +225,10 @@ Queries a specific destination.
Data:
::
type Destination struct {
Id string // Destination id
Prefixes []string // List of prefixes attached to destination
type ApierTPDestination struct {
TPid string // Tariff plan id
DestinationId string // Destination id
Prefixes []string // Prefixes attached to this destination
}
*JSON sample*:
@@ -240,7 +238,8 @@ Queries a specific destination.
"error": null,
"id": 0,
"result": {
"Id": "FIST_DST2",
"TPid":"FIST_TP",
"DestinationId": "FIST_DST2",
"Prefixes": [
"123",
"345"
@@ -272,6 +271,8 @@ Queries destination identities on specific tariff plan.
TPid string // Tariff plan id
}
Required parameters: ``[]string{"TPid"}``
*JSON sample*:
::
@@ -321,36 +322,10 @@ Queries destination identities on specific tariff plan.
Timings
+++++++
::
.. toctree::
:maxdepth: 2
type Timing struct {
Tag
Years
Months
MonthDays
WeekDays
Time
}
**SetTPTiming**
Parametrs:
TPid
A string containing traiff plan id
Timing
A JSON string containing timing data.
Example
SetTPTiming("1dec2012", '{"Tag": "MIDNIGHT", Year: "\*all", Months: "\*all", MonthDays: "\*all", WeekDays: "\*all", "Time": "00:00:00"}')
GetTPTiming
DeleteTPTiming
GetAllTPTimings
api_tptimings
SetTPRate

View File

@@ -19,12 +19,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package rater
import (
// "log"
"sort"
"strconv"
"strings"
"time"
// "log"
"fmt"
"reflect"
)
// Defines years days series
@@ -58,7 +58,7 @@ func (ys Years) Contains(year int) (result bool) {
return
}
// Parse MonthDay elements from string separated by sep.
// Parse Years elements from string separated by sep.
func (ys *Years) Parse(input, sep string) {
switch input {
case "*all", "":
@@ -73,6 +73,24 @@ func (ys *Years) Parse(input, sep string) {
}
}
func (ys Years) Serialize( sep string ) string {
if len(ys) == 0 {
return "*all"
}
var yStr string
for idx, yr := range ys {
if idx != 0 {
yStr = fmt.Sprintf("%s%s%d", yStr, sep, yr)
} else {
yStr = strconv.Itoa(yr)
}
}
return yStr
}
var allMonths []time.Month = []time.Month{time.January, time.February, time.March, time.April, time.May, time.June,
time.July, time.August, time.September, time.October, time.November, time.December}
// Defines months series
type Months []time.Month
@@ -107,8 +125,9 @@ func (m Months) Contains(month time.Month) (result bool) {
func (m *Months) Parse(input, sep string) {
switch input {
case "*all":
*m = []time.Month{time.January, time.February, time.March, time.April, time.May, time.June,
time.July, time.August, time.September, time.October, time.November, time.December}
*m = allMonths
case "*none": // Apier cannot receive empty string, hence using meta-tag
*m = []time.Month{}
case "":
*m = []time.Month{}
default:
@@ -121,6 +140,28 @@ func (m *Months) Parse(input, sep string) {
}
}
// Dumps the months in a serialized string, similar to the one parsed
func (m Months) Serialize( sep string ) string {
if len(m) == 0 {
return "*none"
}
if reflect.DeepEqual( m, Months(allMonths) ) {
return "*all"
}
var mStr string
for idx, mt := range m {
if idx != 0 {
mStr = fmt.Sprintf("%s%s%d", mStr, sep, mt)
} else {
mStr = strconv.Itoa(int(mt))
}
}
return mStr
}
var allMonthDays []int = []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}
// Defines month days series
type MonthDays []int
@@ -156,7 +197,7 @@ func (md MonthDays) Contains(monthDay int) (result bool) {
func (md *MonthDays) Parse(input, sep string) {
switch input {
case "*all":
*md = []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}
*md = allMonthDays
case "":
*md = []int{}
default:
@@ -169,6 +210,26 @@ func (md *MonthDays) Parse(input, sep string) {
}
}
// Dumps the month days in a serialized string, similar to the one parsed
func (md MonthDays) Serialize( sep string ) string {
if len(md) == 0 {
return "*none"
}
if reflect.DeepEqual(md, MonthDays(allMonthDays)) {
return "*all"
}
var mdsStr string
for idx, mDay := range md {
if idx != 0 {
mdsStr = fmt.Sprintf("%s%s%d", mdsStr, sep, mDay)
} else {
mdsStr = strconv.Itoa(mDay)
}
}
return mdsStr
}
var allWeekDays []time.Weekday = []time.Weekday{time.Monday, time.Tuesday, time.Wednesday, time.Thursday, time.Friday, time.Saturday, time.Sunday}
// Defines week days series
type WeekDays []time.Weekday
@@ -203,7 +264,7 @@ func (wd WeekDays) Contains(weekDay time.Weekday) (result bool) {
func (wd *WeekDays) Parse(input, sep string) {
switch input {
case "*all":
*wd = []time.Weekday{time.Monday, time.Tuesday, time.Wednesday, time.Thursday, time.Friday, time.Saturday, time.Sunday}
*wd = allWeekDays
case "":
*wd = []time.Weekday{}
default:
@@ -215,3 +276,22 @@ func (wd *WeekDays) Parse(input, sep string) {
}
}
}
// Dumps the week days in a serialized string, similar to the one parsed
func (wd WeekDays) Serialize( sep string ) string {
if len(wd) == 0 {
return "*none"
}
if reflect.DeepEqual( wd, WeekDays(allWeekDays) ) {
return "*all"
}
var wdStr string
for idx, d := range wd {
if idx != 0 {
wdStr = fmt.Sprintf("%s%s%d", wdStr, sep, d)
} else {
wdStr = strconv.Itoa(int(d))
}
}
return wdStr
}

View File

@@ -63,3 +63,106 @@ func TestWeekDayStoreRestoreJson(t *testing.T) {
t.Errorf("Expected %v was %v", wd, o)
}
}
func TestYearsSerialize(t *testing.T) {
ys := &Years{}
yString := ys.Serialize(";")
expectString := "*all"
if expectString != yString {
t.Errorf("Expected: %s, got: %s", expectString, yString)
}
ys2 := &Years{2012}
yString2 := ys2.Serialize(";")
expectString2 := "2012"
if expectString2 != yString2 {
t.Errorf("Expected: %s, got: %s", expectString2, yString2)
}
ys3 := &Years{2013,2014,2015}
yString3 := ys3.Serialize(";")
expectString3 := "2013;2014;2015"
if expectString3 != yString3 {
t.Errorf("Expected: %s, got: %s", expectString3, yString3)
}
}
func TestMonthsSerialize(t *testing.T) {
mths := &Months{}
mString := mths.Serialize(";")
expectString := "*none"
if expectString != mString {
t.Errorf("Expected: %s, got: %s", expectString, mString)
}
mths1 := Months(allMonths)
mString1 := mths1.Serialize(";")
expectString1 := "*all"
if expectString1 != mString1 {
t.Errorf("Expected: %s, got: %s", expectString1, mString1)
}
mths2 := &Months{time.January}
mString2 := mths2.Serialize(";")
expectString2 := "1"
if expectString2 != mString2 {
t.Errorf("Expected: %s, got: %s", expectString2, mString2)
}
mths3 := &Months{time.January,time.December}
mString3 := mths3.Serialize(";")
expectString3 := "1;12"
if expectString3 != mString3 {
t.Errorf("Expected: %s, got: %s", expectString3, mString3)
}
}
func TestMonthDaysSerialize(t *testing.T) {
mds := &MonthDays{}
mdsString := mds.Serialize(";")
expectString := "*none"
if expectString != mdsString {
t.Errorf("Expected: %s, got: %s", expectString, mdsString)
}
mds1 := MonthDays(allMonthDays)
mdsString1 := mds1.Serialize(";")
expectString1 := "*all"
if expectString1 != mdsString1 {
t.Errorf("Expected: %s, got: %s", expectString1, mdsString1)
}
mds2 := &MonthDays{1}
mdsString2 := mds2.Serialize(";")
expectString2 := "1"
if expectString2 != mdsString2 {
t.Errorf("Expected: %s, got: %s", expectString2, mdsString2)
}
mds3 := &MonthDays{1,2,3,4,5}
mdsString3 := mds3.Serialize(";")
expectString3 := "1;2;3;4;5"
if expectString3 != mdsString3 {
t.Errorf("Expected: %s, got: %s", expectString3, mdsString3)
}
}
func TestWeekDaysSerialize(t *testing.T) {
wds := &WeekDays{}
wdsString := wds.Serialize(";")
expectString := "*none"
if expectString != wdsString {
t.Errorf("Expected: %s, got: %s", expectString, wdsString)
}
wds1 := WeekDays(allWeekDays)
wdsString1 := wds1.Serialize(";")
expectString1 := "*all"
if expectString1 != wdsString1 {
t.Errorf("Expected: %s, got: %s", expectString1, wdsString1)
}
wds2 := &WeekDays{time.Monday}
wdsString2 := wds2.Serialize(";")
expectString2 := "1"
if expectString2 != wdsString2 {
t.Errorf("Expected: %s, got: %s", expectString2, wdsString2)
}
wds3 := &WeekDays{time.Monday, time.Saturday,time.Sunday}
wdsString3 := wds3.Serialize(";")
expectString3 := "1;6;0"
if expectString3 != wdsString3 {
t.Errorf("Expected: %s, got: %s", expectString3, wdsString3)
}
}

View File

@@ -213,7 +213,7 @@ func (csvr *CSVReader) LoadTimings() (err error) {
continue
}
csvr.timings[tag] = NewTiming(record[1:]...)
csvr.timings[tag] = NewTiming(record...)
}
return
}

View File

@@ -86,6 +86,7 @@ type DestinationRate struct {
}
type Timing struct {
Id string
Years Years
Months Months
MonthDays MonthDays
@@ -93,13 +94,14 @@ type Timing struct {
StartTime string
}
func NewTiming(timeingInfo ...string) (rt *Timing) {
func NewTiming(timingInfo ...string) (rt *Timing) {
rt = &Timing{}
rt.Years.Parse(timeingInfo[0], ";")
rt.Months.Parse(timeingInfo[1], ";")
rt.MonthDays.Parse(timeingInfo[2], ";")
rt.WeekDays.Parse(timeingInfo[3], ";")
rt.StartTime = timeingInfo[4]
rt.Id = timingInfo[0]
rt.Years.Parse(timingInfo[1], ";")
rt.Months.Parse(timingInfo[2], ";")
rt.MonthDays.Parse(timingInfo[3], ";")
rt.WeekDays.Parse(timingInfo[4], ";")
rt.StartTime = timingInfo[5]
return
}

View File

@@ -57,10 +57,16 @@ type DataStorage interface {
SetRatingProfile(*RatingProfile) error
GetDestination(string) (*Destination, error)
SetDestination(*Destination) error
GetTPDestinationIds(string) ([]string, error)
// Apier functions
SetTPTiming(string, *Timing) error
ExistsTPTiming(string, string) (bool, error)
GetTPTiming(string, string) (*Timing, error)
GetTPTimingIds(string) ([]string, error)
SetTPDestination(string, *Destination) error
ExistsTPDestination(string, string) (bool, error)
GetTPDestination(string, string) (*Destination, error)
SetTPDestination(string, *Destination) error
GetTPDestinationIds(string) ([]string, error)
// End Apier functions
GetActions(string) (Actions, error)
SetActions(string, Actions) error
GetUserBalance(string) (*UserBalance, error)

View File

@@ -73,10 +73,26 @@ func (ms *MapStorage) SetDestination(dest *Destination) (err error) {
return
}
func (ms *MapStorage) GetTPDestinationIds(tpid string) ([]string, error) {
func (ms *MapStorage) SetTPTiming(tpid string, tm *Timing) error {
return errors.New(utils.ERR_NOT_IMPLEMENTED)
}
func (ms *MapStorage) ExistsTPTiming(tpid, tmId string) (bool, error) {
return false, errors.New(utils.ERR_NOT_IMPLEMENTED)
}
func (ms *MapStorage) GetTPTiming(tpid, tmId string) (*Timing, error) {
return nil, nil
}
func (ms *MapStorage) GetTPTimingIds(tpid string) ([]string, error) {
return nil, errors.New(utils.ERR_NOT_IMPLEMENTED)
}
func (ms *MapStorage) SetTPDestination(tpid string, dest *Destination) error {
return errors.New(utils.ERR_NOT_IMPLEMENTED)
}
func (ms *MapStorage) ExistsTPDestination(tpid, destTag string) (bool, error) {
return false, errors.New(utils.ERR_NOT_IMPLEMENTED)
}
@@ -86,8 +102,8 @@ func (ms *MapStorage) GetTPDestination(tpid, destTag string) (*Destination, erro
return nil, nil
}
func (ms *MapStorage) SetTPDestination(tpid string, dest *Destination) error {
return errors.New(utils.ERR_NOT_IMPLEMENTED)
func (ms *MapStorage) GetTPDestinationIds(tpid string) ([]string, error) {
return nil, errors.New(utils.ERR_NOT_IMPLEMENTED)
}
func (ms *MapStorage) GetActions(key string) (as Actions, err error) {

View File

@@ -147,6 +147,22 @@ func (ms *MongoStorage) SetDestination(dest *Destination) error {
return ms.db.C("destinations").Insert(dest)
}
func (ms *MongoStorage) SetTPTiming(tpid string, tm *Timing) error {
return errors.New(utils.ERR_NOT_IMPLEMENTED)
}
func (ms *MongoStorage) ExistsTPTiming(tpid, tmId string) (bool, error) {
return false, errors.New(utils.ERR_NOT_IMPLEMENTED)
}
func (ms *MongoStorage) GetTPTiming(tpid, tmId string) (*Timing, error) {
return nil, nil
}
func (ms *MongoStorage) GetTPTimingIds(tpid string) ([]string, error) {
return nil, errors.New(utils.ERR_NOT_IMPLEMENTED)
}
func (ms *MongoStorage) GetTPDestinationIds(tpid string) ([]string, error) {
return nil, errors.New(utils.ERR_NOT_IMPLEMENTED)
}

View File

@@ -102,6 +102,22 @@ func (rs *RedisStorage) SetDestination(dest *Destination) (err error) {
return
}
func (rs *RedisStorage) SetTPTiming(tpid string, tm *Timing) error {
return errors.New(utils.ERR_NOT_IMPLEMENTED)
}
func (rs *RedisStorage) ExistsTPTiming(tpid, tmId string) (bool, error) {
return false, errors.New(utils.ERR_NOT_IMPLEMENTED)
}
func (rs *RedisStorage) GetTPTiming(tpid, tmId string) (*Timing, error) {
return nil, nil
}
func (rs *RedisStorage) GetTPTimingIds(tpid string) ([]string, error) {
return nil, errors.New(utils.ERR_NOT_IMPLEMENTED)
}
func (rs *RedisStorage) GetTPDestinationIds(tpid string) ([]string, error) {
return nil, errors.New(utils.ERR_NOT_IMPLEMENTED)
}

View File

@@ -29,34 +29,64 @@ type SQLStorage struct {
Db *sql.DB
}
func (sql *SQLStorage) Close() {}
func (self *SQLStorage) Close() {}
func (sql *SQLStorage) Flush() (err error) {
func (self *SQLStorage) Flush() (err error) {
return
}
func (sql *SQLStorage) GetRatingProfile(string) (rp *RatingProfile, err error) {
/*row := sql.Db.QueryRow(fmt.Sprintf("SELECT * FROM ratingprofiles WHERE id='%s'", id))
func (self *SQLStorage) GetRatingProfile(string) (rp *RatingProfile, err error) {
/*row := self.Db.QueryRow(fmt.Sprintf("SELECT * FROM ratingprofiles WHERE id='%s'", id))
err = row.Scan(&rp, &cc.Direction, &cc.Tenant, &cc.TOR, &cc.Subject, &cc.Destination, &cc.Cost, &cc.ConnectFee, &timespansJson)
err = json.Unmarshal([]byte(timespansJson), cc.Timespans)*/
return
}
func (sql *SQLStorage) SetRatingProfile(rp *RatingProfile) (err error) {
func (self *SQLStorage) SetRatingProfile(rp *RatingProfile) (err error) {
return
}
func (sql *SQLStorage) GetDestination(string) (d *Destination, err error) {
func (self *SQLStorage) GetDestination(string) (d *Destination, err error) {
return
}
func (sql *SQLStorage) SetDestination(d *Destination) (err error) {
func (self *SQLStorage) SetDestination(d *Destination) (err error) {
return
}
// Extracts destinations from StorDB on specific tariffplan id
func (sql *SQLStorage) GetTPDestinationIds(tpid string) ([]string, error) {
rows, err := sql.Db.Query(fmt.Sprintf("SELECT DISTINCT tag FROM %s where tpid='%s'", utils.TBL_TP_DESTINATIONS, tpid))
func (self *SQLStorage) SetTPTiming(tpid string, tm *Timing) error {
if _, err := self.Db.Exec(fmt.Sprintf("INSERT INTO %s (tpid, tag, years, months, month_days, week_days, time) VALUES('%s','%s','%s','%s','%s','%s','%s')",
utils.TBL_TP_TIMINGS, tpid, tm.Id, tm.Years.Serialize(";"), tm.Months.Serialize(";"), tm.MonthDays.Serialize(";"),
tm.WeekDays.Serialize(";"), tm.StartTime )); err != nil {
return err
}
return nil
}
func (self *SQLStorage) ExistsTPTiming(tpid, tmId string) (bool, error) {
var exists bool
err := self.Db.QueryRow(fmt.Sprintf("SELECT EXISTS (SELECT 1 FROM %s WHERE tpid='%s' AND tag='%s')", utils.TBL_TP_TIMINGS, tpid, tmId)).Scan(&exists)
if err != nil {
return false, err
}
return exists, nil
}
func (self *SQLStorage) GetTPTiming(tpid, tmId string) (*Timing, error) {
var years, months, monthDays, weekDays, time string
err := self.Db.QueryRow(fmt.Sprintf("SELECT years, months, month_days, week_days, time FROM %s WHERE tpid='%s' AND tag='%s' LIMIT 1",
utils.TBL_TP_TIMINGS, tpid, tmId)).Scan(&years,&months,&monthDays,&weekDays,&time)
switch {
case err == sql.ErrNoRows:
return nil,nil
case err!=nil:
return nil, err
}
return NewTiming( tmId, years, months, monthDays, weekDays, time ), nil
}
func (self *SQLStorage) GetTPTimingIds(tpid string) ([]string, error) {
rows, err := self.Db.Query(fmt.Sprintf("SELECT DISTINCT tag FROM %s where tpid='%s'", utils.TBL_TP_TIMINGS, tpid))
if err != nil {
return nil, err
}
@@ -64,7 +94,7 @@ func (sql *SQLStorage) GetTPDestinationIds(tpid string) ([]string, error) {
ids := []string{}
i := 0
for rows.Next() {
i++ //Keep here a reference so we know we got at least one prefix
i++ //Keep here a reference so we know we got at least one
var id string
err = rows.Scan(&id)
if err != nil {
@@ -78,9 +108,33 @@ func (sql *SQLStorage) GetTPDestinationIds(tpid string) ([]string, error) {
return ids, nil
}
func (sql *SQLStorage) ExistsTPDestination(tpid, destTag string) (bool, error) {
// Extracts destinations from StorDB on specific tariffplan id
func (self *SQLStorage) GetTPDestinationIds(tpid string) ([]string, error) {
rows, err := self.Db.Query(fmt.Sprintf("SELECT DISTINCT tag FROM %s where tpid='%s'", utils.TBL_TP_DESTINATIONS, tpid))
if err != nil {
return nil, err
}
defer rows.Close()
ids := []string{}
i := 0
for rows.Next() {
i++ //Keep here a reference so we know we got at least one
var id string
err = rows.Scan(&id)
if err != nil {
return nil, err
}
ids = append(ids, id)
}
if i == 0 {
return nil, nil
}
return ids, nil
}
func (self *SQLStorage) ExistsTPDestination(tpid, destTag string) (bool, error) {
var exists bool
err := sql.Db.QueryRow(fmt.Sprintf("SELECT EXISTS (SELECT 1 FROM %s WHERE tpid='%s' AND tag='%s')", utils.TBL_TP_DESTINATIONS, tpid, destTag)).Scan(&exists)
err := self.Db.QueryRow(fmt.Sprintf("SELECT EXISTS (SELECT 1 FROM %s WHERE tpid='%s' AND tag='%s')", utils.TBL_TP_DESTINATIONS, tpid, destTag)).Scan(&exists)
if err != nil {
return false, err
}
@@ -88,8 +142,8 @@ func (sql *SQLStorage) ExistsTPDestination(tpid, destTag string) (bool, error) {
}
// Extracts destinations from StorDB on specific tariffplan id
func (sql *SQLStorage) GetTPDestination(tpid, destTag string) (*Destination, error) {
rows, err := sql.Db.Query(fmt.Sprintf("SELECT prefix FROM %s WHERE tpid='%s' AND tag='%s'", utils.TBL_TP_DESTINATIONS, tpid, destTag))
func (self *SQLStorage) GetTPDestination(tpid, destTag string) (*Destination, error) {
rows, err := self.Db.Query(fmt.Sprintf("SELECT prefix FROM %s WHERE tpid='%s' AND tag='%s'", utils.TBL_TP_DESTINATIONS, tpid, destTag))
if err != nil {
return nil, err
}
@@ -111,35 +165,35 @@ func (sql *SQLStorage) GetTPDestination(tpid, destTag string) (*Destination, err
return d, nil
}
func (sql *SQLStorage) SetTPDestination(tpid string, dest *Destination) error {
func (self *SQLStorage) SetTPDestination(tpid string, dest *Destination) error {
for _, prefix := range dest.Prefixes {
if _, err := sql.Db.Exec(fmt.Sprintf("INSERT INTO %s (tpid, tag, prefix) VALUES( '%s','%s','%s')", utils.TBL_TP_DESTINATIONS, tpid, dest.Id, prefix)); err != nil {
if _, err := self.Db.Exec(fmt.Sprintf("INSERT INTO %s (tpid, tag, prefix) VALUES( '%s','%s','%s')", utils.TBL_TP_DESTINATIONS, tpid, dest.Id, prefix)); err != nil {
return err
}
}
return nil
}
func (sql *SQLStorage) GetActions(string) (as Actions, err error) {
func (self *SQLStorage) GetActions(string) (as Actions, err error) {
return
}
func (sql *SQLStorage) SetActions(key string, as Actions) (err error) { return }
func (self *SQLStorage) SetActions(key string, as Actions) (err error) { return }
func (sql *SQLStorage) GetUserBalance(string) (ub *UserBalance, err error) { return }
func (self *SQLStorage) GetUserBalance(string) (ub *UserBalance, err error) { return }
func (sql *SQLStorage) SetUserBalance(ub *UserBalance) (err error) { return }
func (self *SQLStorage) SetUserBalance(ub *UserBalance) (err error) { return }
func (sql *SQLStorage) GetActionTimings(key string) (ats ActionTimings, err error) { return }
func (self *SQLStorage) GetActionTimings(key string) (ats ActionTimings, err error) { return }
func (sql *SQLStorage) SetActionTimings(key string, ats ActionTimings) (err error) { return }
func (self *SQLStorage) SetActionTimings(key string, ats ActionTimings) (err error) { return }
func (sql *SQLStorage) GetAllActionTimings() (ats map[string]ActionTimings, err error) {
func (self *SQLStorage) GetAllActionTimings() (ats map[string]ActionTimings, err error) {
return
}
func (sql *SQLStorage) LogCallCost(uuid, source string, cc *CallCost) (err error) {
if sql.Db == nil {
func (self *SQLStorage) LogCallCost(uuid, source string, cc *CallCost) (err error) {
if self.Db == nil {
//timespans.Logger.Warning("Cannot write log to database.")
return
}
@@ -147,7 +201,7 @@ func (sql *SQLStorage) LogCallCost(uuid, source string, cc *CallCost) (err error
if err != nil {
Logger.Err(fmt.Sprintf("Error marshalling timespans to json: %v", err))
}
_, err = sql.Db.Exec(fmt.Sprintf("INSERT INTO callcosts VALUES ('NULL','%s', '%s','%s', '%s', '%s', '%s', '%s', '%s', %v, %v, '%s')",
_, err = self.Db.Exec(fmt.Sprintf("INSERT INTO callcosts VALUES ('NULL','%s', '%s','%s', '%s', '%s', '%s', '%s', '%s', %v, %v, '%s')",
uuid,
source,
cc.Direction,
@@ -165,8 +219,8 @@ func (sql *SQLStorage) LogCallCost(uuid, source string, cc *CallCost) (err error
return
}
func (sql *SQLStorage) GetCallCostLog(uuid, source string) (cc *CallCost, err error) {
row := sql.Db.QueryRow(fmt.Sprintf("SELECT * FROM callcosts WHERE uuid='%s' AND source='%s'", uuid, source))
func (self *SQLStorage) GetCallCostLog(uuid, source string) (cc *CallCost, err error) {
row := self.Db.QueryRow(fmt.Sprintf("SELECT * FROM callcosts WHERE uuid='%s' AND source='%s'", uuid, source))
var uuid_found string
var timespansJson string
err = row.Scan(&uuid_found, &cc.Direction, &cc.Tenant, &cc.TOR, &cc.Subject, &cc.Destination, &cc.Cost, &cc.ConnectFee, &timespansJson)
@@ -174,20 +228,20 @@ func (sql *SQLStorage) GetCallCostLog(uuid, source string) (cc *CallCost, err er
return
}
func (sql *SQLStorage) LogActionTrigger(ubId, source string, at *ActionTrigger, as Actions) (err error) {
func (self *SQLStorage) LogActionTrigger(ubId, source string, at *ActionTrigger, as Actions) (err error) {
return
}
func (sql *SQLStorage) LogActionTiming(source string, at *ActionTiming, as Actions) (err error) {
func (self *SQLStorage) LogActionTiming(source string, at *ActionTiming, as Actions) (err error) {
return
}
func (sql *SQLStorage) LogError(uuid, source, errstr string) (err error) { return }
func (self *SQLStorage) LogError(uuid, source, errstr string) (err error) { return }
func (sql *SQLStorage) SetCdr(cdr utils.CDR) (err error) {
func (self *SQLStorage) SetCdr(cdr utils.CDR) (err error) {
startTime, err := cdr.GetAnswerTime()
if err != nil {
return err
}
_, err = sql.Db.Exec(fmt.Sprintf("INSERT INTO cdrs_primary VALUES (NULL, '%s', '%s','%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)",
_, err = self.Db.Exec(fmt.Sprintf("INSERT INTO cdrs_primary VALUES (NULL, '%s', '%s','%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)",
cdr.GetCgrId(),
cdr.GetAccId(),
cdr.GetCdrHost(),
@@ -208,7 +262,7 @@ func (sql *SQLStorage) SetCdr(cdr utils.CDR) (err error) {
if err != nil {
Logger.Err(fmt.Sprintf("Error marshalling cdr extra fields to json: %v", err))
}
_, err = sql.Db.Exec(fmt.Sprintf("INSERT INTO cdrs_extra VALUES ('NULL','%s', '%s')",
_, err = self.Db.Exec(fmt.Sprintf("INSERT INTO cdrs_extra VALUES ('NULL','%s', '%s')",
cdr.GetCgrId(),
extraFields,
))
@@ -219,8 +273,8 @@ func (sql *SQLStorage) SetCdr(cdr utils.CDR) (err error) {
return
}
func (sql *SQLStorage) SetRatedCdr(cdr utils.CDR, cc *CallCost) (err error) {
_, err = sql.Db.Exec(fmt.Sprintf("INSERT INTO rated_cdrs VALUES ('%s', '%s', '%s', '%s')",
func (self *SQLStorage) SetRatedCdr(cdr utils.CDR, cc *CallCost) (err error) {
_, err = self.Db.Exec(fmt.Sprintf("INSERT INTO rated_cdrs VALUES ('%s', '%s', '%s', '%s')",
cdr.GetCgrId(),
cc.Cost,
"cgrcostid",
@@ -233,17 +287,17 @@ func (sql *SQLStorage) SetRatedCdr(cdr utils.CDR, cc *CallCost) (err error) {
return
}
func (sql *SQLStorage) GetAllRatedCdr() ([]utils.CDR, error) {
func (self *SQLStorage) GetAllRatedCdr() ([]utils.CDR, error) {
return nil, nil
}
func (sql *SQLStorage) GetTpDestinations(tpid, tag string) ([]*Destination, error) {
func (self *SQLStorage) GetTpDestinations(tpid, tag string) ([]*Destination, error) {
var dests []*Destination
q := fmt.Sprintf("SELECT * FROM %s WHERE tpid=%s", utils.TBL_TP_DESTINATIONS, tpid)
if tag != "" {
q += "AND tag=" + tag
}
rows, err := sql.Db.Query(q, tpid)
rows, err := self.Db.Query(q, tpid)
if err != nil {
return nil, err
}
@@ -269,13 +323,13 @@ func (sql *SQLStorage) GetTpDestinations(tpid, tag string) ([]*Destination, erro
return dests, rows.Err()
}
func (sql *SQLStorage) GetTpRates(tpid, tag string) (map[string]*Rate, error) {
func (self *SQLStorage) GetTpRates(tpid, tag string) (map[string]*Rate, error) {
rts := make(map[string]*Rate)
q := fmt.Sprintf("SELECT * FROM %s WHERE tpid=%s", utils.TBL_TP_RATES, tpid)
if tag != "" {
q += "AND tag=" + tag
}
rows, err := sql.Db.Query(q, tpid)
rows, err := self.Db.Query(q, tpid)
if err != nil {
return nil, err
}
@@ -300,13 +354,13 @@ func (sql *SQLStorage) GetTpRates(tpid, tag string) (map[string]*Rate, error) {
return rts, rows.Err()
}
func (sql *SQLStorage) GetTpDestinationRates(tpid, tag string) (map[string][]*DestinationRate, error) {
func (self *SQLStorage) GetTpDestinationRates(tpid, tag string) (map[string][]*DestinationRate, error) {
rts := make(map[string][]*DestinationRate)
q := fmt.Sprintf("SELECT * FROM %s WHERE tpid=%s", utils.TBL_TP_DESTINATION_RATES, tpid)
if tag != "" {
q += "AND tag=" + tag
}
rows, err := sql.Db.Query(q, tpid)
rows, err := self.Db.Query(q, tpid)
if err != nil {
return nil, err
}
@@ -328,13 +382,13 @@ func (sql *SQLStorage) GetTpDestinationRates(tpid, tag string) (map[string][]*De
return rts, rows.Err()
}
func (sql *SQLStorage) GetTpTimings(tpid, tag string) (map[string]*Timing, error) {
func (self *SQLStorage) GetTpTimings(tpid, tag string) (map[string]*Timing, error) {
tms := make(map[string]*Timing)
q := fmt.Sprintf("SELECT * FROM %s WHERE tpid=%s", utils.TBL_TP_TIMINGS, tpid)
if tag != "" {
q += "AND tag=" + tag
}
rows, err := sql.Db.Query(q, tpid)
rows, err := self.Db.Query(q, tpid)
if err != nil {
return nil, err
}
@@ -344,18 +398,18 @@ func (sql *SQLStorage) GetTpTimings(tpid, tag string) (map[string]*Timing, error
if err := rows.Scan(&id, &tpid, &tag, &years, &months, &month_days, &week_days, &start_time); err != nil {
return nil, err
}
tms[tag] = NewTiming(years, months, month_days, week_days, start_time)
tms[tag] = NewTiming(tag, years, months, month_days, week_days, start_time)
}
return tms, rows.Err()
}
func (sql *SQLStorage) GetTpDestinationRateTimings(tpid, tag string) ([]*DestinationRateTiming, error) {
func (self *SQLStorage) GetTpDestinationRateTimings(tpid, tag string) ([]*DestinationRateTiming, error) {
var rts []*DestinationRateTiming
q := fmt.Sprintf("SELECT * FROM %s WHERE tpid=%s", utils.TBL_TP_DESTINATION_RATE_TIMINGS, tpid)
if tag != "" {
q += "AND tag=" + tag
}
rows, err := sql.Db.Query(q, tpid)
rows, err := self.Db.Query(q, tpid)
if err != nil {
return nil, err
}
@@ -377,13 +431,13 @@ func (sql *SQLStorage) GetTpDestinationRateTimings(tpid, tag string) ([]*Destina
return rts, rows.Err()
}
func (sql *SQLStorage) GetTpRatingProfiles(tpid, tag string) (map[string]*RatingProfile, error) {
func (self *SQLStorage) GetTpRatingProfiles(tpid, tag string) (map[string]*RatingProfile, error) {
rpfs := make(map[string]*RatingProfile)
q := fmt.Sprintf("SELECT * FROM %s WHERE tpid=%s", utils.TBL_TP_RATE_PROFILES, tpid)
if tag != "" {
q += "AND tag=" + tag
}
rows, err := sql.Db.Query(q, tpid)
rows, err := self.Db.Query(q, tpid)
if err != nil {
return nil, err
}
@@ -408,13 +462,13 @@ func (sql *SQLStorage) GetTpRatingProfiles(tpid, tag string) (map[string]*Rating
}
return rpfs, rows.Err()
}
func (sql *SQLStorage) GetTpActions(tpid, tag string) (map[string][]*Action, error) {
func (self *SQLStorage) GetTpActions(tpid, tag string) (map[string][]*Action, error) {
as := make(map[string][]*Action)
q := fmt.Sprintf("SELECT * FROM %s WHERE tpid=%s", utils.TBL_TP_ACTIONS, tpid)
if tag != "" {
q += "AND tag=" + tag
}
rows, err := sql.Db.Query(q, tpid)
rows, err := self.Db.Query(q, tpid)
if err != nil {
return nil, err
}
@@ -461,13 +515,13 @@ func (sql *SQLStorage) GetTpActions(tpid, tag string) (map[string][]*Action, err
return as, rows.Err()
}
func (sql *SQLStorage) GetTpActionTimings(tpid, tag string) (ats map[string][]*ActionTiming, err error) {
func (self *SQLStorage) GetTpActionTimings(tpid, tag string) (ats map[string][]*ActionTiming, err error) {
ats = make(map[string][]*ActionTiming)
q := fmt.Sprintf("SELECT * FROM %s WHERE tpid=%s", utils.TBL_TP_ACTION_TIMINGS, tpid)
if tag != "" {
q += "AND tag=" + tag
}
rows, err := sql.Db.Query(q, tpid)
rows, err := self.Db.Query(q, tpid)
if err != nil {
return nil, err
}
@@ -490,13 +544,13 @@ func (sql *SQLStorage) GetTpActionTimings(tpid, tag string) (ats map[string][]*A
return ats, rows.Err()
}
func (sql *SQLStorage) GetTpActionTriggers(tpid, tag string) (map[string][]*ActionTrigger, error) {
func (self *SQLStorage) GetTpActionTriggers(tpid, tag string) (map[string][]*ActionTrigger, error) {
ats := make(map[string][]*ActionTrigger)
q := fmt.Sprintf("SELECT * FROM %s WHERE tpid=%s", utils.TBL_TP_ACTION_TRIGGERS, tpid)
if tag != "" {
q += "AND tag=" + tag
}
rows, err := sql.Db.Query(q, tpid)
rows, err := self.Db.Query(q, tpid)
if err != nil {
return nil, err
}
@@ -522,13 +576,13 @@ func (sql *SQLStorage) GetTpActionTriggers(tpid, tag string) (map[string][]*Acti
return ats, rows.Err()
}
func (sql *SQLStorage) GetTpAccountActions(tpid, tag string) ([]*AccountAction, error) {
func (self *SQLStorage) GetTpAccountActions(tpid, tag string) ([]*AccountAction, error) {
var acs []*AccountAction
q := fmt.Sprintf("SELECT * FROM %s WHERE tpid=%s", utils.TBL_TP_ACCOUNT_ACTIONS, tpid)
if tag != "" {
q += "AND tag=" + tag
}
rows, err := sql.Db.Query(q, tpid)
rows, err := self.Db.Query(q, tpid)
if err != nil {
return nil, err
}