View Javadoc

1   /*
2    *  Copyright 2004-2006 Stefan Reuter
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   *
16   */
17  package org.asteriskjava.manager.event;
18  
19  import java.util.Date;
20  import java.util.TimeZone;
21  
22  import org.asteriskjava.util.DateUtil;
23  
24  /***
25   * A CdrEvent is triggered when a call detail record is generated, usually at the end of a call.<p>
26   * To enable CdrEvents you have to add <code>enabled = yes</code> to the general section in
27   * <code>cdr_manager.conf</code>.<p>
28   * This event is implemented in <code>cdr/cdr_manager.c</code>
29   * 
30   * @author srt
31   * @version $Id: CdrEvent.java 488 2006-07-15 11:46:52Z srt $
32   */
33  public class CdrEvent extends ManagerEvent
34  {
35      /***
36       * Serializable version identifier
37       */
38      private static final long serialVersionUID = 2541424315212201670L;
39      
40      public static final String DISPOSITION_NO_ANSWER = "NO ANSWER";
41      public static final String DISPOSITION_FAILED = "FAILED";
42      public static final String DISPOSITION_BUSY = "BUSY";
43      public static final String DISPOSITION_ANSWERED = "ANSWERED";
44      public static final String DISPOSITION_UNKNOWN = "UNKNOWN";
45      
46      public static final String AMA_FLAG_OMIT = "OMIT";
47      public static final String AMA_FLAG_BILLING = "BILLING";
48      public static final String AMA_FLAG_DOCUMENTATION = "DOCUMENTATION";
49      public static final String AMA_FLAG_UNKNOWN = "Unknown";
50      
51      private String accountCode;
52      private String src;
53      private String destination;
54      private String destinationContext;
55      private String callerId;
56      private String channel;
57      private String destinationChannel;
58      private String lastApplication;
59      private String lastData;
60      private String startTime;
61      private String answerTime;
62      private String endTime;
63      private Integer duration;
64      private Integer billableSeconds;
65      private String disposition;
66      private String amaFlags;
67      private String uniqueId;
68      private String userField;
69  
70      /***
71       * @param source
72       */
73      public CdrEvent(Object source)
74      {
75          super(source);
76      }
77  
78      /***
79       * Returns the account number that is usually used to identify the party to bill for the call.<p>
80       * Corresponds to CDR field <code>accountcode</code>.
81       * 
82       * @return the account number.
83       */
84      public String getAccountCode()
85      {
86          return accountCode;
87      }
88  
89      /***
90       * Sets the account number.
91       * 
92       * @param accountCode the account number.
93       */
94      public void setAccountCode(String accountCode)
95      {
96          this.accountCode = accountCode;
97      }
98  
99      /***
100      * Returns the Caller*ID number.<p>
101      * Corresponds to CDR field <code>src</code>.
102      * 
103      * @return the Caller*ID number.
104      */
105     public String getSrc()
106     {
107         return src;
108     }
109 
110     /***
111      * Sets the Caller*ID number.
112      * 
113      * @param source the Caller*ID number.
114      */
115     public void setSrc(String source)
116     {
117         this.src = source;
118     }
119 
120     /***
121      * Returns the destination extension.<p>
122      * Corresponds to CDR field <code>dst</code>.
123      * 
124      * @return the destination extension.
125      */
126     public String getDestination()
127     {
128         return destination;
129     }
130 
131     /***
132      * Sets the destination extension.
133      * 
134      * @param destination the destination extension.
135      */
136     public void setDestination(String destination)
137     {
138         this.destination = destination;
139     }
140 
141     /***
142      * Returns the destination context.<p>
143      * Corresponds to CDR field <code>dcontext</code>.
144      * 
145      * @return the destination context.
146      */
147     public String getDestinationContext()
148     {
149         return destinationContext;
150     }
151 
152     /***
153      * Sets the destination context.
154      * 
155      * @param destinationContext the destination context.
156      */
157     public void setDestinationContext(String destinationContext)
158     {
159         this.destinationContext = destinationContext;
160     }
161 
162     /***
163      * Returns the Caller*ID with text.<p>
164      * Corresponds to CDR field <code>clid</code>.
165      * 
166      * @return the Caller*ID with text
167      */
168     public String getCallerId()
169     {
170         return callerId;
171     }
172 
173     /***
174      * Sets the Caller*ID with text.
175      * 
176      * @param callerId the Caller*ID with text.
177      */
178     public void setCallerId(String callerId)
179     {
180         this.callerId = callerId;
181     }
182 
183     /***
184      * Returns the name of the channel, for example "SIP/1310-asfe".<p>
185      * Corresponds to CDR field <code>channel</code>.
186      * 
187      * @return the name of the channel.
188      */
189     public String getChannel()
190     {
191         return channel;
192     }
193 
194     /***
195      * Sets the name of the channel.
196      * 
197      * @param channel the name of the channel.
198      */
199     public void setChannel(String channel)
200     {
201         this.channel = channel;
202     }
203 
204     /***
205      * Returns the name of the destination channel if appropriate.<p>
206      * Corresponds to CDR field <code>dstchannel</code>.
207      * 
208      * @return the name of the destination channel or <code>null</code> if not available.
209      */
210     public String getDestinationChannel()
211     {
212         return destinationChannel;
213     }
214 
215     /***
216      * Sets the name of the destination channel.
217      * 
218      * @param destinationChannel the name of the destination channel.
219      */
220     public void setDestinationChannel(String destinationChannel)
221     {
222         this.destinationChannel = destinationChannel;
223     }
224 
225     /***
226      * Returns the last application if appropriate, for example "VoiceMail".<p>
227      * Corresponds to CDR field <code>lastapp</code>.
228      * 
229      * @return the last application or <code>null</code> if not avaialble.
230      */
231     public String getLastApplication()
232     {
233         return lastApplication;
234     }
235 
236     /***
237      * Sets the last application.
238      * 
239      * @param lastApplication the last application.
240      */
241     public void setLastApplication(String lastApplication)
242     {
243         this.lastApplication = lastApplication;
244     }
245 
246     /***
247      * Returns the last application's data (arguments), for example "s1234".<p>
248      * Corresponds to CDR field <code>lastdata</code>.
249      * 
250      * @return the last application's data or <code>null</code> if not avaialble.
251      */
252     public String getLastData()
253     {
254         return lastData;
255     }
256 
257     /***
258      * Set the last application's data.
259      * 
260      * @param lastData the last application's data.
261      */
262     public void setLastData(String lastData)
263     {
264         this.lastData = lastData;
265     }
266 
267     /***
268      * Returns when the call has started.<p>
269      * This corresponds to CDR field <code>start</code>.
270      * 
271      * @return A string of the format "%Y-%m-%d %T" (strftime(3)) representing the date/time the
272      * call has started, for example "2006-05-19 11:54:48".
273      */
274     public String getStartTime()
275     {
276         return startTime;
277     }
278     
279     /***
280      * Returns the start time as Date object.<p>
281      * This method asumes that the Asterisk server's timezone equals the default 
282      * timezone of your JVM.
283      * 
284      * @return the start time as Date object.
285      * @since 0.3
286      */
287     public Date getStartTimeAsDate()
288     {
289         return DateUtil.parseDateTime(startTime);
290     }
291     
292     /***
293      * Returns the start time as Date object.
294      * 
295      * @param tz the timezone of the Asterisk server.
296      * @return the start time as Date object.
297      * @since 0.3
298      */
299     public Date getStartTimeAsDate(TimeZone tz)
300     {
301         return DateUtil.parseDateTime(startTime, tz);
302     }
303 
304     /***
305      * Sets the date/time when the call has started.
306      * 
307      * @param startTime the date/time when the call has started.
308      */
309     public void setStartTime(String startTime)
310     {
311         this.startTime = startTime;
312     }
313 
314     /***
315      * Returns when the call was answered.<p>
316      * This corresponds to CDR field <code>answered</code>.
317      * 
318      * @return A string of the format "%Y-%m-%d %T" (strftime(3)) representing the date/time the
319      * call was answered, for example "2006-05-19 11:55:01"
320      */
321     public String getAnswerTime()
322     {
323         return answerTime;
324     }
325 
326     /***
327      * Returns the answer time as Date object.<p>
328      * This method asumes that the Asterisk server's timezone equals the default 
329      * timezone of your JVM.
330      * 
331      * @return the answer time as Date object.
332      * @since 0.3
333      */
334     public Date getAnswerTimeAsDate()
335     {
336         return DateUtil.parseDateTime(answerTime);
337     }
338 
339     /***
340      * Returns the answer time as Date object.
341      * 
342      * @param tz the timezone of the Asterisk server.
343      * @return the answer time as Date object.
344      * @since 0.3
345      */
346     public Date getAnswerTimeAsDate(TimeZone tz)
347     {
348         return DateUtil.parseDateTime(answerTime, tz);
349     }
350 
351     /***
352      * Sets the date/time when the call was answered.
353      * 
354      * @param answerTime the date/time when the call was answered.
355      */
356     public void setAnswerTime(String answerTime)
357     {
358         this.answerTime = answerTime;
359     }
360 
361     /***
362      * Returns when the call has ended.<p>
363      * This corresponds to CDR field <code>end</code>.
364      * 
365      * @return A string of the format "%Y-%m-%d %T" (strftime(3)) representing the date/time the
366      * call has ended, for example "2006-05-19 11:58:21"
367      */
368     public String getEndTime()
369     {
370         return endTime;
371     }
372 
373     /***
374      * Returns the end time as Date object.<p>
375      * This method asumes that the Asterisk server's timezone equals the default 
376      * timezone of your JVM.
377      * 
378      * @return the end time as Date object.
379      * @since 0.3
380      */
381     public Date getEndTimeAsDate()
382     {
383         return DateUtil.parseDateTime(endTime);
384     }
385     
386     /***
387      * Returns the end time as Date object.
388      * 
389      * @param tz the timezone of the Asterisk server.
390      * @return the end time as Date object.
391      * @since 0.3
392      */
393     public Date getEndTimeAsDate(TimeZone tz)
394     {
395         return DateUtil.parseDateTime(endTime, tz);
396     }
397 
398     /***
399      * Sets the date/time when the call has ended.
400      * 
401      * @param endTime the date/time when the call has ended.
402      */
403     public void setEndTime(String endTime)
404     {
405         this.endTime = endTime;
406     }
407 
408     /***
409      * Returns the total time (in seconds) the caller spent in the system from dial to hangup.<p>
410      * Corresponds to CDR field <code>duration</code>.
411      * 
412      * @return the total time in system in seconds.
413      */
414     public Integer getDuration()
415     {
416         return duration;
417     }
418 
419     /***
420      * Sets the total time in system.
421      * 
422      * @param duration total time in system in seconds.
423      */
424     public void setDuration(Integer duration)
425     {
426         this.duration = duration;
427     }
428 
429     /***
430      * Returns the total time (in seconds) the call was up from answer to hangup.<p>
431      * Corresponds to CDR field <code>billsec</code>.
432      * 
433      * @return the total time in call in seconds.
434      */
435     public Integer getBillableSeconds()
436     {
437         return billableSeconds;
438     }
439 
440     /***
441      * Sets the total time in call.
442      * 
443      * @param billableSeconds the total time in call in seconds.
444      */
445     public void setBillableSeconds(Integer billableSeconds)
446     {
447         this.billableSeconds = billableSeconds;
448     }
449 
450     /***
451      * Returns what happened to the call.<p>
452      * This is one of
453      * <ul>
454      * <li>{@link #DISPOSITION_NO_ANSWER}
455      * <li>{@link #DISPOSITION_FAILED}
456      * <li>{@link #DISPOSITION_BUSY}
457      * <li>{@link #DISPOSITION_ANSWERED}
458      * <li>{@link #DISPOSITION_UNKNOWN}
459      * </ul>
460      * Corresponds to CDR field <code>disposition</code>.
461      * 
462      * @return the disposition.
463      */
464     public String getDisposition()
465     {
466         return disposition;
467     }
468 
469     /***
470      * Sets the disposition.
471      * 
472      * @param disposition the disposition.
473      */
474     public void setDisposition(String disposition)
475     {
476         this.disposition = disposition;
477     }
478 
479     /***
480      * Returns the AMA (Automated Message Accounting) flags.<p>
481      * This is one of
482      * <ul>
483      * <li>{@link #AMA_FLAG_OMIT}
484      * <li>{@link #AMA_FLAG_BILLING}
485      * <li>{@link #AMA_FLAG_DOCUMENTATION}
486      * <li>{@link #AMA_FLAG_UNKNOWN}
487      * </ul>
488      * Corresponds to CDR field <code>amaflags</code>.
489      * 
490      * @return the AMA flags.
491      */
492     public String getAmaFlags()
493     {
494         return amaFlags;
495     }
496 
497     /***
498      * Sets the AMA (Automated Message Accounting) flags.
499      * 
500      * @param amaFlags the AMA (Automated Message Accounting) flags.
501      */
502     public void setAmaFlags(String amaFlags)
503     {
504         this.amaFlags = amaFlags;
505     }
506 
507     /***
508      * Returns the unique id of the channel.
509      * 
510      * @return the unique id of the channel.
511      */
512     public String getUniqueId()
513     {
514         return uniqueId;
515     }
516 
517     /***
518      * Sets the unique id of the channel.
519      * 
520      * @param uniqueId the unique id of the channel.
521      */
522     public void setUniqueId(String uniqueId)
523     {
524         this.uniqueId = uniqueId;
525     }
526 
527     /***
528      * Returns the user-defined field as set by <code>Set(CDR(userfield)=Value)</code>.<p>
529      * Corresponds to CDR field <code>userfield</code>.
530      * 
531      * @return the user-defined field.
532      */
533     public String getUserField()
534     {
535         return userField;
536     }
537 
538     /***
539      * Sets the user-defined field.
540      * 
541      * @param userField the user-defined field
542      */
543     public void setUserField(String userField)
544     {
545         this.userField = userField;
546     }
547 }