From be4c5dbd785f036b4ccec35199890a208b2bd718 Mon Sep 17 00:00:00 2001 From: TeoV Date: Thu, 8 Nov 2018 05:27:49 -0500 Subject: [PATCH] Fixes #1291 In case of mandatory false and err not found ignore record --- agents/agentreq.go | 7 ++++++- console/attributes_remove.go | 10 ++++++---- data/conf/samples/diamagent/dryrun.json | 2 ++ data/conf/samples/diamsctpagent/dryrun.json | 9 ++++++++- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/agents/agentreq.go b/agents/agentreq.go index f160dce7f..da1d9385f 100644 --- a/agents/agentreq.go +++ b/agents/agentreq.go @@ -112,6 +112,7 @@ func (ar *AgentRequest) AsNavigableMap(tplFlds []*config.FCTemplate) ( nM *config.NavigableMap, err error) { nM = config.NewNavigableMap(nil) for _, tplFld := range tplFlds { + fmt.Println(utils.ToJSON(tplFld)) if pass, err := ar.filterS.Pass(ar.tenant, tplFld.Filters, ar); err != nil { return nil, err @@ -127,6 +128,7 @@ func (ar *AgentRequest) AsNavigableMap(tplFlds []*config.FCTemplate) ( nMItm := &config.NMItem{Data: out, Path: fldPath, Config: tplFld} if nMFields, err := nM.FieldAsInterface(fldPath); err != nil { if err != utils.ErrNotFound { + fmt.Println("Return err for : ", utils.ToJSON(tplFld)) return nil, err } } else { @@ -242,9 +244,12 @@ func (aReq *AgentRequest) ParseField( } out, err = utils.Sum(iFaceVals...) } - if err != nil { + if err != nil && + (!strings.HasPrefix(err.Error(), "Could not find") || + cfgFld.Mandatory) { return } + err = nil if isString { // format the string additionally with fmtFieldWidth out, err = utils.FmtFieldWidth(cfgFld.Tag, out.(string), cfgFld.Width, cfgFld.Strip, cfgFld.Padding, cfgFld.Mandatory) diff --git a/console/attributes_remove.go b/console/attributes_remove.go index 5105bdcd6..c479bd4ed 100644 --- a/console/attributes_remove.go +++ b/console/attributes_remove.go @@ -18,13 +18,15 @@ along with this program. If not, see package console -import "github.com/cgrates/cgrates/utils" +import ( + "github.com/cgrates/cgrates/apier/v1" +) func init() { c := &CmdRemoveAttributes{ name: "attributes_remove", rpcMethod: "ApierV1.RemoveAttributeProfile", - rpcParams: &utils.TenantID{}, + rpcParams: &v1.ArgRemoveAttrProfile{}, } commands[c.Name()] = c c.CommandExecuter = &CommandExecuter{c} @@ -33,7 +35,7 @@ func init() { type CmdRemoveAttributes struct { name string rpcMethod string - rpcParams *utils.TenantID + rpcParams *v1.ArgRemoveAttrProfile *CommandExecuter } @@ -47,7 +49,7 @@ func (self *CmdRemoveAttributes) RpcMethod() string { func (self *CmdRemoveAttributes) RpcParams(reset bool) interface{} { if reset || self.rpcParams == nil { - self.rpcParams = &utils.TenantID{} + self.rpcParams = &v1.ArgRemoveAttrProfile{} } return self.rpcParams } diff --git a/data/conf/samples/diamagent/dryrun.json b/data/conf/samples/diamagent/dryrun.json index 72eda2cec..1cbc8d995 100644 --- a/data/conf/samples/diamagent/dryrun.json +++ b/data/conf/samples/diamagent/dryrun.json @@ -12,6 +12,8 @@ {"tag": "Val1", "field_id": "Val1", "type": "*constant", "value": "1"}, {"tag": "Val2", "field_id": "Val2", "type": "*constant", "value": "2"}, {"tag": "Val3", "field_id": "Val3", "type": "*constant", "value": "3"}, + {"tag": "OptionalField", "field_id":"OptionalField", "type":"*composed", + "value":"~*req.Inexistent", "manadatory":false}, {"tag": "OriginID", "field_id": "OriginID", "type": "*composed", "value": "~*req.Session-Id", "mandatory": true}, {"tag": "RequestType", "field_id": "RequestType", "type": "*constant", "value": "*prepaid"}, diff --git a/data/conf/samples/diamsctpagent/dryrun.json b/data/conf/samples/diamsctpagent/dryrun.json index ae8359235..1cbc8d995 100755 --- a/data/conf/samples/diamsctpagent/dryrun.json +++ b/data/conf/samples/diamsctpagent/dryrun.json @@ -9,6 +9,11 @@ "flags": ["*dryrun"], "request_fields":[ {"tag": "TOR", "field_id": "ToR", "type": "*constant", "value": "*sms"}, + {"tag": "Val1", "field_id": "Val1", "type": "*constant", "value": "1"}, + {"tag": "Val2", "field_id": "Val2", "type": "*constant", "value": "2"}, + {"tag": "Val3", "field_id": "Val3", "type": "*constant", "value": "3"}, + {"tag": "OptionalField", "field_id":"OptionalField", "type":"*composed", + "value":"~*req.Inexistent", "manadatory":false}, {"tag": "OriginID", "field_id": "OriginID", "type": "*composed", "value": "~*req.Session-Id", "mandatory": true}, {"tag": "RequestType", "field_id": "RequestType", "type": "*constant", "value": "*prepaid"}, @@ -20,7 +25,9 @@ {"tag": "RatingGroup", "field_id": "Multiple-Services-Credit-Control.Rating-Group", "type": "*constant", "value": "65000","new_branch": true}, {"tag": "RatingGroup", "field_id": "Multiple-Services-Credit-Control.Rating-Group", - "type": "*constant", "value": "100","new_branch": true}, + "type": "*constant", "value": "100","new_branch": true}, + {"tag": "GrantedUsage", "field_id": "Granted-Service-Unit.CC-Time", "type": "*sum", + "value": "~*cgreq.Val1;~*cgreq.Val2;~*cgreq.Val3"}, ], }, ],