View Javadoc
1   /*
2    * Copyright (c) 2002-2024, City of Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.grubusiness.business.web.rs.responseStatus;
35  
36  import com.fasterxml.jackson.annotation.JsonInclude;
37  import com.fasterxml.jackson.annotation.JsonProperty;
38  import com.fasterxml.jackson.annotation.JsonPropertyOrder;
39  
40  import java.beans.ConstructorProperties;
41  import java.util.ArrayList;
42  import java.util.List;
43  
44  
45  
46  @JsonInclude( JsonInclude.Include.NON_EMPTY )
47  public class ResponseStatus
48  {
49  
50      public static final String KEY_ATTRIBUTE_STATUS = "status";
51      public static final String KEY_ATTRIBUTE_STATUS_CODE = "code";
52      public static final String KEY_STATUS = "status";
53      public static final String KEY_MESSAGE = "message";
54      public static final String KEY_MESSAGE_KEY = "message_key";
55      public static final String KEY_HTTP_CODE = "http_code";
56      
57      private final int httpCode;
58      private final ResponseStatusType type;
59      private String message;
60      private String messageKey;
61      
62  
63      @ConstructorProperties( {
64              "httpCode", "status"
65      } )
66      public ResponseStatus( final int httpCode, final ResponseStatusType type )
67      {
68          this.httpCode = httpCode;
69          this.type = type;
70      }
71  
72      @JsonProperty( value = KEY_HTTP_CODE )
73      public int getHttpCode( )
74      {
75          return httpCode;
76      }
77  
78      @JsonProperty( value = KEY_STATUS )
79      public ResponseStatusType getType( )
80      {
81          return type;
82      }
83  
84      @JsonProperty( value = KEY_MESSAGE )
85      public String getMessage( )
86      {
87          return message;
88      }
89  
90      @JsonProperty( value = KEY_MESSAGE )
91      public ResponseStatus setMessage( final String message )
92      {
93          this.message = message;
94          return this;
95      }
96  
97      @JsonProperty( value = KEY_MESSAGE_KEY )
98      public String getMessageKey( )
99      {
100         return messageKey;
101     }
102 
103     @JsonProperty( value = KEY_MESSAGE_KEY )
104     public ResponseStatus setMessageKey( final String messageKey )
105     {
106         this.messageKey = messageKey;
107         return this;
108     }
109 
110     @Override
111     public boolean equals( final Object o )
112     {
113         if ( !( o instanceof ResponseStatus ) )
114         {
115             return false;
116         }
117         final ResponseStatus./../../../../../../fr/paris/lutece/plugins/grubusiness/business/web/rs/responseStatus/ResponseStatus.html#ResponseStatus">ResponseStatus other = (ResponseStatus) o;
118         return this.httpCode == other.httpCode && this.type == other.type;
119     }
120 
121     @Override
122     public String toString() {
123         return "ResponseStatus{" +
124                 "httpCode=" + httpCode +
125                 ", type=" + type +
126                 ", message='" + message + '\'' +
127                 ", messageKey='" + messageKey + '\'' +
128                 '}';
129     }
130 }