Update rest-client with additional operations
[aai/rest-client.git] / src / main / java / org / openecomp / restclient / client / OperationResult.java
1 /**\r
2  * ============LICENSE_START=======================================================\r
3  * RestClient\r
4  * ================================================================================\r
5  * Copyright © 2017 AT&T Intellectual Property.\r
6  * Copyright © 2017 Amdocs\r
7  * All rights reserved.\r
8  * ================================================================================\r
9  * Licensed under the Apache License, Version 2.0 (the "License");\r
10  * you may not use this file except in compliance with the License.\r
11  * You may obtain a copy of the License at\r
12  *\r
13  *    http://www.apache.org/licenses/LICENSE-2.0\r
14  *\r
15  * Unless required by applicable law or agreed to in writing, software\r
16  * distributed under the License is distributed on an "AS IS" BASIS,\r
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
18  * See the License for the specific language governing permissions and\r
19  * limitations under the License.\r
20  * ============LICENSE_END=========================================================\r
21  *\r
22  * ECOMP and OpenECOMP are trademarks\r
23  * and service marks of AT&T Intellectual Property.\r
24  */\r
25 package org.openecomp.restclient.client;\r
26 \r
27 import javax.ws.rs.core.MultivaluedMap;\r
28 \r
29 public class OperationResult {\r
30 \r
31   private String requestedLink;\r
32   private String result;\r
33   private String failureCause;\r
34   private boolean fromCache;\r
35   private int resultCode;\r
36   private int numRetries;\r
37   private MultivaluedMap<String, String> responseHeaders;\r
38 \r
39 \r
40   public OperationResult() {\r
41     super();\r
42     this.numRetries = 0;\r
43     this.fromCache = false;\r
44   }\r
45 \r
46   /**\r
47    * Instantiates a new operation result.\r
48    *\r
49    * @param resultCode the result code\r
50    * @param result the result\r
51    */\r
52   public OperationResult(int resultCode, String result) {\r
53     this();\r
54     this.resultCode = resultCode;\r
55     this.result = result;\r
56   }\r
57 \r
58   /**\r
59    * Get the HTTP headers of the response.\r
60    *\r
61    * @return the HTTP headers of the response.\r
62    */\r
63   public MultivaluedMap<String, String> getHeaders() {\r
64     return responseHeaders;\r
65   }\r
66 \r
67   /**\r
68    * Returns true if the HTTP Status Code 200 <= x <= 299\r
69    *\r
70    * @return true, if successful\r
71    */\r
72   public boolean wasSuccessful() {\r
73     return (resultCode > 199 && resultCode < 300);\r
74   }\r
75 \r
76   public void setHeaders(MultivaluedMap<String, String> headers) {\r
77     this.responseHeaders = headers;\r
78   }\r
79 \r
80   public String getResult() {\r
81     return result;\r
82   }\r
83 \r
84   public void setResult(String result) {\r
85     this.result = result;\r
86   }\r
87 \r
88   public int getResultCode() {\r
89     return resultCode;\r
90   }\r
91 \r
92   public String getFailureCause() {\r
93     return failureCause;\r
94   }\r
95   \r
96   /**\r
97    * Sets the result.\r
98    *\r
99    * @param resultCode the result code\r
100    * @param result the result\r
101    */\r
102   public void setResult(int resultCode, String result) {\r
103     this.resultCode = resultCode;\r
104     this.result = result;\r
105   }\r
106   \r
107   public void setFailureCause(String failureCause) {\r
108     this.failureCause = failureCause;\r
109   }\r
110 \r
111   /**\r
112    * Sets the failure cause.\r
113    *\r
114    * @param resultCode the result code\r
115    * @param failureCause the result error\r
116    */\r
117   public void setFailureCause(int resultCode, String failureCause) {\r
118     this.resultCode = resultCode;\r
119     this.failureCause = failureCause;\r
120   }\r
121 \r
122   \r
123   public void setResultCode(int resultCode) {\r
124     this.resultCode = resultCode;\r
125   }\r
126 \r
127   public String getRequestedLink() {\r
128     return requestedLink;\r
129   }\r
130 \r
131   public void setRequestedLink(String requestedLink) {\r
132     this.requestedLink = requestedLink;\r
133   }\r
134 \r
135   public boolean isFromCache() {\r
136     return fromCache;\r
137   }\r
138 \r
139   public void setFromCache(boolean fromCache) {\r
140     this.fromCache = fromCache;\r
141   }\r
142 \r
143   public int getNumRetries() {\r
144     return numRetries;\r
145   }\r
146 \r
147   public void setNumRetries(int numRetries) {\r
148     this.numRetries = numRetries;\r
149   }\r
150 \r
151   @Override\r
152   public String toString() {\r
153     return "OperationResult [result=" + result + ", requestedLink=" + requestedLink\r
154         + ", failureCause=" + failureCause + ", resultCode=" + resultCode + ", numRetries="\r
155         + numRetries + ", responseHeaders=" + responseHeaders + "]";\r
156   }\r
157 \r
158 }\r