001// Generated by delombok at Fri Oct 11 21:56:28 CEST 2019
002/**
003 * Copyright (c) 2010-2019 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;
024
025import com.restfb.Facebook;
026import com.restfb.JsonMapper;
027import com.restfb.types.webhook.messaging.UserVerbValue;
028
029/**
030 * The transferred change containing the field and the value
031 */
032public class Change {
033  /**
034   * the subscribed field.
035   */
036  @Facebook
037  private String field;
038  /**
039   * value of this change.
040   *
041   * You have to check the current class implementation because the value depends on the change Facebook sends to you.
042   */
043  private ChangeValue value = null;
044  /**
045   * The user object has a different structure and the verb is on another level than in all other elements, so we have
046   * to save it here and use it in the factory afterwards. With this the json is normalized in RestFB.
047   */
048  @Facebook("verb")
049  private ChangeValue.Verb userObjectVerb = null;
050  @Facebook("value")
051  private String rawValue;
052
053  @JsonMapper.JsonMappingCompleted
054  private void convertChangeValue(JsonMapper mapper) {
055    if (rawValue != null) {
056      ChangeValueFactory factory = new ChangeValueFactory().setField(field).setUserObjectVerb(userObjectVerb).setValue(rawValue);
057      value = factory.buildWithMapper(mapper);
058      if (value instanceof UserVerbValue && userObjectVerb != null) {
059        ((UserVerbValue) value).setVerb(userObjectVerb);
060      }
061    } else if (userObjectVerb == ChangeValue.Verb.GRANTED || userObjectVerb == ChangeValue.Verb.REVOKED) {
062      PermissionChangeValue pcv = new PermissionChangeValue();
063      pcv.setVerb(userObjectVerb);
064      pcv.setVerbAsString(userObjectVerb.name().toLowerCase());
065      value = pcv;
066    }
067  }
068
069  @java.lang.Override
070  @java.lang.SuppressWarnings("all")
071  public java.lang.String toString() {
072    return "Change(field=" + this.getField() + ", value=" + this.getValue() + ", userObjectVerb=" + this.userObjectVerb + ", rawValue=" + this.rawValue + ")";
073  }
074
075  /**
076   * the subscribed field.
077   */
078  @java.lang.SuppressWarnings("all")
079  public String getField() {
080    return this.field;
081  }
082
083  /**
084   * the subscribed field.
085   */
086  @java.lang.SuppressWarnings("all")
087  public void setField(final String field) {
088    this.field = field;
089  }
090
091  /**
092   * value of this change.
093   *
094   * You have to check the current class implementation because the value depends on the change Facebook sends to you.
095   *
096   * @return the current changed value, may be {@code null}
097   */
098  @java.lang.SuppressWarnings("all")
099  public ChangeValue getValue() {
100    return this.value;
101  }
102
103  /**
104   * value of this change.
105   *
106   * You have to check the current class implementation because the value depends on the change Facebook sends to you.
107   */
108  @java.lang.SuppressWarnings("all")
109  public void setValue(final ChangeValue value) {
110    this.value = value;
111  }
112}