mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-24 08:38:45 +05:00
Improvements on CDRC Xml parser, goxpath to dependencies list, test for float64 in FSCDR
This commit is contained in:
49
cdrc/xml.go
49
cdrc/xml.go
@@ -18,18 +18,53 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
package cdrc
|
||||
|
||||
//import
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/xml"
|
||||
"io"
|
||||
"path"
|
||||
|
||||
"github.com/ChrisTrenkamp/goxpath"
|
||||
"github.com/ChrisTrenkamp/goxpath/tree"
|
||||
"github.com/ChrisTrenkamp/goxpath/tree/xmltree"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
)
|
||||
|
||||
type XMLRecordsProcessor struct {
|
||||
}
|
||||
|
||||
func (xmlProc *XMLRecordsProcessor) ProcessNextRecord() ([]*engine.CDR, error) {
|
||||
func NewXMLRecordsProcessor(recordsReader io.Reader) (*XMLRecordsProcessor, error) {
|
||||
xp, err := goxpath.Parse(path.Join("/broadWorksCDR/cdrData/"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
optsNotStrict := func(s *xmltree.ParseOptions) {
|
||||
s.Strict = false
|
||||
}
|
||||
xmlNode, err := xmltree.ParseXML(recordsReader, optsNotStrict)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
xmlProc := new(XMLRecordsProcessor)
|
||||
xmlProc.cdrXmlElmts = goxpath.MustExec(xp, xmlNode, nil)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (xmlProc *XMLRecordsProcessor) ProcessedRecordsNr() int64 {
|
||||
return 0
|
||||
type XMLRecordsProcessor struct {
|
||||
cdrXmlElmts []tree.Res // result of splitting the XML doc into CDR elements
|
||||
procItems int // current number of processed records from file
|
||||
}
|
||||
|
||||
func (xmlProc *XMLRecordsProcessor) ProcessedRecordsNr() int64 {
|
||||
return int64(xmlProc.procItems)
|
||||
}
|
||||
|
||||
func (xmlProc *XMLRecordsProcessor) ProcessNextRecord() (cdrs []*engine.CDR, err error) {
|
||||
if len(xmlProc.cdrXmlElmts) <= xmlProc.procItems {
|
||||
return nil, io.EOF // have processed all items
|
||||
}
|
||||
cdrXml := xmlProc.cdrXmlElmts[xmlProc.procItems]
|
||||
xmlProc.procItems += 1
|
||||
cdrBuf := bytes.NewBufferString(xml.Header)
|
||||
if err := goxpath.Marshal(cdrXml.(tree.Node), cdrBuf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -97,6 +98,10 @@ func (fsCdr FSCdr) searchExtraField(field string, body map[string]interface{}) (
|
||||
if key == field {
|
||||
return v
|
||||
}
|
||||
case float64:
|
||||
if key == field {
|
||||
return strconv.FormatFloat(v, 'f', -1, 64)
|
||||
}
|
||||
case map[string]interface{}:
|
||||
if result = fsCdr.searchExtraField(field, v); result != "" {
|
||||
return
|
||||
|
||||
@@ -83,6 +83,7 @@ func TestSearchExtraField(t *testing.T) {
|
||||
extraFields["injected_hdr"] != "injected_value" {
|
||||
t.Error("Error parsing extra fields: ", extraFields)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestSearchExtraFieldInSlice(t *testing.T) {
|
||||
@@ -91,6 +92,9 @@ func TestSearchExtraFieldInSlice(t *testing.T) {
|
||||
if value != "ringback=%(2000,4000,440,480)" {
|
||||
t.Error("Error finding extra field: ", value)
|
||||
}
|
||||
if value := fsCdr.searchExtraField("floatfld1", map[string]interface{}{"floatfld1": 6.4}); value != "6.4" {
|
||||
t.Errorf("Expecting: 6.4, received: %s", value)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSearchReplaceInExtraFields(t *testing.T) {
|
||||
|
||||
21
glide.lock
generated
21
glide.lock
generated
@@ -1,8 +1,6 @@
|
||||
hash: 5c488630d1d32687b7a3c3b22c47ceaf7eb3cffb764799706728a6accbcd3ff5
|
||||
updated: 2016-04-26T18:00:43.651987521+03:00
|
||||
hash: 3140edeb6e77689465bafe5508a04afb78246b5f126488aa6db99f4984c4bbed
|
||||
updated: 2016-05-06T12:33:12.628779842+02:00
|
||||
imports:
|
||||
- name: github.com/cenkalti/hub
|
||||
version: b864404b5f990410d56858a1b0a6fac23a85443f
|
||||
- name: github.com/cenkalti/rpc2
|
||||
version: 2d1be381ce47537e9e076b2b76dc70933162e4e9
|
||||
- name: github.com/cgrates/fsock
|
||||
@@ -13,6 +11,8 @@ imports:
|
||||
version: 3d6beed663452471dec3ca194137a30d379d9e8f
|
||||
- name: github.com/cgrates/rpcclient
|
||||
version: 9a6185f8a2093ce10f1a08242b0d757f24795800
|
||||
- name: github.com/ChrisTrenkamp/goxpath
|
||||
version: 4aad8d0161aae7d17df4755d2c1e86cd1fcaaab6
|
||||
- name: github.com/DisposaBoy/JsonConfigReader
|
||||
version: 33a99fdf1d5ee1f79b5077e9c06f955ad356d5f4
|
||||
- name: github.com/fiorix/go-diameter
|
||||
@@ -23,22 +23,16 @@ imports:
|
||||
- diam/datatype
|
||||
- diam/dict
|
||||
- diam/sm
|
||||
- diam/sm/smparser
|
||||
- diam/sm/smpeer
|
||||
- name: github.com/go-sql-driver/mysql
|
||||
version: 7ebe0a500653eeb1859664bed5e48dec1e164e73
|
||||
- name: github.com/gorhill/cronexpr
|
||||
version: f0984319b44273e83de132089ae42b1810f4933b
|
||||
- name: github.com/jinzhu/gorm
|
||||
version: 5174cc5c242a728b435ea2be8a2f7f998e15429b
|
||||
- name: github.com/jinzhu/inflection
|
||||
version: 3272df6c21d04180007eb3349844c89a3856bc25
|
||||
- name: github.com/kr/pty
|
||||
version: f7ee69f31298ecbe5d2b349c711e2547a617d398
|
||||
- name: github.com/lib/pq
|
||||
version: 3cd0097429be7d611bb644ef85b42bfb102ceea4
|
||||
subpackages:
|
||||
- oid
|
||||
- name: github.com/mediocregopher/radix.v2
|
||||
version: 74e50e64194d2d2f4836212451c28b127f9d7fa1
|
||||
subpackages:
|
||||
@@ -54,17 +48,10 @@ imports:
|
||||
version: b797637b7aeeed133049c7281bfa31dcc9ca42d6
|
||||
subpackages:
|
||||
- websocket
|
||||
- context
|
||||
- name: golang.org/x/sys
|
||||
version: f64b50fbea64174967a8882830d621a18ee1548e
|
||||
subpackages:
|
||||
- unix
|
||||
- name: gopkg.in/fsnotify.v1
|
||||
version: 30411dbcefb7a1da7e84f75530ad3abe4011b4f8
|
||||
- name: gopkg.in/mgo.v2
|
||||
version: b6e2fa371e64216a45e61072a96d4e3859f169da
|
||||
subpackages:
|
||||
- bson
|
||||
- internal/sasl
|
||||
- internal/scram
|
||||
devImports: []
|
||||
|
||||
@@ -33,3 +33,4 @@ import:
|
||||
- package: gopkg.in/mgo.v2
|
||||
subpackages:
|
||||
- bson
|
||||
- package: github.com/ChrisTrenkamp/goxpath
|
||||
|
||||
Reference in New Issue
Block a user