mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-22 07:38:45 +05:00
Updated RPCCDRsFilter
This commit is contained in:
@@ -737,50 +737,47 @@ type CDRsFilter struct {
|
||||
// RPCCDRsFilter is a filter used in Rpc calls
|
||||
// RPCCDRsFilter is slightly different than CDRsFilter by using string instead of Time filters
|
||||
type RPCCDRsFilter struct {
|
||||
CGRIDs []string // If provided, it will filter based on the cgrids present in list
|
||||
NotCGRIDs []string // Filter specific CgrIds out
|
||||
RunIDs []string // If provided, it will filter on mediation runid
|
||||
NotRunIDs []string // Filter specific runIds out
|
||||
OriginIDs []string // If provided, it will filter on OriginIDs
|
||||
NotOriginIDs []string // Filter specific OriginIDs out
|
||||
OriginHosts []string // If provided, it will filter cdrhost
|
||||
NotOriginHosts []string // Filter out specific cdr hosts
|
||||
Sources []string // If provided, it will filter cdrsource
|
||||
NotSources []string // Filter out specific CDR sources
|
||||
ToRs []string // If provided, filter on TypeOfRecord
|
||||
NotToRs []string // Filter specific TORs out
|
||||
RequestTypes []string // If provided, it will fiter reqtype
|
||||
NotRequestTypes []string // Filter out specific request types
|
||||
Tenants []string // If provided, it will filter tenant
|
||||
NotTenants []string // If provided, it will filter tenant
|
||||
Categories []string // If provided, it will filter çategory
|
||||
NotCategories []string // Filter out specific categories
|
||||
Accounts []string // If provided, it will filter account
|
||||
NotAccounts []string // Filter out specific Accounts
|
||||
Subjects []string // If provided, it will filter the rating subject
|
||||
NotSubjects []string // Filter out specific subjects
|
||||
DestinationPrefixes []string // If provided, it will filter on destination prefix
|
||||
NotDestinationPrefixes []string // Filter out specific destination prefixes
|
||||
Costs []float64 // Query based on costs specified
|
||||
NotCosts []float64 // Filter out specific costs out from result
|
||||
ExtraFields map[string]string // Query based on extra fields content
|
||||
NotExtraFields map[string]string // Filter out based on extra fields content
|
||||
OrderIDStart *int64 // Export from this order identifier
|
||||
OrderIDEnd *int64 // Export smaller than this order identifier
|
||||
SetupTimeStart string // Start of interval, bigger or equal than configured
|
||||
SetupTimeEnd string // End interval, smaller than setupTime
|
||||
AnswerTimeStart string // Start of interval, bigger or equal than configured
|
||||
AnswerTimeEnd string // End interval, smaller than answerTime
|
||||
CreatedAtStart string // Start of interval, bigger or equal than configured
|
||||
CreatedAtEnd string // End interval, smaller than
|
||||
UpdatedAtStart string // Start of interval, bigger or equal than configured
|
||||
UpdatedAtEnd string // End interval, smaller than
|
||||
MinUsage string // Start of the usage interval (>=)
|
||||
MaxUsage string // End of the usage interval (<)
|
||||
MinCost *float64 // Start of the cost interval (>=)
|
||||
MaxCost *float64 // End of the usage interval (<)
|
||||
OrderBy string // Ascendent/Descendent
|
||||
Paginator // Add pagination
|
||||
CGRIDs []string // If provided, it will filter based on the cgrids present in list
|
||||
NotCGRIDs []string // Filter specific CgrIds out
|
||||
RunIDs []string // If provided, it will filter on mediation runid
|
||||
NotRunIDs []string // Filter specific runIds out
|
||||
OriginIDs []string // If provided, it will filter on OriginIDs
|
||||
NotOriginIDs []string // Filter specific OriginIDs out
|
||||
OriginHosts []string // If provided, it will filter cdrhost
|
||||
NotOriginHosts []string // Filter out specific cdr hosts
|
||||
Sources []string // If provided, it will filter cdrsource
|
||||
NotSources []string // Filter out specific CDR sources
|
||||
ToRs []string // If provided, filter on TypeOfRecord
|
||||
NotToRs []string // Filter specific TORs out
|
||||
RequestTypes []string // If provided, it will fiter reqtype
|
||||
NotRequestTypes []string // Filter out specific request types
|
||||
Tenants []string // If provided, it will filter tenant
|
||||
NotTenants []string // If provided, it will filter tenant
|
||||
Categories []string // If provided, it will filter çategory
|
||||
NotCategories []string // Filter out specific categories
|
||||
Accounts []string // If provided, it will filter account
|
||||
NotAccounts []string // Filter out specific Accounts
|
||||
Subjects []string // If provided, it will filter the rating subject
|
||||
NotSubjects []string // Filter out specific subjects
|
||||
DestinationPrefixes []string // If provided, it will filter on destination prefix
|
||||
NotDestinationPrefixes []string // Filter out specific destination prefixes
|
||||
Costs []float64 // Query based on costs specified
|
||||
NotCosts []float64 // Filter out specific costs out from result
|
||||
ExtraFields map[string]string // Query based on extra fields content
|
||||
NotExtraFields map[string]string // Filter out based on extra fields content
|
||||
SetupTimeStart string // Start of interval, bigger or equal than configured
|
||||
SetupTimeEnd string // End interval, smaller than setupTime
|
||||
AnswerTimeStart string // Start of interval, bigger or equal than configured
|
||||
AnswerTimeEnd string // End interval, smaller than answerTime
|
||||
CreatedAtStart string // Start of interval, bigger or equal than configured
|
||||
CreatedAtEnd string // End interval, smaller than
|
||||
UpdatedAtStart string // Start of interval, bigger or equal than configured
|
||||
UpdatedAtEnd string // End interval, smaller than
|
||||
MinUsage string // Start of the usage interval (>=)
|
||||
MaxUsage string // End of the usage interval (<)
|
||||
OrderBy string // Ascendent/Descendent
|
||||
ExtraArgs map[string]interface{} // it will contain optional arguments like: OrderIDStart,OrderIDEnd,MinCost and MaxCost
|
||||
Paginator // Add pagination
|
||||
}
|
||||
|
||||
func (fltr *RPCCDRsFilter) AsCDRsFilter(timezone string) (cdrFltr *CDRsFilter, err error) {
|
||||
@@ -817,70 +814,94 @@ func (fltr *RPCCDRsFilter) AsCDRsFilter(timezone string) (cdrFltr *CDRsFilter, e
|
||||
NotCosts: fltr.NotCosts,
|
||||
ExtraFields: fltr.ExtraFields,
|
||||
NotExtraFields: fltr.NotExtraFields,
|
||||
OrderIDStart: fltr.OrderIDStart,
|
||||
OrderIDEnd: fltr.OrderIDEnd,
|
||||
MinUsage: fltr.MinUsage,
|
||||
MaxUsage: fltr.MaxUsage,
|
||||
MinCost: fltr.MinCost,
|
||||
MaxCost: fltr.MaxCost,
|
||||
Paginator: fltr.Paginator,
|
||||
OrderBy: fltr.OrderBy,
|
||||
}
|
||||
if len(fltr.SetupTimeStart) != 0 {
|
||||
if sTimeStart, err := ParseTimeDetectLayout(fltr.SetupTimeStart, timezone); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
cdrFltr.SetupTimeStart = &sTimeStart
|
||||
var sTimeStart time.Time
|
||||
if sTimeStart, err = ParseTimeDetectLayout(fltr.SetupTimeStart, timezone); err != nil {
|
||||
return
|
||||
}
|
||||
cdrFltr.SetupTimeStart = TimePointer(sTimeStart)
|
||||
}
|
||||
if len(fltr.SetupTimeEnd) != 0 {
|
||||
if sTimeEnd, err := ParseTimeDetectLayout(fltr.SetupTimeEnd, timezone); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
cdrFltr.SetupTimeEnd = &sTimeEnd
|
||||
var sTimeEnd time.Time
|
||||
if sTimeEnd, err = ParseTimeDetectLayout(fltr.SetupTimeEnd, timezone); err != nil {
|
||||
return
|
||||
}
|
||||
cdrFltr.SetupTimeEnd = TimePointer(sTimeEnd)
|
||||
}
|
||||
if len(fltr.AnswerTimeStart) != 0 {
|
||||
if aTimeStart, err := ParseTimeDetectLayout(fltr.AnswerTimeStart, timezone); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
cdrFltr.AnswerTimeStart = &aTimeStart
|
||||
var aTimeStart time.Time
|
||||
if aTimeStart, err = ParseTimeDetectLayout(fltr.AnswerTimeStart, timezone); err != nil {
|
||||
return
|
||||
}
|
||||
cdrFltr.AnswerTimeStart = TimePointer(aTimeStart)
|
||||
}
|
||||
if len(fltr.AnswerTimeEnd) != 0 {
|
||||
if aTimeEnd, err := ParseTimeDetectLayout(fltr.AnswerTimeEnd, timezone); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
cdrFltr.AnswerTimeEnd = &aTimeEnd
|
||||
var aTimeEnd time.Time
|
||||
if aTimeEnd, err = ParseTimeDetectLayout(fltr.AnswerTimeEnd, timezone); err != nil {
|
||||
return
|
||||
}
|
||||
cdrFltr.AnswerTimeEnd = TimePointer(aTimeEnd)
|
||||
}
|
||||
if len(fltr.CreatedAtStart) != 0 {
|
||||
if tStart, err := ParseTimeDetectLayout(fltr.CreatedAtStart, timezone); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
cdrFltr.CreatedAtStart = &tStart
|
||||
var tStart time.Time
|
||||
if tStart, err = ParseTimeDetectLayout(fltr.CreatedAtStart, timezone); err != nil {
|
||||
return
|
||||
}
|
||||
cdrFltr.CreatedAtStart = TimePointer(tStart)
|
||||
}
|
||||
if len(fltr.CreatedAtEnd) != 0 {
|
||||
if tEnd, err := ParseTimeDetectLayout(fltr.CreatedAtEnd, timezone); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
cdrFltr.CreatedAtEnd = &tEnd
|
||||
var tEnd time.Time
|
||||
if tEnd, err = ParseTimeDetectLayout(fltr.CreatedAtEnd, timezone); err != nil {
|
||||
return
|
||||
}
|
||||
cdrFltr.CreatedAtEnd = TimePointer(tEnd)
|
||||
}
|
||||
if len(fltr.UpdatedAtStart) != 0 {
|
||||
if tStart, err := ParseTimeDetectLayout(fltr.UpdatedAtStart, timezone); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
cdrFltr.UpdatedAtStart = &tStart
|
||||
var tStart time.Time
|
||||
if tStart, err = ParseTimeDetectLayout(fltr.UpdatedAtStart, timezone); err != nil {
|
||||
return
|
||||
}
|
||||
cdrFltr.UpdatedAtStart = TimePointer(tStart)
|
||||
}
|
||||
if len(fltr.UpdatedAtEnd) != 0 {
|
||||
if tEnd, err := ParseTimeDetectLayout(fltr.UpdatedAtEnd, timezone); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
cdrFltr.UpdatedAtEnd = &tEnd
|
||||
var tEnd time.Time
|
||||
if tEnd, err = ParseTimeDetectLayout(fltr.UpdatedAtEnd, timezone); err != nil {
|
||||
return
|
||||
}
|
||||
cdrFltr.UpdatedAtEnd = TimePointer(tEnd)
|
||||
}
|
||||
if oIDstart, has := fltr.ExtraArgs[OrderIDStart]; has {
|
||||
var oID int64
|
||||
if oID, err = IfaceAsTInt64(oIDstart); err != nil {
|
||||
return
|
||||
}
|
||||
cdrFltr.OrderIDStart = Int64Pointer(oID)
|
||||
}
|
||||
if oIDend, has := fltr.ExtraArgs[OrderIDEnd]; has {
|
||||
var oID int64
|
||||
if oID, err = IfaceAsTInt64(oIDend); err != nil {
|
||||
return
|
||||
}
|
||||
cdrFltr.OrderIDEnd = Int64Pointer(oID)
|
||||
}
|
||||
if mcost, has := fltr.ExtraArgs[MinCost]; has {
|
||||
var mc float64
|
||||
if mc, err = IfaceAsFloat64(mcost); err != nil {
|
||||
return
|
||||
}
|
||||
cdrFltr.MinCost = Float64Pointer(mc)
|
||||
}
|
||||
if mcost, has := fltr.ExtraArgs[MaxCost]; has {
|
||||
var mc float64
|
||||
if mc, err = IfaceAsFloat64(mcost); err != nil {
|
||||
return
|
||||
}
|
||||
cdrFltr.MaxCost = Float64Pointer(mc)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -597,8 +597,6 @@ func TestRPCCDRsFilterAsCDRsFilter(t *testing.T) {
|
||||
NotCosts: []float64{0.3, 0.4},
|
||||
ExtraFields: map[string]string{},
|
||||
NotExtraFields: map[string]string{},
|
||||
OrderIDStart: Int64Pointer(0),
|
||||
OrderIDEnd: Int64Pointer(0),
|
||||
SetupTimeStart: "2020-04-18T11:46:26.371Z",
|
||||
SetupTimeEnd: "2020-04-18T11:46:26.371Z",
|
||||
AnswerTimeStart: "2020-04-18T11:46:26.371Z",
|
||||
@@ -609,9 +607,13 @@ func TestRPCCDRsFilterAsCDRsFilter(t *testing.T) {
|
||||
UpdatedAtEnd: "2020-04-18T11:46:26.371Z",
|
||||
MinUsage: "MinUsage",
|
||||
MaxUsage: "MaxUsage",
|
||||
MinCost: Float64Pointer(0.),
|
||||
MaxCost: Float64Pointer(0.),
|
||||
OrderBy: "OrderBy",
|
||||
ExtraArgs: map[string]interface{}{
|
||||
OrderIDStart: 0,
|
||||
OrderIDEnd: 0,
|
||||
MinCost: 0.,
|
||||
MaxCost: 0.,
|
||||
},
|
||||
}
|
||||
eOut := &CDRsFilter{
|
||||
CGRIDs: rpcCDRsFilter.CGRIDs,
|
||||
@@ -642,12 +644,12 @@ func TestRPCCDRsFilterAsCDRsFilter(t *testing.T) {
|
||||
NotCosts: rpcCDRsFilter.NotCosts,
|
||||
ExtraFields: rpcCDRsFilter.ExtraFields,
|
||||
NotExtraFields: rpcCDRsFilter.NotExtraFields,
|
||||
OrderIDStart: rpcCDRsFilter.OrderIDStart,
|
||||
OrderIDEnd: rpcCDRsFilter.OrderIDEnd,
|
||||
OrderIDStart: Int64Pointer(0),
|
||||
OrderIDEnd: Int64Pointer(0),
|
||||
MinUsage: rpcCDRsFilter.MinUsage,
|
||||
MaxUsage: rpcCDRsFilter.MaxUsage,
|
||||
MinCost: rpcCDRsFilter.MinCost,
|
||||
MaxCost: rpcCDRsFilter.MaxCost,
|
||||
MinCost: Float64Pointer(0.),
|
||||
MaxCost: Float64Pointer(0.),
|
||||
Paginator: rpcCDRsFilter.Paginator,
|
||||
OrderBy: rpcCDRsFilter.OrderBy,
|
||||
}
|
||||
@@ -662,53 +664,61 @@ func TestRPCCDRsFilterAsCDRsFilter(t *testing.T) {
|
||||
eOut.SetupTimeEnd = &tTime
|
||||
eOut.SetupTimeStart = &tTime
|
||||
|
||||
rcv, err = rpcCDRsFilter.AsCDRsFilter("")
|
||||
if err != nil {
|
||||
if rcv, err = rpcCDRsFilter.AsCDRsFilter(""); err != nil {
|
||||
t.Errorf("ParseTimeDetectLayout error")
|
||||
}
|
||||
if !reflect.DeepEqual(eOut, rcv) {
|
||||
} else if !reflect.DeepEqual(eOut, rcv) {
|
||||
t.Errorf("Expected: %s ,received: %s ", ToJSON(eOut), ToJSON(rcv))
|
||||
}
|
||||
|
||||
rpcCDRsFilter.ExtraArgs[MaxCost] = "notFloat64"
|
||||
if rcv, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
|
||||
t.Errorf("MaxCost should not be processed")
|
||||
}
|
||||
|
||||
rpcCDRsFilter.ExtraArgs[MinCost] = "notFloat64"
|
||||
if rcv, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
|
||||
t.Errorf("MinCost should not be processed")
|
||||
}
|
||||
rpcCDRsFilter.ExtraArgs[OrderIDEnd] = "notInt64"
|
||||
if rcv, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
|
||||
t.Errorf("OrderIDEnd should not be processed")
|
||||
}
|
||||
rpcCDRsFilter.ExtraArgs[OrderIDStart] = "notInt64"
|
||||
if rcv, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
|
||||
t.Errorf("OrderIDStart should not be processed")
|
||||
}
|
||||
|
||||
rpcCDRsFilter.UpdatedAtEnd = "wrongUpdatedAtEnd"
|
||||
rcv, err = rpcCDRsFilter.AsCDRsFilter("")
|
||||
if err == nil {
|
||||
t.Errorf("Wrong UpdatedAtEnd not processed")
|
||||
if rcv, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
|
||||
t.Errorf("UpdatedAtEnd should not be processed")
|
||||
}
|
||||
rpcCDRsFilter.UpdatedAtStart = "wrongUpdatedAtStart"
|
||||
rcv, err = rpcCDRsFilter.AsCDRsFilter("")
|
||||
if err == nil {
|
||||
t.Errorf("Wrong UpdatedAtStart not processed")
|
||||
if rcv, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
|
||||
t.Errorf("UpdatedAtStart should not be processed")
|
||||
}
|
||||
rpcCDRsFilter.CreatedAtEnd = "wrongCreatedAtEnd"
|
||||
rcv, err = rpcCDRsFilter.AsCDRsFilter("")
|
||||
if err == nil {
|
||||
t.Errorf("Wrong CreatedAtEnd not processed")
|
||||
if rcv, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
|
||||
t.Errorf("CreatedAtEnd should not be processed")
|
||||
}
|
||||
rpcCDRsFilter.CreatedAtStart = "wrongCreatedAtStart"
|
||||
rcv, err = rpcCDRsFilter.AsCDRsFilter("")
|
||||
if err == nil {
|
||||
t.Errorf("Wrong CreatedAtStart not processed")
|
||||
if rcv, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
|
||||
t.Errorf("CreatedAtStart should not be processed")
|
||||
}
|
||||
rpcCDRsFilter.AnswerTimeEnd = "wrongAnswerTimeEnd"
|
||||
rcv, err = rpcCDRsFilter.AsCDRsFilter("")
|
||||
if err == nil {
|
||||
t.Errorf("Wrong AnswerTimeEnd not processed")
|
||||
if rcv, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
|
||||
t.Errorf("AnswerTimeEnd should not be processed")
|
||||
}
|
||||
rpcCDRsFilter.AnswerTimeStart = "wrongAnswerTimeStart"
|
||||
rcv, err = rpcCDRsFilter.AsCDRsFilter("")
|
||||
if err == nil {
|
||||
t.Errorf("Wrong AnswerTimeStart not processed")
|
||||
if rcv, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
|
||||
t.Errorf("AnswerTimeStart should not be processed")
|
||||
}
|
||||
rpcCDRsFilter.SetupTimeEnd = "wrongSetupTimeEnd"
|
||||
rcv, err = rpcCDRsFilter.AsCDRsFilter("")
|
||||
if err == nil {
|
||||
t.Errorf("Wrong SetupTimeEnd not processed")
|
||||
if rcv, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
|
||||
t.Errorf("SetupTimeEnd should not be processed")
|
||||
}
|
||||
rpcCDRsFilter.SetupTimeStart = "wrongSetupTimeStart"
|
||||
rcv, err = rpcCDRsFilter.AsCDRsFilter("")
|
||||
if err == nil {
|
||||
t.Errorf("Wrong SetupTimeStart not processed")
|
||||
if rcv, err = rpcCDRsFilter.AsCDRsFilter(""); err == nil {
|
||||
t.Errorf("SetupTimeStart should not be processed")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -591,6 +591,10 @@ const (
|
||||
ActivationDate = "ActivationDate"
|
||||
ExpirationDate = "ExpirationDate"
|
||||
MinQueuedItems = "MinQueuedItems"
|
||||
OrderIDStart = "OrderIDStart"
|
||||
OrderIDEnd = "OrderIDEnd"
|
||||
MinCost = "MinCost"
|
||||
MaxCost = "MaxCost"
|
||||
)
|
||||
|
||||
// Migrator Action
|
||||
|
||||
Reference in New Issue
Block a user