Fixes #1291 In case of mandatory false and err not found ignore record

This commit is contained in:
TeoV
2018-11-08 05:27:49 -05:00
committed by Dan Christian Bogos
parent 8d13b924cd
commit be4c5dbd78
4 changed files with 22 additions and 6 deletions

View File

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

View File

@@ -18,13 +18,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
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
}

View File

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

View File

@@ -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"},
],
},
],