diff --git a/apier/v1/tp.go b/apier/v1/tp.go index b08459f6b..42291c5ff 100644 --- a/apier/v1/tp.go +++ b/apier/v1/tp.go @@ -21,6 +21,7 @@ package v1 // Tariff plan related APIs import ( + "encoding/base64" "io/ioutil" "os" "path/filepath" @@ -97,3 +98,76 @@ func (self *ApierV1) ImportTPZipFile(attrs AttrImportTPZipFile, reply *string) e *reply = utils.OK return nil } + +type AttrRemTp struct { + TPid string +} + +func (self *ApierV1) RemTP(attrs AttrRemTp, reply *string) error { + if len(attrs.TPid) == 0 { + return utils.NewErrMandatoryIeMissing("TPid") + } + if err := self.StorDb.RemTpData("", attrs.TPid, nil); err != nil { + return utils.NewErrServerError(err) + } else { + *reply = utils.OK + } + return nil +} + +func (self *ApierV1) ExportTPToFolder(attrs utils.AttrDirExportTP, exported *utils.ExportedTPStats) error { + if attrs.TPid == nil || *attrs.TPid == "" { + return utils.NewErrMandatoryIeMissing("TPid") + } + dir := self.Config.TpExportPath + if attrs.ExportPath != nil { + dir = *attrs.ExportPath + } + fileFormat := utils.CSV + if attrs.FileFormat != nil { + fileFormat = *attrs.FileFormat + } + sep := "," + if attrs.FieldSeparator != nil { + sep = *attrs.FieldSeparator + } + compress := false + if attrs.Compress != nil { + compress = *attrs.Compress + } + tpExporter, err := engine.NewTPExporter(self.StorDb, *attrs.TPid, dir, fileFormat, sep, compress) + if err != nil { + return utils.NewErrServerError(err) + } + if err := tpExporter.Run(); err != nil { + return utils.NewErrServerError(err) + } else { + *exported = *tpExporter.ExportStats() + } + + return nil +} + +func (self *ApierV1) ExportTPToZipString(attrs utils.AttrDirExportTP, reply *string) error { + if attrs.TPid == nil || *attrs.TPid == "" { + return utils.NewErrMandatoryIeMissing("TPid") + } + dir := "" + fileFormat := utils.CSV + if attrs.FileFormat != nil { + fileFormat = *attrs.FileFormat + } + sep := "," + if attrs.FieldSeparator != nil { + sep = *attrs.FieldSeparator + } + tpExporter, err := engine.NewTPExporter(self.StorDb, *attrs.TPid, dir, fileFormat, sep, true) + if err != nil { + return utils.NewErrServerError(err) + } + if err := tpExporter.Run(); err != nil { + return utils.NewErrServerError(err) + } + *reply = base64.StdEncoding.EncodeToString(tpExporter.GetCacheBuffer().Bytes()) + return nil +} diff --git a/apier/v1/tpaccountactions_it_test.go b/apier/v1/tpaccountactions_it_test.go index d0dbe4a18..1f99901c6 100644 --- a/apier/v1/tpaccountactions_it_test.go +++ b/apier/v1/tpaccountactions_it_test.go @@ -73,7 +73,7 @@ func TestTPAccActionsITMongo(t *testing.T) { } } -func TestTTPAccActionsITPG(t *testing.T) { +func TestTPAccActionsITPG(t *testing.T) { tpAccActionsConfigDIR = "tutpostgres" for _, stest := range sTestsTPAccActions { t.Run(tpAccActionsConfigDIR, stest) diff --git a/apier/v2/tp.go b/apier/v2/tp.go deleted file mode 100644 index 2513f87f0..000000000 --- a/apier/v2/tp.go +++ /dev/null @@ -1,99 +0,0 @@ -/* -Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments -Copyright (C) ITsysCOM GmbH - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see -*/ - -package v2 - -import ( - "encoding/base64" - - "github.com/cgrates/cgrates/engine" - "github.com/cgrates/cgrates/utils" -) - -type AttrRemTp struct { - TPid string -} - -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, nil); err != nil { - return utils.NewErrServerError(err) - } else { - *reply = utils.OK - } - return nil -} - -func (self *ApierV2) ExportTPToFolder(attrs utils.AttrDirExportTP, exported *utils.ExportedTPStats) error { - if attrs.TPid == nil || *attrs.TPid == "" { - return utils.NewErrMandatoryIeMissing("TPid") - } - dir := self.Config.TpExportPath - if attrs.ExportPath != nil { - dir = *attrs.ExportPath - } - fileFormat := utils.CSV - if attrs.FileFormat != nil { - fileFormat = *attrs.FileFormat - } - sep := "," - if attrs.FieldSeparator != nil { - sep = *attrs.FieldSeparator - } - compress := false - if attrs.Compress != nil { - compress = *attrs.Compress - } - tpExporter, err := engine.NewTPExporter(self.StorDb, *attrs.TPid, dir, fileFormat, sep, compress) - if err != nil { - return utils.NewErrServerError(err) - } - if err := tpExporter.Run(); err != nil { - return utils.NewErrServerError(err) - } else { - *exported = *tpExporter.ExportStats() - } - - return nil -} - -func (self *ApierV2) ExportTPToZipString(attrs utils.AttrDirExportTP, reply *string) error { - if attrs.TPid == nil || *attrs.TPid == "" { - return utils.NewErrMandatoryIeMissing("TPid") - } - dir := "" - fileFormat := utils.CSV - if attrs.FileFormat != nil { - fileFormat = *attrs.FileFormat - } - sep := "," - if attrs.FieldSeparator != nil { - sep = *attrs.FieldSeparator - } - tpExporter, err := engine.NewTPExporter(self.StorDb, *attrs.TPid, dir, fileFormat, sep, true) - if err != nil { - return utils.NewErrServerError(err) - } - if err := tpExporter.Run(); err != nil { - return utils.NewErrServerError(err) - } - *reply = base64.StdEncoding.EncodeToString(tpExporter.GetCacheBuffer().Bytes()) - return nil -}