RawCDR interface now properly returns duration

This commit is contained in:
DanB
2014-04-27 09:19:30 +02:00
parent 330fb7b894
commit f0095dbcb3
8 changed files with 23 additions and 16 deletions

View File

@@ -104,9 +104,8 @@ func (cgrCdr CgrCdr) GetAnswerTime() (t time.Time, err error) {
}
// Extracts duration as considered by the telecom switch
func (cgrCdr CgrCdr) GetDuration() time.Duration {
dur, _ := ParseDurationWithSecs(cgrCdr[DURATION])
return dur
func (cgrCdr CgrCdr) GetDuration() (time.Duration, error) {
return ParseDurationWithSecs(cgrCdr[DURATION])
}
// Used in mediation, fieldsMandatory marks whether missing field out of request represents error or can be ignored
@@ -126,6 +125,10 @@ func (cgrCdr CgrCdr) AsStoredCdr(runId, reqTypeFld, directionFld, tenantFld, tor
return nil, errors.New(fmt.Sprintf("%s:%s", ERR_MANDATORY_IE_MISSING, ACCID))
}
}
// MetaDefault will automatically be converted to their standard values
//if reqTypeFld == META_DEFAULT {
// reqTypeFld =
//}
if rtCdr.CdrHost, hasKey = cgrCdr[CDRHOST]; !hasKey && fieldsMandatory {
return nil, errors.New(fmt.Sprintf("%s:%s", ERR_MANDATORY_IE_MISSING, CDRHOST))
}

View File

@@ -72,7 +72,8 @@ func TestCgrCdrFields(t *testing.T) {
if answerTime.UTC() != expectedATime {
t.Error("Error parsing cdr: ", cgrCdr)
}
if cgrCdr.GetDuration() != time.Duration(10)*time.Second {
dur, _ := cgrCdr.GetDuration()
if dur != time.Duration(10)*time.Second {
t.Error("Error parsing cdr: ", cgrCdr)
}
extraFields := cgrCdr.GetExtraFields()

View File

@@ -39,7 +39,7 @@ type RawCDR interface {
GetReqType() string
GetSetupTime() (time.Time, error) // Time when the call was set-up
GetAnswerTime() (time.Time, error) // Time when the call was answered
GetDuration() time.Duration
GetDuration() (time.Duration, error)
GetExtraFields() map[string]string //Stores extra CDR Fields
AsStoredCdr(string, string, string, string, string, string, string, string, string, string, string, []string, bool) (*StoredCdr, error) // Based on fields queried will return a particular instance of RatedCDR
}

View File

@@ -45,7 +45,7 @@ func NewStoredCdrFromRawCDR(rawcdr RawCDR) (*StoredCdr, error) {
if rtCdr.AnswerTime, err = rawcdr.GetAnswerTime(); err != nil {
return nil, err
}
rtCdr.Duration = rawcdr.GetDuration()
rtCdr.Duration, _ = rawcdr.GetDuration()
rtCdr.ExtraFields = rawcdr.GetExtraFields()
rtCdr.MediationRunId = DEFAULT_RUNID
rtCdr.Cost = -1
@@ -128,8 +128,8 @@ func (storedCdr *StoredCdr) GetAnswerTime() (time.Time, error) {
return storedCdr.AnswerTime, nil
}
func (storedCdr *StoredCdr) GetDuration() time.Duration {
return storedCdr.Duration
func (storedCdr *StoredCdr) GetDuration() (time.Duration, error) {
return storedCdr.Duration, nil
}
func (storedCdr *StoredCdr) GetExtraFields() map[string]string {

View File

@@ -90,7 +90,8 @@ func TestStoredCdrFields(t *testing.T) {
if answerTime.UTC() != expectedATime {
t.Error("Error parsing cdr: ", ratedCdr)
}
if ratedCdr.GetDuration() != 10 {
dur, _ := ratedCdr.GetDuration()
if dur != 10 {
t.Error("Error parsing cdr: ", ratedCdr)
}
extraFields := ratedCdr.GetExtraFields()