001/* 002 * Copyright 2020 Vonage 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package com.vonage.client.voice; 017 018 019import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 020import com.fasterxml.jackson.annotation.JsonInclude; 021import com.fasterxml.jackson.annotation.JsonProperty; 022import com.fasterxml.jackson.databind.ObjectMapper; 023import com.fasterxml.jackson.databind.SerializationFeature; 024import com.vonage.client.VonageUnexpectedException; 025 026import java.io.IOException; 027import java.util.Date; 028 029/** 030 * CallInfo holds the information related to a call. It is obtained using {@link VoiceClient#listCalls} 031 */ 032@JsonInclude(value = JsonInclude.Include.NON_NULL) 033@JsonIgnoreProperties(value = { "_links" }, ignoreUnknown = true) 034public class CallInfo { 035 private Endpoint to; 036 private Endpoint from; 037 038 private String conversationUuid = null; 039 private CallDirection direction = null; 040 private Integer duration = null; 041 private Date endTime = null; 042 private String network = null; 043 private String price = null; 044 private String rate = null; 045 private Date startTime = null; 046 private CallStatus status = null; 047 private String uuid = null; 048 049 public CallInfo() {} 050 051 public CallInfo(String to, String from) { 052 this(new PhoneEndpoint(to), new PhoneEndpoint(from)); 053 } 054 055 public CallInfo(Endpoint to, Endpoint from) { 056 this.to = to; 057 this.from = from; 058 } 059 060 public Endpoint getTo() { 061 return to; 062 } 063 064 public void setTo(Endpoint to) { 065 this.to = to; 066 } 067 068 public Endpoint getFrom() { 069 return from; 070 } 071 072 public void setFrom(Endpoint from) { 073 this.from = from; 074 } 075 076 public String getUuid() { 077 return uuid; 078 } 079 080 public void setUuid(String uuid) { 081 this.uuid = uuid; 082 } 083 084 @JsonProperty("conversation_uuid") 085 public String getConversationUuid() { 086 return conversationUuid; 087 } 088 089 public void setConversationUuid(String conversationUuid) { 090 this.conversationUuid = conversationUuid; 091 } 092 093 public Integer getDuration() { 094 return duration; 095 } 096 097 public void setDuration(Integer duration) { 098 this.duration = duration; 099 } 100 101 @JsonProperty("end_time") 102 public Date getEndTime() { 103 return endTime; 104 } 105 106 public void setEndTime(Date endTime) { 107 this.endTime = endTime; 108 } 109 110 public String getPrice() { 111 return price; 112 } 113 114 public void setPrice(String price) { 115 this.price = price; 116 } 117 118 public String getRate() { 119 return rate; 120 } 121 122 public void setRate(String rate) { 123 this.rate = rate; 124 } 125 126 @JsonProperty("start_time") 127 public Date getStartTime() { 128 return this.startTime; 129 } 130 131 public void setStartTime(Date startTime) { 132 this.startTime = startTime; 133 } 134 135 public CallStatus getStatus() { 136 return status; 137 } 138 139 public void setStatus(CallStatus status) { 140 this.status = status; 141 } 142 143 public CallDirection getDirection() { 144 return direction; 145 } 146 147 public void setDirection(CallDirection direction) { 148 this.direction = direction; 149 } 150 151 public String getNetwork() { 152 return network; 153 } 154 155 public void setNetwork(String network) { 156 this.network = network; 157 } 158 159 public String toString() { 160 return new StringBuilder() 161 .append("<CallInfo ") 162 .append("ID: ").append(this.getUuid()).append(", ") 163 .append("From: ").append(this.getFrom().toLog()).append(", ") 164 .append("To: ").append(this.getTo().toLog()).append(", ") 165 .append("Status: ").append(this.getStatus()) 166 .append(">") 167 .toString(); 168 } 169 170 public static CallInfo fromJson(String json) { 171 try { 172 ObjectMapper mapper = new ObjectMapper(); 173 mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); 174 return mapper.readValue(json, CallInfo.class); 175 } catch (IOException jpe) { 176 throw new VonageUnexpectedException("Failed to produce json from CallInfo object.", jpe); 177 } 178 } 179}