Open Kilda Java Documentation
MessageError.java
Go to the documentation of this file.
1 /* Copyright 2017 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.messaging.error;
17 
18 import static com.google.common.base.MoreObjects.firstNonNull;
19 import static com.google.common.base.MoreObjects.toStringHelper;
22 import static org.openkilda.messaging.Utils.TIMESTAMP;
23 
24 import com.fasterxml.jackson.annotation.JsonCreator;
25 import com.fasterxml.jackson.annotation.JsonInclude;
26 import com.fasterxml.jackson.annotation.JsonProperty;
27 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
28 
29 import java.io.Serializable;
30 import java.util.Objects;
31 
35 @JsonSerialize
36 @JsonInclude(JsonInclude.Include.NON_NULL)
37 public class MessageError implements Serializable {
41  private static final long serialVersionUID = 1L;
42 
46  @JsonProperty(CORRELATION_ID)
47  private String correlationId;
48 
52  @JsonProperty(TIMESTAMP)
53  private long timestamp;
54 
58  @JsonProperty("error-type")
59  private String errorType;
60 
64  @JsonProperty("error-message")
65  private String errorMessage;
66 
70  @JsonProperty("error-description")
71  private String errorDescription;
72 
82  @JsonCreator
83  public MessageError(@JsonProperty(CORRELATION_ID) final String correlationId,
84  @JsonProperty(TIMESTAMP) final long timestamp,
85  @JsonProperty("error-type") final String type,
86  @JsonProperty("error-message") final String message,
87  @JsonProperty("error-description") final String description) {
88  this.correlationId = firstNonNull(correlationId, DEFAULT_CORRELATION_ID);
89  this.timestamp = timestamp;
90  this.errorType = type;
91  this.errorMessage = message;
92  this.errorDescription = description;
93  }
94 
98  @Override
99  public String toString() {
100  return toStringHelper(this)
101  .add(CORRELATION_ID, correlationId)
102  .add(TIMESTAMP, timestamp)
103  .add("error-type", errorType)
104  .add("error-message", errorMessage)
105  .add("error-description", errorDescription)
106  .toString();
107  }
108 
112  @Override
113  public int hashCode() {
114  return Objects.hash(correlationId, timestamp, errorType, errorMessage, errorDescription);
115  }
116 
120  @Override
121  public boolean equals(Object object) {
122  if (this == object) {
123  return true;
124  }
125  if (object == null || getClass() != object.getClass()) {
126  return false;
127  }
128 
129  MessageError that = (MessageError) object;
130  return Objects.equals(this.correlationId, that.correlationId)
131  && Objects.equals(this.errorType, that.errorType)
132  && Objects.equals(this.errorMessage, that.errorMessage)
133  && Objects.equals(this.errorDescription, that.errorDescription);
134  }
135 }
description
Definition: setup.py:26
static final String DEFAULT_CORRELATION_ID
Definition: Utils.java:69
static final String CORRELATION_ID
Definition: Utils.java:43
static final String TIMESTAMP
Definition: Utils.java:35
MessageError(@JsonProperty(CORRELATION_ID) final String correlationId, @JsonProperty(TIMESTAMP) final long timestamp, @JsonProperty("error-type") final String type, @JsonProperty("error-message") final String message, @JsonProperty("error-description") final String description)