001/* 002 * Copyright (c) 2011-2018 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.incoming; 023 024import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 025import com.fasterxml.jackson.annotation.JsonProperty; 026import com.fasterxml.jackson.databind.ObjectMapper; 027import com.nexmo.client.NexmoUnexpectedException; 028 029import java.io.IOException; 030import java.text.DateFormat; 031import java.text.SimpleDateFormat; 032import java.util.Date; 033import java.util.TimeZone; 034 035@JsonIgnoreProperties(ignoreUnknown = true) 036public class MessageEvent { 037 private String msisdn; 038 private String to; 039 private String messageId; 040 private String text; 041 private MessageType type; 042 private String keyword; 043 private Date messageTimestamp; 044 private String timestamp; 045 private String nonce; 046 private Boolean concat; 047 private int concatRef; 048 private int concatTotal; 049 private int concatPart; 050 private String data; 051 private String udh; 052 053 public String getMsisdn() { 054 return msisdn; 055 } 056 057 public String getTo() { 058 return to; 059 } 060 061 public String getMessageId() { 062 return messageId; 063 } 064 065 public String getText() { 066 return text; 067 } 068 069 public MessageType getType() { 070 return type; 071 } 072 073 public String getKeyword() { 074 return keyword; 075 } 076 077 @JsonProperty("message-timestamp") 078 public Date getMessageTimestamp() { 079 return messageTimestamp; 080 } 081 082 public String getTimestamp() { 083 return timestamp; 084 } 085 086 public String getNonce() { 087 return nonce; 088 } 089 090 public Boolean getConcat() { 091 return concat; 092 } 093 094 @JsonProperty("concat-ref") 095 public int getConcatRef() { 096 return concatRef; 097 } 098 099 @JsonProperty("concat-total") 100 public int getConcatTotal() { 101 return concatTotal; 102 } 103 104 @JsonProperty("concat-part") 105 public int getConcatPart() { 106 return concatPart; 107 } 108 109 public String getData() { 110 return data; 111 } 112 113 public String getUdh() { 114 return udh; 115 } 116 117 public static MessageEvent fromJson(String json) { 118 try { 119 DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 120 dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); 121 122 ObjectMapper mapper = new ObjectMapper(); 123 mapper.setDateFormat(dateFormat); 124 return mapper.readValue(json, MessageEvent.class); 125 } catch (IOException jpe) { 126 throw new NexmoUnexpectedException("Failed to produce MessageEvent from json.", jpe); 127 } 128 } 129}