added svcapi ui and camunda code
[it/otf.git] / otf-camunda / 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)\r
44               .type(MediaType.APPLICATION_JSON)\r
45               .entity(obj)\r
46               .build();\r
47     }\r
48 \r
49     public static Response badRequestWithMessage(String msg) {\r
50       return Response.status(400)\r
51           .type(MediaType.APPLICATION_JSON)\r
52           .entity(new OTFApiResponse(400, msg))\r
53           .build();\r
54     }\r
55 \r
56     public static Response internalServerError() {\r
57       return Response.status(500).build();\r
58     }\r
59 \r
60     public static Response internalServerErrorWithMessage(String msg) {\r
61       return Response.status(500)\r
62           .type(MediaType.APPLICATION_JSON)\r
63           .entity(new OTFApiResponse(500, msg))\r
64           .build();\r
65     }\r
66 \r
67     public static Response unauthorized() {\r
68       return Response.status(401).build();\r
69     }\r
70 \r
71     public static Response unauthorizedWithMessage(String msg) {\r
72       return Response.status(401)\r
73           .type(MediaType.APPLICATION_JSON)\r
74           .entity(new OTFApiResponse(401, msg))\r
75           .build();\r
76     }\r
77 \r
78     public static Response notFound() {\r
79       return Response.status(404).build();\r
80     }\r
81 \r
82     public static Response notFoundWithMessage(String msg) {\r
83       return Response.status(404)\r
84               .type(MediaType.APPLICATION_JSON)\r
85               .entity(new OTFApiResponse(404, msg))\r
86               .build();\r
87     }\r
88 \r
89     public static Response genericWithCode(int code) {\r
90       return Response.status(code).build();\r
91     }\r
92 \r
93     public static Response genericWithMessage(int code, String msg) {\r
94       return Response.status(code)\r
95               .type(MediaType.APPLICATION_JSON)\r
96           .entity(new OTFApiResponse(code, msg))\r
97               .build();\r
98     }\r
99 \r
100     public static Response genericWithObject(int code, Object obj) {\r
101       return Response.status(code)\r
102               .type(MediaType.APPLICATION_JSON)\r
103               .entity(obj)\r
104               .build();\r
105     }\r
106   }\r
107 }\r