Removed unnecessary if from AsNavigableMap methods in sessions

This commit is contained in:
porosnicuadrian
2021-01-11 15:59:55 +02:00
committed by Dan Christian Bogos
parent 36fa7c234a
commit 0958def326

View File

@@ -1857,40 +1857,38 @@ type V1AuthorizeReply struct {
// AsNavigableMap is part of engine.NavigableMapper interface
func (v1AuthReply *V1AuthorizeReply) AsNavigableMap() utils.NavigableMap2 {
cgrReply := make(utils.NavigableMap2)
if v1AuthReply != nil {
if v1AuthReply.Attributes != nil {
attrs := make(utils.NavigableMap2)
for _, fldName := range v1AuthReply.Attributes.AlteredFields {
fldName = strings.TrimPrefix(fldName, utils.MetaReq+utils.NestingSep)
if v1AuthReply.Attributes.CGREvent.HasField(fldName) {
attrs[fldName] = utils.NewNMData(v1AuthReply.Attributes.CGREvent.Event[fldName])
}
if v1AuthReply.Attributes != nil {
attrs := make(utils.NavigableMap2)
for _, fldName := range v1AuthReply.Attributes.AlteredFields {
fldName = strings.TrimPrefix(fldName, utils.MetaReq+utils.NestingSep)
if v1AuthReply.Attributes.CGREvent.HasField(fldName) {
attrs[fldName] = utils.NewNMData(v1AuthReply.Attributes.CGREvent.Event[fldName])
}
cgrReply[utils.CapAttributes] = attrs
}
if v1AuthReply.ResourceAllocation != nil {
cgrReply[utils.CapResourceAllocation] = utils.NewNMData(*v1AuthReply.ResourceAllocation)
cgrReply[utils.CapAttributes] = attrs
}
if v1AuthReply.ResourceAllocation != nil {
cgrReply[utils.CapResourceAllocation] = utils.NewNMData(*v1AuthReply.ResourceAllocation)
}
if v1AuthReply.MaxUsage != nil {
cgrReply[utils.CapMaxUsage] = utils.NewNMData(*v1AuthReply.MaxUsage)
}
if v1AuthReply.Routes != nil {
cgrReply[utils.CapRoutes] = v1AuthReply.Routes.AsNavigableMap()
}
if v1AuthReply.ThresholdIDs != nil {
thIDs := make(utils.NMSlice, len(*v1AuthReply.ThresholdIDs))
for i, v := range *v1AuthReply.ThresholdIDs {
thIDs[i] = utils.NewNMData(v)
}
if v1AuthReply.MaxUsage != nil {
cgrReply[utils.CapMaxUsage] = utils.NewNMData(*v1AuthReply.MaxUsage)
}
if v1AuthReply.Routes != nil {
cgrReply[utils.CapRoutes] = v1AuthReply.Routes.AsNavigableMap()
}
if v1AuthReply.ThresholdIDs != nil {
thIDs := make(utils.NMSlice, len(*v1AuthReply.ThresholdIDs))
for i, v := range *v1AuthReply.ThresholdIDs {
thIDs[i] = utils.NewNMData(v)
}
cgrReply[utils.CapThresholds] = &thIDs
}
if v1AuthReply.StatQueueIDs != nil {
stIDs := make(utils.NMSlice, len(*v1AuthReply.StatQueueIDs))
for i, v := range *v1AuthReply.StatQueueIDs {
stIDs[i] = utils.NewNMData(v)
}
cgrReply[utils.CapStatQueues] = &stIDs
cgrReply[utils.CapThresholds] = &thIDs
}
if v1AuthReply.StatQueueIDs != nil {
stIDs := make(utils.NMSlice, len(*v1AuthReply.StatQueueIDs))
for i, v := range *v1AuthReply.StatQueueIDs {
stIDs[i] = utils.NewNMData(v)
}
cgrReply[utils.CapStatQueues] = &stIDs
}
return cgrReply
}
@@ -2141,38 +2139,36 @@ type V1InitSessionReply struct {
// AsNavigableMap is part of engine.NavigableMapper interface
func (v1Rply *V1InitSessionReply) AsNavigableMap() utils.NavigableMap2 {
cgrReply := make(utils.NavigableMap2)
if v1Rply != nil {
if v1Rply.Attributes != nil {
attrs := make(utils.NavigableMap2)
for _, fldName := range v1Rply.Attributes.AlteredFields {
fldName = strings.TrimPrefix(fldName, utils.MetaReq+utils.NestingSep)
if v1Rply.Attributes.CGREvent.HasField(fldName) {
attrs[fldName] = utils.NewNMData(v1Rply.Attributes.CGREvent.Event[fldName])
}
if v1Rply.Attributes != nil {
attrs := make(utils.NavigableMap2)
for _, fldName := range v1Rply.Attributes.AlteredFields {
fldName = strings.TrimPrefix(fldName, utils.MetaReq+utils.NestingSep)
if v1Rply.Attributes.CGREvent.HasField(fldName) {
attrs[fldName] = utils.NewNMData(v1Rply.Attributes.CGREvent.Event[fldName])
}
cgrReply[utils.CapAttributes] = attrs
}
if v1Rply.ResourceAllocation != nil {
cgrReply[utils.CapResourceAllocation] = utils.NewNMData(*v1Rply.ResourceAllocation)
}
if v1Rply.MaxUsage != nil {
cgrReply[utils.CapMaxUsage] = utils.NewNMData(*v1Rply.MaxUsage)
}
cgrReply[utils.CapAttributes] = attrs
}
if v1Rply.ResourceAllocation != nil {
cgrReply[utils.CapResourceAllocation] = utils.NewNMData(*v1Rply.ResourceAllocation)
}
if v1Rply.MaxUsage != nil {
cgrReply[utils.CapMaxUsage] = utils.NewNMData(*v1Rply.MaxUsage)
}
if v1Rply.ThresholdIDs != nil {
thIDs := make(utils.NMSlice, len(*v1Rply.ThresholdIDs))
for i, v := range *v1Rply.ThresholdIDs {
thIDs[i] = utils.NewNMData(v)
}
cgrReply[utils.CapThresholds] = &thIDs
if v1Rply.ThresholdIDs != nil {
thIDs := make(utils.NMSlice, len(*v1Rply.ThresholdIDs))
for i, v := range *v1Rply.ThresholdIDs {
thIDs[i] = utils.NewNMData(v)
}
if v1Rply.StatQueueIDs != nil {
stIDs := make(utils.NMSlice, len(*v1Rply.StatQueueIDs))
for i, v := range *v1Rply.StatQueueIDs {
stIDs[i] = utils.NewNMData(v)
}
cgrReply[utils.CapStatQueues] = &stIDs
cgrReply[utils.CapThresholds] = &thIDs
}
if v1Rply.StatQueueIDs != nil {
stIDs := make(utils.NMSlice, len(*v1Rply.StatQueueIDs))
for i, v := range *v1Rply.StatQueueIDs {
stIDs[i] = utils.NewNMData(v)
}
cgrReply[utils.CapStatQueues] = &stIDs
}
return cgrReply
}
@@ -2394,20 +2390,18 @@ type V1UpdateSessionReply struct {
// AsNavigableMap is part of engine.NavigableMapper interface
func (v1Rply *V1UpdateSessionReply) AsNavigableMap() utils.NavigableMap2 {
cgrReply := make(utils.NavigableMap2)
if v1Rply != nil {
if v1Rply.Attributes != nil {
attrs := make(utils.NavigableMap2)
for _, fldName := range v1Rply.Attributes.AlteredFields {
fldName = strings.TrimPrefix(fldName, utils.MetaReq+utils.NestingSep)
if v1Rply.Attributes.CGREvent.HasField(fldName) {
attrs[fldName] = utils.NewNMData(v1Rply.Attributes.CGREvent.Event[fldName])
}
if v1Rply.Attributes != nil {
attrs := make(utils.NavigableMap2)
for _, fldName := range v1Rply.Attributes.AlteredFields {
fldName = strings.TrimPrefix(fldName, utils.MetaReq+utils.NestingSep)
if v1Rply.Attributes.CGREvent.HasField(fldName) {
attrs[fldName] = utils.NewNMData(v1Rply.Attributes.CGREvent.Event[fldName])
}
cgrReply[utils.CapAttributes] = attrs
}
if v1Rply.MaxUsage != nil {
cgrReply[utils.CapMaxUsage] = utils.NewNMData(*v1Rply.MaxUsage)
}
cgrReply[utils.CapAttributes] = attrs
}
if v1Rply.MaxUsage != nil {
cgrReply[utils.CapMaxUsage] = utils.NewNMData(*v1Rply.MaxUsage)
}
return cgrReply
}
@@ -2827,40 +2821,38 @@ type V1ProcessMessageReply struct {
// AsNavigableMap is part of engine.NavigableMapper interface
func (v1Rply *V1ProcessMessageReply) AsNavigableMap() utils.NavigableMap2 {
cgrReply := make(utils.NavigableMap2)
if v1Rply != nil {
if v1Rply.MaxUsage != nil {
cgrReply[utils.CapMaxUsage] = utils.NewNMData(*v1Rply.MaxUsage)
}
if v1Rply.ResourceAllocation != nil {
cgrReply[utils.CapResourceAllocation] = utils.NewNMData(*v1Rply.ResourceAllocation)
}
if v1Rply.Attributes != nil {
attrs := make(utils.NavigableMap2)
for _, fldName := range v1Rply.Attributes.AlteredFields {
fldName = strings.TrimPrefix(fldName, utils.MetaReq+utils.NestingSep)
if v1Rply.Attributes.CGREvent.HasField(fldName) {
attrs[fldName] = utils.NewNMData(v1Rply.Attributes.CGREvent.Event[fldName])
}
if v1Rply.MaxUsage != nil {
cgrReply[utils.CapMaxUsage] = utils.NewNMData(*v1Rply.MaxUsage)
}
if v1Rply.ResourceAllocation != nil {
cgrReply[utils.CapResourceAllocation] = utils.NewNMData(*v1Rply.ResourceAllocation)
}
if v1Rply.Attributes != nil {
attrs := make(utils.NavigableMap2)
for _, fldName := range v1Rply.Attributes.AlteredFields {
fldName = strings.TrimPrefix(fldName, utils.MetaReq+utils.NestingSep)
if v1Rply.Attributes.CGREvent.HasField(fldName) {
attrs[fldName] = utils.NewNMData(v1Rply.Attributes.CGREvent.Event[fldName])
}
cgrReply[utils.CapAttributes] = attrs
}
if v1Rply.Routes != nil {
cgrReply[utils.CapRoutes] = v1Rply.Routes.AsNavigableMap()
cgrReply[utils.CapAttributes] = attrs
}
if v1Rply.Routes != nil {
cgrReply[utils.CapRoutes] = v1Rply.Routes.AsNavigableMap()
}
if v1Rply.ThresholdIDs != nil {
thIDs := make(utils.NMSlice, len(*v1Rply.ThresholdIDs))
for i, v := range *v1Rply.ThresholdIDs {
thIDs[i] = utils.NewNMData(v)
}
if v1Rply.ThresholdIDs != nil {
thIDs := make(utils.NMSlice, len(*v1Rply.ThresholdIDs))
for i, v := range *v1Rply.ThresholdIDs {
thIDs[i] = utils.NewNMData(v)
}
cgrReply[utils.CapThresholds] = &thIDs
}
if v1Rply.StatQueueIDs != nil {
stIDs := make(utils.NMSlice, len(*v1Rply.StatQueueIDs))
for i, v := range *v1Rply.StatQueueIDs {
stIDs[i] = utils.NewNMData(v)
}
cgrReply[utils.CapStatQueues] = &stIDs
cgrReply[utils.CapThresholds] = &thIDs
}
if v1Rply.StatQueueIDs != nil {
stIDs := make(utils.NMSlice, len(*v1Rply.StatQueueIDs))
for i, v := range *v1Rply.StatQueueIDs {
stIDs[i] = utils.NewNMData(v)
}
cgrReply[utils.CapStatQueues] = &stIDs
}
return cgrReply
}
@@ -3004,77 +2996,75 @@ type V1ProcessEventReply struct {
// AsNavigableMap is part of engine.NavigableMapper interface
func (v1Rply *V1ProcessEventReply) AsNavigableMap() utils.NavigableMap2 {
cgrReply := make(utils.NavigableMap2)
if v1Rply != nil {
if v1Rply.MaxUsage != nil {
usage := make(utils.NavigableMap2)
for k, v := range v1Rply.MaxUsage {
usage[k] = utils.NewNMData(v)
}
cgrReply[utils.CapMaxUsage] = usage
if v1Rply.MaxUsage != nil {
usage := make(utils.NavigableMap2)
for k, v := range v1Rply.MaxUsage {
usage[k] = utils.NewNMData(v)
}
if v1Rply.ResourceAllocation != nil {
res := make(utils.NavigableMap2)
for k, v := range v1Rply.ResourceAllocation {
res[k] = utils.NewNMData(v)
}
cgrReply[utils.CapResourceAllocation] = res
cgrReply[utils.CapMaxUsage] = usage
}
if v1Rply.ResourceAllocation != nil {
res := make(utils.NavigableMap2)
for k, v := range v1Rply.ResourceAllocation {
res[k] = utils.NewNMData(v)
}
if v1Rply.Attributes != nil {
atts := make(utils.NavigableMap2)
for k, att := range v1Rply.Attributes {
attrs := make(utils.NavigableMap2)
for _, fldName := range att.AlteredFields {
fldName = strings.TrimPrefix(fldName, utils.MetaReq+utils.NestingSep)
if att.CGREvent.HasField(fldName) {
attrs[fldName] = utils.NewNMData(att.CGREvent.Event[fldName])
}
cgrReply[utils.CapResourceAllocation] = res
}
if v1Rply.Attributes != nil {
atts := make(utils.NavigableMap2)
for k, att := range v1Rply.Attributes {
attrs := make(utils.NavigableMap2)
for _, fldName := range att.AlteredFields {
fldName = strings.TrimPrefix(fldName, utils.MetaReq+utils.NestingSep)
if att.CGREvent.HasField(fldName) {
attrs[fldName] = utils.NewNMData(att.CGREvent.Event[fldName])
}
atts[k] = attrs
}
cgrReply[utils.CapAttributes] = atts
atts[k] = attrs
}
if v1Rply.Routes != nil {
routes := make(utils.NavigableMap2)
for k, route := range v1Rply.Routes {
routes[k] = route.AsNavigableMap()
cgrReply[utils.CapAttributes] = atts
}
if v1Rply.Routes != nil {
routes := make(utils.NavigableMap2)
for k, route := range v1Rply.Routes {
routes[k] = route.AsNavigableMap()
}
cgrReply[utils.CapRoutes] = routes
}
if v1Rply.ThresholdIDs != nil {
th := make(utils.NavigableMap2)
for k, thr := range v1Rply.ThresholdIDs {
thIDs := make(utils.NMSlice, len(thr))
for i, v := range thr {
thIDs[i] = utils.NewNMData(v)
}
cgrReply[utils.CapRoutes] = routes
th[k] = &thIDs
}
if v1Rply.ThresholdIDs != nil {
th := make(utils.NavigableMap2)
for k, thr := range v1Rply.ThresholdIDs {
thIDs := make(utils.NMSlice, len(thr))
for i, v := range thr {
thIDs[i] = utils.NewNMData(v)
}
th[k] = &thIDs
cgrReply[utils.CapThresholds] = th
}
if v1Rply.StatQueueIDs != nil {
st := make(utils.NavigableMap2)
for k, sts := range v1Rply.StatQueueIDs {
stIDs := make(utils.NMSlice, len(sts))
for i, v := range sts {
stIDs[i] = utils.NewNMData(v)
}
cgrReply[utils.CapThresholds] = th
st[k] = &stIDs
}
if v1Rply.StatQueueIDs != nil {
st := make(utils.NavigableMap2)
for k, sts := range v1Rply.StatQueueIDs {
stIDs := make(utils.NMSlice, len(sts))
for i, v := range sts {
stIDs[i] = utils.NewNMData(v)
}
st[k] = &stIDs
}
cgrReply[utils.CapStatQueues] = st
cgrReply[utils.CapStatQueues] = st
}
if v1Rply.Cost != nil {
costs := make(utils.NavigableMap2)
for k, cost := range v1Rply.Cost {
costs[k] = utils.NewNMData(cost)
}
if v1Rply.Cost != nil {
costs := make(utils.NavigableMap2)
for k, cost := range v1Rply.Cost {
costs[k] = utils.NewNMData(cost)
}
}
if v1Rply.STIRIdentity != nil {
stir := make(utils.NavigableMap2)
for k, v := range v1Rply.STIRIdentity {
stir[k] = utils.NewNMData(v)
}
cgrReply[utils.OptsStirIdentity] = stir
}
if v1Rply.STIRIdentity != nil {
stir := make(utils.NavigableMap2)
for k, v := range v1Rply.STIRIdentity {
stir[k] = utils.NewNMData(v)
}
cgrReply[utils.OptsStirIdentity] = stir
}
return cgrReply
}