mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-22 23:58:44 +05:00
Better AttributeS and SupplierS digests as string
This commit is contained in:
@@ -114,12 +114,31 @@ func (alS *AttributeService) attributeProfileForEvent(ev *utils.CGREvent) (attrP
|
||||
return attrPrfls[0], nil
|
||||
}
|
||||
|
||||
// AttrSFldNameValue is a helper struct for AttrSDigest deserialization
|
||||
type AttrSFieldNameValue struct {
|
||||
FieldName string
|
||||
FieldValue string
|
||||
}
|
||||
|
||||
type AttrSProcessEventReply struct {
|
||||
MatchedProfile string
|
||||
AlteredFields []string
|
||||
CGREvent *utils.CGREvent
|
||||
}
|
||||
|
||||
// Digest returns serialized version of alteredFields in AttrSProcessEventReply
|
||||
// format fldName1:fldVal1,fldName2:fldVal2
|
||||
func (attrReply *AttrSProcessEventReply) Digest() (rplyDigest string) {
|
||||
for i, fld := range attrReply.AlteredFields {
|
||||
if i != 0 {
|
||||
rplyDigest += utils.FIELDS_SEP
|
||||
}
|
||||
fldStrVal, _ := attrReply.CGREvent.FieldAsString(fld)
|
||||
rplyDigest += fld + utils.InInFieldSep + fldStrVal
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// processEvent will match event with attribute profile and do the necessary replacements
|
||||
func (alS *AttributeService) processEvent(ev *utils.CGREvent) (rply *AttrSProcessEventReply, err error) {
|
||||
attrPrf, err := alS.attributeProfileForEvent(ev)
|
||||
|
||||
@@ -21,7 +21,7 @@ package engine
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
// "time"
|
||||
"strings"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
@@ -29,8 +29,8 @@ import (
|
||||
// SupplierReply represents one supplier in
|
||||
type SortedSupplier struct {
|
||||
SupplierID string
|
||||
SortingData map[string]interface{} // store here extra info like cost or stats
|
||||
SupplierParameters string
|
||||
SortingData map[string]interface{} // store here extra info like cost or stats
|
||||
}
|
||||
|
||||
// SuppliersReply is returned as part of GetSuppliers call
|
||||
@@ -49,6 +49,18 @@ func (sSpls *SortedSuppliers) SupplierIDs() (sIDs []string) {
|
||||
return
|
||||
}
|
||||
|
||||
// SupplierIDs returns list of suppliers
|
||||
func (sSpls *SortedSuppliers) SuppliersWithParams() (sPs []string) {
|
||||
sPs = make([]string, len(sSpls.SortedSuppliers))
|
||||
for i, spl := range sSpls.SortedSuppliers {
|
||||
sPs[i] = spl.SupplierID
|
||||
if spl.SupplierParameters != "" {
|
||||
sPs[i] += utils.InInFieldSep + spl.SupplierParameters
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// SortWeight is part of sort interface, sort based on Weight
|
||||
func (sSpls *SortedSuppliers) SortWeight() {
|
||||
sort.Slice(sSpls.SortedSuppliers, func(i, j int) bool {
|
||||
@@ -68,16 +80,14 @@ func (sSpls *SortedSuppliers) SortCost() {
|
||||
}
|
||||
|
||||
// Digest returns list of supplierIDs + parameters for easier outside access
|
||||
func (sSpls *SortedSuppliers) SuppliersDigest() (sDigest []string) {
|
||||
sDigest = make([]string, len(sSpls.SortedSuppliers))
|
||||
for i, sSpl := range sSpls.SortedSuppliers {
|
||||
sDigest[i] = sSpl.SupplierID
|
||||
if sSpl.SupplierParameters != "" {
|
||||
sDigest[i] += utils.InInFieldSep + sSpl.SupplierParameters
|
||||
}
|
||||
// format suppl1:suppl1params,suppl2:suppl2params
|
||||
func (sSpls *SortedSuppliers) Digest() string {
|
||||
return strings.Join(sSpls.SuppliersWithParams(), utils.FIELDS_SEP)
|
||||
}
|
||||
|
||||
}
|
||||
return
|
||||
type SupplierWithParams struct {
|
||||
SupplierName string
|
||||
SupplierParams string
|
||||
}
|
||||
|
||||
// SuppliersSorter is the interface which needs to be implemented by supplier sorters
|
||||
|
||||
Reference in New Issue
Block a user