001/* 002 * Copyright (c) 2011-2017 Nexmo Inc 003 * 004 * Permission is hereby granted, free of charge, to any person obtaining a copy 005 * of this software and associated documentation files (the "Software"), to deal 006 * in the Software without restriction, including without limitation the rights 007 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 008 * copies of the Software, and to permit persons to whom the Software is 009 * furnished to do so, subject to the following conditions: 010 * 011 * The above copyright notice and this permission notice shall be included in 012 * all copies or substantial portions of the Software. 013 * 014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 020 * THE SOFTWARE. 021 */ 022package com.nexmo.client.voice; 023 024 025 026import com.fasterxml.jackson.databind.util.ISO8601Utils; 027import org.apache.http.NameValuePair; 028import org.apache.http.message.BasicNameValuePair; 029 030import java.util.ArrayList; 031import java.util.Date; 032import java.util.List; 033 034public class CallsFilter { 035 private CallStatus status; 036 private Date dateStart; 037 private Date dateEnd; 038 private Integer pageSize; 039 private Integer recordIndex; 040 private String order; 041 private String conversationUuid; 042 043 public CallStatus getStatus() { 044 return status; 045 } 046 047 public void setStatus(CallStatus status) { 048 this.status = status; 049 } 050 051 public Date getDateStart() { 052 return dateStart; 053 } 054 055 public void setDateStart(Date dateStart) { 056 this.dateStart = dateStart; 057 } 058 059 public Date getDateEnd() { 060 return dateEnd; 061 } 062 063 public void setDateEnd(Date dateEnd) { 064 this.dateEnd = dateEnd; 065 } 066 067 public Integer getPageSize() { 068 return pageSize; 069 } 070 071 public void setPageSize(Integer pageSize) { 072 this.pageSize = pageSize; 073 } 074 075 public Integer getRecordIndex() { 076 return recordIndex; 077 } 078 079 public void setRecordIndex(Integer recordIndex) { 080 this.recordIndex = recordIndex; 081 } 082 083 public String getOrder() { 084 return order; 085 } 086 087 public void setOrder(String order) { 088 this.order = order; 089 } 090 091 public String getConversationUuid() { 092 return conversationUuid; 093 } 094 095 public void setConversationUuid(String conversationUuid) { 096 this.conversationUuid = conversationUuid; 097 } 098 099 public List<NameValuePair> toUrlParams() { 100 List<NameValuePair> result = new ArrayList<NameValuePair>(10); 101 conditionalAdd(result, "status", this.status); 102 conditionalAdd(result, "date_start", this.dateStart); 103 conditionalAdd(result, "date_end", this.dateEnd); 104 conditionalAdd(result, "page_size", this.pageSize); 105 conditionalAdd(result, "record_index", this.recordIndex); 106 conditionalAdd(result, "order", this.order); 107 conditionalAdd(result, "conversation_uuid", this.conversationUuid); 108 109 return result; 110 } 111 112 private void conditionalAdd(List<NameValuePair> params, String name, String value) { 113 if (value != null) { 114 params.add(new BasicNameValuePair(name, value)); 115 } 116 } 117 118 private void conditionalAdd(List<NameValuePair> params, String name, Date value) { 119 if (value != null) { 120 params.add(new BasicNameValuePair(name, ISO8601Utils.format(value))); 121 } 122 } 123 124 private void conditionalAdd(List<NameValuePair> params, String name, Object value) { 125 if (value != null) { 126 params.add(new BasicNameValuePair(name, value.toString())); 127 } 128 } 129}