added svcapi ui and camunda code
[it/otf.git] / otf-service-api / src / main / java / org / oran / otf / common / utility / http / ResponseUtility.java
1 /*  Copyright (c) 2019 AT&T Intellectual Property.                             #\r
2 #                                                                              #\r
3 #   Licensed under the Apache License, Version 2.0 (the "License");            #\r
4 #   you may not use this file except in compliance with the License.           #\r
5 #   You may obtain a copy of the License at                                    #\r
6 #                                                                              #\r
7 #       http://www.apache.org/licenses/LICENSE-2.0                             #\r
8 #                                                                              #\r
9 #   Unless required by applicable law or agreed to in writing, software        #\r
10 #   distributed under the License is distributed on an "AS IS" BASIS,          #\r
11 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #\r
12 #   See the License for the specific language governing permissions and        #\r
13 #   limitations under the License.                                             #\r
14 ##############################################################################*/\r
15 \r
16 \r
17 package org.oran.otf.common.utility.http;\r
18 \r
19 import org.oran.otf.common.model.local.OTFApiResponse;\r
20 import javax.ws.rs.core.MediaType;\r
21 import javax.ws.rs.core.Response;\r
22 \r
23 public class ResponseUtility {\r
24 \r
25   public static class Build {\r
26 \r
27     public static Response okRequest() {\r
28       return Response.ok().build();\r
29     }\r
30 \r
31     public static Response badRequest() {\r
32       return Response.status(400).build();\r
33     }\r
34 \r
35     public static Response okRequestWithMessage(String msg) {\r
36       return Response.status(200)\r
37           .type(MediaType.APPLICATION_JSON)\r
38           .entity(new OTFApiResponse(200, msg))\r
39           .build();\r
40     }\r
41 \r
42     public static Response okRequestWithObject(Object obj) {\r
43       return Response.status(200).type(MediaType.APPLICATION_JSON).entity(obj).build();\r
44     }\r
45 \r
46     public static Response badRequestWithMessage(String msg) {\r
47       return Response.status(400)\r
48           .type(MediaType.APPLICATION_JSON)\r
49           .entity(new OTFApiResponse(400, msg))\r
50           .build();\r
51     }\r
52 \r
53     public static Response internalServerError() {\r
54       return Response.status(500).build();\r
55     }\r
56 \r
57     public static Response internalServerErrorWithMessage(String msg) {\r
58       return Response.status(500)\r
59           .type(MediaType.APPLICATION_JSON)\r
60           .entity(new OTFApiResponse(500, msg))\r
61           .build();\r
62     }\r
63 \r
64     public static Response unauthorized() {\r
65       return Response.status(401).build();\r
66     }\r
67     public static Response unauthorizedWithMessage(String msg) {\r
68       return Response.status(401)\r
69           .type(MediaType.APPLICATION_JSON)\r
70           .entity(new OTFApiResponse(401, msg))\r
71           .build();\r
72     }\r
73 \r
74     public static Response notFoundWithMessage(String msg) {\r
75       return Response.status(404)\r
76           .type(MediaType.APPLICATION_JSON)\r
77           .entity(new OTFApiResponse(404, msg))\r
78           .build();\r
79     }\r
80 \r
81     public static Response serviceUnavailableWithMessage(String msg) {\r
82       return Response.status(503)\r
83           .type(MediaType.APPLICATION_JSON)\r
84           .entity(new OTFApiResponse(503, msg))\r
85           .build();\r
86     }\r
87 \r
88     public static Response serviceUnavailable() {\r
89       return Response.status(503).build();\r
90     }\r
91 \r
92     public static Response genericWithCode(int code) {\r
93       return Response.status(code).build();\r
94     }\r
95 \r
96     public static Response genericWithMessage(int code, String msg) {\r
97       return Response.status(code)\r
98           .type(MediaType.APPLICATION_JSON)\r
99           .entity(new OTFApiResponse(code, msg))\r
100           .build();\r
101     }\r
102 \r
103     public static Response genericWithObject(int code, Object obj) {\r
104       return Response.status(code).type(MediaType.APPLICATION_JSON).entity(obj).build();\r
105     }\r
106   }\r
107 }\r