Write out on tpattributes

This commit is contained in:
porosnicuadrian
2022-03-08 17:30:16 +02:00
committed by Dan Christian Bogos
parent 8cb837b39c
commit e56ce31509
2 changed files with 21 additions and 23 deletions

View File

@@ -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
}

View File

@@ -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
}