ChargerS.processEvent to return []*AttrSProcessEventReply

This commit is contained in:
TeoV
2018-07-16 07:59:35 -04:00
committed by Dan Christian Bogos
parent fc3000b30f
commit d829b17745
5 changed files with 27 additions and 28 deletions

View File

@@ -95,6 +95,6 @@ func (cSv1 *ChargerSv1) GetChargersForEvent(cgrEv *utils.CGREvent,
// ProcessEvent
func (cSv1 *ChargerSv1) ProcessEvent(args *utils.CGREvent,
reply *[]*utils.CGREvent) error {
reply *[]*engine.AttrSProcessEventReply) error {
return cSv1.cS.V1ProcessEvent(args, reply)
}

View File

@@ -173,19 +173,23 @@ func testChargerSGetChargersForEvent(t *testing.T) {
}
func testChargerSProcessEvent(t *testing.T) {
processedEv := &[]*utils.CGREvent{
&utils.CGREvent{ // matching Charger1
Tenant: "cgrates.org",
ID: "event1",
Context: utils.StringPointer(utils.MetaChargers),
Event: map[string]interface{}{
utils.Account: "1001",
"Password": "CGRateS.org",
"RunID": "*rated",
processedEv := &[]*engine.AttrSProcessEventReply{
&engine.AttrSProcessEventReply{
MatchedProfile: "ATTR_1001_SIMPLEAUTH",
AlteredFields: []string{"Password"},
CGREvent: &utils.CGREvent{ // matching Charger1
Tenant: "cgrates.org",
ID: "event1",
Context: utils.StringPointer(utils.MetaChargers),
Event: map[string]interface{}{
utils.Account: "1001",
"Password": "CGRateS.org",
"RunID": "*rated",
},
},
},
}
var result *[]*utils.CGREvent
var result *[]*engine.AttrSProcessEventReply
if err := chargerRPC.Call(utils.ChargerSv1ProcessEvent, chargerEvent[1], &result); err == nil ||
err.Error() != utils.ErrNotFound.Error() {
t.Error(err)

View File

@@ -22,7 +22,6 @@ import (
"github.com/cgrates/cgrates/dispatcher"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/sessions"
"github.com/cgrates/cgrates/utils"
)
func NewDispatcherThresholdSv1(dps *dispatcher.DispatcherService) *DispatcherThresholdSv1 {
@@ -219,6 +218,6 @@ func (dC *DispatcherChargerSv1) GetChargersForEvent(args *dispatcher.CGREvWithAp
// ProcessEvent implements ChargerSv1ProcessEvent
func (dC *DispatcherChargerSv1) ProcessEvent(args *dispatcher.CGREvWithApiKey,
reply *[]*utils.CGREvent) (err error) {
reply *[]*engine.AttrSProcessEventReply) (err error) {
return dC.dC.ChargerSv1ProcessEvent(args, reply)
}

View File

@@ -43,7 +43,7 @@ func (dS *DispatcherService) ChargerSv1GetChargersForEvent(args *CGREvWithApiKey
}
func (dS *DispatcherService) ChargerSv1ProcessEvent(args *CGREvWithApiKey,
reply *[]*utils.CGREvent) (err error) {
reply *[]*engine.AttrSProcessEventReply) (err error) {
if dS.chargerS == nil {
return utils.NewErrNotConnected(utils.ChargerS)
}

View File

@@ -96,31 +96,27 @@ func (cS *ChargerService) matchingChargerProfilesForEvent(cgrEv *utils.CGREvent)
return
}
func (cS *ChargerService) processEvent(cgrEv *utils.CGREvent) (cgrEvs []*utils.CGREvent, err error) {
func (cS *ChargerService) processEvent(cgrEv *utils.CGREvent) (rply []*AttrSProcessEventReply, err error) {
var cPs ChargerProfiles
if cPs, err = cS.matchingChargerProfilesForEvent(cgrEv); err != nil {
return nil, err
}
cgrEvs = make([]*utils.CGREvent, len(cPs))
for i, cP := range cPs {
cgrEvs[i] = cgrEv.Clone()
cgrEvs[i].Event[utils.RunID] = cP.RunID
for _, cP := range cPs {
cgrEv.Event[utils.RunID] = cP.RunID
if len(cP.AttributeIDs) != 0 { // Attributes should process the event
if cS.attrS == nil {
return nil, errors.New("no connection to AttributeS")
}
if cgrEvs[i].Context == nil {
cgrEvs[i].Context = utils.StringPointer(utils.MetaChargers)
if cgrEv.Context == nil {
cgrEv.Context = utils.StringPointer(utils.MetaChargers)
}
var rply AttrSProcessEventReply
var evRply AttrSProcessEventReply
if err = cS.attrS.Call(utils.AttributeSv1ProcessEvent,
&AttrArgsProcessEvent{cP.AttributeIDs, *cgrEvs[i]},
&rply); err != nil {
&AttrArgsProcessEvent{cP.AttributeIDs, *cgrEv},
&evRply); err != nil {
return nil, err
}
if len(rply.AlteredFields) != 0 {
cgrEvs[i] = rply.CGREvent // modified event by attributeS
}
rply = append(rply, &evRply)
}
}
return
@@ -128,7 +124,7 @@ func (cS *ChargerService) processEvent(cgrEv *utils.CGREvent) (cgrEvs []*utils.C
// V1ProcessEvent will process the event received via API and return list of events forked
func (cS *ChargerService) V1ProcessEvent(args *utils.CGREvent,
reply *[]*utils.CGREvent) (err error) {
reply *[]*AttrSProcessEventReply) (err error) {
if args.Event == nil {
return utils.NewErrMandatoryIeMissing("Event")
}