mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 13:19:53 +05:00
Write out on tpattributes
This commit is contained in:
committed by
Dan Christian Bogos
parent
8cb837b39c
commit
e56ce31509
@@ -19,6 +19,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package tpes
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/csv"
|
||||
"fmt"
|
||||
|
||||
"github.com/cgrates/birpc/context"
|
||||
@@ -50,8 +52,8 @@ func (tpAttr TPAttributes) exportItems(ctx *context.Context, tnt string, itmIDs
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
var attrMdl []interface{}
|
||||
attrMdl = engine.APItoModelTPAttribute(engine.AttributeProfileToAPI(attrPrf))
|
||||
|
||||
attrMdl := engine.APItoModelTPAttribute(engine.AttributeProfileToAPI(attrPrf))
|
||||
if err := writeOut(utils.AttributesCsv, attrMdl); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -59,3 +61,20 @@ func (tpAttr TPAttributes) exportItems(ctx *context.Context, tnt string, itmIDs
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func writeOut(fileName string, tpData engine.AttributeMdls) error {
|
||||
buff := new(bytes.Buffer)
|
||||
|
||||
csvWriter := csv.NewWriter(buff)
|
||||
for _, tpItem := range tpData {
|
||||
record, err := engine.CsvDump(tpItem)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := csvWriter.Write(record); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -19,9 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package tpes
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/csv"
|
||||
|
||||
"github.com/cgrates/birpc/context"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
@@ -55,21 +52,3 @@ func newTPExporter(expType string, dm *engine.DataManager) (tpE tpExporter, err
|
||||
return nil, utils.ErrPrefix(utils.ErrUnsupportedTPExporterType, expType)
|
||||
}
|
||||
}
|
||||
|
||||
func writeOut(fileName string, tpData []interface{}) error {
|
||||
buff := new(bytes.Buffer)
|
||||
|
||||
csvWriter := csv.NewWriter(buff)
|
||||
for _, tpItem := range tpData {
|
||||
record, err := engine.CsvDump(tpItem)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := csvWriter.Write(record); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
utils.Logger.Debug(buff.String())
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user