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