diff --git a/agents/agentreq.go b/agents/agentreq.go index 5da832fad..6b8a71760 100644 --- a/agents/agentreq.go +++ b/agents/agentreq.go @@ -33,18 +33,18 @@ import ( // NewAgentRequest returns a new AgentRequest func NewAgentRequest(req utils.DataProvider, - vars utils.NavigableMap2, - cgrRply *utils.NavigableMap2, + vars utils.NavigableMap, + cgrRply *utils.NavigableMap, rply, opts *utils.OrderedNavigableMap, tntTpl config.RSRParsers, dfltTenant, timezone string, filterS *engine.FilterS, header, trailer utils.DataProvider) (ar *AgentRequest) { if cgrRply == nil { - cgrRply = &utils.NavigableMap2{} + cgrRply = &utils.NavigableMap{} } if vars == nil { - vars = make(utils.NavigableMap2) + vars = make(utils.NavigableMap) } if rply == nil { rply = utils.NewOrderedNavigableMap() @@ -82,9 +82,9 @@ func NewAgentRequest(req utils.DataProvider, // implements utils.DataProvider so we can pass it to filters type AgentRequest struct { Request utils.DataProvider // request - Vars utils.NavigableMap2 // shared data + Vars utils.NavigableMap // shared data CGRRequest *utils.OrderedNavigableMap // Used in reply to access the request that was send - CGRReply *utils.NavigableMap2 + CGRReply *utils.NavigableMap Reply *utils.OrderedNavigableMap Tenant string Timezone string @@ -92,7 +92,7 @@ type AgentRequest struct { Header utils.DataProvider Trailer utils.DataProvider diamreq *utils.OrderedNavigableMap // used in case of building requests (ie. DisconnectSession) - tmp utils.NavigableMap2 // used in case you want to store temporary items and access them later + tmp utils.NavigableMap // used in case you want to store temporary items and access them later Opts *utils.OrderedNavigableMap Cfg utils.DataProvider } @@ -184,7 +184,7 @@ func (ar *AgentRequest) FieldAsString(fldPath []string) (val string, err error) //SetFields will populate fields of AgentRequest out of templates func (ar *AgentRequest) SetFields(tplFlds []*config.FCTemplate) (err error) { - ar.tmp = utils.NavigableMap2{} + ar.tmp = utils.NavigableMap{} for _, tplFld := range tplFlds { if pass, err := ar.filterS.Pass(ar.Tenant, tplFld.Filters, ar); err != nil { @@ -295,17 +295,17 @@ func (ar *AgentRequest) RemoveAll(prefix string) error { default: return fmt.Errorf("unsupported field prefix: <%s> when set fields", prefix) case utils.MetaVars: - ar.Vars = utils.NavigableMap2{} + ar.Vars = utils.NavigableMap{} case utils.MetaCgreq: ar.CGRRequest.RemoveAll() case utils.MetaCgrep: - ar.CGRReply = &utils.NavigableMap2{} + ar.CGRReply = &utils.NavigableMap{} case utils.MetaRep: ar.Reply.RemoveAll() case utils.MetaDiamreq: ar.diamreq.RemoveAll() case utils.MetaTmp: - ar.tmp = utils.NavigableMap2{} + ar.tmp = utils.NavigableMap{} case utils.MetaUCH: engine.Cache.Clear([]string{utils.CacheUCH}) case utils.MetaOpts: @@ -509,11 +509,11 @@ func (ar *AgentRequest) ParseField( // setCGRReply will set the aReq.cgrReply based on reply coming from upstream or error // returns error in case of reply not converting to NavigableMap func (ar *AgentRequest) setCGRReply(rply utils.NavigableMapper, errRply error) (err error) { - var nm utils.NavigableMap2 + var nm utils.NavigableMap if errRply != nil { - nm = utils.NavigableMap2{utils.Error: utils.NewNMData(errRply.Error())} + nm = utils.NavigableMap{utils.Error: utils.NewNMData(errRply.Error())} } else { - nm = utils.NavigableMap2{} + nm = utils.NavigableMap{} if rply != nil { nm = rply.AsNavigableMap() } diff --git a/agents/agentreq_test.go b/agents/agentreq_test.go index fef1b2c7a..c465ed772 100644 --- a/agents/agentreq_test.go +++ b/agents/agentreq_test.go @@ -54,8 +54,8 @@ func TestAgReqSetFields(t *testing.T) { agReq.CGRRequest.Set(&utils.FullPath{Path: utils.RequestType, PathItems: utils.PathItems{{Field: utils.RequestType}}}, utils.NewNMData(utils.MetaPrepaid)) agReq.CGRRequest.Set(&utils.FullPath{Path: utils.Usage, PathItems: utils.PathItems{{Field: utils.Usage}}}, utils.NewNMData(3*time.Minute)) - cgrRply := utils.NavigableMap2{ - utils.CapAttributes: utils.NavigableMap2{ + cgrRply := utils.NavigableMap{ + utils.CapAttributes: utils.NavigableMap{ "PaypalAccount": utils.NewNMData("cgrates@paypal.com"), }, utils.CapMaxUsage: utils.NewNMData(120 * time.Second), @@ -498,7 +498,7 @@ func TestAgReqMaxCost(t *testing.T) { // populate request, emulating the way will be done in HTTPAgent agReq.CGRRequest.Set(&utils.FullPath{Path: utils.CapMaxUsage, PathItems: utils.PathItems{{Field: utils.CapMaxUsage}}}, utils.NewNMData("120s")) - cgrRply := utils.NavigableMap2{ + cgrRply := utils.NavigableMap{ utils.CapMaxUsage: utils.NewNMData(120 * time.Second), } agReq.CGRReply = &cgrRply @@ -759,7 +759,7 @@ func TestAgReqEmptyFilter(t *testing.T) { for _, v := range tplFlds { v.ComputePath() } - eMp := &utils.NavigableMap2{} + eMp := &utils.NavigableMap{} eMp.Set(utils.PathItems{{Field: utils.Tenant}}, &utils.NMSlice{ &config.NMItem{Data: "cgrates.org", Path: []string{utils.Tenant}, Config: tplFlds[0]}}) @@ -792,7 +792,7 @@ func TestAgReqMetaExponent(t *testing.T) { Value: config.NewRSRParsersMustCompile("~*cgreq.Value;~*cgreq.Exponent", utils.InfieldSep)}, } tplFlds[0].ComputePath() - eMp := &utils.NavigableMap2{} + eMp := &utils.NavigableMap{} eMp.Set(utils.PathItems{{Field: "TestExpo"}}, &utils.NMSlice{ &config.NMItem{Data: "200", Path: []string{"TestExpo"}, Config: tplFlds[0]}}) @@ -830,7 +830,7 @@ func TestAgReqFieldAsNone(t *testing.T) { for _, v := range tplFlds { v.ComputePath() } - eMp := &utils.NavigableMap2{} + eMp := &utils.NavigableMap{} eMp.Set(utils.PathItems{{Field: utils.Tenant}}, &utils.NMSlice{ &config.NMItem{Data: "cgrates.org", Path: []string{utils.Tenant}, Config: tplFlds[0]}}) @@ -870,7 +870,7 @@ func TestAgReqFieldAsNone2(t *testing.T) { for _, v := range tplFlds { v.ComputePath() } - eMp := &utils.NavigableMap2{} + eMp := &utils.NavigableMap{} eMp.Set(utils.PathItems{{Field: utils.Tenant}}, &utils.NMSlice{ &config.NMItem{Data: "cgrates.org", Path: []string{utils.Tenant}, Config: tplFlds[0]}}) @@ -901,7 +901,7 @@ func TestAgReqSetField2(t *testing.T) { time.Date(2013, 12, 30, 15, 0, 1, 0, time.UTC))) agReq.CGRRequest.Set(&utils.FullPath{Path: utils.RequestType, PathItems: utils.PathItems{{Field: utils.RequestType}}}, utils.NewNMData(utils.MetaPrepaid)) - agReq.CGRReply = &utils.NavigableMap2{} + agReq.CGRReply = &utils.NavigableMap{} tplFlds := []*config.FCTemplate{ {Tag: "Tenant", @@ -924,7 +924,7 @@ func TestAgReqSetField2(t *testing.T) { for _, v := range tplFlds { v.ComputePath() } - eMp := &utils.NavigableMap2{} + eMp := &utils.NavigableMap{} eMp.Set(utils.PathItems{{Field: utils.Tenant}}, &utils.NMSlice{ &config.NMItem{Data: "cgrates.org", Path: []string{utils.Tenant}, Config: tplFlds[0]}}) @@ -1009,8 +1009,8 @@ func TestAgReqNewARWithCGRRplyAndRply(t *testing.T) { {Field: "SecondLevel"}, {Field: "Fld1"}, }}, utils.NewNMData("Val1")) - cgrRply := &utils.NavigableMap2{ - utils.CapAttributes: utils.NavigableMap2{ + cgrRply := &utils.NavigableMap{ + utils.CapAttributes: utils.NavigableMap{ "PaypalAccount": utils.NewNMData("cgrates@paypal.com"), }, utils.CapMaxUsage: utils.NewNMData(120 * time.Second), @@ -1084,8 +1084,8 @@ func TestAgReqSetCGRReplyWithError(t *testing.T) { type myEv map[string]utils.NMInterface -func (ev myEv) AsNavigableMap() utils.NavigableMap2 { - return utils.NavigableMap2(ev) +func (ev myEv) AsNavigableMap() utils.NavigableMap { + return utils.NavigableMap(ev) } func TestAgReqSetCGRReplyWithoutError(t *testing.T) { @@ -1104,7 +1104,7 @@ func TestAgReqSetCGRReplyWithoutError(t *testing.T) { }}, utils.NewNMData("Val1")) myEv := myEv{ - utils.CapAttributes: utils.NavigableMap2{ + utils.CapAttributes: utils.NavigableMap{ "PaypalAccount": utils.NewNMData("cgrates@paypal.com"), }, utils.CapMaxUsage: utils.NewNMData(120 * time.Second), @@ -1547,7 +1547,7 @@ func TestAgReqOverwrite(t *testing.T) { time.Date(2013, 12, 30, 15, 0, 1, 0, time.UTC))) agReq.CGRRequest.Set(&utils.FullPath{Path: utils.RequestType, PathItems: utils.PathItems{{Field: utils.RequestType}}}, utils.NewNMData(utils.MetaPrepaid)) - agReq.CGRReply = &utils.NavigableMap2{} + agReq.CGRReply = &utils.NavigableMap{} tplFlds := []*config.FCTemplate{ {Tag: "Account", @@ -1599,7 +1599,7 @@ func TestAgReqGroupType(t *testing.T) { time.Date(2013, 12, 30, 15, 0, 1, 0, time.UTC))) agReq.CGRRequest.Set(&utils.FullPath{Path: utils.RequestType, PathItems: utils.PathItems{{Field: utils.RequestType}}}, utils.NewNMData(utils.MetaPrepaid)) - agReq.CGRReply = &utils.NavigableMap2{} + agReq.CGRReply = &utils.NavigableMap{} tplFlds := []*config.FCTemplate{ {Tag: "Account", @@ -1648,7 +1648,7 @@ func TestAgReqSetFieldsInTmp(t *testing.T) { for _, v := range tplFlds { v.ComputePath() } - eMp := utils.NavigableMap2{} + eMp := utils.NavigableMap{} eMp.Set(utils.PathItems{{Field: utils.Tenant}}, &utils.NMSlice{ &config.NMItem{Data: "cgrates.org", Path: []string{utils.Tenant}, Config: tplFlds[0]}}) @@ -1679,7 +1679,7 @@ func TestAgReqSetFieldsIp2Hex(t *testing.T) { for _, v := range tplFlds { v.ComputePath() } - eMp := utils.NavigableMap2{} + eMp := utils.NavigableMap{} eMp.Set(utils.PathItems{{Field: "IP"}}, &utils.NMSlice{ &config.NMItem{Data: "0x3e5772f4", Path: []string{"IP"}, Config: tplFlds[0]}}) @@ -1707,7 +1707,7 @@ func TestAgReqSetFieldsString2Hex(t *testing.T) { for _, v := range tplFlds { v.ComputePath() } - eMp := utils.NavigableMap2{} + eMp := utils.NavigableMap{} eMp.Set(utils.PathItems{{Field: "CustomField"}}, &utils.NMSlice{ &config.NMItem{Data: "0x947102310159", Path: []string{"CustomField"}, Config: tplFlds[0]}}) @@ -1736,8 +1736,8 @@ func TestAgReqSetFieldsWithRemove(t *testing.T) { agReq.CGRRequest.Set(&utils.FullPath{Path: utils.RequestType, PathItems: utils.PathItems{{Field: utils.RequestType}}}, utils.NewNMData(utils.MetaPrepaid)) agReq.CGRRequest.Set(&utils.FullPath{Path: utils.Usage, PathItems: utils.PathItems{{Field: utils.Usage}}}, utils.NewNMData(3*time.Minute)) - agReq.CGRReply = &utils.NavigableMap2{ - utils.CapAttributes: utils.NavigableMap2{ + agReq.CGRReply = &utils.NavigableMap{ + utils.CapAttributes: utils.NavigableMap{ "PaypalAccount": utils.NewNMData("cgrates@paypal.com"), }, utils.CapMaxUsage: utils.NewNMData(120 * time.Second), @@ -2041,7 +2041,7 @@ func TestAgReqDynamicPath(t *testing.T) { agReq.CGRRequest.Set(&utils.FullPath{Path: "Routes.CGR_ROUTE2", PathItems: utils.PathItems{{Field: "Routes"}, {Field: "CGR_ROUTE2"}}}, utils.NewNMData(1002)) agReq.CGRRequest.Set(&utils.FullPath{Path: "BestRoute", PathItems: utils.PathItems{{Field: "BestRoute"}}}, utils.NewNMData("ROUTE1")) - agReq.CGRReply = &utils.NavigableMap2{} + agReq.CGRReply = &utils.NavigableMap{} val1, err := config.NewRSRParsersFromSlice([]string{"~*cgreq.Routes."}) if err != nil { t.Error(err) @@ -2071,7 +2071,7 @@ func TestAgReqDynamicPath(t *testing.T) { for _, v := range tplFlds { v.ComputePath() } - eMp := &utils.NavigableMap2{} + eMp := &utils.NavigableMap{} eMp.Set(utils.PathItems{{Field: utils.Tenant}}, &utils.NMSlice{ &config.NMItem{Data: "cgrates.org", Path: []string{utils.Tenant}, Config: tplFlds[0]}}) @@ -2113,7 +2113,7 @@ func TestAgReqRoundingDecimals(t *testing.T) { agReq.CGRRequest.Set(&utils.FullPath{Path: utils.RequestType, PathItems: utils.PathItems{{Field: utils.RequestType}}}, utils.NewNMData(utils.MetaPrepaid)) agReq.CGRRequest.Set(&utils.FullPath{Path: utils.Cost, PathItems: utils.PathItems{{Field: utils.Cost}}}, utils.NewNMData(12.12645)) - agReq.CGRReply = &utils.NavigableMap2{} + agReq.CGRReply = &utils.NavigableMap{} tplFlds := []*config.FCTemplate{ {Tag: "Cost", @@ -2169,14 +2169,14 @@ func BenchmarkAgReqSetField(b *testing.B) { for _, v := range tplFlds { v.ComputePath() } - eMp := &utils.NavigableMap2{} + eMp := &utils.NavigableMap{} eMp.Set(utils.PathItems{{Field: utils.Tenant}}, &utils.NMSlice{ &config.NMItem{Data: "cgrates.org", Path: []string{utils.Tenant}, Config: tplFlds[0]}}) - eMp.Set(utils.PathItems{{Field: utils.AccountField, Index: utils.StringPointer("0")}, {Field: "ID"}}, &utils.NMSlice{ + eMp.Set(utils.PathItems{{Field: utils.AccountField, Index: []string{"0"}}, {Field: "ID"}}, &utils.NMSlice{ &config.NMItem{Data: "1001", Path: []string{utils.AccountField + "[0]", "ID"}, Config: tplFlds[1]}}) - eMp.Set(utils.PathItems{{Field: utils.AccountField, Index: utils.StringPointer("1")}, {Field: "ID"}}, &utils.NMSlice{ + eMp.Set(utils.PathItems{{Field: utils.AccountField, Index: []string{"1"}}, {Field: "ID"}}, &utils.NMSlice{ &config.NMItem{Data: "1003", Path: []string{utils.AccountField + "[1]", "ID"}, Config: tplFlds[2]}}) @@ -2190,7 +2190,7 @@ func BenchmarkAgReqSetField(b *testing.B) { agReq.CGRRequest.Set(&utils.FullPath{Path: utils.AnswerTime, PathItems: utils.PathItems{{Field: utils.AnswerTime}}}, utils.NewNMData( time.Date(2013, 12, 30, 15, 0, 1, 0, time.UTC))) agReq.CGRRequest.Set(&utils.FullPath{Path: utils.RequestType, PathItems: utils.PathItems{{Field: utils.RequestType}}}, utils.NewNMData(utils.MetaPrepaid)) - agReq.CGRReply = &utils.NavigableMap2{} + agReq.CGRReply = &utils.NavigableMap{} if err := agReq.SetFields(tplFlds); err != nil { b.Error(err) diff --git a/agents/astagent.go b/agents/astagent.go index d6741a43a..1ee53acad 100644 --- a/agents/astagent.go +++ b/agents/astagent.go @@ -213,10 +213,10 @@ func (sma *AsteriskAgent) handleStasisStart(ev *SMAsteriskEvent) { return } } - if authReply.Routes != nil { - for i, route := range authReply.Routes.Routes { + if authReply.RouteProfiles != nil { + for i, route := range authReply.RouteProfiles.RouteIDs() { if !sma.setChannelVar(ev.ChannelID(), - CGRRoute+strconv.Itoa(i+1), route.RouteID) { + CGRRoute+strconv.Itoa(i+1), route) { return } } diff --git a/agents/diamagent.go b/agents/diamagent.go index 8b997d6bf..9ec8adb7b 100644 --- a/agents/diamagent.go +++ b/agents/diamagent.go @@ -198,7 +198,7 @@ func (da *DiameterAgent) handleMessage(c diam.Conn, m *diam.Message) { return } diamDP := newDADataProvider(c, m) - reqVars := utils.NavigableMap2{ + reqVars := utils.NavigableMap{ utils.OriginHost: utils.NewNMData(da.cgrCfg.DiameterAgentCfg().OriginHost), // used in templates utils.OriginRealm: utils.NewNMData(da.cgrCfg.DiameterAgentCfg().OriginRealm), utils.ProductName: utils.NewNMData(da.cgrCfg.DiameterAgentCfg().ProductName), @@ -258,7 +258,7 @@ func (da *DiameterAgent) handleMessage(c diam.Conn, m *diam.Message) { da.aReqsLck.Unlock() }() } - cgrRplyNM := utils.NavigableMap2{} + cgrRplyNM := utils.NavigableMap{} rply := utils.NewOrderedNavigableMap() // share it among different processors opts := utils.NewOrderedNavigableMap() var processed bool diff --git a/agents/diamagent_test.go b/agents/diamagent_test.go index 539c73515..7d42ecbe9 100644 --- a/agents/diamagent_test.go +++ b/agents/diamagent_test.go @@ -62,7 +62,7 @@ func TestProcessRequest(t *testing.T) { dm := engine.NewDataManager(data, config.CgrConfig().CacheCfg(), nil) filters := engine.NewFilterS(config.CgrConfig(), nil, dm) // no need for filterS but still try to configure the dm :D - cgrRplyNM := utils.NavigableMap2{} + cgrRplyNM := utils.NavigableMap{} rply := utils.NewOrderedNavigableMap() diamDP := utils.MapStorage{ "SessionId": "123456", @@ -112,7 +112,7 @@ func TestProcessRequest(t *testing.T) { for _, v := range reqProcessor.ReplyFields { v.ComputePath() } - reqVars := utils.NavigableMap2{ + reqVars := utils.NavigableMap{ utils.OriginHost: utils.NewNMData(config.CgrConfig().DiameterAgentCfg().OriginHost), utils.OriginRealm: utils.NewNMData(config.CgrConfig().DiameterAgentCfg().OriginRealm), utils.ProductName: utils.NewNMData(config.CgrConfig().DiameterAgentCfg().ProductName), @@ -467,7 +467,7 @@ func TestProcessRequest(t *testing.T) { } reqProcessor.Flags = utils.FlagsWithParamsFromSlice([]string{utils.MetaInitiate, utils.MetaAccounts, utils.MetaAttributes}) - cgrRplyNM = utils.NavigableMap2{} + cgrRplyNM = utils.NavigableMap{} rply = utils.NewOrderedNavigableMap() agReq = NewAgentRequest(diamDP, reqVars, &cgrRplyNM, rply, nil, @@ -484,7 +484,7 @@ func TestProcessRequest(t *testing.T) { } reqProcessor.Flags = utils.FlagsWithParamsFromSlice([]string{utils.MetaUpdate, utils.MetaAccounts, utils.MetaAttributes}) - cgrRplyNM = utils.NavigableMap2{} + cgrRplyNM = utils.NavigableMap{} rply = utils.NewOrderedNavigableMap() agReq = NewAgentRequest(diamDP, reqVars, &cgrRplyNM, rply, nil, @@ -507,7 +507,7 @@ func TestProcessRequest(t *testing.T) { for _, v := range reqProcessor.ReplyFields { v.ComputePath() } - cgrRplyNM = utils.NavigableMap2{} + cgrRplyNM = utils.NavigableMap{} rply = utils.NewOrderedNavigableMap() agReq = NewAgentRequest(diamDP, reqVars, &cgrRplyNM, rply, nil, @@ -524,7 +524,7 @@ func TestProcessRequest(t *testing.T) { } reqProcessor.Flags = utils.FlagsWithParamsFromSlice([]string{utils.MetaMessage, utils.MetaAccounts, utils.MetaAttributes}) - cgrRplyNM = utils.NavigableMap2{} + cgrRplyNM = utils.NavigableMap{} rply = utils.NewOrderedNavigableMap() agReq = NewAgentRequest(diamDP, reqVars, &cgrRplyNM, rply, nil, diff --git a/agents/dnsagent.go b/agents/dnsagent.go index 3c7625b4e..a97c7fb4a 100644 --- a/agents/dnsagent.go +++ b/agents/dnsagent.go @@ -89,7 +89,7 @@ func (da *DNSAgent) Reload() (err error) { // requests are reaching here asynchronously func (da *DNSAgent) handleMessage(w dns.ResponseWriter, req *dns.Msg) { dnsDP := newDNSDataProvider(req, w) - reqVars := make(utils.NavigableMap2) + reqVars := make(utils.NavigableMap) reqVars[QueryType] = utils.NewNMData(dns.TypeToString[req.Question[0].Qtype]) rply := new(dns.Msg) rply.SetReply(req) @@ -110,7 +110,7 @@ func (da *DNSAgent) handleMessage(w dns.ResponseWriter, req *dns.Msg) { reqVars[DomainName] = utils.NewNMData(domainNameFromNAPTR(req.Question[0].Name)) } reqVars[utils.RemoteHost] = utils.NewNMData(w.RemoteAddr().String()) - cgrRplyNM := utils.NavigableMap2{} + cgrRplyNM := utils.NavigableMap{} rplyNM := utils.NewOrderedNavigableMap() // share it among different processors opts := utils.NewOrderedNavigableMap() var processed bool diff --git a/agents/fsagent.go b/agents/fsagent.go index a17edf307..4279ea44d 100644 --- a/agents/fsagent.go +++ b/agents/fsagent.go @@ -194,8 +194,8 @@ func (fsa *FSsessions) onChannelPark(fsev FSEvent, connIdx int) { return } } - if authReply.Routes != nil { - fsArray := SliceAsFsArray(authReply.Routes.RoutesWithParams()) + if authReply.RouteProfiles != nil { + fsArray := SliceAsFsArray(authReply.RouteProfiles.RoutesWithParams()) if _, err := fsa.conns[connIdx].SendApiCmd(fmt.Sprintf("uuid_setvar %s %s %s\n\n", fsev.GetUUID(), utils.CGRRoutes, fsArray)); err != nil { utils.Logger.Info(fmt.Sprintf("<%s> error setting routes: %s", diff --git a/agents/httpagent.go b/agents/httpagent.go index 0755405b8..be5eb56d5 100644 --- a/agents/httpagent.go +++ b/agents/httpagent.go @@ -63,10 +63,10 @@ func (ha *HTTPAgent) ServeHTTP(w http.ResponseWriter, req *http.Request) { utils.HTTPAgent, err.Error())) return } - cgrRplyNM := utils.NavigableMap2{} + cgrRplyNM := utils.NavigableMap{} rplyNM := utils.NewOrderedNavigableMap() opts := utils.NewOrderedNavigableMap() - reqVars := utils.NavigableMap2{utils.RemoteHost: utils.NewNMData(req.RemoteAddr)} + reqVars := utils.NavigableMap{utils.RemoteHost: utils.NewNMData(req.RemoteAddr)} for _, reqProcessor := range ha.reqProcessors { agReq := NewAgentRequest(dcdr, reqVars, &cgrRplyNM, rplyNM, opts, reqProcessor.Tenant, ha.dfltTenant, diff --git a/agents/kamevent.go b/agents/kamevent.go index 22861c073..f5151a0b1 100644 --- a/agents/kamevent.go +++ b/agents/kamevent.go @@ -245,8 +245,8 @@ func (kev KamEvent) AsKamAuthReply(authArgs *sessions.V1AuthorizeArgs, kar.MaxUsage = 0 } } - if authArgs.GetRoutes && authReply.Routes != nil { - kar.Routes = authReply.Routes.Digest() + if authArgs.GetRoutes && authReply.RouteProfiles != nil { + kar.Routes = authReply.RouteProfiles.Digest() } if authArgs.ProcessThresholds && authReply.ThresholdIDs != nil { @@ -328,8 +328,8 @@ func (kev KamEvent) AsKamProcessMessageReply(procEvArgs *sessions.V1ProcessMessa if procEvArgs.Debit { kar.MaxUsage = int(utils.Round(procEvReply.MaxUsage.Seconds(), 0, utils.MetaRoundingMiddle)) } - if procEvArgs.GetRoutes && procEvReply.Routes != nil { - kar.Routes = procEvReply.Routes.Digest() + if procEvArgs.GetRoutes && procEvReply.RouteProfiles != nil { + kar.Routes = procEvReply.RouteProfiles.Digest() } if procEvArgs.ProcessThresholds { diff --git a/agents/libdiam.go b/agents/libdiam.go index fb1711815..fb66f992a 100644 --- a/agents/libdiam.go +++ b/agents/libdiam.go @@ -466,7 +466,7 @@ func diamAnswer(m *diam.Message, resCode uint32, errFlag bool, // negDiamAnswer is used to return the negative answer we need previous to func diamErr(m *diam.Message, resCode uint32, - reqVars utils.NavigableMap2, + reqVars utils.NavigableMap, tpl []*config.FCTemplate, tnt, tmz string, filterS *engine.FilterS) (a *diam.Message, err error) { aReq := NewAgentRequest( @@ -502,5 +502,5 @@ func disectDiamListen(addrs string) (ipAddrs []net.IP) { type diamMsgData struct { c diam.Conn m *diam.Message - vars utils.NavigableMap2 + vars utils.NavigableMap } diff --git a/agents/libsip.go b/agents/libsip.go index 5eb3cf26a..5b0aea0f6 100644 --- a/agents/libsip.go +++ b/agents/libsip.go @@ -50,7 +50,7 @@ func updateSIPMsgFromNavMap(m sipingo.Message, navMp *utils.OrderedNavigableMap) } func sipErr(m utils.DataProvider, sipMessage sipingo.Message, - reqVars utils.NavigableMap2, + reqVars utils.NavigableMap, tpl []*config.FCTemplate, tnt, tmz string, filterS *engine.FilterS) (a sipingo.Message, err error) { aReq := NewAgentRequest( diff --git a/agents/radagent.go b/agents/radagent.go index 1592c049a..5b2181941 100644 --- a/agents/radagent.go +++ b/agents/radagent.go @@ -79,11 +79,11 @@ func (ra *RadiusAgent) handleAuth(req *radigo.Packet) (rpl *radigo.Packet, err e dcdr := newRADataProvider(req) // dcdr will provide information from request rpl = req.Reply() rpl.Code = radigo.AccessAccept - cgrRplyNM := utils.NavigableMap2{} + cgrRplyNM := utils.NavigableMap{} rplyNM := utils.NewOrderedNavigableMap() opts := utils.NewOrderedNavigableMap() var processed bool - reqVars := utils.NavigableMap2{utils.RemoteHost: utils.NewNMData(req.RemoteAddr().String())} + reqVars := utils.NavigableMap{utils.RemoteHost: utils.NewNMData(req.RemoteAddr().String())} for _, reqProcessor := range ra.cgrCfg.RadiusAgentCfg().RequestProcessors { agReq := NewAgentRequest(dcdr, reqVars, &cgrRplyNM, rplyNM, opts, reqProcessor.Tenant, ra.cgrCfg.GeneralCfg().DefaultTenant, @@ -124,11 +124,11 @@ func (ra *RadiusAgent) handleAcct(req *radigo.Packet) (rpl *radigo.Packet, err e dcdr := newRADataProvider(req) // dcdr will provide information from request rpl = req.Reply() rpl.Code = radigo.AccountingResponse - cgrRplyNM := utils.NavigableMap2{} + cgrRplyNM := utils.NavigableMap{} rplyNM := utils.NewOrderedNavigableMap() opts := utils.NewOrderedNavigableMap() var processed bool - reqVars := utils.NavigableMap2{utils.RemoteHost: utils.NewNMData(req.RemoteAddr().String())} + reqVars := utils.NavigableMap{utils.RemoteHost: utils.NewNMData(req.RemoteAddr().String())} for _, reqProcessor := range ra.cgrCfg.RadiusAgentCfg().RequestProcessors { agReq := NewAgentRequest(dcdr, reqVars, &cgrRplyNM, rplyNM, opts, reqProcessor.Tenant, ra.cgrCfg.GeneralCfg().DefaultTenant, diff --git a/agents/sipagent.go b/agents/sipagent.go index 5ced80911..9027351ed 100644 --- a/agents/sipagent.go +++ b/agents/sipagent.go @@ -303,10 +303,10 @@ func (sa *SIPAgent) handleMessage(sipMessage sipingo.Message, remoteHost string) } dp := utils.MapStorage(sipMessageIface) var processed bool - cgrRplyNM := utils.NavigableMap2{} + cgrRplyNM := utils.NavigableMap{} rplyNM := utils.NewOrderedNavigableMap() opts := utils.NewOrderedNavigableMap() - reqVars := utils.NavigableMap2{ + reqVars := utils.NavigableMap{ utils.RemoteHost: utils.NewNMData(remoteHost), method: utils.NewNMData(sipMessage.MethodFrom(requestHeader)), } diff --git a/apier/v1/routes_it_test.go b/apier/v1/routes_it_test.go index ce2ab21a8..108bcef82 100644 --- a/apier/v1/routes_it_test.go +++ b/apier/v1/routes_it_test.go @@ -71,6 +71,7 @@ var ( testV1RouteRemRouteProfilesWithoutTenant, // reset the database and load the TP again testV1RouteInitDataDb, + testV1RouteClearCache, // reset the cache so the indexes are created corectly testV1RouteFromFolder, testV1RoutesOneRouteWithoutDestination, testV1RouteRoutePing, @@ -113,6 +114,13 @@ func testV1RouteInitDataDb(t *testing.T) { } } +func testV1RouteClearCache(t *testing.T) { + var reply string + if err := routeSv1Rpc.Call(utils.CacheSv1Clear, &utils.AttrCacheIDsWithOpts{}, &reply); err != nil { + t.Fatal(err) + } +} + // Wipe out the cdr database func testV1RouteResetStorDb(t *testing.T) { if err := engine.InitStorDb(routeSv1Cfg); err != nil { @@ -169,7 +177,6 @@ func testV1RouteGetWeightRoutes(t *testing.T) { eSpls := engine.SortedRoutesList{{ ProfileID: "ROUTE_WEIGHT_1", Sorting: utils.MetaWeight, - Count: 2, Routes: []*engine.SortedRoute{ { RouteID: "route2", @@ -222,7 +229,6 @@ func testV1RouteGetLeastCostRoutes(t *testing.T) { eSpls := engine.SortedRoutesList{{ ProfileID: "ROUTE_LEASTCOST_1", Sorting: utils.MetaLC, - Count: 3, Routes: []*engine.SortedRoute{ { RouteID: "route3", @@ -277,7 +283,6 @@ func testV1RouteGetLeastCostRoutesWithoutUsage(t *testing.T) { eSpls := engine.SortedRoutesList{{ ProfileID: "ROUTE_LEASTCOST_1", Sorting: utils.MetaLC, - Count: 3, Routes: []*engine.SortedRoute{ { RouteID: "route3", @@ -334,7 +339,6 @@ func testV1RouteGetLeastCostRoutesWithMaxCost(t *testing.T) { eSpls := engine.SortedRoutesList{{ ProfileID: "ROUTE_LEASTCOST_1", Sorting: utils.MetaLC, - Count: 2, Routes: []*engine.SortedRoute{ { RouteID: "route3", @@ -406,7 +410,6 @@ func testV1RouteGetLeastCostRoutesWithMaxCost2(t *testing.T) { eSpls := engine.SortedRoutesList{{ ProfileID: "ROUTE_LEASTCOST_1", Sorting: utils.MetaLC, - Count: 2, Routes: []*engine.SortedRoute{ { RouteID: "route3", @@ -454,7 +457,6 @@ func testV1RouteGetHighestCostRoutes(t *testing.T) { eSpls := engine.SortedRoutesList{{ ProfileID: "ROUTE_HIGHESTCOST_1", Sorting: utils.MetaHC, - Count: 3, Routes: []*engine.SortedRoute{ { RouteID: "route2", @@ -824,7 +826,6 @@ func testV1RouteGetRouteWithoutFilter(t *testing.T) { eSpls := engine.SortedRoutesList{{ ProfileID: "ROUTE_WEIGHT_2", Sorting: utils.MetaWeight, - Count: 1, Routes: []*engine.SortedRoute{ { RouteID: "route1", @@ -1147,12 +1148,12 @@ func testV1RoutesOneRouteWithoutDestination(t *testing.T) { utils.SetupTime: utils.MetaNow, utils.Usage: "2m", }, + Opts: map[string]interface{}{utils.OptsRouteProfilesCount: 1}, }, } eSpls := engine.SortedRoutesList{{ ProfileID: "ROUTE_DESTINATION", Sorting: utils.MetaLC, - Count: 1, Routes: []*engine.SortedRoute{ { RouteID: "local", @@ -1224,12 +1225,12 @@ func testV1RouteMultipleRouteSameID(t *testing.T) { utils.Usage: "2m", "Month": "April", }, + Opts: map[string]interface{}{utils.OptsRouteProfilesCount: 1}, }, } eSpls := engine.SortedRoutesList{{ ProfileID: "MULTIPLE_ROUTES", Sorting: utils.MetaLC, - Count: 1, Routes: []*engine.SortedRoute{ { RouteID: "Route1", @@ -1262,12 +1263,12 @@ func testV1RouteMultipleRouteSameID(t *testing.T) { utils.Usage: "2m", "Month": "May", }, + Opts: map[string]interface{}{utils.OptsRouteProfilesCount: 1}, }, } eSpls = engine.SortedRoutesList{{ ProfileID: "MULTIPLE_ROUTES", Sorting: utils.MetaLC, - Count: 1, Routes: []*engine.SortedRoute{ { RouteID: "Route1", @@ -1360,12 +1361,12 @@ func testV1RouteAccountWithRatingPlan(t *testing.T) { utils.Usage: "30s", "EventType": "testV1RouteAccountWithRatingPlan", }, + Opts: map[string]interface{}{utils.OptsRouteProfilesCount: 1}, }, } eSpls := &engine.SortedRoutesList{{ ProfileID: "RouteWithAccAndRP", Sorting: utils.MetaLC, - Count: 2, Routes: []*engine.SortedRoute{ { RouteID: "RouteWithAccAndRP", @@ -1430,12 +1431,12 @@ func testV1RouteAccountWithRatingPlan(t *testing.T) { utils.Usage: "60s", "EventType": "testV1RouteAccountWithRatingPlan", }, + Opts: map[string]interface{}{utils.OptsRouteProfilesCount: 1}, }, } eSpls = &engine.SortedRoutesList{{ ProfileID: "RouteWithAccAndRP", Sorting: utils.MetaLC, - Count: 2, Routes: []*engine.SortedRoute{ { RouteID: "RouteWithAccAndRP", @@ -1502,12 +1503,12 @@ func testV1RouteAccountWithRatingPlan(t *testing.T) { utils.Usage: "1m1s", "EventType": "testV1RouteAccountWithRatingPlan", }, + Opts: map[string]interface{}{utils.OptsRouteProfilesCount: 1}, }, } eSpls = &engine.SortedRoutesList{{ ProfileID: "RouteWithAccAndRP", Sorting: utils.MetaLC, - Count: 2, Routes: []*engine.SortedRoute{ { RouteID: "RouteWithRP", diff --git a/apier/v1/sessions_process_event_it_test.go b/apier/v1/sessions_process_event_it_test.go index f7f3ad56a..77b57911d 100644 --- a/apier/v1/sessions_process_event_it_test.go +++ b/apier/v1/sessions_process_event_it_test.go @@ -198,7 +198,6 @@ func testSSv1ItProcessEventAuth(t *testing.T) { eSplrs := engine.SortedRoutesList{{ ProfileID: "ROUTE_ACNT_1001", Sorting: utils.MetaWeight, - Count: 2, Routes: []*engine.SortedRoute{ { RouteID: "route1", @@ -216,7 +215,6 @@ func testSSv1ItProcessEventAuth(t *testing.T) { }, { ProfileID: "ROUTE_WEIGHT_2", Sorting: utils.MetaWeight, - Count: 1, Routes: []*engine.SortedRoute{{ RouteID: "route1", SortingData: map[string]interface{}{ @@ -224,8 +222,8 @@ func testSSv1ItProcessEventAuth(t *testing.T) { }, }}, }} - if !reflect.DeepEqual(eSplrs, rply.Routes[utils.MetaRaw]) { - t.Errorf("expecting: %+v,\n received: %+v", utils.ToJSON(eSplrs), utils.ToJSON(rply.Routes[utils.MetaRaw])) + if !reflect.DeepEqual(eSplrs, rply.RouteProfiles[utils.MetaRaw]) { + t.Errorf("expecting: %+v,\n received: %+v", utils.ToJSON(eSplrs), utils.ToJSON(rply.RouteProfiles[utils.MetaRaw])) } eAttrs := &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_ACNT_1001"}, diff --git a/apier/v1/sessionsv1_it_test.go b/apier/v1/sessionsv1_it_test.go index 5f6d17395..d21f0fe42 100644 --- a/apier/v1/sessionsv1_it_test.go +++ b/apier/v1/sessionsv1_it_test.go @@ -235,7 +235,6 @@ func testSSv1ItAuth(t *testing.T) { eSplrs := engine.SortedRoutesList{{ ProfileID: "ROUTE_ACNT_1001", Sorting: utils.MetaWeight, - Count: 2, Routes: []*engine.SortedRoute{ { RouteID: "route1", @@ -253,7 +252,6 @@ func testSSv1ItAuth(t *testing.T) { }, { ProfileID: "ROUTE_WEIGHT_2", Sorting: utils.MetaWeight, - Count: 1, Routes: []*engine.SortedRoute{{ RouteID: "route1", SortingData: map[string]interface{}{ @@ -261,8 +259,8 @@ func testSSv1ItAuth(t *testing.T) { }, }}, }} - if !reflect.DeepEqual(eSplrs, rply.Routes) { - t.Errorf("expecting: %+v,\n received: %+v", utils.ToJSON(eSplrs), utils.ToJSON(rply.Routes)) + if !reflect.DeepEqual(eSplrs, rply.RouteProfiles) { + t.Errorf("expecting: %+v,\n received: %+v", utils.ToJSON(eSplrs), utils.ToJSON(rply.RouteProfiles)) } eAttrs := &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_ACNT_1001"}, diff --git a/config/fctemplate_test.go b/config/fctemplate_test.go index 3da4a579c..9a67844b6 100644 --- a/config/fctemplate_test.go +++ b/config/fctemplate_test.go @@ -74,11 +74,11 @@ func TestFCTemplatePathItems(t *testing.T) { }, { Field: "Account", - Index: utils.StringPointer("1"), + Index: []string{"1"}, }, { Field: "Balance", - Index: utils.StringPointer("*monetary"), + Index: []string{"*monetary"}, }, { Field: "Value", diff --git a/data/conf/samples/dnsagent_internal/suppliers.json b/data/conf/samples/dnsagent_internal/suppliers.json index 6290fc820..c3a0d8c18 100644 --- a/data/conf/samples/dnsagent_internal/suppliers.json +++ b/data/conf/samples/dnsagent_internal/suppliers.json @@ -19,7 +19,8 @@ "id": "NAPTRSuppliersOneSupplier", "filters": ["*string:~*vars.QueryType:NAPTR", "*string:~*vars.E164Address:4986517174965", - "*gte:~*cgrep.Routes.Count:1"], + "*gte:~*cgrep.RouteProfiles.Length:1", + "*gte:~*cgrep.RouteProfiles[0].Routes.Length:1"], "flags": ["*none","*continue"], // do not send request to CGRateS "reply_fields":[ {"tag": "NAPTROrder", "path": "*rep.Order", @@ -31,7 +32,7 @@ {"tag": "NAPTRService", "path": "*rep.Service", "type": "*group", "value": "E2U+SIP"}, {"tag": "NAPTRRegexp", "path": "*rep.Regexp", "type": "*group", - "value": "~*cgrep.Routes.SortedRoutes[0].RouteParameters"}, + "value": "~*cgrep.RouteProfiles[0].Routes[0].RouteParameters"}, {"tag": "NAPTRReplacement", "path": "*rep.Replacement", "type": "*group", "value": "."}, ], @@ -40,7 +41,8 @@ "id": "NAPTRSuppliersTwoSuppliers", "filters": ["*string:~*vars.QueryType:NAPTR", "*string:~*vars.E164Address:4986517174965", - "*gte:~*cgrep.Routes.Count:2"], + "*gte:~*cgrep.RouteProfiles.Length:1", + "*gte:~*cgrep.RouteProfiles[0].Routes.Length:2"], "flags": ["*none","*continue"], "reply_fields":[ {"tag": "NAPTROrder", "type": "*group", "new_branch": true, @@ -52,7 +54,7 @@ {"tag": "NAPTRService", "path": "*rep.Service", "type": "*group", "value": "E2U+SIP"}, {"tag": "NAPTRRegexp", "path": "*rep.Regexp", "type": "*group", - "value": "~*cgrep.Routes.SortedRoutes[1].RouteParameters"}, + "value": "~*cgrep.RouteProfiles[0].Routes[1].RouteParameters"}, {"tag": "NAPTRReplacement", "path": "*rep.Replacement", "type": "*group", "value": "."}, ], diff --git a/data/conf/samples/dnsagent_mongo/suppliers.json b/data/conf/samples/dnsagent_mongo/suppliers.json index 7078bac4c..72204f004 100644 --- a/data/conf/samples/dnsagent_mongo/suppliers.json +++ b/data/conf/samples/dnsagent_mongo/suppliers.json @@ -19,7 +19,8 @@ "id": "NAPTRSuppliersOneSupplier", "filters": ["*string:~*vars.QueryType:NAPTR", "*string:~*vars.E164Address:4986517174965", - "*gte:~*cgrep.Routes.Count:1"], + "*gte:~*cgrep.RouteProfiles.Length:1", + "*gte:~*cgrep.RouteProfiles[0].Routes.Length:1"], "flags": ["*none","*continue"], // do not send request to CGRateS "reply_fields":[ {"tag": "NAPTROrder", "path": "*rep.Order", @@ -31,7 +32,7 @@ {"tag": "NAPTRService", "path": "*rep.Service", "type": "*group", "value": "E2U+SIP"}, {"tag": "NAPTRRegexp", "path": "*rep.Regexp", "type": "*group", - "value": "~*cgrep.Routes.SortedRoutes[0].RouteParameters"}, + "value": "~*cgrep.RouteProfiles[0].Routes[0].RouteParameters"}, {"tag": "NAPTRReplacement", "path": "*rep.Replacement", "type": "*group", "value": "."}, ], @@ -40,7 +41,8 @@ "id": "NAPTRSuppliersTwoSuppliers", "filters": ["*string:~*vars.QueryType:NAPTR", "*string:~*vars.E164Address:4986517174965", - "*gte:~*cgrep.Routes.Count:2"], + "*gte:~*cgrep.RouteProfiles.Length:1", + "*gte:~*cgrep.RouteProfiles[0].Routes.Length:1"], "flags": ["*none","*continue"], "reply_fields":[ {"tag": "NAPTROrder", "type": "*group", "new_branch": true, @@ -52,7 +54,7 @@ {"tag": "NAPTRService", "path": "*rep.Service", "type": "*group", "value": "E2U+SIP"}, {"tag": "NAPTRRegexp", "path": "*rep.Regexp", "type": "*group", - "value": "~*cgrep.Routes.SortedRoutes[1].RouteParameters"}, + "value": "~*cgrep.RouteProfiles[0].Routes[1].RouteParameters"}, {"tag": "NAPTRReplacement", "path": "*rep.Replacement", "type": "*group", "value": "."}, ], diff --git a/data/conf/samples/dnsagent_mysql/suppliers.json b/data/conf/samples/dnsagent_mysql/suppliers.json index 7078bac4c..9441d4dd8 100644 --- a/data/conf/samples/dnsagent_mysql/suppliers.json +++ b/data/conf/samples/dnsagent_mysql/suppliers.json @@ -19,7 +19,8 @@ "id": "NAPTRSuppliersOneSupplier", "filters": ["*string:~*vars.QueryType:NAPTR", "*string:~*vars.E164Address:4986517174965", - "*gte:~*cgrep.Routes.Count:1"], + "*gte:~*cgrep.RouteProfiles.Length:1", + "*gte:~*cgrep.RouteProfiles[0].Routes.Length:1"], "flags": ["*none","*continue"], // do not send request to CGRateS "reply_fields":[ {"tag": "NAPTROrder", "path": "*rep.Order", @@ -31,7 +32,7 @@ {"tag": "NAPTRService", "path": "*rep.Service", "type": "*group", "value": "E2U+SIP"}, {"tag": "NAPTRRegexp", "path": "*rep.Regexp", "type": "*group", - "value": "~*cgrep.Routes.SortedRoutes[0].RouteParameters"}, + "value": "~*cgrep.RouteProfiles[0].Routes[0].RouteParameters"}, {"tag": "NAPTRReplacement", "path": "*rep.Replacement", "type": "*group", "value": "."}, ], @@ -40,7 +41,8 @@ "id": "NAPTRSuppliersTwoSuppliers", "filters": ["*string:~*vars.QueryType:NAPTR", "*string:~*vars.E164Address:4986517174965", - "*gte:~*cgrep.Routes.Count:2"], + "*gte:~*cgrep.RouteProfiles.Length:1", + "*gte:~*cgrep.RouteProfiles[0].Routes.Length:2"], "flags": ["*none","*continue"], "reply_fields":[ {"tag": "NAPTROrder", "type": "*group", "new_branch": true, @@ -52,7 +54,7 @@ {"tag": "NAPTRService", "path": "*rep.Service", "type": "*group", "value": "E2U+SIP"}, {"tag": "NAPTRRegexp", "path": "*rep.Regexp", "type": "*group", - "value": "~*cgrep.Routes.SortedRoutes[1].RouteParameters"}, + "value": "~*cgrep.RouteProfiles[0].Routes[1].RouteParameters"}, {"tag": "NAPTRReplacement", "path": "*rep.Replacement", "type": "*group", "value": "."}, ], diff --git a/data/conf/samples/sipagent_internal/cgrates.json b/data/conf/samples/sipagent_internal/cgrates.json index 6de778f3e..82aae0dc1 100644 --- a/data/conf/samples/sipagent_internal/cgrates.json +++ b/data/conf/samples/sipagent_internal/cgrates.json @@ -12,6 +12,13 @@ }, +"rpc_conns": { + "*jsonbirpc": { + "conns": [{"address": "127.0.0.1:2014", "transport":"*birpc_json"}], + }, +}, + + "data_db": { // database used to store runtime data (eg: accounts, cdr stats) "db_type": "*internal", // stor database type to use: }, diff --git a/data/conf/samples/sipagent_internal/redirect.json b/data/conf/samples/sipagent_internal/redirect.json index 1907f1c82..99100d64f 100644 --- a/data/conf/samples/sipagent_internal/redirect.json +++ b/data/conf/samples/sipagent_internal/redirect.json @@ -32,7 +32,8 @@ { "id": "RoutesQueryOneRoute", "filters": ["*string:~*vars.Method:INVITE", - "*gte:~*cgrep.Routes[*raw].Count:1", + "*gte:~*cgrep.RouteProfiles[*raw].Length:1", + "*gte:~*cgrep.RouteProfiles[*raw][0].Routes.Length:1", ], "flags": ["*none","*continue"], // do not send request to CGRateS "reply_fields":[ @@ -49,24 +50,25 @@ {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"@"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value": "~*cgrep.Routes[*raw].SortedRoutes[0].RouteParameters"}, + "value": "~*cgrep.RouteProfiles[*raw][0].Routes[0].RouteParameters"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"`>;q=0.7; expires=3600;cgr_cost=`"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value":"~*cgrep.Routes[*raw].SortedRoutes[0].SortingData.Cost"}, + "value":"~*cgrep.RouteProfiles[*raw][0].Routes[0].SortingData.Cost"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"`;cgr_maxusage=`"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value":"~*cgrep.Routes[*raw].SortedRoutes[0].SortingData.MaxUsage"}, + "value":"~*cgrep.RouteProfiles[*raw][0].Routes[0].SortingData.MaxUsage"}, {"tag": "P-Charge-Info", "path": "*rep.P-Charge-Info", "type": "*composed", - "filters": ["*notempty:~*cgrep.Attributes[<~*cgrep.Routes[*raw].SortedRoutes[0].RouteID>].P-Charge-Info:"], - "value": "~*cgrep.Attributes[<~*cgrep.Routes[*raw].SortedRoutes[0].RouteID>].P-Charge-Info"}, + "filters": ["*notempty:~*cgrep.Attributes[<~*cgrep.RouteProfiles[*raw][0].Routes[0].RouteID>].P-Charge-Info:"], + "value": "~*cgrep.Attributes[<~*cgrep.RouteProfiles[*raw][0].Routes[0].RouteID>].P-Charge-Info"}, ] }, { "id": "RoutesQueryTwoRoutes", "filters": ["*string:~*vars.Method:INVITE", - "*gte:~*cgrep.Routes[*raw].Count:2", + "*gte:~*cgrep.RouteProfiles[*raw].Length:1", + "*gte:~*cgrep.RouteProfiles[*raw][0].Routes.Length:2", ], "flags": ["*none","*continue"], "reply_fields":[ @@ -81,21 +83,22 @@ {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"@"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value": "~*cgrep.Routes[*raw].SortedRoutes[1].RouteParameters"}, + "value": "~*cgrep.RouteProfiles[*raw][0].Routes[1].RouteParameters"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"`>;q=0.2;cgr_cost=`"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value":"~*cgrep.Routes[*raw].SortedRoutes[1].SortingData.Cost"}, + "value":"~*cgrep.RouteProfiles[*raw][0].Routes[1].SortingData.Cost"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"`;cgr_maxusage=`"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value":"~*cgrep.Routes[*raw].SortedRoutes[1].SortingData.MaxUsage"} + "value":"~*cgrep.RouteProfiles[*raw][0].Routes[1].SortingData.MaxUsage"} ] }, { "id": "RoutesQueryThreeRoutes", "filters": ["*string:~*vars.Method:INVITE", - "*gte:~*cgrep.Routes[*raw].Count:3", + "*gte:~*cgrep.RouteProfiles[*raw].Length:1", + "*gte:~*cgrep.RouteProfiles[*raw][0].Routes.Length:3", ], "flags": ["*none","*continue"], "reply_fields":[ @@ -110,15 +113,15 @@ {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"@"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value": "~*cgrep.Routes[*raw].SortedRoutes[2].RouteParameters"}, + "value": "~*cgrep.RouteProfiles[*raw][0].Routes[2].RouteParameters"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"`>;q=0.1;cgr_cost=`"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value":"~*cgrep.Routes[*raw].SortedRoutes[2].SortingData.Cost"}, + "value":"~*cgrep.RouteProfiles[*raw][0].Routes[2].SortingData.Cost"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"`;cgr_maxusage=`"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value":"~*cgrep.Routes[*raw].SortedRoutes[2].SortingData.MaxUsage"} + "value":"~*cgrep.RouteProfiles[*raw][0].Routes[2].SortingData.MaxUsage"} ] } ] diff --git a/data/conf/samples/sipagent_mongo/redirect.json b/data/conf/samples/sipagent_mongo/redirect.json index 1907f1c82..99100d64f 100644 --- a/data/conf/samples/sipagent_mongo/redirect.json +++ b/data/conf/samples/sipagent_mongo/redirect.json @@ -32,7 +32,8 @@ { "id": "RoutesQueryOneRoute", "filters": ["*string:~*vars.Method:INVITE", - "*gte:~*cgrep.Routes[*raw].Count:1", + "*gte:~*cgrep.RouteProfiles[*raw].Length:1", + "*gte:~*cgrep.RouteProfiles[*raw][0].Routes.Length:1", ], "flags": ["*none","*continue"], // do not send request to CGRateS "reply_fields":[ @@ -49,24 +50,25 @@ {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"@"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value": "~*cgrep.Routes[*raw].SortedRoutes[0].RouteParameters"}, + "value": "~*cgrep.RouteProfiles[*raw][0].Routes[0].RouteParameters"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"`>;q=0.7; expires=3600;cgr_cost=`"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value":"~*cgrep.Routes[*raw].SortedRoutes[0].SortingData.Cost"}, + "value":"~*cgrep.RouteProfiles[*raw][0].Routes[0].SortingData.Cost"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"`;cgr_maxusage=`"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value":"~*cgrep.Routes[*raw].SortedRoutes[0].SortingData.MaxUsage"}, + "value":"~*cgrep.RouteProfiles[*raw][0].Routes[0].SortingData.MaxUsage"}, {"tag": "P-Charge-Info", "path": "*rep.P-Charge-Info", "type": "*composed", - "filters": ["*notempty:~*cgrep.Attributes[<~*cgrep.Routes[*raw].SortedRoutes[0].RouteID>].P-Charge-Info:"], - "value": "~*cgrep.Attributes[<~*cgrep.Routes[*raw].SortedRoutes[0].RouteID>].P-Charge-Info"}, + "filters": ["*notempty:~*cgrep.Attributes[<~*cgrep.RouteProfiles[*raw][0].Routes[0].RouteID>].P-Charge-Info:"], + "value": "~*cgrep.Attributes[<~*cgrep.RouteProfiles[*raw][0].Routes[0].RouteID>].P-Charge-Info"}, ] }, { "id": "RoutesQueryTwoRoutes", "filters": ["*string:~*vars.Method:INVITE", - "*gte:~*cgrep.Routes[*raw].Count:2", + "*gte:~*cgrep.RouteProfiles[*raw].Length:1", + "*gte:~*cgrep.RouteProfiles[*raw][0].Routes.Length:2", ], "flags": ["*none","*continue"], "reply_fields":[ @@ -81,21 +83,22 @@ {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"@"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value": "~*cgrep.Routes[*raw].SortedRoutes[1].RouteParameters"}, + "value": "~*cgrep.RouteProfiles[*raw][0].Routes[1].RouteParameters"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"`>;q=0.2;cgr_cost=`"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value":"~*cgrep.Routes[*raw].SortedRoutes[1].SortingData.Cost"}, + "value":"~*cgrep.RouteProfiles[*raw][0].Routes[1].SortingData.Cost"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"`;cgr_maxusage=`"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value":"~*cgrep.Routes[*raw].SortedRoutes[1].SortingData.MaxUsage"} + "value":"~*cgrep.RouteProfiles[*raw][0].Routes[1].SortingData.MaxUsage"} ] }, { "id": "RoutesQueryThreeRoutes", "filters": ["*string:~*vars.Method:INVITE", - "*gte:~*cgrep.Routes[*raw].Count:3", + "*gte:~*cgrep.RouteProfiles[*raw].Length:1", + "*gte:~*cgrep.RouteProfiles[*raw][0].Routes.Length:3", ], "flags": ["*none","*continue"], "reply_fields":[ @@ -110,15 +113,15 @@ {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"@"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value": "~*cgrep.Routes[*raw].SortedRoutes[2].RouteParameters"}, + "value": "~*cgrep.RouteProfiles[*raw][0].Routes[2].RouteParameters"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"`>;q=0.1;cgr_cost=`"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value":"~*cgrep.Routes[*raw].SortedRoutes[2].SortingData.Cost"}, + "value":"~*cgrep.RouteProfiles[*raw][0].Routes[2].SortingData.Cost"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"`;cgr_maxusage=`"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value":"~*cgrep.Routes[*raw].SortedRoutes[2].SortingData.MaxUsage"} + "value":"~*cgrep.RouteProfiles[*raw][0].Routes[2].SortingData.MaxUsage"} ] } ] diff --git a/data/conf/samples/sipagent_mysql/redirect.json b/data/conf/samples/sipagent_mysql/redirect.json index 1907f1c82..99100d64f 100644 --- a/data/conf/samples/sipagent_mysql/redirect.json +++ b/data/conf/samples/sipagent_mysql/redirect.json @@ -32,7 +32,8 @@ { "id": "RoutesQueryOneRoute", "filters": ["*string:~*vars.Method:INVITE", - "*gte:~*cgrep.Routes[*raw].Count:1", + "*gte:~*cgrep.RouteProfiles[*raw].Length:1", + "*gte:~*cgrep.RouteProfiles[*raw][0].Routes.Length:1", ], "flags": ["*none","*continue"], // do not send request to CGRateS "reply_fields":[ @@ -49,24 +50,25 @@ {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"@"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value": "~*cgrep.Routes[*raw].SortedRoutes[0].RouteParameters"}, + "value": "~*cgrep.RouteProfiles[*raw][0].Routes[0].RouteParameters"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"`>;q=0.7; expires=3600;cgr_cost=`"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value":"~*cgrep.Routes[*raw].SortedRoutes[0].SortingData.Cost"}, + "value":"~*cgrep.RouteProfiles[*raw][0].Routes[0].SortingData.Cost"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"`;cgr_maxusage=`"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value":"~*cgrep.Routes[*raw].SortedRoutes[0].SortingData.MaxUsage"}, + "value":"~*cgrep.RouteProfiles[*raw][0].Routes[0].SortingData.MaxUsage"}, {"tag": "P-Charge-Info", "path": "*rep.P-Charge-Info", "type": "*composed", - "filters": ["*notempty:~*cgrep.Attributes[<~*cgrep.Routes[*raw].SortedRoutes[0].RouteID>].P-Charge-Info:"], - "value": "~*cgrep.Attributes[<~*cgrep.Routes[*raw].SortedRoutes[0].RouteID>].P-Charge-Info"}, + "filters": ["*notempty:~*cgrep.Attributes[<~*cgrep.RouteProfiles[*raw][0].Routes[0].RouteID>].P-Charge-Info:"], + "value": "~*cgrep.Attributes[<~*cgrep.RouteProfiles[*raw][0].Routes[0].RouteID>].P-Charge-Info"}, ] }, { "id": "RoutesQueryTwoRoutes", "filters": ["*string:~*vars.Method:INVITE", - "*gte:~*cgrep.Routes[*raw].Count:2", + "*gte:~*cgrep.RouteProfiles[*raw].Length:1", + "*gte:~*cgrep.RouteProfiles[*raw][0].Routes.Length:2", ], "flags": ["*none","*continue"], "reply_fields":[ @@ -81,21 +83,22 @@ {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"@"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value": "~*cgrep.Routes[*raw].SortedRoutes[1].RouteParameters"}, + "value": "~*cgrep.RouteProfiles[*raw][0].Routes[1].RouteParameters"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"`>;q=0.2;cgr_cost=`"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value":"~*cgrep.Routes[*raw].SortedRoutes[1].SortingData.Cost"}, + "value":"~*cgrep.RouteProfiles[*raw][0].Routes[1].SortingData.Cost"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"`;cgr_maxusage=`"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value":"~*cgrep.Routes[*raw].SortedRoutes[1].SortingData.MaxUsage"} + "value":"~*cgrep.RouteProfiles[*raw][0].Routes[1].SortingData.MaxUsage"} ] }, { "id": "RoutesQueryThreeRoutes", "filters": ["*string:~*vars.Method:INVITE", - "*gte:~*cgrep.Routes[*raw].Count:3", + "*gte:~*cgrep.RouteProfiles[*raw].Length:1", + "*gte:~*cgrep.RouteProfiles[*raw][0].Routes.Length:3", ], "flags": ["*none","*continue"], "reply_fields":[ @@ -110,15 +113,15 @@ {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"@"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value": "~*cgrep.Routes[*raw].SortedRoutes[2].RouteParameters"}, + "value": "~*cgrep.RouteProfiles[*raw][0].Routes[2].RouteParameters"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"`>;q=0.1;cgr_cost=`"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value":"~*cgrep.Routes[*raw].SortedRoutes[2].SortingData.Cost"}, + "value":"~*cgrep.RouteProfiles[*raw][0].Routes[2].SortingData.Cost"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"`;cgr_maxusage=`"}, {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", - "value":"~*cgrep.Routes[*raw].SortedRoutes[2].SortingData.MaxUsage"} + "value":"~*cgrep.RouteProfiles[*raw][0].Routes[2].SortingData.MaxUsage"} ] } ] diff --git a/data/conf/samples/tutmongo/cgrates.json b/data/conf/samples/tutmongo/cgrates.json index b8bb82914..914cc46ff 100644 --- a/data/conf/samples/tutmongo/cgrates.json +++ b/data/conf/samples/tutmongo/cgrates.json @@ -38,13 +38,22 @@ "schedulers": { "enabled": true, - "cdrs_conns": ["*localhost"], + "cdrs_conns": ["*internal"], "stats_conns": ["*localhost"], }, "cdrs": { "enabled": true, + "chargers_conns":["*internal"], +}, + + +"attributes": { + "enabled": true, + "stats_conns": ["*localhost"], + "resources_conns": ["*localhost"], + "apiers_conns": ["*localhost"] }, @@ -76,22 +85,18 @@ "routes": { "enabled": true, - "stats_conns": ["*localhost"], - "resources_conns": ["*localhost"], + "prefix_indexed_fields":["*req.Destination"], + "stats_conns": ["*internal"], + "resources_conns": ["*internal"], "rals_conns": ["*internal"], }, -"attributes": { - "enabled": true, - "stats_conns": ["*localhost"], - "resources_conns": ["*localhost"], - "apiers_conns": ["*localhost"] -}, - - "sessions": { "enabled": true, + "routes_conns": ["*internal"], + "resources_conns": ["*internal"], + "attributes_conns": ["*internal"], "rals_conns": ["*internal"], "cdrs_conns": ["*internal"], "chargers_conns": ["*internal"], @@ -127,7 +132,7 @@ "accounts": { - "enabled": true, + "enabled": true }, diff --git a/data/conf/samples/tutmysql/cgrates.json b/data/conf/samples/tutmysql/cgrates.json index 15c08e1da..422b140e1 100644 --- a/data/conf/samples/tutmysql/cgrates.json +++ b/data/conf/samples/tutmysql/cgrates.json @@ -5,7 +5,6 @@ "general": { "log_level": 7, - //"dbdata_encoding": "*json", "reply_timeout": "50s", }, @@ -74,6 +73,7 @@ "thresholds_conns": ["*internal"], }, + "thresholds": { "enabled": true, "store_interval": "1s", @@ -106,7 +106,6 @@ }, - "apiers": { "enabled": true, "scheduler_conns": ["*internal"], diff --git a/data/tutorials/sip_redirect/cgrates/etc/cgrates/redirect.json b/data/tutorials/sip_redirect/cgrates/etc/cgrates/redirect.json index 6f183cec1..b82a3c7bd 100644 --- a/data/tutorials/sip_redirect/cgrates/etc/cgrates/redirect.json +++ b/data/tutorials/sip_redirect/cgrates/etc/cgrates/redirect.json @@ -39,7 +39,8 @@ { "id": "RoutesQueryOneRoute", "filters": ["*string:~*vars.Method:INVITE", - "*gte:~*cgrep.Routes[*raw].Count:1", + "*gte:~*cgrep.RouteProfiles[*raw].Length:1", + "*gte:~*cgrep.RouteProfiles[*raw][0].Routes.Length:1", ], "flags": ["*none","*continue"], // do not send request to CGRateS "reply_fields":[ @@ -48,57 +49,58 @@ {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"\"1003\" `"}, {"tag": "X-Identity", "path": "*rep.X-Identity", "type": "*variable", - "value":"~*cgrep.STIRIdentity.<~*cgrep.Routes[*raw].SortedRoutes[0].RouteID>"}, + "value":"~*cgrep.STIRIdentity.<~*cgrep.RouteProfiles[*raw][0].Routes[0].RouteID>"}, ] }, { "id": "RoutesQueryTwoRoute", "filters": ["*string:~*vars.Method:INVITE", - "*gte:~*cgrep.Routes[*raw].Count:2", + "*gte:~*cgrep.RouteProfiles[*raw].Length:1", + "*gte:~*cgrep.RouteProfiles[*raw][0].Routes.Length:1", ], "flags": ["*none","*continue"], // do not send request to CGRateS "reply_fields":[ {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":",\"1004\" `"}, @@ -107,29 +109,30 @@ { "id": "RoutesQueryThreeRoute", "filters": ["*string:~*vars.Method:INVITE", - "*gte:~*cgrep.Routes[*raw].Count:2", + "*gte:~*cgrep.RouteProfiles[*raw].Length:1", + "*gte:~*cgrep.RouteProfiles[*raw][0].Routes.Length:3", ], "flags": ["*none","*continue"], // do not send request to CGRateS "reply_fields":[ {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":",\"1005\" `"}, diff --git a/dispatchers/routes_it_test.go b/dispatchers/routes_it_test.go index 52196a1ef..28cd619d1 100755 --- a/dispatchers/routes_it_test.go +++ b/dispatchers/routes_it_test.go @@ -128,7 +128,6 @@ func testDspSupGetSupFailover(t *testing.T) { eRpl1 := engine.SortedRoutesList{{ ProfileID: "ROUTE_WEIGHT_2", Sorting: utils.MetaWeight, - Count: 1, Routes: []*engine.SortedRoute{ { RouteID: "route1", @@ -142,7 +141,6 @@ func testDspSupGetSupFailover(t *testing.T) { eRpl := engine.SortedRoutesList{{ ProfileID: "ROUTE_ACNT_1002", Sorting: utils.MetaLC, - Count: 2, Routes: []*engine.SortedRoute{ { RouteID: "route1", @@ -229,7 +227,6 @@ func testDspSupTestAuthKey2(t *testing.T) { eRpl := engine.SortedRoutesList{{ ProfileID: "ROUTE_ACNT_1002", Sorting: utils.MetaLC, - Count: 2, Routes: []*engine.SortedRoute{ { RouteID: "route1", @@ -282,7 +279,6 @@ func testDspSupGetSupRoundRobin(t *testing.T) { eRpl1 := engine.SortedRoutesList{{ ProfileID: "ROUTE_WEIGHT_2", Sorting: utils.MetaWeight, - Count: 1, Routes: []*engine.SortedRoute{ { RouteID: "route1", @@ -296,7 +292,6 @@ func testDspSupGetSupRoundRobin(t *testing.T) { eRpl := engine.SortedRoutesList{{ ProfileID: "ROUTE_ACNT_1002", Sorting: utils.MetaLC, - Count: 2, Routes: []*engine.SortedRoute{ { RouteID: "route1", diff --git a/engine/libroutes.go b/engine/libroutes.go index 031a971c7..55cfd9e37 100644 --- a/engine/libroutes.go +++ b/engine/libroutes.go @@ -37,7 +37,6 @@ type SortedRoute struct { type SortedRoutes struct { ProfileID string // Profile matched Sorting string // Sorting algorithm - Count int // number of routes returned Routes []*SortedRoute // list of route IDs and SortingData data } @@ -182,12 +181,12 @@ func (sRoutes *SortedRoutes) Digest() string { return strings.Join(sRoutes.RoutesWithParams(), utils.FieldsSep) } -func (ss *SortedRoute) AsNavigableMap() (nm utils.NavigableMap2) { - nm = utils.NavigableMap2{ +func (ss *SortedRoute) AsNavigableMap() (nm utils.NavigableMap) { + nm = utils.NavigableMap{ utils.RouteID: utils.NewNMData(ss.RouteID), utils.RouteParameters: utils.NewNMData(ss.RouteParameters), } - sd := utils.NavigableMap2{} + sd := utils.NavigableMap{} for k, d := range ss.SortingData { sd[k] = utils.NewNMData(d) } @@ -195,17 +194,16 @@ func (ss *SortedRoute) AsNavigableMap() (nm utils.NavigableMap2) { return } -func (sRoutes *SortedRoutes) AsNavigableMap() (nm utils.NavigableMap2) { - nm = utils.NavigableMap2{ +func (sRoutes *SortedRoutes) AsNavigableMap() (nm utils.NavigableMap) { + nm = utils.NavigableMap{ utils.ProfileID: utils.NewNMData(sRoutes.ProfileID), utils.Sorting: utils.NewNMData(sRoutes.Sorting), - utils.Count: utils.NewNMData(sRoutes.Count), } sr := make(utils.NMSlice, len(sRoutes.Routes)) for i, ss := range sRoutes.Routes { sr[i] = ss.AsNavigableMap() } - nm[utils.SortedRoutes] = &sr + nm[utils.CapRoutes] = &sr return } diff --git a/engine/libroutes_test.go b/engine/libroutes_test.go index 0d07653ff..62d9d1bef 100644 --- a/engine/libroutes_test.go +++ b/engine/libroutes_test.go @@ -1012,10 +1012,10 @@ func TestSortedRouteAsNavigableMap(t *testing.T) { utils.Weight: 15.5, }, } - expNavMap := utils.NavigableMap2{ + expNavMap := utils.NavigableMap{ utils.RouteID: utils.NewNMData("ROUTE1"), utils.RouteParameters: utils.NewNMData("SORTING_PARAMETER"), - utils.SortingData: utils.NavigableMap2{ + utils.SortingData: utils.NavigableMap{ utils.Ratio: utils.NewNMData(6.0), utils.Load: utils.NewNMData(10.0), utils.Weight: utils.NewNMData(15.5), @@ -1030,7 +1030,6 @@ func TestSortedRoutesAsNavigableMap(t *testing.T) { sSpls := &SortedRoutes{ ProfileID: "TEST_ID1", Sorting: utils.MetaWeight, - Count: 100, Routes: []*SortedRoute{ { RouteID: "ROUTE1", @@ -1052,24 +1051,23 @@ func TestSortedRoutesAsNavigableMap(t *testing.T) { }, } - expNavMap := utils.NavigableMap2{ + expNavMap := utils.NavigableMap{ utils.ProfileID: utils.NewNMData("TEST_ID1"), utils.Sorting: utils.NewNMData(utils.MetaWeight), - utils.Count: utils.NewNMData(100), - utils.SortedRoutes: &utils.NMSlice{ - utils.NavigableMap2{ + utils.CapRoutes: &utils.NMSlice{ + utils.NavigableMap{ utils.RouteID: utils.NewNMData("ROUTE1"), utils.RouteParameters: utils.NewNMData("SORTING_PARAMETER"), - utils.SortingData: utils.NavigableMap2{ + utils.SortingData: utils.NavigableMap{ utils.Ratio: utils.NewNMData(6.0), utils.Load: utils.NewNMData(10.0), utils.Weight: utils.NewNMData(15.5), }, }, - utils.NavigableMap2{ + utils.NavigableMap{ utils.RouteID: utils.NewNMData("ROUTE2"), utils.RouteParameters: utils.NewNMData("SORTING_PARAMETER_SECOND"), - utils.SortingData: utils.NavigableMap2{ + utils.SortingData: utils.NavigableMap{ utils.Ratio: utils.NewNMData(7.0), utils.Load: utils.NewNMData(10.0), }, diff --git a/engine/routes.go b/engine/routes.go index 1291da83d..aac0b892b 100644 --- a/engine/routes.go +++ b/engine/routes.go @@ -674,7 +674,6 @@ func (rpS *RouteService) sortedRoutesForProfile(tnt string, rPrfl *RouteProfile, sortedRoutes.Routes = sortedRoutes.Routes[:*pag.Limit] } } - sortedRoutes.Count = len(sortedRoutes.Routes) return } @@ -731,7 +730,7 @@ func (rpS *RouteService) sortedRoutesForEvent(tnt string, args *ArgsGetRoutes) ( if sr, err = rpS.sortedRoutesForProfile(tnt, rPrfl, args.CGREvent, prfPag, extraOpts); err != nil { return } - noSrtRoutes += sr.Count + noSrtRoutes += len(sr.Routes) sortedRoutes = append(sortedRoutes, sr) if len(sortedRoutes) == prfCount { // the profile count was reached break diff --git a/engine/routes_test.go b/engine/routes_test.go index 81488d5ad..f9e1c578d 100644 --- a/engine/routes_test.go +++ b/engine/routes_test.go @@ -799,7 +799,6 @@ func TestRoutesSortedForEvent(t *testing.T) { eFirstRouteProfile := SortedRoutesList{&SortedRoutes{ ProfileID: "RouteProfile1", Sorting: utils.MetaWeight, - Count: 1, Routes: []*SortedRoute{ { RouteID: "route1", @@ -821,7 +820,6 @@ func TestRoutesSortedForEvent(t *testing.T) { eFirstRouteProfile = SortedRoutesList{&SortedRoutes{ ProfileID: "RouteProfile2", Sorting: utils.MetaWeight, - Count: 3, Routes: []*SortedRoute{ { RouteID: "route1", @@ -858,7 +856,6 @@ func TestRoutesSortedForEvent(t *testing.T) { eFirstRouteProfile = SortedRoutesList{&SortedRoutes{ ProfileID: "RouteProfilePrefix", Sorting: utils.MetaWeight, - Count: 1, Routes: []*SortedRoute{ { RouteID: "route1", @@ -1110,7 +1107,6 @@ func TestRoutesSortedForEventWithLimit(t *testing.T) { eFirstRouteProfile := SortedRoutesList{&SortedRoutes{ ProfileID: "RouteProfile2", Sorting: utils.MetaWeight, - Count: 2, Routes: []*SortedRoute{ { RouteID: "route1", @@ -1371,7 +1367,6 @@ func TestRoutesSortedForEventWithOffset(t *testing.T) { eFirstRouteProfile := SortedRoutesList{&SortedRoutes{ ProfileID: "RouteProfile2", Sorting: utils.MetaWeight, - Count: 1, Routes: []*SortedRoute{ { RouteID: "route3", @@ -1625,7 +1620,6 @@ func TestRoutesSortedForEventWithLimitAndOffset(t *testing.T) { eFirstRouteProfile := SortedRoutesList{&SortedRoutes{ ProfileID: "RouteProfile2", Sorting: utils.MetaWeight, - Count: 1, Routes: []*SortedRoute{ { RouteID: "route2", @@ -2290,7 +2284,6 @@ func TestRoutesSortedForEventWithLimitAndOffset2(t *testing.T) { { ProfileID: "RouteProfile1", Sorting: utils.MetaWeight, - Count: 1, Routes: []*SortedRoute{ { RouteID: "route2", @@ -2304,7 +2297,6 @@ func TestRoutesSortedForEventWithLimitAndOffset2(t *testing.T) { { ProfileID: "RouteProfile2", Sorting: utils.MetaWeight, - Count: 1, Routes: []*SortedRoute{ { RouteID: "route1", diff --git a/ers/filecsv.go b/ers/filecsv.go index 9b43d0da1..272540ffd 100644 --- a/ers/filecsv.go +++ b/ers/filecsv.go @@ -141,7 +141,7 @@ func (rdr *CSVFileER) processFile(fPath, fName string) (err error) { rowNr := 0 // This counts the rows in the file, not really number of CDRs evsPosted := 0 timeStart := time.Now() - reqVars := utils.NavigableMap2{utils.FileName: utils.NewNMData(fName)} + reqVars := utils.NavigableMap{utils.FileName: utils.NewNMData(fName)} for { var record []string if record, err = csvReader.Read(); err != nil { diff --git a/ers/filefwv.go b/ers/filefwv.go index 7b561ac59..5b5334a9e 100644 --- a/ers/filefwv.go +++ b/ers/filefwv.go @@ -140,7 +140,7 @@ func (rdr *FWVFileER) processFile(fPath, fName string) (err error) { rowNr := 0 // This counts the rows in the file, not really number of CDRs evsPosted := 0 timeStart := time.Now() - reqVars := utils.NavigableMap2{utils.FileName: utils.NewNMData(fName)} + reqVars := utils.NavigableMap{utils.FileName: utils.NewNMData(fName)} for { var hasHeader, hasTrailer bool diff --git a/ers/filejson.go b/ers/filejson.go index 2e4891b98..37d05210c 100644 --- a/ers/filejson.go +++ b/ers/filejson.go @@ -142,7 +142,7 @@ func (rdr *JSONFileER) processFile(fPath, fName string) (err error) { } evsPosted := 0 - reqVars := utils.NavigableMap2{utils.FileName: utils.NewNMData(fName)} + reqVars := utils.NavigableMap{utils.FileName: utils.NewNMData(fName)} agReq := agents.NewAgentRequest( utils.MapStorage(data), reqVars, diff --git a/ers/filexml.go b/ers/filexml.go index 7893e9312..8527f5dee 100644 --- a/ers/filexml.go +++ b/ers/filexml.go @@ -138,7 +138,7 @@ func (rdr *XMLFileER) processFile(fPath, fName string) (err error) { rowNr := 0 // This counts the rows in the file, not really number of CDRs evsPosted := 0 timeStart := time.Now() - reqVars := utils.NavigableMap2{utils.FileName: utils.NewNMData(fName)} + reqVars := utils.NavigableMap{utils.FileName: utils.NewNMData(fName)} for _, xmlElmt := range xmlElmts { rowNr++ // increment the rowNr after checking if it's not the end of file agReq := agents.NewAgentRequest( diff --git a/ers/flatstore.go b/ers/flatstore.go index d81f85886..55101ccf5 100644 --- a/ers/flatstore.go +++ b/ers/flatstore.go @@ -147,7 +147,7 @@ func (rdr *FlatstoreER) processFile(fPath, fName string) (err error) { rowNr := 0 // This counts the rows in the file, not really number of CDRs evsPosted := 0 timeStart := time.Now() - reqVars := utils.NavigableMap2{utils.FileName: utils.NewNMData(fName)} + reqVars := utils.NavigableMap{utils.FileName: utils.NewNMData(fName)} for { var record []string if record, err = csvReader.Read(); err != nil { diff --git a/ers/partial_csv.go b/ers/partial_csv.go index 730b738ce..0e5d92408 100644 --- a/ers/partial_csv.go +++ b/ers/partial_csv.go @@ -155,7 +155,7 @@ func (rdr *PartialCSVFileER) processFile(fPath, fName string) (err error) { rowNr := 0 // This counts the rows in the file, not really number of CDRs evsPosted := 0 timeStart := time.Now() - reqVars := utils.NavigableMap2{utils.FileName: utils.NewNMData(fName)} + reqVars := utils.NavigableMap{utils.FileName: utils.NewNMData(fName)} for { var record []string if record, err = csvReader.Read(); err != nil { diff --git a/general_tests/route_it_test.go b/general_tests/route_it_test.go index 8f4f4cb29..0b0b6a4b9 100644 --- a/general_tests/route_it_test.go +++ b/general_tests/route_it_test.go @@ -174,7 +174,7 @@ func testV1SplSSetSupplierProfilesWithoutRatingPlanIDs(t *testing.T) { }, }, } - var suplsReply engine.SortedRoutes + var suplsReply engine.SortedRoutesList if err := splSv1Rpc.Call(utils.RouteSv1GetRoutes, ev, &suplsReply); err == nil || err.Error() != utils.NewErrServerError(utils.ErrAccountNotFound).Error() { t.Error(err) @@ -445,18 +445,18 @@ func testV1SplSGetSortedSuppliers(t *testing.T) { }, } expSupplierIDs := []string{"route3", "route2", "route1"} - var suplsReply engine.SortedRoutes + var suplsReply engine.SortedRoutesList if err := splSv1Rpc.Call(utils.RouteSv1GetRoutes, ev, &suplsReply); err != nil { t.Error(err) } else { - rcvSupl := make([]string, len(suplsReply.Routes)) - for i, supl := range suplsReply.Routes { + rcvSupl := make([]string, len(suplsReply[0].Routes)) + for i, supl := range suplsReply[0].Routes { rcvSupl[i] = supl.RouteID } - if suplsReply.ProfileID != "ROUTE_ResourceTest" { + if suplsReply[0].ProfileID != "ROUTE_ResourceTest" { t.Errorf("Expecting: ROUTE_ResourceTest, received: %s", - suplsReply.ProfileID) + suplsReply[0].ProfileID) } if !reflect.DeepEqual(rcvSupl, expSupplierIDs) { t.Errorf("Expecting: %+v, \n received: %+v", @@ -529,18 +529,18 @@ func testV1SplSGetSortedSuppliers2(t *testing.T) { }, } expSupplierIDs := []string{"route1", "route3", "route2"} - var suplsReply engine.SortedRoutes + var suplsReply engine.SortedRoutesList if err := splSv1Rpc.Call(utils.RouteSv1GetRoutes, ev, &suplsReply); err != nil { t.Error(err) } else { - rcvSupl := make([]string, len(suplsReply.Routes)) - for i, supl := range suplsReply.Routes { + rcvSupl := make([]string, len(suplsReply[0].Routes)) + for i, supl := range suplsReply[0].Routes { rcvSupl[i] = supl.RouteID } - if suplsReply.ProfileID != "ROUTE_ResourceDescendent" { + if suplsReply[0].ProfileID != "ROUTE_ResourceDescendent" { t.Errorf("Expecting: ROUTE_ResourceDescendent, received: %s", - suplsReply.ProfileID) + suplsReply[0].ProfileID) } if !reflect.DeepEqual(rcvSupl, expSupplierIDs) { t.Errorf("Expecting: %+v, \n received: %+v", @@ -743,18 +743,18 @@ func testV1SplSGetSoredSuppliersWithLoad(t *testing.T) { }, } - var suplsReply engine.SortedRoutes + var suplsReply engine.SortedRoutesList if err := splSv1Rpc.Call(utils.RouteSv1GetRoutes, ev, &suplsReply); err != nil { t.Error(err) } else { - if suplsReply.ProfileID != "ROUTE_LOAD_DIST" { + if suplsReply[0].ProfileID != "ROUTE_LOAD_DIST" { t.Errorf("Expecting: ROUTE_LOAD_DIST, received: %s", - suplsReply.ProfileID) + suplsReply[0].ProfileID) } - if !reflect.DeepEqual(suplsReply.Routes, expSuppliers) { + if !reflect.DeepEqual(suplsReply[0].Routes, expSuppliers) { t.Errorf("Expecting: %+v, \n received: %+v", - utils.ToJSON(expSuppliers), utils.ToJSON(suplsReply.Routes)) + utils.ToJSON(expSuppliers), utils.ToJSON(suplsReply[0].Routes)) } } } diff --git a/general_tests/sessionroutes_it_test.go b/general_tests/sessionroutes_it_test.go index f3e076835..5b928d562 100644 --- a/general_tests/sessionroutes_it_test.go +++ b/general_tests/sessionroutes_it_test.go @@ -131,6 +131,7 @@ func testSesRoutesAuthorizeEvent(t *testing.T) { utils.SetupTime: time.Date(2018, 8, 24, 16, 00, 00, 0, time.UTC), utils.Usage: time.Minute, }, + Opts: map[string]interface{}{utils.OptsRouteProfilesCount: 1}, } args := sessions.NewV1AuthorizeArgs(false, []string{}, false, []string{}, false, []string{}, false, false, @@ -141,10 +142,9 @@ func testSesRoutesAuthorizeEvent(t *testing.T) { t.Fatal(err) } expected := sessions.V1AuthorizeReply{ - Routes: engine.SortedRoutesList{{ + RouteProfiles: engine.SortedRoutesList{{ ProfileID: "ROUTE_LEASTCOST_1", Sorting: "*lc", - Count: 3, Routes: []*engine.SortedRoute{ { RouteID: "route3", @@ -192,10 +192,9 @@ func testSesRoutesAuthorizeEvent(t *testing.T) { } expected = sessions.V1AuthorizeReply{ - Routes: engine.SortedRoutesList{{ + RouteProfiles: engine.SortedRoutesList{{ ProfileID: "ROUTE_LEASTCOST_1", Sorting: "*lc", - Count: 2, Routes: []*engine.SortedRoute{ { RouteID: "route3", @@ -263,6 +262,7 @@ func testSesRoutesProcessMessage(t *testing.T) { utils.SetupTime: time.Date(2018, 8, 24, 16, 00, 00, 0, time.UTC), utils.Usage: time.Minute, }, + Opts: map[string]interface{}{utils.OptsRouteProfilesCount: 1}, } args := sessions.NewV1ProcessMessageArgs(false, []string{}, false, []string{}, false, []string{}, false, false, @@ -274,10 +274,9 @@ func testSesRoutesProcessMessage(t *testing.T) { t.Fatal(err) } expected := sessions.V1ProcessMessageReply{ - Routes: engine.SortedRoutesList{{ + RouteProfiles: engine.SortedRoutesList{{ ProfileID: "ROUTE_LEASTCOST_1", Sorting: "*lc", - Count: 3, Routes: []*engine.SortedRoute{ { RouteID: "route3", @@ -326,10 +325,9 @@ func testSesRoutesProcessMessage(t *testing.T) { } expected = sessions.V1ProcessMessageReply{ - Routes: engine.SortedRoutesList{{ + RouteProfiles: engine.SortedRoutesList{{ ProfileID: "ROUTE_LEASTCOST_1", Sorting: "*lc", - Count: 2, Routes: []*engine.SortedRoute{ { RouteID: "route3", @@ -397,6 +395,7 @@ func testSesRoutesProcessEvent(t *testing.T) { utils.SetupTime: time.Date(2018, 8, 24, 16, 00, 00, 0, time.UTC), utils.Usage: time.Minute, }, + Opts: map[string]interface{}{utils.OptsRouteProfilesCount: 1}, } args := sessions.V1ProcessEventArgs{ Flags: []string{"*routes"}, @@ -409,11 +408,10 @@ func testSesRoutesProcessEvent(t *testing.T) { t.Fatal(err) } expected := sessions.V1ProcessEventReply{ - Routes: map[string]engine.SortedRoutesList{ + RouteProfiles: map[string]engine.SortedRoutesList{ utils.MetaRaw: {{ ProfileID: "ROUTE_LEASTCOST_1", Sorting: "*lc", - Count: 3, Routes: []*engine.SortedRoute{ { RouteID: "route3", @@ -465,11 +463,10 @@ func testSesRoutesProcessEvent(t *testing.T) { } expected = sessions.V1ProcessEventReply{ - Routes: map[string]engine.SortedRoutesList{ + RouteProfiles: map[string]engine.SortedRoutesList{ utils.MetaRaw: {{ ProfileID: "ROUTE_LEASTCOST_1", Sorting: "*lc", - Count: 2, Routes: []*engine.SortedRoute{ { RouteID: "route3", diff --git a/packages/debian/changelog b/packages/debian/changelog index 2be22052d..b18fa5a57 100644 --- a/packages/debian/changelog +++ b/packages/debian/changelog @@ -150,6 +150,8 @@ cgrates (0.11.0~dev) UNRELEASED; urgency=medium * [DataDB] Added replication filtering * [ApierS] Moved Cache field as options * [RouteS] Updated RouteSv1.GetRoutes API to return multiple profiles + * [Templates] Added support for Length Field in case of NMSlice + * [Templates] Added support for multiple indexes -- DanB Wed, 19 Feb 2020 13:25:52 +0200 diff --git a/sessions/sessions.go b/sessions/sessions.go index e41c7c934..e20018520 100644 --- a/sessions/sessions.go +++ b/sessions/sessions.go @@ -1856,7 +1856,7 @@ type V1AuthorizeReply struct { Attributes *engine.AttrSProcessEventReply `json:",omitempty"` ResourceAllocation *string `json:",omitempty"` MaxUsage *time.Duration `json:",omitempty"` - Routes engine.SortedRoutesList `json:",omitempty"` + RouteProfiles engine.SortedRoutesList `json:",omitempty"` ThresholdIDs *[]string `json:",omitempty"` StatQueueIDs *[]string `json:",omitempty"` @@ -1873,10 +1873,10 @@ func (v1AuthReply *V1AuthorizeReply) SetMaxUsageNeeded(getMaxUsage bool) { } // AsNavigableMap is part of engine.NavigableMapper interface -func (v1AuthReply *V1AuthorizeReply) AsNavigableMap() utils.NavigableMap2 { - cgrReply := make(utils.NavigableMap2) +func (v1AuthReply *V1AuthorizeReply) AsNavigableMap() utils.NavigableMap { + cgrReply := make(utils.NavigableMap) if v1AuthReply.Attributes != nil { - attrs := make(utils.NavigableMap2) + attrs := make(utils.NavigableMap) for _, fldName := range v1AuthReply.Attributes.AlteredFields { fldName = strings.TrimPrefix(fldName, utils.MetaReq+utils.NestingSep) if v1AuthReply.Attributes.CGREvent.HasField(fldName) { @@ -1894,9 +1894,9 @@ func (v1AuthReply *V1AuthorizeReply) AsNavigableMap() utils.NavigableMap2 { cgrReply[utils.CapMaxUsage] = utils.NewNMData(0) } - if v1AuthReply.Routes != nil { - nm := v1AuthReply.Routes.AsNavigableMap() - cgrReply[utils.CapRoutes] = &nm + if v1AuthReply.RouteProfiles != nil { + nm := v1AuthReply.RouteProfiles.AsNavigableMap() + cgrReply[utils.CapRouteProfiles] = &nm } if v1AuthReply.ThresholdIDs != nil { thIDs := make(utils.NMSlice, len(*v1AuthReply.ThresholdIDs)) @@ -2005,7 +2005,7 @@ func (sS *SessionS) BiRPCv1AuthorizeEvent(clnt rpcclient.ClientConnector, return err } if routesReply != nil { - authReply.Routes = routesReply + authReply.RouteProfiles = routesReply } } if args.ProcessThresholds { @@ -2063,7 +2063,7 @@ func (sS *SessionS) BiRPCv1AuthorizeEventWithDigest(clnt rpcclient.ClientConnect authReply.MaxUsage = initAuthRply.MaxUsage.Seconds() } if args.GetRoutes { - authReply.RoutesDigest = utils.StringPointer(initAuthRply.Routes.Digest()) + authReply.RoutesDigest = utils.StringPointer(initAuthRply.RouteProfiles.Digest()) } if args.ProcessThresholds { authReply.Thresholds = utils.StringPointer( @@ -2159,10 +2159,10 @@ func (v1Rply *V1InitSessionReply) SetMaxUsageNeeded(getMaxUsage bool) { } // AsNavigableMap is part of engine.NavigableMapper interface -func (v1Rply *V1InitSessionReply) AsNavigableMap() utils.NavigableMap2 { - cgrReply := make(utils.NavigableMap2) +func (v1Rply *V1InitSessionReply) AsNavigableMap() utils.NavigableMap { + cgrReply := make(utils.NavigableMap) if v1Rply.Attributes != nil { - attrs := make(utils.NavigableMap2) + attrs := make(utils.NavigableMap) for _, fldName := range v1Rply.Attributes.AlteredFields { fldName = strings.TrimPrefix(fldName, utils.MetaReq+utils.NestingSep) if v1Rply.Attributes.CGREvent.HasField(fldName) { @@ -2409,10 +2409,10 @@ func (v1Rply *V1UpdateSessionReply) SetMaxUsageNeeded(getMaxUsage bool) { } // AsNavigableMap is part of engine.NavigableMapper interface -func (v1Rply *V1UpdateSessionReply) AsNavigableMap() utils.NavigableMap2 { - cgrReply := make(utils.NavigableMap2) +func (v1Rply *V1UpdateSessionReply) AsNavigableMap() utils.NavigableMap { + cgrReply := make(utils.NavigableMap) if v1Rply.Attributes != nil { - attrs := make(utils.NavigableMap2) + attrs := make(utils.NavigableMap) for _, fldName := range v1Rply.Attributes.AlteredFields { fldName = strings.TrimPrefix(fldName, utils.MetaReq+utils.NestingSep) if v1Rply.Attributes.CGREvent.HasField(fldName) { @@ -2825,7 +2825,7 @@ type V1ProcessMessageReply struct { MaxUsage *time.Duration `json:",omitempty"` ResourceAllocation *string `json:",omitempty"` Attributes *engine.AttrSProcessEventReply `json:",omitempty"` - Routes engine.SortedRoutesList `json:",omitempty"` + RouteProfiles engine.SortedRoutesList `json:",omitempty"` ThresholdIDs *[]string `json:",omitempty"` StatQueueIDs *[]string `json:",omitempty"` @@ -2842,8 +2842,8 @@ func (v1Rply *V1ProcessMessageReply) SetMaxUsageNeeded(getMaxUsage bool) { } // AsNavigableMap is part of engine.NavigableMapper interface -func (v1Rply *V1ProcessMessageReply) AsNavigableMap() utils.NavigableMap2 { - cgrReply := make(utils.NavigableMap2) +func (v1Rply *V1ProcessMessageReply) AsNavigableMap() utils.NavigableMap { + cgrReply := make(utils.NavigableMap) if v1Rply.MaxUsage != nil { cgrReply[utils.CapMaxUsage] = utils.NewNMData(*v1Rply.MaxUsage) } else if v1Rply.needsMaxUsage { @@ -2853,7 +2853,7 @@ func (v1Rply *V1ProcessMessageReply) AsNavigableMap() utils.NavigableMap2 { cgrReply[utils.CapResourceAllocation] = utils.NewNMData(*v1Rply.ResourceAllocation) } if v1Rply.Attributes != nil { - attrs := make(utils.NavigableMap2) + attrs := make(utils.NavigableMap) for _, fldName := range v1Rply.Attributes.AlteredFields { fldName = strings.TrimPrefix(fldName, utils.MetaReq+utils.NestingSep) if v1Rply.Attributes.CGREvent.HasField(fldName) { @@ -2862,9 +2862,9 @@ func (v1Rply *V1ProcessMessageReply) AsNavigableMap() utils.NavigableMap2 { } cgrReply[utils.CapAttributes] = attrs } - if v1Rply.Routes != nil { - nm := v1Rply.Routes.AsNavigableMap() - cgrReply[utils.CapRoutes] = &nm + if v1Rply.RouteProfiles != nil { + nm := v1Rply.RouteProfiles.AsNavigableMap() + cgrReply[utils.CapRouteProfiles] = &nm } if v1Rply.ThresholdIDs != nil { thIDs := make(utils.NMSlice, len(*v1Rply.ThresholdIDs)) @@ -2955,7 +2955,7 @@ func (sS *SessionS) BiRPCv1ProcessMessage(clnt rpcclient.ClientConnector, return err } if routesReply != nil { - rply.Routes = routesReply + rply.RouteProfiles = routesReply } } if args.Debit { @@ -3006,33 +3006,33 @@ type V1ProcessEventReply struct { Cost map[string]float64 `json:",omitempty"` // Cost is the cost received from Rater, ignoring accounting part ResourceAllocation map[string]string `json:",omitempty"` Attributes map[string]*engine.AttrSProcessEventReply `json:",omitempty"` - Routes map[string]engine.SortedRoutesList `json:",omitempty"` + RouteProfiles map[string]engine.SortedRoutesList `json:",omitempty"` ThresholdIDs map[string][]string `json:",omitempty"` StatQueueIDs map[string][]string `json:",omitempty"` STIRIdentity map[string]string `json:",omitempty"` } // AsNavigableMap is part of engine.NavigableMapper interface -func (v1Rply *V1ProcessEventReply) AsNavigableMap() utils.NavigableMap2 { - cgrReply := make(utils.NavigableMap2) +func (v1Rply *V1ProcessEventReply) AsNavigableMap() utils.NavigableMap { + cgrReply := make(utils.NavigableMap) if v1Rply.MaxUsage != nil { - usage := make(utils.NavigableMap2) + usage := make(utils.NavigableMap) for k, v := range v1Rply.MaxUsage { usage[k] = utils.NewNMData(v) } cgrReply[utils.CapMaxUsage] = usage } if v1Rply.ResourceAllocation != nil { - res := make(utils.NavigableMap2) + res := make(utils.NavigableMap) for k, v := range v1Rply.ResourceAllocation { res[k] = utils.NewNMData(v) } cgrReply[utils.CapResourceAllocation] = res } if v1Rply.Attributes != nil { - atts := make(utils.NavigableMap2) + atts := make(utils.NavigableMap) for k, att := range v1Rply.Attributes { - attrs := make(utils.NavigableMap2) + attrs := make(utils.NavigableMap) for _, fldName := range att.AlteredFields { fldName = strings.TrimPrefix(fldName, utils.MetaReq+utils.NestingSep) if att.CGREvent.HasField(fldName) { @@ -3043,16 +3043,16 @@ func (v1Rply *V1ProcessEventReply) AsNavigableMap() utils.NavigableMap2 { } cgrReply[utils.CapAttributes] = atts } - if v1Rply.Routes != nil { - routes := make(utils.NavigableMap2) - for k, route := range v1Rply.Routes { + if v1Rply.RouteProfiles != nil { + routes := make(utils.NavigableMap) + for k, route := range v1Rply.RouteProfiles { nm := route.AsNavigableMap() routes[k] = &nm } - cgrReply[utils.CapRoutes] = routes + cgrReply[utils.CapRouteProfiles] = routes } if v1Rply.ThresholdIDs != nil { - th := make(utils.NavigableMap2) + th := make(utils.NavigableMap) for k, thr := range v1Rply.ThresholdIDs { thIDs := make(utils.NMSlice, len(thr)) for i, v := range thr { @@ -3063,7 +3063,7 @@ func (v1Rply *V1ProcessEventReply) AsNavigableMap() utils.NavigableMap2 { cgrReply[utils.CapThresholds] = th } if v1Rply.StatQueueIDs != nil { - st := make(utils.NavigableMap2) + st := make(utils.NavigableMap) for k, sts := range v1Rply.StatQueueIDs { stIDs := make(utils.NMSlice, len(sts)) for i, v := range sts { @@ -3074,13 +3074,13 @@ func (v1Rply *V1ProcessEventReply) AsNavigableMap() utils.NavigableMap2 { cgrReply[utils.CapStatQueues] = st } if v1Rply.Cost != nil { - costs := make(utils.NavigableMap2) + costs := make(utils.NavigableMap) for k, cost := range v1Rply.Cost { costs[k] = utils.NewNMData(cost) } } if v1Rply.STIRIdentity != nil { - stir := make(utils.NavigableMap2) + stir := make(utils.NavigableMap) for k, v := range v1Rply.STIRIdentity { stir[k] = utils.NewNMData(v) } @@ -3161,7 +3161,7 @@ func (sS *SessionS) BiRPCv1ProcessEvent(clnt rpcclient.ClientConnector, // get routes if required if argsFlagsWithParams.GetBool(utils.MetaRoutes) { - rply.Routes = make(map[string]engine.SortedRoutesList) + rply.RouteProfiles = make(map[string]engine.SortedRoutesList) // check in case we have options for suppliers flags := argsFlagsWithParams[utils.MetaRoutes] ignoreErrors := flags.Has(utils.MetaIgnoreErrors) @@ -3177,7 +3177,7 @@ func (sS *SessionS) BiRPCv1ProcessEvent(clnt rpcclient.ClientConnector, return err } if routesReply != nil { - rply.Routes[runID] = routesReply + rply.RouteProfiles[runID] = routesReply } } } diff --git a/sessions/sessions_test.go b/sessions/sessions_test.go index 643943b5a..b826137fe 100644 --- a/sessions/sessions_test.go +++ b/sessions/sessions_test.go @@ -1305,12 +1305,12 @@ func TestSessionSV1AuthorizeReplyAsNavigableMap(t *testing.T) { thIDs := &[]string{"THD_RES_1", "THD_STATS_1", "THD_STATS_2", "THD_CDRS_1"} statIDs := &[]string{"Stats2", "Stats1", "Stats3"} v1AuthRpl := new(V1AuthorizeReply) - expected := utils.NavigableMap2{} + expected := utils.NavigableMap{} if rply := v1AuthRpl.AsNavigableMap(); !reflect.DeepEqual(expected, rply) { t.Errorf("Expecting \n%+v\n, received: \n%+v", expected, rply) } v1AuthRpl.Attributes = attrs - expected[utils.CapAttributes] = utils.NavigableMap2{"OfficeGroup": utils.NewNMData("Marketing")} + expected[utils.CapAttributes] = utils.NavigableMap{"OfficeGroup": utils.NewNMData("Marketing")} if rply := v1AuthRpl.AsNavigableMap(); !reflect.DeepEqual(expected, rply) { t.Errorf("Expecting \n%+v\n, received: \n%+v", expected, rply) } @@ -1328,16 +1328,16 @@ func TestSessionSV1AuthorizeReplyAsNavigableMap(t *testing.T) { Attributes: attrs, ResourceAllocation: utils.StringPointer("ResGr1"), MaxUsage: utils.DurationPointer(5 * time.Minute), - Routes: splrs, + RouteProfiles: splrs, ThresholdIDs: thIDs, StatQueueIDs: statIDs, } nm := splrs.AsNavigableMap() - expected = utils.NavigableMap2{ - utils.CapAttributes: utils.NavigableMap2{"OfficeGroup": utils.NewNMData("Marketing")}, + expected = utils.NavigableMap{ + utils.CapAttributes: utils.NavigableMap{"OfficeGroup": utils.NewNMData("Marketing")}, utils.CapResourceAllocation: utils.NewNMData("ResGr1"), utils.CapMaxUsage: utils.NewNMData(5 * time.Minute), - utils.CapRoutes: &nm, + utils.CapRouteProfiles: &nm, utils.CapThresholds: &utils.NMSlice{utils.NewNMData("THD_RES_1"), utils.NewNMData("THD_STATS_1"), utils.NewNMData("THD_STATS_2"), utils.NewNMData("THD_CDRS_1")}, utils.CapStatQueues: &utils.NMSlice{utils.NewNMData("Stats2"), utils.NewNMData("Stats1"), utils.NewNMData("Stats3")}, } @@ -1350,12 +1350,12 @@ func TestSessionSV1InitSessionReplyAsNavigableMap(t *testing.T) { thIDs := &[]string{"THD_RES_1", "THD_STATS_1", "THD_STATS_2", "THD_CDRS_1"} statIDs := &[]string{"Stats2", "Stats1", "Stats3"} v1InitRpl := new(V1InitSessionReply) - expected := utils.NavigableMap2{} + expected := utils.NavigableMap{} if rply := v1InitRpl.AsNavigableMap(); !reflect.DeepEqual(expected, rply) { t.Errorf("Expecting \n%+v\n, received: \n%+v", expected, rply) } v1InitRpl.Attributes = attrs - expected[utils.CapAttributes] = utils.NavigableMap2{"OfficeGroup": utils.NewNMData("Marketing")} + expected[utils.CapAttributes] = utils.NavigableMap{"OfficeGroup": utils.NewNMData("Marketing")} if rply := v1InitRpl.AsNavigableMap(); !reflect.DeepEqual(expected, rply) { t.Errorf("Expecting \n%+v\n, received: \n%+v", expected, rply) } @@ -1376,8 +1376,8 @@ func TestSessionSV1InitSessionReplyAsNavigableMap(t *testing.T) { ThresholdIDs: thIDs, StatQueueIDs: statIDs, } - expected = utils.NavigableMap2{ - utils.CapAttributes: utils.NavigableMap2{"OfficeGroup": utils.NewNMData("Marketing")}, + expected = utils.NavigableMap{ + utils.CapAttributes: utils.NavigableMap{"OfficeGroup": utils.NewNMData("Marketing")}, utils.CapResourceAllocation: utils.NewNMData("ResGr1"), utils.CapMaxUsage: utils.NewNMData(5 * time.Minute), utils.CapThresholds: &utils.NMSlice{utils.NewNMData("THD_RES_1"), utils.NewNMData("THD_STATS_1"), utils.NewNMData("THD_STATS_2"), utils.NewNMData("THD_CDRS_1")}, @@ -1390,12 +1390,12 @@ func TestSessionSV1InitSessionReplyAsNavigableMap(t *testing.T) { func TestSessionSV1UpdateSessionReplyAsNavigableMap(t *testing.T) { v1UpdtRpl := new(V1UpdateSessionReply) - expected := utils.NavigableMap2{} + expected := utils.NavigableMap{} if rply := v1UpdtRpl.AsNavigableMap(); !reflect.DeepEqual(expected, rply) { t.Errorf("Expecting \n%+v\n, received: \n%+v", expected, rply) } v1UpdtRpl.Attributes = attrs - expected[utils.CapAttributes] = utils.NavigableMap2{"OfficeGroup": utils.NewNMData("Marketing")} + expected[utils.CapAttributes] = utils.NavigableMap{"OfficeGroup": utils.NewNMData("Marketing")} if rply := v1UpdtRpl.AsNavigableMap(); !reflect.DeepEqual(expected, rply) { t.Errorf("Expecting \n%+v\n, received: \n%+v", expected, rply) } @@ -1467,13 +1467,13 @@ func TestSetMaxUsageNeededAuthorizeReply(t *testing.T) { func TestSessionSV1ProcessMessageReplyAsNavigableMap(t *testing.T) { v1PrcEvRpl := new(V1ProcessMessageReply) - expected := utils.NavigableMap2{} + expected := utils.NavigableMap{} if rply := v1PrcEvRpl.AsNavigableMap(); !reflect.DeepEqual(expected, rply) { t.Errorf("Expecting \n%+v\n, received: \n%+v", expected, rply) } v1PrcEvRpl.Attributes = attrs - expected[utils.CapAttributes] = utils.NavigableMap2{"OfficeGroup": utils.NewNMData("Marketing")} + expected[utils.CapAttributes] = utils.NavigableMap{"OfficeGroup": utils.NewNMData("Marketing")} if rply := v1PrcEvRpl.AsNavigableMap(); !reflect.DeepEqual(expected, rply) { t.Errorf("Expecting \n%+v\n, received: \n%+v", expected, rply) } @@ -1501,14 +1501,13 @@ func TestSessionSV1ProcessMessageReplyAsNavigableMap(t *testing.T) { tmpStatQueueIDs := []string{"Que1", "Que2"} tmpRoutes := engine.SortedRoutesList{{ ProfileID: "Route1", - Count: 1, }} - v1PrcEvRpl.Routes = tmpRoutes + v1PrcEvRpl.RouteProfiles = tmpRoutes v1PrcEvRpl.ThresholdIDs = &tmpTresholdIDs v1PrcEvRpl.StatQueueIDs = &tmpStatQueueIDs expected[utils.CapResourceAllocation] = utils.NewNMData("ResGr1") nm := tmpRoutes.AsNavigableMap() - expected[utils.CapRoutes] = &nm + expected[utils.CapRouteProfiles] = &nm expected[utils.CapThresholds] = &utils.NMSlice{utils.NewNMData("ID1"), utils.NewNMData("ID2")} expected[utils.CapStatQueues] = &utils.NMSlice{utils.NewNMData("Que1"), utils.NewNMData("Que2")} if rply := v1PrcEvRpl.AsNavigableMap(); !reflect.DeepEqual(expected, rply) { @@ -1519,38 +1518,37 @@ func TestSessionSV1ProcessMessageReplyAsNavigableMap(t *testing.T) { func TestV1ProcessEventReplyAsNavigableMap(t *testing.T) { //empty check v1per := new(V1ProcessEventReply) - expected := utils.NavigableMap2{} + expected := utils.NavigableMap{} if rply := v1per.AsNavigableMap(); !reflect.DeepEqual(expected, rply) { t.Errorf("Expecting \n%+v\n, received: \n%+v", expected, rply) } //max usage check v1per.MaxUsage = map[string]time.Duration{utils.MetaDefault: 5 * time.Minute} - expected[utils.CapMaxUsage] = utils.NavigableMap2{utils.MetaDefault: utils.NewNMData(5 * time.Minute)} + expected[utils.CapMaxUsage] = utils.NavigableMap{utils.MetaDefault: utils.NewNMData(5 * time.Minute)} if rply := v1per.AsNavigableMap(); !reflect.DeepEqual(expected, rply) { t.Errorf("Expecting \n%+v\n, received: \n%+v", expected, rply) } //resource message check v1per.ResourceAllocation = map[string]string{utils.MetaDefault: "Resource"} - expected[utils.CapResourceAllocation] = utils.NavigableMap2{utils.MetaDefault: utils.NewNMData("Resource")} + expected[utils.CapResourceAllocation] = utils.NavigableMap{utils.MetaDefault: utils.NewNMData("Resource")} if rply := v1per.AsNavigableMap(); !reflect.DeepEqual(expected, rply) { t.Errorf("Expecting \n%+v\n, received: \n%+v", expected, rply) } //attributes check v1per.Attributes = make(map[string]*engine.AttrSProcessEventReply) v1per.Attributes[utils.MetaRaw] = attrs - expected[utils.CapAttributes] = utils.NavigableMap2{utils.MetaRaw: utils.NavigableMap2{"OfficeGroup": utils.NewNMData("Marketing")}} + expected[utils.CapAttributes] = utils.NavigableMap{utils.MetaRaw: utils.NavigableMap{"OfficeGroup": utils.NewNMData("Marketing")}} if rply := v1per.AsNavigableMap(); !reflect.DeepEqual(expected, rply) { t.Errorf("Expecting \n%+v\n, received: \n%+v", expected, rply) } //routes check tmpRoutes := engine.SortedRoutesList{{ ProfileID: "Route1", - Count: 1, }} nm := tmpRoutes.AsNavigableMap() - v1per.Routes = make(map[string]engine.SortedRoutesList) - v1per.Routes[utils.MetaRaw] = tmpRoutes - expected[utils.CapRoutes] = utils.NavigableMap2{utils.MetaRaw: &nm} + v1per.RouteProfiles = make(map[string]engine.SortedRoutesList) + v1per.RouteProfiles[utils.MetaRaw] = tmpRoutes + expected[utils.CapRouteProfiles] = utils.NavigableMap{utils.MetaRaw: &nm} if rply := v1per.AsNavigableMap(); !reflect.DeepEqual(expected, rply) { t.Errorf("Expecting \n%+v\n, received: \n%+v", expected, rply) } @@ -1558,7 +1556,7 @@ func TestV1ProcessEventReplyAsNavigableMap(t *testing.T) { tmpTresholdIDs := []string{"ID1", "ID2"} v1per.ThresholdIDs = map[string][]string{} v1per.ThresholdIDs[utils.MetaRaw] = tmpTresholdIDs - expected[utils.CapThresholds] = utils.NavigableMap2{utils.MetaRaw: &utils.NMSlice{utils.NewNMData("ID1"), utils.NewNMData("ID2")}} + expected[utils.CapThresholds] = utils.NavigableMap{utils.MetaRaw: &utils.NMSlice{utils.NewNMData("ID1"), utils.NewNMData("ID2")}} if rply := v1per.AsNavigableMap(); !reflect.DeepEqual(expected, rply) { t.Errorf("Expecting \n%+v\n, received: \n%+v", expected, rply) } @@ -1566,7 +1564,7 @@ func TestV1ProcessEventReplyAsNavigableMap(t *testing.T) { tmpStatQueueIDs := []string{"Que1", "Que2"} v1per.StatQueueIDs = make(map[string][]string) v1per.StatQueueIDs[utils.MetaRaw] = tmpStatQueueIDs - expected[utils.CapStatQueues] = utils.NavigableMap2{utils.MetaRaw: &utils.NMSlice{utils.NewNMData("Que1"), utils.NewNMData("Que2")}} + expected[utils.CapStatQueues] = utils.NavigableMap{utils.MetaRaw: &utils.NMSlice{utils.NewNMData("Que1"), utils.NewNMData("Que2")}} if rply := v1per.AsNavigableMap(); !reflect.DeepEqual(expected, rply) { t.Errorf("Expecting \n%+v\n, received: \n%+v", expected, rply) } @@ -1580,7 +1578,7 @@ func TestV1ProcessEventReplyAsNavigableMap(t *testing.T) { v1per.STIRIdentity = make(map[string]string) v1per.STIRIdentity[utils.MetaRaw] = utils.EmptyString - expected[utils.OptsStirIdentity] = utils.NavigableMap2{utils.MetaRaw: utils.NewNMData(utils.EmptyString)} + expected[utils.OptsStirIdentity] = utils.NavigableMap{utils.MetaRaw: utils.NewNMData(utils.EmptyString)} if rply := v1per.AsNavigableMap(); !reflect.DeepEqual(expected, rply) { t.Errorf("Expecting \n%+v\n, received: \n%+v", utils.ToJSON(expected), utils.ToJSON(rply)) } diff --git a/sessions/sessionscover_test.go b/sessions/sessionscover_test.go index 6cc35c04a..92ace619d 100644 --- a/sessions/sessionscover_test.go +++ b/sessions/sessionscover_test.go @@ -2421,10 +2421,10 @@ func TestBiRPCv1AuthorizeEvent(t *testing.T) { false, false, false, nil, utils.Paginator{}, false, "") rply := &V1AuthorizeReply{ - Attributes: &engine.AttrSProcessEventReply{}, - Routes: engine.SortedRoutesList{}, - StatQueueIDs: &[]string{}, - ThresholdIDs: &[]string{}, + Attributes: &engine.AttrSProcessEventReply{}, + RouteProfiles: engine.SortedRoutesList{}, + StatQueueIDs: &[]string{}, + ThresholdIDs: &[]string{}, } expected := "MANDATORY_IE_MISSING: [CGREvent]" @@ -2541,10 +2541,10 @@ func TestBiRPCv1AuthorizeEvent2(t *testing.T) { false, false, false, cgrEvent, utils.Paginator{}, false, "") rply := &V1AuthorizeReply{ - Attributes: &engine.AttrSProcessEventReply{}, - Routes: engine.SortedRoutesList{}, - StatQueueIDs: &[]string{}, - ThresholdIDs: &[]string{}, + Attributes: &engine.AttrSProcessEventReply{}, + RouteProfiles: engine.SortedRoutesList{}, + StatQueueIDs: &[]string{}, + ThresholdIDs: &[]string{}, } //GetMaxUsage diff --git a/utils/consts.go b/utils/consts.go index e00e5b286..4745bd89a 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -792,6 +792,7 @@ const ( ProductName = "ProductName" IdxStart = "[" IdxEnd = "]" + IdxCombination = "][" MetaRemoteHost = "*remote_host" RemoteHost = "RemoteHost" @@ -968,6 +969,7 @@ const ( Diktats = "Diktats" BalanceIDs = "BalanceIDs" MetaCostIncrement = "*costIncrement" + Length = "Length" ) // Migrator Action @@ -1139,6 +1141,7 @@ const ( CapResourceAllocation = "ResourceAllocation" CapMaxUsage = "MaxUsage" CapRoutes = "Routes" + CapRouteProfiles = "RouteProfiles" CapThresholds = "Thresholds" CapStatQueues = "StatQueues" ) diff --git a/utils/dataprovider.go b/utils/dataprovider.go index 07033472f..57d4c2c8a 100644 --- a/utils/dataprovider.go +++ b/utils/dataprovider.go @@ -49,7 +49,7 @@ type RWDataProvider interface { // NavigableMapper is the interface supported by replies convertible to CGRReply type NavigableMapper interface { - AsNavigableMap() NavigableMap2 + AsNavigableMap() NavigableMap } // DPDynamicInterface returns the value of the field if the path is dynamic @@ -104,7 +104,7 @@ func AppendNavMapVal(nm navMap, fldPath *FullPath, val NMInterface) (err error) } else { indx = prevItm.Len() } - fldPath.PathItems[len(fldPath.PathItems)-1].Index = StringPointer(strconv.Itoa(indx)) + fldPath.PathItems[len(fldPath.PathItems)-1].Index = []string{strconv.Itoa(indx)} _, err = nm.Set(fldPath, val) return } @@ -120,7 +120,7 @@ func ComposeNavMapVal(nm navMap, fldPath *FullPath, val NMInterface) (err error) } else { indx = prevItmSlice.Len() - 1 var prevItm NMInterface - if prevItm, err = prevItmSlice.Field(PathItems{{Index: StringPointer(strconv.Itoa(indx))}}); err != nil { + if prevItm, err = prevItmSlice.Field(PathItems{{Index: []string{strconv.Itoa(indx)}}}); err != nil { if err != ErrNotFound { return } @@ -128,7 +128,7 @@ func ComposeNavMapVal(nm navMap, fldPath *FullPath, val NMInterface) (err error) return } } - fldPath.PathItems[len(fldPath.PathItems)-1].Index = StringPointer(strconv.Itoa(indx)) + fldPath.PathItems[len(fldPath.PathItems)-1].Index = []string{strconv.Itoa(indx)} _, err = nm.Set(fldPath, val) return } diff --git a/utils/dataprovider_test.go b/utils/dataprovider_test.go index 6aa64a333..98cefcd70 100644 --- a/utils/dataprovider_test.go +++ b/utils/dataprovider_test.go @@ -23,10 +23,10 @@ import ( ) func TestDPDynamicInterface(t *testing.T) { - nm := NavigableMap2{ + nm := NavigableMap{ "Field1": NewNMData("1001"), "Field2": NewNMData("1003"), - "Field3": NavigableMap2{"Field4": NewNMData("Val")}, + "Field3": NavigableMap{"Field4": NewNMData("Val")}, "Field5": &NMSlice{NewNMData(10), NewNMData(101)}, } var expected interface{} = "Field5[1]" @@ -46,10 +46,10 @@ func TestDPDynamicInterface(t *testing.T) { } func TestDPDynamicString(t *testing.T) { - nm := NavigableMap2{ + nm := NavigableMap{ "Field1": NewNMData("1001"), "Field2": NewNMData("1003"), - "Field3": NavigableMap2{"Field4": NewNMData("Val")}, + "Field3": NavigableMap{"Field4": NewNMData("Val")}, "Field5": &NMSlice{NewNMData(10), NewNMData(101)}, } var expected interface{} = "Field5[1]" @@ -70,17 +70,17 @@ func TestDPDynamicString(t *testing.T) { func TestAppendNavMapVal(t *testing.T) { onm := NewOrderedNavigableMap() - nm := NavigableMap2{ + nm := NavigableMap{ "Field1": NewNMData("1001"), "Field2": NewNMData("1003"), - "Field3": NavigableMap2{"Field4": NewNMData("Val")}, + "Field3": NavigableMap{"Field4": NewNMData("Val")}, "Field5": &NMSlice{NewNMData(10), NewNMData(101)}, } onm.nm = nm - expected := NavigableMap2{ + expected := NavigableMap{ "Field1": NewNMData("1001"), "Field2": NewNMData("1003"), - "Field3": NavigableMap2{"Field4": NewNMData("Val")}, + "Field3": NavigableMap{"Field4": NewNMData("Val")}, "Field5": &NMSlice{NewNMData(10), NewNMData(101), NewNMData(18)}, } if err := AppendNavMapVal(onm, &FullPath{Path: "Field5", PathItems: PathItems{{Field: "Field5"}}}, NewNMData(18)); err != nil { @@ -96,7 +96,7 @@ func TestAppendNavMapVal(t *testing.T) { func TestComposeNavMapVal(t *testing.T) { onm := NewOrderedNavigableMap() - nm := NavigableMap2{ + nm := NavigableMap{ "Field4": &NMSlice{}, "Field5": &NMSlice{NewNMData(10), NewNMData(101)}, } @@ -104,7 +104,7 @@ func TestComposeNavMapVal(t *testing.T) { if err := ComposeNavMapVal(onm, &FullPath{Path: "Field4", PathItems: PathItems{{Field: "Field4"}}}, NewNMData(18)); err != ErrWrongPath { t.Error(err) } - expected := NavigableMap2{ + expected := NavigableMap{ "Field4": &NMSlice{}, "Field5": &NMSlice{NewNMData(10), NewNMData("10118")}, } @@ -114,7 +114,7 @@ func TestComposeNavMapVal(t *testing.T) { t.Errorf("Expected %v ,received: %v", expected, nm) } - expected = NavigableMap2{ + expected = NavigableMap{ "Field4": &NMSlice{}, "Field5": &NMSlice{NewNMData(10), NewNMData("10118")}, "Field6": &NMSlice{NewNMData(10)}, @@ -125,7 +125,7 @@ func TestComposeNavMapVal(t *testing.T) { t.Errorf("Expected %v ,received: %v", expected, nm) } - onm.nm = NavigableMap2{ + onm.nm = NavigableMap{ "Field4": NewNMData(1), "Field5": &NMSlice{NewNMData(10), NewNMData(101)}, } diff --git a/utils/navigablemap.go b/utils/navigablemap.go index 9f4dd1afa..b1d8a893a 100644 --- a/utils/navigablemap.go +++ b/utils/navigablemap.go @@ -22,10 +22,10 @@ import ( "net" ) -// NavigableMap2 is the basic map of NM interface -type NavigableMap2 map[string]NMInterface +// NavigableMap is the basic map of NM interface +type NavigableMap map[string]NMInterface -func (nm NavigableMap2) String() (out string) { +func (nm NavigableMap) String() (out string) { for k, v := range nm { out += ",\"" + k + "\":" + v.String() } @@ -37,12 +37,12 @@ func (nm NavigableMap2) String() (out string) { } // Interface returns itself -func (nm NavigableMap2) Interface() interface{} { +func (nm NavigableMap) Interface() interface{} { return nm } // Field returns the item on the given path -func (nm NavigableMap2) Field(path PathItems) (val NMInterface, err error) { +func (nm NavigableMap) Field(path PathItems) (val NMInterface, err error) { if len(path) == 0 { return nil, ErrWrongPath } @@ -50,16 +50,17 @@ func (nm NavigableMap2) Field(path PathItems) (val NMInterface, err error) { if !has { return nil, ErrNotFound } - if len(path) == 1 && path[0].Index == nil { + if len(path) == 1 && + len(path[0].Index) == 0 { return el, nil } switch el.Type() { default: return nil, ErrNotFound case NMMapType: - if path[0].Index != nil { - path[0].Field = *path[0].Index - path[0].Index = nil + if len(path[0].Index) != 0 { // in case we have multiple indexes move the cursor and send the path to next element + path[0].Field = path[0].Index[0] + path[0].Index = path[0].Index[1:] // this should not panic as the length is not 0 return el.Field(path) } return el.Field(path[1:]) @@ -69,12 +70,13 @@ func (nm NavigableMap2) Field(path PathItems) (val NMInterface, err error) { } // Set sets the value for the given path -func (nm NavigableMap2) Set(path PathItems, val NMInterface) (added bool, err error) { +func (nm NavigableMap) Set(path PathItems, val NMInterface) (added bool, err error) { if len(path) == 0 { return false, ErrWrongPath } nmItm, has := nm[path[0].Field] + // for the moment we do not support nested indexes for set if path[0].Index != nil { // has index, should be a slice which is kinda part of our map, hence separate handling if !has { nmItm = &NMSlice{} @@ -101,7 +103,7 @@ func (nm NavigableMap2) Set(path PathItems, val NMInterface) (added bool, err er } // from here we should deal only with navmaps due to multiple path if !has { - nmItm = NavigableMap2{} + nmItm = NavigableMap{} nm[path[0].Field] = nmItm } if nmItm.Type() != NMMapType { // do not try to overwrite an interface @@ -111,7 +113,7 @@ func (nm NavigableMap2) Set(path PathItems, val NMInterface) (added bool, err er } // Remove removes the item for the given path -func (nm NavigableMap2) Remove(path PathItems) (err error) { +func (nm NavigableMap) Remove(path PathItems) (err error) { if len(path) == 0 { return ErrWrongPath } @@ -119,6 +121,7 @@ func (nm NavigableMap2) Remove(path PathItems) (err error) { if !has { return // already removed } + // we do not support nested indexes for remove in similar way we do not support them for set if len(path) == 1 { if path[0].Index != nil { if el.Type() != NMSliceType { @@ -160,23 +163,23 @@ func (nm NavigableMap2) Remove(path PathItems) (err error) { } // Type returns the type of the NM map -func (nm NavigableMap2) Type() NMType { +func (nm NavigableMap) Type() NMType { return NMMapType } // Empty returns true if the NM is empty(no data) -func (nm NavigableMap2) Empty() bool { +func (nm NavigableMap) Empty() bool { return nm == nil || len(nm) == 0 } // Len returns the lenght of the map -func (nm NavigableMap2) Len() int { +func (nm NavigableMap) Len() int { return len(nm) } // FieldAsInterface returns the interface at the path // Is used by AgentRequest FieldAsInterface -func (nm NavigableMap2) FieldAsInterface(fldPath []string) (str interface{}, err error) { +func (nm NavigableMap) FieldAsInterface(fldPath []string) (str interface{}, err error) { var nmi NMInterface if nmi, err = nm.Field(NewPathItems(fldPath)); err != nil { return @@ -186,7 +189,7 @@ func (nm NavigableMap2) FieldAsInterface(fldPath []string) (str interface{}, err // FieldAsString returns the string at the path // Used only to implement the DataProvider interface -func (nm NavigableMap2) FieldAsString(fldPath []string) (str string, err error) { +func (nm NavigableMap) FieldAsString(fldPath []string) (str string, err error) { var val interface{} val, err = nm.FieldAsInterface(fldPath) if err != nil { @@ -196,6 +199,6 @@ func (nm NavigableMap2) FieldAsString(fldPath []string) (str string, err error) } // RemoteHost is part of dataStorage interface -func (NavigableMap2) RemoteHost() net.Addr { +func (NavigableMap) RemoteHost() net.Addr { return LocalAddr() } diff --git a/utils/navigablemap_test.go b/utils/navigablemap_test.go index 01895d056..40d7c8b1d 100644 --- a/utils/navigablemap_test.go +++ b/utils/navigablemap_test.go @@ -23,36 +23,36 @@ import ( "testing" ) -func TestNavigableMap2String(t *testing.T) { - var nm NMInterface = NavigableMap2{"Field1": NewNMData("1001")} +func TestNavigableMapString(t *testing.T) { + var nm NMInterface = NavigableMap{"Field1": NewNMData("1001")} expected := `{"Field1":1001}` if rply := nm.String(); rply != expected { t.Errorf("Expected %q ,received: %q", expected, rply) } - nm = NavigableMap2{} + nm = NavigableMap{} expected = `{}` if rply := nm.String(); rply != expected { t.Errorf("Expected %q ,received: %q", expected, rply) } } -func TestNavigableMap2Interface(t *testing.T) { - nm := NavigableMap2{"Field1": NewNMData("1001"), "Field2": NewNMData("1003")} - expected := NavigableMap2{"Field1": NewNMData("1001"), "Field2": NewNMData("1003")} +func TestNavigableMapInterface(t *testing.T) { + nm := NavigableMap{"Field1": NewNMData("1001"), "Field2": NewNMData("1003")} + expected := NavigableMap{"Field1": NewNMData("1001"), "Field2": NewNMData("1003")} if rply := nm.Interface(); !reflect.DeepEqual(expected, rply) { t.Errorf("Expected %s ,received: %s", ToJSON(expected), ToJSON(rply)) } } -func TestNavigableMap2Field(t *testing.T) { - nm := NavigableMap2{} +func TestNavigableMapField(t *testing.T) { + nm := NavigableMap{} if _, err := nm.Field(PathItems{{}}); err != ErrNotFound { t.Error(err) } - nm = NavigableMap2{ + nm = NavigableMap{ "Field1": NewNMData("1001"), "Field2": NewNMData("1003"), - "Field3": NavigableMap2{"Field4": NewNMData("Val")}, + "Field3": NavigableMap{"Field4": NewNMData("Val")}, "Field5": &NMSlice{NewNMData(10), NewNMData(101)}, } if _, err := nm.Field(nil); err != ErrWrongPath { @@ -68,15 +68,15 @@ func TestNavigableMap2Field(t *testing.T) { t.Errorf("Expected %q ,received: %q", "1001", val.Interface()) } - if _, err := nm.Field(PathItems{{Field: "Field1", Index: StringPointer("0")}}); err != ErrNotFound { + if _, err := nm.Field(PathItems{{Field: "Field1", Index: []string{"0"}}}); err != ErrNotFound { t.Error(err) } - if val, err := nm.Field(PathItems{{Field: "Field5", Index: StringPointer("0")}}); err != nil { + if val, err := nm.Field(PathItems{{Field: "Field5", Index: []string{"0"}}}); err != nil { t.Error(err) } else if val.Interface() != 10 { t.Errorf("Expected %q ,received: %q", 10, val.Interface()) } - if _, err := nm.Field(PathItems{{Field: "Field3", Index: StringPointer("0")}}); err != ErrNotFound { + if _, err := nm.Field(PathItems{{Field: "Field3", Index: []string{"0"}}}); err != ErrNotFound { t.Error(err) } if val, err := nm.Field(PathItems{{Field: "Field3"}, {Field: "Field4"}}); err != nil { @@ -86,21 +86,21 @@ func TestNavigableMap2Field(t *testing.T) { } } -func TestNavigableMap2Set(t *testing.T) { - nm := NavigableMap2{} +func TestNavigableMapSet(t *testing.T) { + nm := NavigableMap{} if _, err := nm.Set(nil, nil); err != ErrWrongPath { t.Error(err) } - if _, err := nm.Set(PathItems{{Field: "Field1", Index: StringPointer("10")}}, NewNMData("1001")); err != ErrWrongPath { + if _, err := nm.Set(PathItems{{Field: "Field1", Index: []string{"10"}}}, NewNMData("1001")); err != ErrWrongPath { t.Error(err) } - expected := NavigableMap2{"Field1": &NMSlice{NewNMData("1001")}} - if _, err := nm.Set(PathItems{{Field: "Field1", Index: StringPointer("0")}}, NewNMData("1001")); err != nil { + expected := NavigableMap{"Field1": &NMSlice{NewNMData("1001")}} + if _, err := nm.Set(PathItems{{Field: "Field1", Index: []string{"0"}}}, NewNMData("1001")); err != nil { t.Error(err) } else if !reflect.DeepEqual(nm, expected) { t.Errorf("Expected %s ,received: %s", expected, nm) } - expected = NavigableMap2{ + expected = NavigableMap{ "Field1": &NMSlice{NewNMData("1001")}, "Field2": NewNMData("1002"), } @@ -109,19 +109,19 @@ func TestNavigableMap2Set(t *testing.T) { } else if !reflect.DeepEqual(nm, expected) { t.Errorf("Expected %s ,received: %s", expected, nm) } - if _, err := nm.Set(PathItems{{Field: "Field2", Index: StringPointer("1")}}, NewNMData("1003")); err != ErrWrongPath { + if _, err := nm.Set(PathItems{{Field: "Field2", Index: []string{"1"}}}, NewNMData("1003")); err != ErrWrongPath { t.Error(err) } - expected = NavigableMap2{ + expected = NavigableMap{ "Field1": &NMSlice{NewNMData("1001"), NewNMData("1003")}, "Field2": NewNMData("1002"), } - if _, err := nm.Set(PathItems{{Field: "Field1", Index: StringPointer("1")}}, NewNMData("1003")); err != nil { + if _, err := nm.Set(PathItems{{Field: "Field1", Index: []string{"1"}}}, NewNMData("1003")); err != nil { t.Error(err) } else if !reflect.DeepEqual(nm, expected) { t.Errorf("Expected %s ,received: %s", expected, nm) } - expected = NavigableMap2{ + expected = NavigableMap{ "Field1": &NMSlice{NewNMData("1001"), NewNMData("1003")}, "Field2": NewNMData("1004"), } @@ -131,29 +131,29 @@ func TestNavigableMap2Set(t *testing.T) { t.Errorf("Expected %s ,received: %s", expected, nm) } - if _, err := nm.Set(PathItems{{Field: "Field3", Index: StringPointer("10")}, {}}, NewNMData("1001")); err != ErrWrongPath { + if _, err := nm.Set(PathItems{{Field: "Field3", Index: []string{"10"}}, {}}, NewNMData("1001")); err != ErrWrongPath { t.Error(err) } - expected = NavigableMap2{ + expected = NavigableMap{ "Field1": &NMSlice{NewNMData("1001"), NewNMData("1003")}, "Field2": NewNMData("1004"), - "Field3": &NMSlice{NavigableMap2{"Field4": NewNMData("1005")}}, + "Field3": &NMSlice{NavigableMap{"Field4": NewNMData("1005")}}, } - if _, err := nm.Set(PathItems{{Field: "Field3", Index: StringPointer("0")}, {Field: "Field4"}}, NewNMData("1005")); err != nil { + if _, err := nm.Set(PathItems{{Field: "Field3", Index: []string{"0"}}, {Field: "Field4"}}, NewNMData("1005")); err != nil { t.Error(err) } else if !reflect.DeepEqual(nm, expected) { t.Errorf("Expected %s ,received: %s", expected, nm) } - if _, err := nm.Set(PathItems{{Field: "Field5"}, {Field: "Field6", Index: StringPointer("10")}}, NewNMData("1006")); err != ErrWrongPath { + if _, err := nm.Set(PathItems{{Field: "Field5"}, {Field: "Field6", Index: []string{"10"}}}, NewNMData("1006")); err != ErrWrongPath { t.Error(err) } - expected = NavigableMap2{ + expected = NavigableMap{ "Field1": &NMSlice{NewNMData("1001"), NewNMData("1003")}, "Field2": NewNMData("1004"), - "Field3": &NMSlice{NavigableMap2{"Field4": NewNMData("1005")}}, - "Field5": NavigableMap2{"Field6": NewNMData("1006")}, + "Field3": &NMSlice{NavigableMap{"Field4": NewNMData("1005")}}, + "Field5": NavigableMap{"Field6": NewNMData("1006")}, } if _, err := nm.Set(PathItems{{Field: "Field5"}, {Field: "Field6"}}, NewNMData("1006")); err != nil { t.Error(err) @@ -161,16 +161,16 @@ func TestNavigableMap2Set(t *testing.T) { t.Errorf("Expected %s ,received: %s", expected, nm) } - if _, err := nm.Set(PathItems{{Field: "Field2", Index: StringPointer("0")}, {}}, NewNMData("1006")); err != ErrWrongPath { + if _, err := nm.Set(PathItems{{Field: "Field2", Index: []string{"0"}}, {}}, NewNMData("1006")); err != ErrWrongPath { t.Error(err) } - expected = NavigableMap2{ - "Field1": &NMSlice{NewNMData("1001"), NewNMData("1003"), NavigableMap2{"Field6": NewNMData("1006")}}, + expected = NavigableMap{ + "Field1": &NMSlice{NewNMData("1001"), NewNMData("1003"), NavigableMap{"Field6": NewNMData("1006")}}, "Field2": NewNMData("1004"), - "Field3": &NMSlice{NavigableMap2{"Field4": NewNMData("1005")}}, - "Field5": NavigableMap2{"Field6": NewNMData("1006")}, + "Field3": &NMSlice{NavigableMap{"Field4": NewNMData("1005")}}, + "Field5": NavigableMap{"Field6": NewNMData("1006")}, } - if _, err := nm.Set(PathItems{{Field: "Field1", Index: StringPointer("2")}, {Field: "Field6"}}, NewNMData("1006")); err != nil { + if _, err := nm.Set(PathItems{{Field: "Field1", Index: []string{"2"}}, {Field: "Field6"}}, NewNMData("1006")); err != nil { t.Error(err) } else if !reflect.DeepEqual(nm, expected) { t.Errorf("Expected %s ,received: %s", expected, nm) @@ -179,11 +179,11 @@ func TestNavigableMap2Set(t *testing.T) { t.Error(err) } - expected = NavigableMap2{ - "Field1": &NMSlice{NewNMData("1001"), NewNMData("1003"), NavigableMap2{"Field6": NewNMData("1006")}}, + expected = NavigableMap{ + "Field1": &NMSlice{NewNMData("1001"), NewNMData("1003"), NavigableMap{"Field6": NewNMData("1006")}}, "Field2": NewNMData("1004"), - "Field3": &NMSlice{NavigableMap2{"Field4": NewNMData("1005")}}, - "Field5": NavigableMap2{"Field6": NewNMData("1007")}, + "Field3": &NMSlice{NavigableMap{"Field4": NewNMData("1005")}}, + "Field5": NavigableMap{"Field6": NewNMData("1007")}, } if _, err := nm.Set(PathItems{{Field: "Field5"}, {Field: "Field6"}}, NewNMData("1007")); err != nil { t.Error(err) @@ -192,40 +192,40 @@ func TestNavigableMap2Set(t *testing.T) { } } -func TestNavigableMap2Type(t *testing.T) { - var nm NMInterface = NavigableMap2{} +func TestNavigableMapType(t *testing.T) { + var nm NMInterface = NavigableMap{} if nm.Type() != NMMapType { t.Errorf("Expected %v ,received: %v", NMMapType, nm.Type()) } } -func TestNavigableMap2Empty(t *testing.T) { - var nm NMInterface = NavigableMap2{} +func TestNavigableMapEmpty(t *testing.T) { + var nm NMInterface = NavigableMap{} if !nm.Empty() { t.Error("Expected empty type") } - nm = NavigableMap2{"Field1": NewNMData("1001")} + nm = NavigableMap{"Field1": NewNMData("1001")} if nm.Empty() { t.Error("Expected not empty type") } } -func TestNavigableMap2Len(t *testing.T) { - var nm NMInterface = NavigableMap2{} +func TestNavigableMapLen(t *testing.T) { + var nm NMInterface = NavigableMap{} if rply := nm.Len(); rply != 0 { t.Errorf("Expected 0 ,received: %v", rply) } - nm = NavigableMap2{"Field1": NewNMData("1001")} + nm = NavigableMap{"Field1": NewNMData("1001")} if rply := nm.Len(); rply != 1 { t.Errorf("Expected 1 ,received: %v", rply) } } -func TestNavigableMap2Remove(t *testing.T) { - nm := NavigableMap2{ +func TestNavigableMapRemove(t *testing.T) { + nm := NavigableMap{ "Field1": NewNMData("1001"), "Field2": NewNMData("1003"), - "Field3": NavigableMap2{"Field4": NewNMData("Val")}, + "Field3": NavigableMap{"Field4": NewNMData("Val")}, "Field5": &NMSlice{NewNMData(10), NewNMData(101)}, } if err := nm.Remove(nil); err != ErrWrongPath { @@ -238,22 +238,22 @@ func TestNavigableMap2Remove(t *testing.T) { t.Error(err) } - if err := nm.Remove(PathItems{{Index: StringPointer("-1")}, {}}); err != nil { + if err := nm.Remove(PathItems{{Index: []string{"-1"}}, {}}); err != nil { t.Error(err) } - expected := NavigableMap2{ + expected := NavigableMap{ "Field1": NewNMData("1001"), "Field2": NewNMData("1003"), - "Field3": NavigableMap2{"Field4": NewNMData("Val")}, + "Field3": NavigableMap{"Field4": NewNMData("Val")}, "Field5": &NMSlice{NewNMData(10), NewNMData(101)}, } if !reflect.DeepEqual(nm, expected) { t.Errorf("Expected %s ,received: %s", expected, nm) } - expected = NavigableMap2{ + expected = NavigableMap{ "Field1": NewNMData("1001"), - "Field3": NavigableMap2{"Field4": NewNMData("Val")}, + "Field3": NavigableMap{"Field4": NewNMData("Val")}, "Field5": &NMSlice{NewNMData(10), NewNMData(101)}, } @@ -263,49 +263,49 @@ func TestNavigableMap2Remove(t *testing.T) { t.Errorf("Expected %s ,received: %s", expected, nm) } - expected = NavigableMap2{ + expected = NavigableMap{ "Field1": NewNMData("1001"), - "Field3": NavigableMap2{"Field4": NewNMData("Val")}, + "Field3": NavigableMap{"Field4": NewNMData("Val")}, "Field5": &NMSlice{NewNMData(101)}, } - if err := nm.Remove(PathItems{{Field: "Field5", Index: StringPointer("0")}}); err != nil { + if err := nm.Remove(PathItems{{Field: "Field5", Index: []string{"0"}}}); err != nil { t.Error(err) } else if !reflect.DeepEqual(nm, expected) { t.Errorf("Expected %s ,received: %s", expected, nm) } - if err := nm.Remove(PathItems{{Field: "Field1", Index: StringPointer("0")}, {}}); err != ErrWrongPath { + if err := nm.Remove(PathItems{{Field: "Field1", Index: []string{"0"}}, {}}); err != ErrWrongPath { t.Error(err) } - expected = NavigableMap2{ + expected = NavigableMap{ "Field1": NewNMData("1001"), - "Field3": NavigableMap2{"Field4": NewNMData("Val")}, + "Field3": NavigableMap{"Field4": NewNMData("Val")}, } - if err := nm.Remove(PathItems{{Field: "Field5", Index: StringPointer("0")}}); err != nil { + if err := nm.Remove(PathItems{{Field: "Field5", Index: []string{"0"}}}); err != nil { t.Error(err) } else if !reflect.DeepEqual(nm, expected) { t.Errorf("Expected %s ,received: %s", expected, nm) } - nm = NavigableMap2{ + nm = NavigableMap{ "Field1": NewNMData("1001"), "Field2": NewNMData("1003"), - "Field3": NavigableMap2{"Field4": NewNMData("Val")}, - "Field5": &NMSlice{NavigableMap2{"Field42": NewNMData("Val2")}}, + "Field3": NavigableMap{"Field4": NewNMData("Val")}, + "Field5": &NMSlice{NavigableMap{"Field42": NewNMData("Val2")}}, } - if err := nm.Remove(PathItems{{Field: "Field5", Index: StringPointer("0")}, {Field: "Field42", Index: StringPointer("0")}}); err != ErrWrongPath { + if err := nm.Remove(PathItems{{Field: "Field5", Index: []string{"0"}}, {Field: "Field42", Index: []string{"0"}}}); err != ErrWrongPath { t.Error(err) } - expected = NavigableMap2{ + expected = NavigableMap{ "Field1": NewNMData("1001"), "Field2": NewNMData("1003"), - "Field3": NavigableMap2{"Field4": NewNMData("Val")}, + "Field3": NavigableMap{"Field4": NewNMData("Val")}, } - if err := nm.Remove(PathItems{{Field: "Field5", Index: StringPointer("0")}, {Field: "Field42"}}); err != nil { + if err := nm.Remove(PathItems{{Field: "Field5", Index: []string{"0"}}, {Field: "Field42"}}); err != nil { t.Error(err) } else if !reflect.DeepEqual(nm, expected) { t.Errorf("Expected %s ,received: %s", expected, nm) @@ -314,10 +314,10 @@ func TestNavigableMap2Remove(t *testing.T) { if err := nm.Remove(PathItems{{Field: "Field1"}, {}}); err != ErrWrongPath { t.Error(err) } - if err := nm.Remove(PathItems{{Field: "Field3"}, {Field: "Field4", Index: StringPointer("0")}}); err != ErrWrongPath { + if err := nm.Remove(PathItems{{Field: "Field3"}, {Field: "Field4", Index: []string{"0"}}}); err != ErrWrongPath { t.Error(err) } - expected = NavigableMap2{ + expected = NavigableMap{ "Field1": NewNMData("1001"), "Field2": NewNMData("1003"), } @@ -328,17 +328,17 @@ func TestNavigableMap2Remove(t *testing.T) { } } -func TestNavigableMap2GetSet(t *testing.T) { - var nm NMInterface = NavigableMap2{ +func TestNavigableMapGetSet(t *testing.T) { + var nm NMInterface = NavigableMap{ "Field1": NewNMData(10), "Field2": &NMSlice{ NewNMData("1001"), - NavigableMap2{ + NavigableMap{ "Account": &NMSlice{NewNMData(10), NewNMData(11)}, }, }, - "Field3": NavigableMap2{ - "Field4": NavigableMap2{ + "Field3": NavigableMap{ + "Field4": NavigableMap{ "Field5": NewNMData(5), }, }, @@ -357,7 +357,7 @@ func TestNavigableMap2GetSet(t *testing.T) { t.Errorf("Expected %q ,received: %q", 5, val.Interface()) } - path = PathItems{{Field: "Field2", Index: StringPointer("2")}} + path = PathItems{{Field: "Field2", Index: []string{"2"}}} if _, err := nm.Set(path, NewNMData("500")); err != nil { t.Error(err) } @@ -367,27 +367,27 @@ func TestNavigableMap2GetSet(t *testing.T) { t.Errorf("Expected %q ,received: %q", "500", val.Interface()) } - path = PathItems{{Field: "Field2", Index: StringPointer("1")}, {Field: "Account"}} + path = PathItems{{Field: "Field2", Index: []string{"1"}}, {Field: "Account"}} if _, err := nm.Set(path, NewNMData("5")); err != nil { t.Error(err) } - path = PathItems{{Field: "Field2", Index: StringPointer("1")}, {Field: "Account"}} + path = PathItems{{Field: "Field2", Index: []string{"1"}}, {Field: "Account"}} if val, err := nm.Field(path); err != nil { t.Error(err) } else if val.Interface() != "5" { t.Errorf("Expected %q ,received: %q", "5", val.Interface()) } - path = PathItems{{Field: "Field2", Index: StringPointer("1")}, {Field: "Account", Index: StringPointer("0")}} + path = PathItems{{Field: "Field2", Index: []string{"1"}}, {Field: "Account", Index: []string{"0"}}} if _, err := nm.Field(path); err != ErrNotFound { t.Error(err) } } -func TestNavigableMap2FieldAsInterface(t *testing.T) { - nm := NavigableMap2{ +func TestNavigableMapFieldAsInterface(t *testing.T) { + nm := NavigableMap{ "Field1": NewNMData("1001"), "Field2": NewNMData("1003"), - "Field3": NavigableMap2{"Field4": NewNMData("Val")}, + "Field3": NavigableMap{"Field4": NewNMData("Val")}, "Field5": &NMSlice{NewNMData(10), NewNMData(101)}, } if _, err := nm.FieldAsInterface(nil); err != ErrWrongPath { @@ -407,11 +407,11 @@ func TestNavigableMap2FieldAsInterface(t *testing.T) { } } -func TestNavigableMap2FieldAsString(t *testing.T) { - nm := NavigableMap2{ +func TestNavigableMapFieldAsString(t *testing.T) { + nm := NavigableMap{ "Field1": NewNMData("1001"), "Field2": NewNMData("1003"), - "Field3": NavigableMap2{"Field4": NewNMData("Val")}, + "Field3": NavigableMap{"Field4": NewNMData("Val")}, "Field5": &NMSlice{NewNMData(10), NewNMData(101)}, } if _, err := nm.FieldAsString(nil); err != ErrWrongPath { @@ -432,7 +432,7 @@ func TestNavigableMap2FieldAsString(t *testing.T) { } func TestNavigableMapRemote(t *testing.T) { - nm := NavigableMap2{"Field1": NewNMData("1001")} + nm := NavigableMap{"Field1": NewNMData("1001")} eOut := LocalAddr() if rcv := nm.RemoteHost(); !reflect.DeepEqual(eOut, rcv) { t.Errorf("Expecting: %+v, received: %+v", eOut, rcv) diff --git a/utils/nmslice.go b/utils/nmslice.go index af3b2e562..a48077ab8 100644 --- a/utils/nmslice.go +++ b/utils/nmslice.go @@ -18,7 +18,9 @@ along with this program. If not, see package utils -import "strconv" +import ( + "strconv" +) // NMSlice is the basic slice of NM interface type NMSlice []NMInterface @@ -45,11 +47,19 @@ func (nms *NMSlice) Field(path PathItems) (val NMInterface, err error) { if len(path) == 0 { return nil, ErrWrongPath } - if nms.Empty() || path[0].Index == nil { + if len(path[0].Index) == 0 { + if len(path) != 2 || + path[1].Field != Length || + path[1].Index != nil { + return nil, ErrNotFound + } + return NewNMData(nms.Len()), nil + } + if nms.Empty() { return nil, ErrNotFound } var idx int - if idx, err = strconv.Atoi(*path[0].Index); err != nil { + if idx, err = strconv.Atoi(path[0].Index[0]); err != nil { return } if idx < 0 { @@ -58,6 +68,11 @@ func (nms *NMSlice) Field(path PathItems) (val NMInterface, err error) { if idx < 0 || idx >= len(*nms) { return nil, ErrNotFound } + if len(path[0].Index) != 1 { + path[0].Field = path[0].Index[0] + path[0].Index = path[0].Index[1:] + return (*nms)[idx].Field(path) + } if len(path) == 1 { return (*nms)[idx], nil } @@ -70,7 +85,8 @@ func (nms *NMSlice) Set(path PathItems, val NMInterface) (addedNew bool, err err return false, ErrWrongPath } var idx int - if idx, err = strconv.Atoi(*path[0].Index); err != nil { + // for the moment we do not support nested indexes for set + if idx, err = strconv.Atoi(path[0].Index[0]); err != nil { return } if idx == len(*nms) { // append element @@ -79,7 +95,7 @@ func (nms *NMSlice) Set(path PathItems, val NMInterface) (addedNew bool, err err *nms = append(*nms, val) return } - nel := NavigableMap2{} + nel := NavigableMap{} if _, err = nel.Set(path[1:], val); err != nil { return } @@ -92,7 +108,7 @@ func (nms *NMSlice) Set(path PathItems, val NMInterface) (addedNew bool, err err if idx < 0 || idx >= len(*nms) { return false, ErrWrongPath } - path[0].Index = StringPointer(strconv.Itoa(idx)) + path[0].Index = []string{strconv.Itoa(idx)} if len(path) == 1 { (*nms)[idx] = val return @@ -109,7 +125,8 @@ func (nms *NMSlice) Remove(path PathItems) (err error) { return ErrWrongPath } var idx int - if idx, err = strconv.Atoi(*path[0].Index); err != nil { + // we do not support nested indexes for remove in similar way we do not support them for set + if idx, err = strconv.Atoi(path[0].Index[0]); err != nil { return } if idx < 0 { @@ -118,7 +135,7 @@ func (nms *NMSlice) Remove(path PathItems) (err error) { if idx < 0 || idx >= len(*nms) { // already removed return } - path[0].Index = StringPointer(strconv.Itoa(idx)) + path[0].Index = []string{strconv.Itoa(idx)} if len(path) == 1 { *nms = append((*nms)[:idx], (*nms)[idx+1:]...) return diff --git a/utils/nmslice_test.go b/utils/nmslice_test.go index 2623aa542..02040dad1 100644 --- a/utils/nmslice_test.go +++ b/utils/nmslice_test.go @@ -52,29 +52,29 @@ func TestNMSliceField(t *testing.T) { nm = &NMSlice{ NewNMData("1001"), NewNMData("1003"), - &NavigableMap2{"Field1": NewNMData("Val")}, + &NavigableMap{"Field1": NewNMData("Val")}, } if _, err := nm.Field(PathItems{{}}); err != ErrNotFound { t.Error(err) } - if _, err := nm.Field(PathItems{{Index: StringPointer("4")}}); err != ErrNotFound { + if _, err := nm.Field(PathItems{{Index: []string{"4"}}}); err != ErrNotFound { t.Error(err) } if _, err := nm.Field(nil); err != ErrWrongPath { t.Error(err) } - if val, err := nm.Field(PathItems{{Field: "None", Index: StringPointer("-1")}, {Field: "Field1"}}); err != nil { + if val, err := nm.Field(PathItems{{Field: "None", Index: []string{"-1"}}, {Field: "Field1"}}); err != nil { t.Error(err) } else if val.Interface() != "Val" { t.Errorf("Expected %q ,received: %q", "Val", val.Interface()) } - if val, err := nm.Field(PathItems{{Field: "1234", Index: StringPointer("1")}}); err != nil { + if val, err := nm.Field(PathItems{{Field: "1234", Index: []string{"1"}}}); err != nil { t.Error(err) } else if val.Interface() != "1003" { t.Errorf("Expected %q ,received: %q", "Val", val.Interface()) } expError := `strconv.Atoi: parsing "nan": invalid syntax` - if _, err := nm.Field(PathItems{{Field: "1234", Index: StringPointer("nan")}}); err == nil || err.Error() != expError { + if _, err := nm.Field(PathItems{{Field: "1234", Index: []string{"nan"}}}); err == nil || err.Error() != expError { t.Errorf("Expected error %s received: %v", expError, err) } } @@ -85,36 +85,36 @@ func TestNMSliceSet(t *testing.T) { t.Error(err) } expected := &NMSlice{NewNMData("1001")} - if _, err := nm.Set(PathItems{{Field: "1234", Index: StringPointer("0")}}, NewNMData("1001")); err != nil { + if _, err := nm.Set(PathItems{{Field: "1234", Index: []string{"0"}}}, NewNMData("1001")); err != nil { t.Error(err) } else if !reflect.DeepEqual(nm, expected) { t.Errorf("Expected %s ,received: %s", expected, nm) } - if _, err := nm.Set(PathItems{{Field: "1234", Index: StringPointer("1")}, {Field: "Field1", Index: StringPointer("1")}}, + if _, err := nm.Set(PathItems{{Field: "1234", Index: []string{"1"}}, {Field: "Field1", Index: []string{"1"}}}, NewNMData("1001")); err != ErrWrongPath { t.Error(err) } - expected = &NMSlice{NewNMData("1001"), NavigableMap2{"Field1": NewNMData("1001")}} - if _, err := nm.Set(PathItems{{Field: "1234", Index: StringPointer("1")}, {Field: "Field1"}}, + expected = &NMSlice{NewNMData("1001"), NavigableMap{"Field1": NewNMData("1001")}} + if _, err := nm.Set(PathItems{{Field: "1234", Index: []string{"1"}}, {Field: "Field1"}}, NewNMData("1001")); err != nil { t.Error(err) } else if !reflect.DeepEqual(nm, expected) { t.Errorf("Expected %s ,received: %s", expected, nm) } expected = &NMSlice{NewNMData("1001"), NewNMData("1001")} - if _, err := nm.Set(PathItems{{Field: "1234", Index: StringPointer("-1")}}, NewNMData("1001")); err != nil { + if _, err := nm.Set(PathItems{{Field: "1234", Index: []string{"-1"}}}, NewNMData("1001")); err != nil { t.Error(err) } else if !reflect.DeepEqual(nm, expected) { t.Errorf("Expected %s ,received: %s", expected, nm) } nm = &NMSlice{&NMSlice{}} - if _, err := nm.Set(PathItems{{Field: "1234", Index: StringPointer("0")}, {}}, NewNMData("1001")); err != ErrWrongPath { + if _, err := nm.Set(PathItems{{Field: "1234", Index: []string{"0"}}, {}}, NewNMData("1001")); err != ErrWrongPath { t.Error(err) } expError := `strconv.Atoi: parsing "nan": invalid syntax` - if _, err := nm.Set(PathItems{{Field: "1234", Index: StringPointer("nan")}, {}}, NewNMData("1001")); err == nil || err.Error() != expError { + if _, err := nm.Set(PathItems{{Field: "1234", Index: []string{"nan"}}, {}}, NewNMData("1001")); err == nil || err.Error() != expError { t.Errorf("Expected error %s received: %v", expError, err) } } @@ -152,7 +152,7 @@ func TestNMSliceRemove(t *testing.T) { nm := &NMSlice{ NewNMData("1001"), NewNMData("1003"), - &NavigableMap2{"Field1": NewNMData("Val")}, + &NavigableMap{"Field1": NewNMData("Val")}, &NMSlice{}, } if err := nm.Remove(nil); err != ErrWrongPath { @@ -165,55 +165,55 @@ func TestNMSliceRemove(t *testing.T) { t.Error(err) } - if err := nm.Remove(PathItems{{Index: StringPointer("-1")}, {}}); err != ErrWrongPath { + if err := nm.Remove(PathItems{{Index: []string{"-1"}}, {}}); err != ErrWrongPath { t.Error(err) } expected := &NMSlice{ NewNMData("1001"), NewNMData("1003"), - &NavigableMap2{"Field1": NewNMData("Val")}, + &NavigableMap{"Field1": NewNMData("Val")}, } - if err := nm.Remove(PathItems{{Index: StringPointer("-1")}}); err != nil { + if err := nm.Remove(PathItems{{Index: []string{"-1"}}}); err != nil { t.Error(err) } else if !reflect.DeepEqual(nm, expected) { t.Errorf("Expected %s ,received: %s", expected, nm) } - if err := nm.Remove(PathItems{{Index: StringPointer("1")}, {}}); err != ErrWrongPath { + if err := nm.Remove(PathItems{{Index: []string{"1"}}, {}}); err != ErrWrongPath { t.Error(err) } expected = &NMSlice{ NewNMData("1001"), - &NavigableMap2{"Field1": NewNMData("Val")}, + &NavigableMap{"Field1": NewNMData("Val")}, } - if err := nm.Remove(PathItems{{Index: StringPointer("1")}}); err != nil { + if err := nm.Remove(PathItems{{Index: []string{"1"}}}); err != nil { t.Error(err) } else if !reflect.DeepEqual(nm, expected) { t.Errorf("Expected %s ,received: %s", expected, nm) } - if err := nm.Remove(PathItems{{Index: StringPointer("10")}}); err != nil { + if err := nm.Remove(PathItems{{Index: []string{"10"}}}); err != nil { t.Error(err) } else if !reflect.DeepEqual(nm, expected) { t.Errorf("Expected %s ,received: %s", expected, nm) } - if err := nm.Remove(PathItems{{Index: StringPointer("1")}, {Field: "Field1", Index: StringPointer("1")}}); err != ErrWrongPath { + if err := nm.Remove(PathItems{{Index: []string{"1"}}, {Field: "Field1", Index: []string{"1"}}}); err != ErrWrongPath { t.Error(err) } expected = &NMSlice{ NewNMData("1001"), } - if err := nm.Remove(PathItems{{Index: StringPointer("1")}, {Field: "Field1"}}); err != nil { + if err := nm.Remove(PathItems{{Index: []string{"1"}}, {Field: "Field1"}}); err != nil { t.Error(err) } else if !reflect.DeepEqual(nm, expected) { t.Errorf("Expected %s ,received: %s", expected, nm) } expError := `strconv.Atoi: parsing "nan": invalid syntax` - if err := nm.Remove(PathItems{{Field: "1234", Index: StringPointer("nan")}}); err == nil || err.Error() != expError { + if err := nm.Remove(PathItems{{Field: "1234", Index: []string{"nan"}}}); err == nil || err.Error() != expError { t.Errorf("Expected error %s received: %v", expError, err) } diff --git a/utils/orderednavigablemap.go b/utils/orderednavigablemap.go index 87b1ae281..f17f73ef6 100644 --- a/utils/orderednavigablemap.go +++ b/utils/orderednavigablemap.go @@ -27,7 +27,7 @@ import ( // NewOrderedNavigableMap initializates a structure of OrderedNavigableMap with a NavigableMap2 func NewOrderedNavigableMap() *OrderedNavigableMap { return &OrderedNavigableMap{ - nm: NavigableMap2{}, + nm: NavigableMap{}, orderIdx: NewPathItemList(), orderRef: make(map[string][]*PathItemElement), } @@ -109,7 +109,7 @@ func (onm *OrderedNavigableMap) Set(fullPath *FullPath, val NMInterface) (addedN pathItmsSet = make([]PathItems, len(*val.(*NMSlice))) for i := 0; i < val.Len(); i++ { pathItms := fullPath.PathItems.Clone() - pathItms[len(pathItms)-1].Index = StringPointer(strconv.Itoa(i)) + pathItms[len(pathItms)-1].Index = []string{(strconv.Itoa(i))} pathItmsSet[i] = pathItms } } else { @@ -188,7 +188,7 @@ func (onm *OrderedNavigableMap) OrderedFields() (flds []interface{}) { // RemoveAll will clean the data and the odrder from OrderedNavigableMap func (onm *OrderedNavigableMap) RemoveAll() { - onm.nm = NavigableMap2{} + onm.nm = NavigableMap{} onm.orderIdx = NewPathItemList() onm.orderRef = make(map[string][]*PathItemElement) } diff --git a/utils/orderednavigablemap_test.go b/utils/orderednavigablemap_test.go index 2348b1c2a..886df2b35 100644 --- a/utils/orderednavigablemap_test.go +++ b/utils/orderednavigablemap_test.go @@ -38,11 +38,11 @@ func TestOrderedNavigableMap(t *testing.T) { onm.Set(&FullPath{ Path: "Field2[0]", - PathItems: PathItems{{Field: "Field2", Index: StringPointer("0")}}, + PathItems: PathItems{{Field: "Field2", Index: []string{"0"}}}, }, NewNMData("1001")) expOrder = []PathItems{ {{Field: "Field1"}}, - {{Field: "Field2", Index: StringPointer("0")}}, + {{Field: "Field2", Index: []string{"0"}}}, } if !reflect.DeepEqual(expOrder, onm.GetOrder()) { t.Errorf("Expected %s ,received: %s", expOrder, ToJSON(onm.GetOrder())) @@ -51,15 +51,15 @@ func TestOrderedNavigableMap(t *testing.T) { onm.Set(&FullPath{ Path: "Field2[1].Account[0]", PathItems: PathItems{ - {Field: "Field2", Index: StringPointer("1")}, - {Field: "Account", Index: StringPointer("0")}}, + {Field: "Field2", Index: []string{"1"}}, + {Field: "Account", Index: []string{"0"}}}, }, NewNMData(10)) expOrder = []PathItems{ {{Field: "Field1"}}, - {{Field: "Field2", Index: StringPointer("0")}}, + {{Field: "Field2", Index: []string{"0"}}}, { - {Field: "Field2", Index: StringPointer("1")}, - {Field: "Account", Index: StringPointer("0")}}, + {Field: "Field2", Index: []string{"1"}}, + {Field: "Account", Index: []string{"0"}}}, } if !reflect.DeepEqual(expOrder, onm.GetOrder()) { t.Errorf("Expected %s ,received: %s", expOrder, ToJSON(onm.GetOrder())) @@ -68,18 +68,18 @@ func TestOrderedNavigableMap(t *testing.T) { onm.Set(&FullPath{ Path: "Field2[1].Account[1]", PathItems: PathItems{ - {Field: "Field2", Index: StringPointer("1")}, - {Field: "Account", Index: StringPointer("1")}}, + {Field: "Field2", Index: []string{"1"}}, + {Field: "Account", Index: []string{"1"}}}, }, NewNMData(11)) expOrder = []PathItems{ {{Field: "Field1"}}, - {{Field: "Field2", Index: StringPointer("0")}}, + {{Field: "Field2", Index: []string{"0"}}}, { - {Field: "Field2", Index: StringPointer("1")}, - {Field: "Account", Index: StringPointer("0")}}, + {Field: "Field2", Index: []string{"1"}}, + {Field: "Account", Index: []string{"0"}}}, { - {Field: "Field2", Index: StringPointer("1")}, - {Field: "Account", Index: StringPointer("1")}}, + {Field: "Field2", Index: []string{"1"}}, + {Field: "Account", Index: []string{"1"}}}, } if !reflect.DeepEqual(expOrder, onm.GetOrder()) { t.Errorf("Expected %s ,received: %s", expOrder, ToJSON(onm.GetOrder())) @@ -87,18 +87,18 @@ func TestOrderedNavigableMap(t *testing.T) { onm.Set(&FullPath{ Path: "Field2[2]", - PathItems: PathItems{{Field: "Field2", Index: StringPointer("2")}}, + PathItems: PathItems{{Field: "Field2", Index: []string{"2"}}}, }, NewNMData(111)) expOrder = []PathItems{ {{Field: "Field1"}}, - {{Field: "Field2", Index: StringPointer("0")}}, + {{Field: "Field2", Index: []string{"0"}}}, { - {Field: "Field2", Index: StringPointer("1")}, - {Field: "Account", Index: StringPointer("0")}}, + {Field: "Field2", Index: []string{"1"}}, + {Field: "Account", Index: []string{"0"}}}, { - {Field: "Field2", Index: StringPointer("1")}, - {Field: "Account", Index: StringPointer("1")}}, - {{Field: "Field2", Index: StringPointer("2")}}, + {Field: "Field2", Index: []string{"1"}}, + {Field: "Account", Index: []string{"1"}}}, + {{Field: "Field2", Index: []string{"2"}}}, } if !reflect.DeepEqual(expOrder, onm.GetOrder()) { t.Errorf("Expected %s ,received: %s", expOrder, ToJSON(onm.GetOrder())) @@ -113,14 +113,14 @@ func TestOrderedNavigableMap(t *testing.T) { }, NewNMData(5)) expOrder = []PathItems{ {{Field: "Field1"}}, - {{Field: "Field2", Index: StringPointer("0")}}, + {{Field: "Field2", Index: []string{"0"}}}, { - {Field: "Field2", Index: StringPointer("1")}, - {Field: "Account", Index: StringPointer("0")}}, + {Field: "Field2", Index: []string{"1"}}, + {Field: "Account", Index: []string{"0"}}}, { - {Field: "Field2", Index: StringPointer("1")}, - {Field: "Account", Index: StringPointer("1")}}, - {{Field: "Field2", Index: StringPointer("2")}}, + {Field: "Field2", Index: []string{"1"}}, + {Field: "Account", Index: []string{"1"}}}, + {{Field: "Field2", Index: []string{"2"}}}, { {Field: "Field3"}, {Field: "Field4"}, @@ -130,17 +130,17 @@ func TestOrderedNavigableMap(t *testing.T) { t.Errorf("Expected %s ,received: %s", expOrder, ToJSON(onm.GetOrder())) } - var expnm NMInterface = NavigableMap2{ + var expnm NMInterface = NavigableMap{ "Field1": NewNMData(10), "Field2": &NMSlice{ NewNMData("1001"), - NavigableMap2{ + NavigableMap{ "Account": &NMSlice{NewNMData(10), NewNMData(11)}, }, NewNMData(111), }, - "Field3": NavigableMap2{ - "Field4": NavigableMap2{ + "Field3": NavigableMap{ + "Field4": NavigableMap{ "Field5": NewNMData(5), }, }, @@ -173,23 +173,23 @@ func TestOrderedNavigableMap(t *testing.T) { {Field: "Field3"}, {Field: "Field4"}, {Field: "Field5"}}, - {{Field: "Field2", Index: StringPointer("0")}}, - {{Field: "Field2", Index: StringPointer("1")}}, + {{Field: "Field2", Index: []string{"0"}}}, + {{Field: "Field2", Index: []string{"1"}}}, } if !reflect.DeepEqual(expOrder, onm.GetOrder()) { t.Errorf("Expected %s ,received: %s", expOrder, onm.GetOrder()) } - path = PathItems{{Field: "Field2", Index: StringPointer("0")}} + path = PathItems{{Field: "Field2", Index: []string{"0"}}} if val, err := onm.Field(path); err != nil { t.Error(err) } else if val.Interface() != "500" { t.Errorf("Expected %q ,received: %q", "500", val.Interface()) } - expnm = NavigableMap2{ + expnm = NavigableMap{ "Field1": NewNMData(10), - "Field3": NavigableMap2{ - "Field4": NavigableMap2{ + "Field3": NavigableMap{ + "Field4": NavigableMap{ "Field5": NewNMData(5), }, }, @@ -204,12 +204,12 @@ func TestOrderedNavigableMap(t *testing.T) { } func TestOrderedNavigableMapString(t *testing.T) { - nm := &OrderedNavigableMap{nm: NavigableMap2{"Field1": NewNMData("1001")}} + nm := &OrderedNavigableMap{nm: NavigableMap{"Field1": NewNMData("1001")}} expected := `{"Field1":1001}` if rply := nm.String(); rply != expected { t.Errorf("Expected %q ,received: %q", expected, rply) } - nm = &OrderedNavigableMap{nm: NavigableMap2{}} + nm = &OrderedNavigableMap{nm: NavigableMap{}} expected = `{}` if rply := nm.String(); rply != expected { t.Errorf("Expected %q ,received: %q", expected, rply) @@ -217,22 +217,22 @@ func TestOrderedNavigableMapString(t *testing.T) { } func TestOrderedNavigableMapInterface(t *testing.T) { - nm := &OrderedNavigableMap{nm: NavigableMap2{"Field1": NewNMData("1001"), "Field2": NewNMData("1003")}} - expected := NavigableMap2{"Field1": NewNMData("1001"), "Field2": NewNMData("1003")} + nm := &OrderedNavigableMap{nm: NavigableMap{"Field1": NewNMData("1001"), "Field2": NewNMData("1003")}} + expected := NavigableMap{"Field1": NewNMData("1001"), "Field2": NewNMData("1003")} if rply := nm.Interface(); !reflect.DeepEqual(expected, rply) { t.Errorf("Expected %s ,received: %s", ToJSON(expected), ToJSON(rply)) } } func TestOrderedNavigableMapField(t *testing.T) { - nm := &OrderedNavigableMap{nm: NavigableMap2{}} + nm := &OrderedNavigableMap{nm: NavigableMap{}} if _, err := nm.Field(PathItems{{}}); err != ErrNotFound { t.Error(err) } - nm = &OrderedNavigableMap{nm: NavigableMap2{ + nm = &OrderedNavigableMap{nm: NavigableMap{ "Field1": NewNMData("1001"), "Field2": NewNMData("1003"), - "Field3": NavigableMap2{"Field4": NewNMData("Val")}, + "Field3": NavigableMap{"Field4": NewNMData("Val")}, "Field5": &NMSlice{NewNMData(10), NewNMData(101)}, }} if _, err := nm.Field(nil); err != ErrWrongPath { @@ -248,15 +248,15 @@ func TestOrderedNavigableMapField(t *testing.T) { t.Errorf("Expected %q ,received: %q", "1001", val.Interface()) } - if _, err := nm.Field(PathItems{{Field: "Field1", Index: StringPointer("0")}}); err != ErrNotFound { + if _, err := nm.Field(PathItems{{Field: "Field1", Index: []string{"0"}}}); err != ErrNotFound { t.Error(err) } - if val, err := nm.Field(PathItems{{Field: "Field5", Index: StringPointer("0")}}); err != nil { + if val, err := nm.Field(PathItems{{Field: "Field5", Index: []string{"0"}}}); err != nil { t.Error(err) } else if val.Interface() != 10 { t.Errorf("Expected %q ,received: %q", 10, val.Interface()) } - if _, err := nm.Field(PathItems{{Field: "Field3", Index: StringPointer("0")}}); err != ErrNotFound { + if _, err := nm.Field(PathItems{{Field: "Field3", Index: []string{"0"}}}); err != ErrNotFound { t.Error(err) } if val, err := nm.Field(PathItems{{Field: "Field3"}, {Field: "Field4"}}); err != nil { @@ -267,29 +267,29 @@ func TestOrderedNavigableMapField(t *testing.T) { } func TestOrderedNavigableMapType(t *testing.T) { - nm := &OrderedNavigableMap{nm: NavigableMap2{}} + nm := &OrderedNavigableMap{nm: NavigableMap{}} if nm.Type() != NMMapType { t.Errorf("Expected %v ,received: %v", NMMapType, nm.Type()) } } func TestOrderedNavigableMapEmpty(t *testing.T) { - nm := &OrderedNavigableMap{nm: NavigableMap2{}} + nm := &OrderedNavigableMap{nm: NavigableMap{}} if !nm.Empty() { t.Error("Expected empty type") } - nm = &OrderedNavigableMap{nm: NavigableMap2{"Field1": NewNMData("1001")}} + nm = &OrderedNavigableMap{nm: NavigableMap{"Field1": NewNMData("1001")}} if nm.Empty() { t.Error("Expected not empty type") } } func TestOrderedNavigableMapLen(t *testing.T) { - nm := &OrderedNavigableMap{nm: NavigableMap2{}} + nm := &OrderedNavigableMap{nm: NavigableMap{}} if rply := nm.Len(); rply != 0 { t.Errorf("Expected 0 ,received: %v", rply) } - nm = &OrderedNavigableMap{nm: NavigableMap2{"Field1": NewNMData("1001")}} + nm = &OrderedNavigableMap{nm: NavigableMap{"Field1": NewNMData("1001")}} if rply := nm.Len(); rply != 1 { t.Errorf("Expected 1 ,received: %v", rply) } @@ -298,33 +298,33 @@ func TestOrderedNavigableMapLen(t *testing.T) { func TestOrderedNavigableMapGetSet(t *testing.T) { nm := NewOrderedNavigableMap() nm.Set(&FullPath{ - PathItems: PathItems{{Field: "Account", Index: StringPointer("0")}}, + PathItems: PathItems{{Field: "Account", Index: []string{"0"}}}, Path: "Account", }, NewNMData(1001)) nm.Set(&FullPath{ - PathItems: PathItems{{Field: "Account", Index: StringPointer("1")}}, + PathItems: PathItems{{Field: "Account", Index: []string{"1"}}}, Path: "Account", }, NewNMData("account_on_new_branch")) expectedOrder := []PathItems{ - {{Field: "Account", Index: StringPointer("0")}}, - {{Field: "Account", Index: StringPointer("1")}}, + {{Field: "Account", Index: []string{"0"}}}, + {{Field: "Account", Index: []string{"1"}}}, } if receivedOrder := nm.GetOrder(); !reflect.DeepEqual(expectedOrder, receivedOrder) { t.Errorf("Expected %s ,received: %s", expectedOrder, receivedOrder) } nm = &OrderedNavigableMap{ - nm: NavigableMap2{ + nm: NavigableMap{ "Field1": NewNMData(10), "Field2": &NMSlice{ NewNMData("1001"), - NavigableMap2{ + NavigableMap{ "Account": &NMSlice{NewNMData(10), NewNMData(11)}, }, }, - "Field3": NavigableMap2{ - "Field4": NavigableMap2{ + "Field3": NavigableMap{ + "Field4": NavigableMap{ "Field5": NewNMData(5), }, }, @@ -346,7 +346,7 @@ func TestOrderedNavigableMapGetSet(t *testing.T) { t.Errorf("Expected %q ,received: %q", 5, val.Interface()) } - path = PathItems{{Field: "Field2", Index: StringPointer("2")}} + path = PathItems{{Field: "Field2", Index: []string{"2"}}} if _, err := nm.Set(&FullPath{Path: path.String(), PathItems: path}, NewNMData("500")); err != nil { t.Error(err) } @@ -356,27 +356,27 @@ func TestOrderedNavigableMapGetSet(t *testing.T) { t.Errorf("Expected %q ,received: %q", "500", val.Interface()) } - path = PathItems{{Field: "Field2", Index: StringPointer("1")}, {Field: "Account"}} + path = PathItems{{Field: "Field2", Index: []string{"1"}}, {Field: "Account"}} if _, err := nm.Set(&FullPath{Path: path.String(), PathItems: path}, NewNMData("5")); err != nil { t.Error(err) } - path = PathItems{{Field: "Field2", Index: StringPointer("1")}, {Field: "Account"}} + path = PathItems{{Field: "Field2", Index: []string{"1"}}, {Field: "Account"}} if val, err := nm.Field(path); err != nil { t.Error(err) } else if val.Interface() != "5" { t.Errorf("Expected %q ,received: %q", "5", val.Interface()) } - path = PathItems{{Field: "Field2", Index: StringPointer("1")}, {Field: "Account", Index: StringPointer("0")}} + path = PathItems{{Field: "Field2", Index: []string{"1"}}, {Field: "Account", Index: []string{"0"}}} if _, err := nm.Field(path); err != ErrNotFound { t.Error(err) } } func TestOrderedNavigableMapFieldAsInterface(t *testing.T) { - nm := &OrderedNavigableMap{nm: NavigableMap2{ + nm := &OrderedNavigableMap{nm: NavigableMap{ "Field1": NewNMData("1001"), "Field2": NewNMData("1003"), - "Field3": NavigableMap2{"Field4": NewNMData("Val")}, + "Field3": NavigableMap{"Field4": NewNMData("Val")}, "Field5": &NMSlice{NewNMData(10), NewNMData(101)}, }} if _, err := nm.FieldAsInterface(nil); err != ErrWrongPath { @@ -397,10 +397,10 @@ func TestOrderedNavigableMapFieldAsInterface(t *testing.T) { } func TestOrderedNavigableMapFieldAsString(t *testing.T) { - nm := &OrderedNavigableMap{nm: NavigableMap2{ + nm := &OrderedNavigableMap{nm: NavigableMap{ "Field1": NewNMData("1001"), "Field2": NewNMData("1003"), - "Field3": NavigableMap2{"Field4": NewNMData("Val")}, + "Field3": NavigableMap{"Field4": NewNMData("Val")}, "Field5": &NMSlice{NewNMData(10), NewNMData(101)}, }} if _, err := nm.FieldAsString(nil); err != ErrWrongPath { @@ -423,26 +423,26 @@ func TestOrderedNavigableMapFieldAsString(t *testing.T) { func TestOrderedNavigableMapGetOrder(t *testing.T) { nm := NewOrderedNavigableMap() nm.Set(&FullPath{ - PathItems: PathItems{{Field: "Field1"}, {Field: "Field2", Index: StringPointer("0")}}, + PathItems: PathItems{{Field: "Field1"}, {Field: "Field2", Index: []string{"0"}}}, Path: "Field1.Field2[0]", }, NewNMData("1003")) nm.Set(&FullPath{ - PathItems: PathItems{{Field: "Field1"}, {Field: "Field2", Index: StringPointer("1")}}, + PathItems: PathItems{{Field: "Field1"}, {Field: "Field2", Index: []string{"1"}}}, Path: "Field1.Field2[1]", }, NewNMData("Val")) nm.Set(&FullPath{ - PathItems: PathItems{{Field: "Field3"}, {Field: "Field4"}, {Field: "Field5", Index: StringPointer("0")}}, + PathItems: PathItems{{Field: "Field3"}, {Field: "Field4"}, {Field: "Field5", Index: []string{"0"}}}, Path: "Field3.Field4.Field5", }, NewNMData("1001")) nm.Set(&FullPath{ - PathItems: PathItems{{Field: "Field1"}, {Field: "Field2", Index: StringPointer("2")}}, + PathItems: PathItems{{Field: "Field1"}, {Field: "Field2", Index: []string{"2"}}}, Path: "Field1.Field2[2]", }, NewNMData(101)) expected := []PathItems{ - {{Field: "Field1"}, {Field: "Field2", Index: StringPointer("0")}}, - {{Field: "Field1"}, {Field: "Field2", Index: StringPointer("1")}}, - {{Field: "Field3"}, {Field: "Field4"}, {Field: "Field5", Index: StringPointer("0")}}, - {{Field: "Field1"}, {Field: "Field2", Index: StringPointer("2")}}, + {{Field: "Field1"}, {Field: "Field2", Index: []string{"0"}}}, + {{Field: "Field1"}, {Field: "Field2", Index: []string{"1"}}}, + {{Field: "Field3"}, {Field: "Field4"}, {Field: "Field5", Index: []string{"0"}}}, + {{Field: "Field1"}, {Field: "Field2", Index: []string{"2"}}}, } if rply := nm.GetOrder(); !reflect.DeepEqual(rply, expected) { t.Errorf("Expected %s ,received: %s", expected, rply) @@ -457,18 +457,18 @@ func TestOrderedNavigableMapSet(t *testing.T) { t.Error(err) } if _, err := nm.Set(&FullPath{ - PathItems: PathItems{{Field: "Field1", Index: StringPointer("10")}}, + PathItems: PathItems{{Field: "Field1", Index: []string{"10"}}}, Path: "Field1[10]", }, NewNMData("1001")); err != ErrWrongPath { t.Error(err) } if _, err := nm.Set(&FullPath{ - PathItems: PathItems{{Field: "Field1", Index: StringPointer("10")}, {Field: "Field2"}}, + PathItems: PathItems{{Field: "Field1", Index: []string{"10"}}, {Field: "Field2"}}, Path: "Field1[10].Field2", }, NewNMData("1001")); err != ErrWrongPath { t.Error(err) } - path := PathItems{{Field: "Field1", Index: StringPointer("0")}} + path := PathItems{{Field: "Field1", Index: []string{"0"}}} if addedNew, err := nm.Set(&FullPath{ PathItems: path, Path: path.String(), @@ -477,7 +477,7 @@ func TestOrderedNavigableMapSet(t *testing.T) { } else if !addedNew { t.Error("Expected the field to be added new") } - nMap := NavigableMap2{"Field1": &NMSlice{NewNMData("1001")}} + nMap := NavigableMap{"Field1": &NMSlice{NewNMData("1001")}} order := []PathItems{path} if !reflect.DeepEqual(nm.nm, nMap) { t.Errorf("Expected %s ,received: %s", nMap, nm) @@ -486,32 +486,32 @@ func TestOrderedNavigableMapSet(t *testing.T) { t.Errorf("Expected %s ,received: %s", order, nm.GetOrder()) } if _, err := nm.Set(&FullPath{ - PathItems: PathItems{{Field: "Field1", Index: StringPointer("0")}, {}}, + PathItems: PathItems{{Field: "Field1", Index: []string{"0"}}, {}}, Path: "Field1[0]", }, NewNMData("1001")); err != ErrWrongPath { t.Error(err) } if _, err := nm.Set(&FullPath{ - PathItems: PathItems{{Field: "Field1", Index: StringPointer("10")}}, + PathItems: PathItems{{Field: "Field1", Index: []string{"10"}}}, Path: "Field1[10]", }, NewNMData("1001")); err != ErrWrongPath { t.Error(err) } if _, err := nm.Set(&FullPath{ - PathItems: PathItems{{Field: "Field1", Index: StringPointer("0")}, {}}, + PathItems: PathItems{{Field: "Field1", Index: []string{"0"}}, {}}, Path: "Field1[0]", }, &NMSlice{}); err != ErrWrongPath { t.Error(err) } if _, err := nm.Set(&FullPath{ - PathItems: PathItems{{Field: "Field1", Index: StringPointer("10")}}, + PathItems: PathItems{{Field: "Field1", Index: []string{"10"}}}, Path: "Field[10]", }, &NMSlice{}); err != ErrWrongPath { t.Error(err) } - nMap = NavigableMap2{"Field1": &NMSlice{NewNMData("1002")}} + nMap = NavigableMap{"Field1": &NMSlice{NewNMData("1002")}} order = []PathItems{path} if addedNew, err := nm.Set(&FullPath{ PathItems: path, @@ -528,7 +528,7 @@ func TestOrderedNavigableMapSet(t *testing.T) { t.Errorf("Expected %s ,received: %s", order, nm.GetOrder()) } path = PathItems{{Field: "Field2"}} - nMap = NavigableMap2{ + nMap = NavigableMap{ "Field1": &NMSlice{NewNMData("1002")}, "Field2": NewNMData("1002"), } @@ -547,8 +547,8 @@ func TestOrderedNavigableMapSet(t *testing.T) { if !reflect.DeepEqual(nm.GetOrder(), order) { t.Errorf("Expected %s ,received: %s", order, nm.GetOrder()) } - path = PathItems{{Field: "Field1", Index: StringPointer("1")}} - nMap = NavigableMap2{ + path = PathItems{{Field: "Field1", Index: []string{"1"}}} + nMap = NavigableMap{ "Field1": &NMSlice{NewNMData("1002"), NewNMData("1003")}, "Field2": NewNMData("1002"), } @@ -569,12 +569,12 @@ func TestOrderedNavigableMapSet(t *testing.T) { } path = PathItems{{Field: "Field3"}} obj := &NMSlice{NewNMData("1004"), NewNMData("1005")} - nMap = NavigableMap2{ + nMap = NavigableMap{ "Field1": &NMSlice{NewNMData("1002"), NewNMData("1003")}, "Field2": NewNMData("1002"), "Field3": obj, } - order = append(order, PathItems{{Field: "Field3", Index: StringPointer("0")}}, PathItems{{Field: "Field3", Index: StringPointer("1")}}) + order = append(order, PathItems{{Field: "Field3", Index: []string{"0"}}}, PathItems{{Field: "Field3", Index: []string{"1"}}}) if addedNew, err := nm.Set(&FullPath{ PathItems: path, Path: path.String(), @@ -590,17 +590,17 @@ func TestOrderedNavigableMapSet(t *testing.T) { t.Errorf("Expected %s ,received: %s", order, nm.GetOrder()) } obj = &NMSlice{NewNMData("1005"), NewNMData("1006")} - nMap = NavigableMap2{ + nMap = NavigableMap{ "Field1": &NMSlice{NewNMData("1005"), NewNMData("1006")}, "Field2": NewNMData("1002"), "Field3": &NMSlice{NewNMData("1004"), NewNMData("1005")}, } order = []PathItems{ {{Field: "Field2"}}, - {{Field: "Field3", Index: StringPointer("0")}}, - {{Field: "Field3", Index: StringPointer("1")}}, - {{Field: "Field1", Index: StringPointer("0")}}, - {{Field: "Field1", Index: StringPointer("1")}}, + {{Field: "Field3", Index: []string{"0"}}}, + {{Field: "Field3", Index: []string{"1"}}}, + {{Field: "Field1", Index: []string{"0"}}}, + {{Field: "Field1", Index: []string{"1"}}}, } if addedNew, err := nm.Set(&FullPath{ PathItems: PathItems{{Field: "Field1"}}, @@ -617,20 +617,20 @@ func TestOrderedNavigableMapSet(t *testing.T) { t.Errorf("Expected %s ,received: %s", order, nm.GetOrder()) } obj = &NMSlice{NewNMData("1005"), NewNMData("1006")} - nMap = NavigableMap2{ + nMap = NavigableMap{ "Field1": &NMSlice{NewNMData("1005"), NewNMData("1006")}, "Field2": NewNMData("1002"), "Field3": &NMSlice{NewNMData("1004"), NewNMData("1007")}, } order = []PathItems{ {{Field: "Field2"}}, - {{Field: "Field3", Index: StringPointer("0")}}, - {{Field: "Field1", Index: StringPointer("0")}}, - {{Field: "Field1", Index: StringPointer("1")}}, - {{Field: "Field3", Index: StringPointer("1")}}, + {{Field: "Field3", Index: []string{"0"}}}, + {{Field: "Field1", Index: []string{"0"}}}, + {{Field: "Field1", Index: []string{"1"}}}, + {{Field: "Field3", Index: []string{"1"}}}, } if addedNew, err := nm.Set(&FullPath{ - PathItems: PathItems{{Field: "Field3", Index: StringPointer("-1")}}, + PathItems: PathItems{{Field: "Field3", Index: []string{"-1"}}}, Path: "Field3[-1]", }, NewNMData("1007")); err != nil { t.Error(err) @@ -674,21 +674,21 @@ func TestOrderedNavigableMapRemove(t *testing.T) { t.Error(err) } - if err := nm.Remove(&FullPath{PathItems: PathItems{{Index: StringPointer("-1")}, {}}}); err != ErrWrongPath { + if err := nm.Remove(&FullPath{PathItems: PathItems{{Index: []string{"-1"}}, {}}}); err != ErrWrongPath { t.Error(err) } - nMap := NavigableMap2{ + nMap := NavigableMap{ "Field1": NewNMData("1001"), "Field2": NewNMData("1003"), - "Field3": NavigableMap2{"Field4": NewNMData("Val")}, + "Field3": NavigableMap{"Field4": NewNMData("Val")}, "Field5": &NMSlice{NewNMData(10), NewNMData(101)}, } order := []PathItems{ {{Field: "Field2"}}, {{Field: "Field3"}, {Field: "Field4"}}, {{Field: "Field1"}}, - {{Field: "Field5", Index: StringPointer("0")}}, - {{Field: "Field5", Index: StringPointer("1")}}, + {{Field: "Field5", Index: []string{"0"}}}, + {{Field: "Field5", Index: []string{"1"}}}, } if !reflect.DeepEqual(nm.nm, nMap) { t.Errorf("Expected %s ,received: %s", nMap, nm) @@ -696,16 +696,16 @@ func TestOrderedNavigableMapRemove(t *testing.T) { if !reflect.DeepEqual(nm.GetOrder(), order) { t.Errorf("Expected %s ,received: %s", order, nm.GetOrder()) } - nMap = NavigableMap2{ + nMap = NavigableMap{ "Field1": NewNMData("1001"), - "Field3": NavigableMap2{"Field4": NewNMData("Val")}, + "Field3": NavigableMap{"Field4": NewNMData("Val")}, "Field5": &NMSlice{NewNMData(10), NewNMData(101)}, } order = []PathItems{ {{Field: "Field3"}, {Field: "Field4"}}, {{Field: "Field1"}}, - {{Field: "Field5", Index: StringPointer("0")}}, - {{Field: "Field5", Index: StringPointer("1")}}, + {{Field: "Field5", Index: []string{"0"}}}, + {{Field: "Field5", Index: []string{"1"}}}, } if err := nm.Remove(&FullPath{PathItems: PathItems{{Field: "Field2"}}, Path: "Field2"}); err != nil { @@ -717,9 +717,9 @@ func TestOrderedNavigableMapRemove(t *testing.T) { if !reflect.DeepEqual(nm.GetOrder(), order) { t.Errorf("Expected %s ,received: %s", order, nm.GetOrder()) } - nMap = NavigableMap2{ + nMap = NavigableMap{ "Field1": NewNMData("1001"), - "Field3": NavigableMap2{"Field4": NewNMData("Val")}, + "Field3": NavigableMap{"Field4": NewNMData("Val")}, } order = []PathItems{ {{Field: "Field3"}, {Field: "Field4"}}, @@ -735,13 +735,13 @@ func TestOrderedNavigableMapRemove(t *testing.T) { if !reflect.DeepEqual(nm.GetOrder(), order) { t.Errorf("Expected %s ,received: %s", order, nm.GetOrder()) } - if err := nm.Remove(&FullPath{PathItems: PathItems{{Field: "Field1", Index: StringPointer("0")}, {}}}); err != ErrWrongPath { + if err := nm.Remove(&FullPath{PathItems: PathItems{{Field: "Field1", Index: []string{"0"}}, {}}}); err != ErrWrongPath { t.Error(err) } } func TestOrderedNavigableRemote(t *testing.T) { - nm := &OrderedNavigableMap{nm: NavigableMap2{"Field1": NewNMData("1001")}} + nm := &OrderedNavigableMap{nm: NavigableMap{"Field1": NewNMData("1001")}} eOut := LocalAddr() if rcv := nm.RemoteHost(); !reflect.DeepEqual(eOut, rcv) { t.Errorf("Expecting: %+v, received: %+v", eOut, rcv) @@ -762,7 +762,7 @@ func BenchmarkOrderdNavigableMapSet(b *testing.B) { } func BenchmarkNavigableMapSet(b *testing.B) { - nm := NavigableMap2{} + nm := NavigableMap{} b.ResetTimer() for n := 0; n < b.N; n++ { for _, data := range gen { @@ -805,7 +805,7 @@ func BenchmarkOrderdNavigableMapFieldAsInterface(b *testing.B) { } func BenchmarkNavigableMapFieldAsInterface(b *testing.B) { - nm := NavigableMap2{} + nm := NavigableMap{} for _, data := range gen { if _,err := nm.Set(data.pathItems, NewNMData(data.data)); err != nil { b.Log(err, data.path) @@ -883,7 +883,7 @@ func BenchmarkOrderdNavigableMapField(b *testing.B) { } func BenchmarkNavigableMapField(b *testing.B) { - nm := NavigableMap2{} + nm := NavigableMap{} for _, data := range gen { if _,err := nm.Set(data.pathItems, NewNMData(data.data)); err != nil { b.Log(err, data.path) @@ -930,12 +930,12 @@ func TestOrderedNavigableMapRemoveAll(t *testing.T) { func TestOrderedNavigableMapRemove2(t *testing.T) { nm := &OrderedNavigableMap{ - nm: NavigableMap2{ + nm: NavigableMap{ "Field1": &NMSlice{}, }, } expErr := `strconv.Atoi: parsing "nan": invalid syntax` - if err := nm.Remove(&FullPath{PathItems: PathItems{{Field: "Field1", Index: StringPointer("nan")}, {}}, Path: "Field1[nan]"}); err == nil || err.Error() != expErr { + if err := nm.Remove(&FullPath{PathItems: PathItems{{Field: "Field1", Index: []string{"nan"}}, {}}, Path: "Field1[nan]"}); err == nil || err.Error() != expErr { t.Errorf("Expected error: %s,received: %v", expErr, err) } } @@ -943,11 +943,11 @@ func TestOrderedNavigableMapRemove2(t *testing.T) { func TestOrderedNavigableMapOrderedFields(t *testing.T) { nm := NewOrderedNavigableMap() nm.Set(&FullPath{ - PathItems: PathItems{{Field: "Field1"}, {Field: "Field2", Index: StringPointer("0")}}, + PathItems: PathItems{{Field: "Field1"}, {Field: "Field2", Index: []string{"0"}}}, Path: "Field1.Field2[0]", }, NewNMData("1003")) nm.Set(&FullPath{ - PathItems: PathItems{{Field: "Field1"}, {Field: "Field3", Index: StringPointer("0")}}, + PathItems: PathItems{{Field: "Field1"}, {Field: "Field3", Index: []string{"0"}}}, Path: "Field1.Field3[0]", }, NewNMData("1004")) nm.Set(&FullPath{ diff --git a/utils/pathitem.go b/utils/pathitem.go index 9e0c97795..7bb3a4ef4 100644 --- a/utils/pathitem.go +++ b/utils/pathitem.go @@ -52,7 +52,7 @@ type FullPath struct { func NewPathItems(path []string) (pItms PathItems) { pItms = make(PathItems, len(path)) for i, v := range path { - field, indx := GetPathIndexString(v) + field, indx := GetPathIndexSlice(v) pItms[i] = PathItem{ Field: field, Index: indx, @@ -98,39 +98,25 @@ func (path PathItems) Slice() (out []string) { // PathItem used by the NM interface to store the path information type PathItem struct { Field string - Index *string -} - -// Equal returns true if p==p2 -func (p PathItem) Equal(p2 PathItem) bool { - if p.Field != p2.Field { - return false - } - if p.Index == nil && p2.Index == nil { - return true - } - if p.Index != nil && p2.Index != nil { - return *p.Index == *p2.Index - } - return false + Index []string } func (p PathItem) String() (out string) { out = p.Field - if p.Index != nil { - out += IdxStart + *p.Index + IdxEnd + for _, indx := range p.Index { + out += IdxStart + indx + IdxEnd } return } // Clone creates a copy func (p PathItem) Clone() (c PathItem) { - // if p == nil { - // return - // } c.Field = p.Field if p.Index != nil { - c.Index = StringPointer(*p.Index) + c.Index = make([]string, len(p.Index)) + for i, indx := range p.Index { + c.Index[i] = indx + } } return } @@ -176,3 +162,16 @@ func GetPathIndexString(spath string) (opath string, idx *string) { opath = spath[:idxStart] return opath, &idxVal } + +// GetPathIndexSlice returns the path and index as string if index present +// path[index]=>path,[index1,index2] +// path=>path,nil +func GetPathIndexSlice(spath string) (opath string, idx []string) { + idxStart := strings.Index(spath, IdxStart) + if idxStart == -1 || !strings.HasSuffix(spath, IdxEnd) { + return spath, nil + } + idxVal := spath[idxStart+1 : len(spath)-1] + opath = spath[:idxStart] + return opath, strings.Split(idxVal, IdxCombination) +} diff --git a/utils/pathitem_test.go b/utils/pathitem_test.go index 095337631..be7e355f3 100644 --- a/utils/pathitem_test.go +++ b/utils/pathitem_test.go @@ -56,7 +56,7 @@ func TestStripIdxFromLastPathElm(t *testing.T) { func TestNewPathItems(t *testing.T) { pathSlice := strings.Split("*req.Field1[0].Account", NestingSep) - expected := PathItems{{Field: MetaReq}, {Field: "Field1", Index: StringPointer("0")}, {Field: AccountField}} + expected := PathItems{{Field: MetaReq}, {Field: "Field1", Index: []string{"0"}}, {Field: AccountField}} if rply := NewPathItems(pathSlice); !reflect.DeepEqual(expected, rply) { t.Errorf("Expected: %s, received: %s", ToJSON(expected), ToJSON(rply)) } @@ -73,38 +73,18 @@ func TestPathItemString(t *testing.T) { if rply := path.String(); expected != rply { t.Errorf("Expected: %q, received: %q", expected, rply) } - path = PathItem{Field: MetaReq, Index: StringPointer("10")} + path = PathItem{Field: MetaReq, Index: []string{"10"}} expected = MetaReq + "[10]" if rply := path.String(); expected != rply { t.Errorf("Expected: %q, received: %q", expected, rply) } } -func TestPathItemEqual(t *testing.T) { - path := PathItem{Field: MetaReq} - p1 := PathItem{Field: MetaReq} - if !path.Equal(p1) { - t.Errorf("Expected %s to be equal to %s", ToJSON(path), ToJSON(p1)) - } - p1 = PathItem{Field: MetaRep} - if path.Equal(p1) { - t.Errorf("Expected %s to not be equal to %s", ToJSON(path), ToJSON(p1)) - } - p1 = PathItem{Field: MetaReq, Index: StringPointer("0")} - if path.Equal(p1) { - t.Errorf("Expected %s to not be equal to %s", ToJSON(path), ToJSON(p1)) - } - path = PathItem{Field: MetaReq, Index: StringPointer("0")} - if !path.Equal(p1) { - t.Errorf("Expected %s to be equal to %s", ToJSON(path), ToJSON(p1)) - } -} - func TestPathItemClone(t *testing.T) { - path := PathItem{Field: MetaReq, Index: StringPointer("0")} - expected := PathItem{Field: MetaReq, Index: StringPointer("0")} + path := PathItem{Field: MetaReq, Index: []string{"0"}} + expected := PathItem{Field: MetaReq, Index: []string{"0"}} rply := path.Clone() - *path.Index = "1" + path.Index[0] = "1" if !reflect.DeepEqual(expected, rply) { t.Errorf("Expected: %s, received: %s", ToJSON(expected), ToJSON(rply)) }