// Path: src/main/java/com/sonymobile/tools/gerrit/gerritevents/dto/GerritEventKeys.java
// public static final String BY = "by";
// 
// Path: src/main/java/com/sonymobile/tools/gerrit/gerritevents/dto/GerritEventKeys.java
// public static final String TYPE = "type";
// 
// Path: src/main/java/com/sonymobile/tools/gerrit/gerritevents/dto/GerritEventKeys.java
// public static final String VALUE = "value";
// 
// Path: src/main/java/com/sonymobile/tools/gerrit/gerritevents/dto/GerritEventKeys.java
// public static final String UPDATED = "updated";
// 
// Path: src/main/java/com/sonymobile/tools/gerrit/gerritevents/dto/GerritEventKeys.java
// public static final String OLD_VALUE = "oldValue";


import static com.sonymobile.tools.gerrit.gerritevents.dto.GerritEventKeys.VALUE;
import static com.sonymobile.tools.gerrit.gerritevents.dto.GerritEventKeys.UPDATED;
import static com.sonymobile.tools.gerrit.gerritevents.dto.GerritEventKeys.OLD_VALUE;
import static com.sonymobile.tools.gerrit.gerritevents.GerritJsonEventFactory.getString;
import static com.sonymobile.tools.gerrit.gerritevents.GerritJsonEventFactory.getBoolean;
import com.sonymobile.tools.gerrit.gerritevents.dto.GerritJsonDTO;
import net.sf.json.JSONObject;
import static com.sonymobile.tools.gerrit.gerritevents.dto.GerritEventKeys.BY;
import static com.sonymobile.tools.gerrit.gerritevents.dto.GerritEventKeys.TYPE;
/*
 *  The MIT License
 *
 *  Copyright 2012 Copyright 2012 Hewlett-Packard Development Company, L.P.
 *
 *  Permission is hereby granted, free of charge, to any person obtaining a copy
 *  of this software and associated documentation files (the "Software"), to deal
 *  in the Software without restriction, including without limitation the rights
 *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *  copies of the Software, and to permit persons to whom the Software is
 *  furnished to do so, subject to the following conditions:
 *
 *  The above copyright notice and this permission notice shall be included in
 *  all copies or substantial portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 *  THE SOFTWARE.
 */
package com.sonymobile.tools.gerrit.gerritevents.dto.attr;



/**
 * Represents a Gerrit JSON Approval DTO.
 *
 * @author James E. Blair &lt;jeblair@hp.com&gt;
 */
public class Approval implements GerritJsonDTO {

    /**
     * The approval category.
     */
    private String type;
    /**
     * The approval value
     */
    private String value;
    /**
     * Approval value update indicator
     */
    private Boolean updated;
    /**
     * The old (or previous) approval value
     */
    private String oldValue;
    /**
     * The user who has approved the patch
     */
    private Account by;

    /* username has been replaced by Approval.by Account.
     * This allows old builds to deserialize without warnings.
     * Below readResolve() method will handle the migration.
     * I can't flag it transient as it will skip the deserialization
     *  part, preventing any migration. */
    @SuppressWarnings("unused")
    private String username;

    /**
     * Default constructor.
     */
    public Approval() {
    }



    /**
     * Constructor that fills with data directly.
     *
     * @param json the JSON object with corresponding data.
     */
    public Approval(JSONObject json) {
        this.fromJson(json);
    }

    @Override
    public void fromJson(JSONObject json) {
        if (json.containsKey(TYPE) && json.containsKey(VALUE)) {
            type = getString(json, TYPE);
            value = getString(json, VALUE);
        }
        if (json.containsKey(BY)) {
            by = new Account(json.getJSONObject(BY));
        }
// Path: src/main/java/com/sonymobile/tools/gerrit/gerritevents/dto/GerritEventKeys.java
// public static final String BY = "by";
// 
// Path: src/main/java/com/sonymobile/tools/gerrit/gerritevents/dto/GerritEventKeys.java
// public static final String TYPE = "type";
// 
// Path: src/main/java/com/sonymobile/tools/gerrit/gerritevents/dto/GerritEventKeys.java
// public static final String VALUE = "value";
// 
// Path: src/main/java/com/sonymobile/tools/gerrit/gerritevents/dto/GerritEventKeys.java
// public static final String UPDATED = "updated";
// 
// Path: src/main/java/com/sonymobile/tools/gerrit/gerritevents/dto/GerritEventKeys.java
// public static final String OLD_VALUE = "oldValue";


// Path: src/main/java/com/sonymobile/tools/gerrit/gerritevents/dto/attr/Approval.java
import static com.sonymobile.tools.gerrit.gerritevents.dto.GerritEventKeys.VALUE;
import static com.sonymobile.tools.gerrit.gerritevents.dto.GerritEventKeys.UPDATED;
import static com.sonymobile.tools.gerrit.gerritevents.dto.GerritEventKeys.OLD_VALUE;
import static com.sonymobile.tools.gerrit.gerritevents.GerritJsonEventFactory.getString;
import static com.sonymobile.tools.gerrit.gerritevents.GerritJsonEventFactory.getBoolean;
import com.sonymobile.tools.gerrit.gerritevents.dto.GerritJsonDTO;
import net.sf.json.JSONObject;
import static com.sonymobile.tools.gerrit.gerritevents.dto.GerritEventKeys.BY;
import static com.sonymobile.tools.gerrit.gerritevents.dto.GerritEventKeys.TYPE;

/*
 *  The MIT License
 *
 *  Copyright 2012 Copyright 2012 Hewlett-Packard Development Company, L.P.
 *
 *  Permission is hereby granted, free of charge, to any person obtaining a copy
 *  of this software and associated documentation files (the "Software"), to deal
 *  in the Software without restriction, including without limitation the rights
 *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *  copies of the Software, and to permit persons to whom the Software is
 *  furnished to do so, subject to the following conditions:
 *
 *  The above copyright notice and this permission notice shall be included in
 *  all copies or substantial portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 *  THE SOFTWARE.
 */
package com.sonymobile.tools.gerrit.gerritevents.dto.attr;



/**
 * Represents a Gerrit JSON Approval DTO.
 *
 * @author James E. Blair &lt;jeblair@hp.com&gt;
 */
public class Approval implements GerritJsonDTO {

    /**
     * The approval category.
     */
    private String type;
    /**
     * The approval value
     */
    private String value;
    /**
     * Approval value update indicator
     */
    private Boolean updated;
    /**
     * The old (or previous) approval value
     */
    private String oldValue;
    /**
     * The user who has approved the patch
     */
    private Account by;

    /* username has been replaced by Approval.by Account.
     * This allows old builds to deserialize without warnings.
     * Below readResolve() method will handle the migration.
     * I can't flag it transient as it will skip the deserialization
     *  part, preventing any migration. */
    @SuppressWarnings("unused")
    private String username;

    /**
     * Default constructor.
     */
    public Approval() {
    }



    /**
     * Constructor that fills with data directly.
     *
     * @param json the JSON object with corresponding data.
     */
    public Approval(JSONObject json) {
        this.fromJson(json);
    }

    @Override
    public void fromJson(JSONObject json) {
        if (json.containsKey(TYPE) && json.containsKey(VALUE)) {
            type = getString(json, TYPE);
            value = getString(json, VALUE);
        }
        if (json.containsKey(BY)) {
            by = new Account(json.getJSONObject(BY));
        }
        if (json.containsKey(UPDATED)) {