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