001// Generated by delombok at Wed Nov 11 21:20:25 CET 2020
002/*
003 * Copyright (c) 2010-2020 Mark Allen, Norbert Bartels.
004 *
005 * Permission is hereby granted, free of charge, to any person obtaining a copy
006 * of this software and associated documentation files (the "Software"), to deal
007 * in the Software without restriction, including without limitation the rights
008 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
009 * copies of the Software, and to permit persons to whom the Software is
010 * furnished to do so, subject to the following conditions:
011 *
012 * The above copyright notice and this permission notice shall be included in
013 * all copies or substantial portions of the Software.
014 *
015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
016 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
017 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
018 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
019 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
020 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
021 * THE SOFTWARE.
022 */
023package com.restfb.types.webhook.messaging;
024
025import java.util.ArrayList;
026import java.util.Date;
027import java.util.List;
028import com.restfb.Facebook;
029import com.restfb.JsonMapper;
030import com.restfb.json.JsonObject;
031import com.restfb.json.JsonValue;
032
033public class MessagingItem {
034  @Facebook
035  private MessagingParticipant sender;
036  @Facebook
037  private MessagingParticipant recipient;
038  @Facebook("timestamp")
039  private Long rawTimestamp;
040  private Date timestamp;
041  @Facebook
042  private DeliveryItem delivery;
043  @Facebook
044  private ReadItem read;
045  @Facebook
046  private MessageItem message;
047  @Facebook
048  private PostbackItem postback;
049  @Facebook
050  private OptinItem optin;
051  @Facebook("account_linking")
052  private AccountLinkingItem accountLinking;
053  @Facebook("checkout_update")
054  private CheckoutUpdateItem checkoutUpdate;
055  @Facebook
056  private PaymentItem payment;
057  @Facebook
058  private ReferralItem referral;
059  @Facebook("policy-enforcement")
060  private PolicyEnforcementItem policyEnforcement;
061  @Facebook("pass_thread_control")
062  private PassThreadControlItem passThreadControl;
063  @Facebook("take_thread_control")
064  private TakeThreadControlItem takeThreadControl;
065  @Facebook("request_thread_control")
066  private RequestThreadControlItem requestThreadControl;
067  private AppRoles appRoles;
068  @Facebook("prior_message")
069  private PriorMessage priorMessage;
070  @Facebook
071  private MessageReaction reaction;
072  @Facebook("app_roles")
073  private JsonObject rawAppRoles;
074
075  /**
076   * generic access to the inner item.
077   * 
078   * depending on the inner elements the corresponding element is returned. So you can get an {@link OptinItem},
079   * {@link PostbackItem}, {@link DeliveryItem}, {@link AccountLinkingItem} or {@link MessageItem}
080   * 
081   * @return the inner item.
082   */
083  public InnerMessagingItem getItem() {
084    if (optin != null) {
085      return optin;
086    }
087    if (postback != null) {
088      return postback;
089    }
090    if (delivery != null) {
091      return delivery;
092    }
093    if (read != null) {
094      return read;
095    }
096    if (accountLinking != null) {
097      return accountLinking;
098    }
099    if (message != null) {
100      return message;
101    }
102    if (checkoutUpdate != null) {
103      return checkoutUpdate;
104    }
105    if (payment != null) {
106      return payment;
107    }
108    if (referral != null) {
109      return referral;
110    }
111    if (policyEnforcement != null) {
112      return policyEnforcement;
113    }
114    if (passThreadControl != null) {
115      return passThreadControl;
116    }
117    if (takeThreadControl != null) {
118      return takeThreadControl;
119    }
120    if (requestThreadControl != null) {
121      return requestThreadControl;
122    }
123    if (appRoles != null) {
124      return appRoles;
125    }
126    if (reaction != null) {
127      return reaction;
128    }
129    return null;
130  }
131
132  public boolean isDelivery() {
133    return getItem() instanceof DeliveryItem;
134  }
135
136  public boolean isRead() {
137    return getItem() instanceof ReadItem;
138  }
139
140  public boolean isMessage() {
141    return getItem() instanceof MessageItem;
142  }
143
144  public boolean isPostback() {
145    return getItem() instanceof PostbackItem;
146  }
147
148  public boolean isOptin() {
149    return getItem() instanceof OptinItem;
150  }
151
152  public boolean isAccountLinking() {
153    return getItem() instanceof AccountLinkingItem;
154  }
155
156  public boolean isCheckoutUpdate() {
157    return getItem() instanceof CheckoutUpdateItem;
158  }
159
160  public boolean isPayment() {
161    return getItem() instanceof PaymentItem;
162  }
163
164  public boolean isReferral() {
165    return getItem() instanceof ReferralItem;
166  }
167
168  public boolean isPolicyEnforcement() {
169    return getItem() instanceof PolicyEnforcementItem;
170  }
171
172  public boolean isPassThreadControl() {
173    return getItem() instanceof PassThreadControlItem;
174  }
175
176  public boolean isTakeThreadControl() {
177    return getItem() instanceof TakeThreadControlItem;
178  }
179
180  public boolean isRequestThreadControl() {
181    return getItem() instanceof RequestThreadControlItem;
182  }
183
184  public boolean isAppRoles() {
185    return getItem() instanceof AppRoles;
186  }
187
188  public boolean hasPriorMessage() {
189    return priorMessage != null;
190  }
191
192  public boolean isReaction() {
193    return getItem() instanceof MessageReaction;
194  }
195
196  @JsonMapper.JsonMappingCompleted
197  private void convertDate() {
198    if (rawTimestamp != null) {
199      timestamp = new Date(rawTimestamp);
200    }
201  }
202
203  @JsonMapper.JsonMappingCompleted
204  private void convertAppRoles() {
205    if (rawAppRoles != null) {
206      AppRoles appRoles = new AppRoles();
207      for (String appId : rawAppRoles.names()) {
208        List<JsonValue> rawRoles = rawAppRoles.get(appId).asArray().values();
209        List<String> roles = new ArrayList<>();
210        for (JsonValue rawValue : rawRoles) {
211          roles.add(rawValue.asString());
212        }
213        appRoles.addRoles(appId, roles);
214      }
215      this.appRoles = appRoles;
216    }
217  }
218
219  @java.lang.Override
220  @java.lang.SuppressWarnings("all")
221  public java.lang.String toString() {
222    return "MessagingItem(sender=" + this.getSender() + ", recipient=" + this.getRecipient() + ", rawTimestamp=" + this.rawTimestamp + ", timestamp=" + this.getTimestamp() + ", delivery=" + this.getDelivery() + ", read=" + this.getRead() + ", message=" + this.getMessage() + ", postback=" + this.getPostback() + ", optin=" + this.getOptin() + ", accountLinking=" + this.getAccountLinking() + ", checkoutUpdate=" + this.getCheckoutUpdate() + ", payment=" + this.getPayment() + ", referral=" + this.getReferral() + ", policyEnforcement=" + this.getPolicyEnforcement() + ", passThreadControl=" + this.getPassThreadControl() + ", takeThreadControl=" + this.getTakeThreadControl() + ", requestThreadControl=" + this.getRequestThreadControl() + ", appRoles=" + this.getAppRoles() + ", priorMessage=" + this.getPriorMessage() + ", reaction=" + this.getReaction() + ", rawAppRoles=" + this.rawAppRoles + ")";
223  }
224
225  @java.lang.SuppressWarnings("all")
226  public MessagingParticipant getSender() {
227    return this.sender;
228  }
229
230  @java.lang.SuppressWarnings("all")
231  public void setSender(final MessagingParticipant sender) {
232    this.sender = sender;
233  }
234
235  @java.lang.SuppressWarnings("all")
236  public MessagingParticipant getRecipient() {
237    return this.recipient;
238  }
239
240  @java.lang.SuppressWarnings("all")
241  public void setRecipient(final MessagingParticipant recipient) {
242    this.recipient = recipient;
243  }
244
245  @java.lang.SuppressWarnings("all")
246  public Date getTimestamp() {
247    return this.timestamp;
248  }
249
250  @java.lang.SuppressWarnings("all")
251  public void setTimestamp(final Date timestamp) {
252    this.timestamp = timestamp;
253  }
254
255  @java.lang.SuppressWarnings("all")
256  public DeliveryItem getDelivery() {
257    return this.delivery;
258  }
259
260  @java.lang.SuppressWarnings("all")
261  public void setDelivery(final DeliveryItem delivery) {
262    this.delivery = delivery;
263  }
264
265  @java.lang.SuppressWarnings("all")
266  public ReadItem getRead() {
267    return this.read;
268  }
269
270  @java.lang.SuppressWarnings("all")
271  public void setRead(final ReadItem read) {
272    this.read = read;
273  }
274
275  @java.lang.SuppressWarnings("all")
276  public MessageItem getMessage() {
277    return this.message;
278  }
279
280  @java.lang.SuppressWarnings("all")
281  public void setMessage(final MessageItem message) {
282    this.message = message;
283  }
284
285  @java.lang.SuppressWarnings("all")
286  public PostbackItem getPostback() {
287    return this.postback;
288  }
289
290  @java.lang.SuppressWarnings("all")
291  public void setPostback(final PostbackItem postback) {
292    this.postback = postback;
293  }
294
295  @java.lang.SuppressWarnings("all")
296  public OptinItem getOptin() {
297    return this.optin;
298  }
299
300  @java.lang.SuppressWarnings("all")
301  public void setOptin(final OptinItem optin) {
302    this.optin = optin;
303  }
304
305  @java.lang.SuppressWarnings("all")
306  public AccountLinkingItem getAccountLinking() {
307    return this.accountLinking;
308  }
309
310  @java.lang.SuppressWarnings("all")
311  public void setAccountLinking(final AccountLinkingItem accountLinking) {
312    this.accountLinking = accountLinking;
313  }
314
315  @java.lang.SuppressWarnings("all")
316  public CheckoutUpdateItem getCheckoutUpdate() {
317    return this.checkoutUpdate;
318  }
319
320  @java.lang.SuppressWarnings("all")
321  public void setCheckoutUpdate(final CheckoutUpdateItem checkoutUpdate) {
322    this.checkoutUpdate = checkoutUpdate;
323  }
324
325  @java.lang.SuppressWarnings("all")
326  public PaymentItem getPayment() {
327    return this.payment;
328  }
329
330  @java.lang.SuppressWarnings("all")
331  public void setPayment(final PaymentItem payment) {
332    this.payment = payment;
333  }
334
335  @java.lang.SuppressWarnings("all")
336  public ReferralItem getReferral() {
337    return this.referral;
338  }
339
340  @java.lang.SuppressWarnings("all")
341  public void setReferral(final ReferralItem referral) {
342    this.referral = referral;
343  }
344
345  @java.lang.SuppressWarnings("all")
346  public PolicyEnforcementItem getPolicyEnforcement() {
347    return this.policyEnforcement;
348  }
349
350  @java.lang.SuppressWarnings("all")
351  public void setPolicyEnforcement(final PolicyEnforcementItem policyEnforcement) {
352    this.policyEnforcement = policyEnforcement;
353  }
354
355  @java.lang.SuppressWarnings("all")
356  public PassThreadControlItem getPassThreadControl() {
357    return this.passThreadControl;
358  }
359
360  @java.lang.SuppressWarnings("all")
361  public void setPassThreadControl(final PassThreadControlItem passThreadControl) {
362    this.passThreadControl = passThreadControl;
363  }
364
365  @java.lang.SuppressWarnings("all")
366  public TakeThreadControlItem getTakeThreadControl() {
367    return this.takeThreadControl;
368  }
369
370  @java.lang.SuppressWarnings("all")
371  public void setTakeThreadControl(final TakeThreadControlItem takeThreadControl) {
372    this.takeThreadControl = takeThreadControl;
373  }
374
375  @java.lang.SuppressWarnings("all")
376  public RequestThreadControlItem getRequestThreadControl() {
377    return this.requestThreadControl;
378  }
379
380  @java.lang.SuppressWarnings("all")
381  public void setRequestThreadControl(final RequestThreadControlItem requestThreadControl) {
382    this.requestThreadControl = requestThreadControl;
383  }
384
385  @java.lang.SuppressWarnings("all")
386  public AppRoles getAppRoles() {
387    return this.appRoles;
388  }
389
390  @java.lang.SuppressWarnings("all")
391  public void setAppRoles(final AppRoles appRoles) {
392    this.appRoles = appRoles;
393  }
394
395  @java.lang.SuppressWarnings("all")
396  public PriorMessage getPriorMessage() {
397    return this.priorMessage;
398  }
399
400  @java.lang.SuppressWarnings("all")
401  public void setPriorMessage(final PriorMessage priorMessage) {
402    this.priorMessage = priorMessage;
403  }
404
405  @java.lang.SuppressWarnings("all")
406  public MessageReaction getReaction() {
407    return this.reaction;
408  }
409
410  @java.lang.SuppressWarnings("all")
411  public void setReaction(final MessageReaction reaction) {
412    this.reaction = reaction;
413  }
414}