001/*
002 * Copyright 2010-2014 Ning, Inc.
003 * Copyright 2014-2015 The Billing Project, LLC
004 *
005 * The Billing Project licenses this file to you under the Apache License, version 2.0
006 * (the "License"); you may not use this file except in compliance with the
007 * License.  You may obtain a copy of the License at:
008 *
009 *    http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
013 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
014 * License for the specific language governing permissions and limitations
015 * under the License.
016 */
017
018package com.ning.billing.recurly.model;
019
020import java.util.Map;
021
022import javax.xml.bind.annotation.XmlElement;
023import javax.xml.bind.annotation.XmlRootElement;
024
025import com.google.common.base.Objects;
026
027@XmlRootElement(name = "errors")
028public class Errors extends RecurlyObject {
029
030    @XmlElement(name = "transaction_error")
031    private TransactionError transactionError;
032
033    @XmlElement(name = "transaction")
034    private Transaction transaction;
035
036    @XmlElement(name = "error")
037    private RecurlyErrors recurlyErrors;
038
039    public TransactionError getTransactionError() {
040        return transactionError;
041    }
042
043    public void setTransactionError(final TransactionError transactionError) {
044        this.transactionError = transactionError;
045    }
046
047    public Transaction getTransaction() {
048        return transaction;
049    }
050
051    public void setTransaction(final Transaction transaction) {
052        this.transaction = transaction;
053    }
054
055    public RecurlyErrors getRecurlyErrors() {
056        return recurlyErrors;
057    }
058
059    public void setRecurlyErrors(final Object recurlyError) {
060        if (recurlyError instanceof Map) {
061            final RecurlyError error = new RecurlyError();
062            error.setField((String) ((Map) recurlyError).get("field"));
063            error.setSymbol((String) ((Map) recurlyError).get("symbol"));
064            error.setMessage((String) ((Map) recurlyError).get(""));
065
066            if (this.recurlyErrors == null) {
067                this.recurlyErrors = new RecurlyErrors();
068            }
069            this.recurlyErrors.add(error);
070        } else {
071            this.recurlyErrors = (RecurlyErrors) recurlyErrors;
072        }
073    }
074
075    @Override
076    public String toString() {
077        final StringBuilder sb = new StringBuilder("Errors{");
078        sb.append("transactionError=").append(transactionError);
079        sb.append(", transaction=").append(transaction);
080        sb.append(", recurlyErrors=").append(recurlyErrors);
081        sb.append('}');
082        return sb.toString();
083    }
084
085    @Override
086    public boolean equals(final Object o) {
087        if (this == o) {
088            return true;
089        }
090        if (o == null || getClass() != o.getClass()) {
091            return false;
092        }
093
094        final Errors errors = (Errors) o;
095
096        if (recurlyErrors != null ? !recurlyErrors.equals(errors.recurlyErrors) : errors.recurlyErrors != null) {
097            return false;
098        }
099        if (transaction != null ? !transaction.equals(errors.transaction) : errors.transaction != null) {
100            return false;
101        }
102        if (transactionError != null ? !transactionError.equals(errors.transactionError) : errors.transactionError != null) {
103            return false;
104        }
105
106        return true;
107    }
108
109    @Override
110    public int hashCode() {
111        return Objects.hashCode(
112                transactionError,
113                transaction,
114                recurlyErrors
115        );
116    }
117}