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.live.internal;
18  
19  import org.asteriskjava.live.AmaFlags;
20  import org.asteriskjava.live.AsteriskChannel;
21  import org.asteriskjava.live.CallDetailRecord;
22  import org.asteriskjava.live.Disposition;
23  import org.asteriskjava.manager.event.CdrEvent;
24  
25  import java.util.Date;
26  import java.util.HashMap;
27  import java.util.Map;
28  import java.util.TimeZone;
29  
30  /**
31   * Default implementation of the CallDetailRecord interface.
32   */
33  public class CallDetailRecordImpl implements CallDetailRecord
34  {
35      private static final Map<String, Disposition> DISPOSITION_MAP;
36      private static final Map<String, AmaFlags> AMA_FLAGS_MAP;
37      private final AsteriskChannelImpl channel;
38      private final AsteriskChannelImpl destinationChannel;
39  
40      private final String accountCode;
41      private final String destinationContext;
42      private final String destinationExtension;
43      private final String lastApplication;
44      private final String lastAppData;
45      private final Date startDate;
46      private final Date answerDate;
47      private final Date endDate;
48      private final Integer duration;
49      private final Integer billableSeconds;
50      private final Disposition disposition;
51      private final AmaFlags amaFlags;
52      private final String userField;
53  
54      static
55      {
56          DISPOSITION_MAP = new HashMap<String, Disposition>();
57          DISPOSITION_MAP.put(CdrEvent.DISPOSITION_ANSWERED, Disposition.ANSWERED);
58          DISPOSITION_MAP.put(CdrEvent.DISPOSITION_BUSY, Disposition.BUSY);
59          DISPOSITION_MAP.put(CdrEvent.DISPOSITION_FAILED, Disposition.FAILED);
60          DISPOSITION_MAP.put(CdrEvent.DISPOSITION_NO_ANSWER, Disposition.NO_ANSWER);
61          DISPOSITION_MAP.put(CdrEvent.DISPOSITION_UNKNOWN, Disposition.UNKNOWN);
62  
63          AMA_FLAGS_MAP = new HashMap<String, AmaFlags>();
64          AMA_FLAGS_MAP.put(CdrEvent.AMA_FLAG_BILLING, AmaFlags.BILLING);
65          AMA_FLAGS_MAP.put(CdrEvent.AMA_FLAG_DOCUMENTATION, AmaFlags.DOCUMENTATION);
66          AMA_FLAGS_MAP.put(CdrEvent.AMA_FLAG_OMIT, AmaFlags.OMIT);
67          AMA_FLAGS_MAP.put(CdrEvent.AMA_FLAG_UNKNOWN, AmaFlags.UNKNOWN);
68      }
69  
70      CallDetailRecordImpl(AsteriskChannelImpl channel, AsteriskChannelImpl destinationChannel, CdrEvent cdrEvent)
71      {
72          //TODO add timezone to AsteriskServer
73          TimeZone tz = TimeZone.getDefault();
74          this.channel = channel;
75          this.destinationChannel = destinationChannel;
76  
77          accountCode = cdrEvent.getAccountCode();
78          destinationContext = cdrEvent.getDestinationContext();
79          destinationExtension = cdrEvent.getDestination();
80          lastApplication = cdrEvent.getLastApplication();
81          lastAppData = cdrEvent.getLastData();
82          startDate = cdrEvent.getStartTimeAsDate(tz);
83          answerDate = cdrEvent.getAnswerTimeAsDate(tz);
84          endDate = cdrEvent.getEndTimeAsDate(tz);
85          duration = cdrEvent.getDuration();
86          billableSeconds = cdrEvent.getBillableSeconds();
87          if (cdrEvent.getAmaFlags() != null)
88          {
89              amaFlags = AMA_FLAGS_MAP.get(cdrEvent.getAmaFlags());
90          }
91          else
92          {
93              amaFlags = null;
94          }
95          if (cdrEvent.getDisposition() != null)
96          {
97              disposition = DISPOSITION_MAP.get(cdrEvent.getDisposition());
98          }
99          else
100         {
101             disposition = null;
102         }
103         userField = cdrEvent.getUserField();
104     }
105 
106     public AsteriskChannel getChannel()
107     {
108         return channel;
109     }
110 
111     public AsteriskChannel getDestinationChannel()
112     {
113         return destinationChannel;
114     }
115 
116     public String getAccountCode()
117     {
118         return accountCode;
119     }
120 
121     public AmaFlags getAmaFlags()
122     {
123         return amaFlags;
124     }
125 
126     public Date getAnswerDate()
127     {
128         return answerDate;
129     }
130 
131     public Integer getBillableSeconds()
132     {
133         return billableSeconds;
134     }
135 
136     public String getDestinationContext()
137     {
138         return destinationContext;
139     }
140 
141     public String getDestinationExtension()
142     {
143         return destinationExtension;
144     }
145 
146     public Disposition getDisposition()
147     {
148         return disposition;
149     }
150 
151     public Integer getDuration()
152     {
153         return duration;
154     }
155 
156     public Date getEndDate()
157     {
158         return endDate;
159     }
160 
161     public String getLastApplication()
162     {
163         return lastApplication;
164     }
165 
166     public String getLastAppData()
167     {
168         return lastAppData;
169     }
170 
171     public Date getStartDate()
172     {
173         return startDate;
174     }
175 
176     public String getUserField()
177     {
178         return userField;
179     }
180 }