|
| 1 | +/* |
| 2 | + * Copyright (C) 2007-2017, GoodData(R) Corporation. All rights reserved. |
| 3 | + * This source code is licensed under the BSD-style license found in the |
| 4 | + * LICENSE.txt file in the root directory of this source tree. |
| 5 | + */ |
| 6 | +package com.gooddata.executeafm.result; |
| 7 | + |
| 8 | +import com.fasterxml.jackson.annotation.JsonCreator; |
| 9 | +import com.fasterxml.jackson.annotation.JsonProperty; |
| 10 | +import com.gooddata.util.GoodDataToStringBuilder; |
| 11 | + |
| 12 | +import java.util.List; |
| 13 | + |
| 14 | +import static com.gooddata.util.Validate.notEmpty; |
| 15 | +import static com.gooddata.util.Validate.notNull; |
| 16 | +import static java.util.Collections.emptyList; |
| 17 | + |
| 18 | +/** |
| 19 | + * {@link ExecutionResult}'s warning. |
| 20 | + */ |
| 21 | +public class Warning { |
| 22 | + private final String warningCode; |
| 23 | + private final String message; |
| 24 | + private final List<Object> parameters; |
| 25 | + |
| 26 | + /** |
| 27 | + * Creates new instance |
| 28 | + * @param warningCode error code |
| 29 | + * @param message message |
| 30 | + */ |
| 31 | + public Warning(final String warningCode, final String message) { |
| 32 | + this(warningCode, message, emptyList()); |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * Creates new instance |
| 37 | + * @param warningCode error code |
| 38 | + * @param message message |
| 39 | + * @param parameters message's parameters |
| 40 | + */ |
| 41 | + @JsonCreator |
| 42 | + public Warning(@JsonProperty("warningCode") final String warningCode, |
| 43 | + @JsonProperty("message") final String message, |
| 44 | + @JsonProperty("parameters") final List<Object> parameters) { |
| 45 | + this.warningCode = notEmpty(warningCode, "warningCode"); |
| 46 | + this.message = notEmpty(message, "message"); |
| 47 | + this.parameters = notNull(parameters, "parameters"); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * @return warning's error code |
| 52 | + */ |
| 53 | + public String getWarningCode() { |
| 54 | + return warningCode; |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * @return warning's message |
| 59 | + */ |
| 60 | + public String getMessage() { |
| 61 | + return message; |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * @return message's parameters |
| 66 | + */ |
| 67 | + public List<Object> getParameters() { |
| 68 | + return parameters; |
| 69 | + } |
| 70 | + |
| 71 | + @Override |
| 72 | + public boolean equals(Object o) { |
| 73 | + if (this == o) return true; |
| 74 | + if (o == null || getClass() != o.getClass()) return false; |
| 75 | + |
| 76 | + Warning warning = (Warning) o; |
| 77 | + |
| 78 | + if (warningCode != null ? !warningCode.equals(warning.warningCode) : warning.warningCode != null) return false; |
| 79 | + if (message != null ? !message.equals(warning.message) : warning.message != null) return false; |
| 80 | + return parameters != null ? parameters.equals(warning.parameters) : warning.parameters == null; |
| 81 | + } |
| 82 | + |
| 83 | + @Override |
| 84 | + public int hashCode() { |
| 85 | + int result = warningCode != null ? warningCode.hashCode() : 0; |
| 86 | + result = 31 * result + (message != null ? message.hashCode() : 0); |
| 87 | + result = 31 * result + (parameters != null ? parameters.hashCode() : 0); |
| 88 | + return result; |
| 89 | + } |
| 90 | + |
| 91 | + @Override |
| 92 | + public String toString() { |
| 93 | + return GoodDataToStringBuilder.defaultToString(this); |
| 94 | + } |
| 95 | +} |
0 commit comments