added svcapi ui and camunda code
[it/otf.git] / otf-service-api / src / main / java / org / oran / otf / common / utility / http / ResponseUtility.java
diff --git a/otf-service-api/src/main/java/org/oran/otf/common/utility/http/ResponseUtility.java b/otf-service-api/src/main/java/org/oran/otf/common/utility/http/ResponseUtility.java
new file mode 100644 (file)
index 0000000..919897c
--- /dev/null
@@ -0,0 +1,107 @@
+/*  Copyright (c) 2019 AT&T Intellectual Property.                             #\r
+#                                                                              #\r
+#   Licensed under the Apache License, Version 2.0 (the "License");            #\r
+#   you may not use this file except in compliance with the License.           #\r
+#   You may obtain a copy of the License at                                    #\r
+#                                                                              #\r
+#       http://www.apache.org/licenses/LICENSE-2.0                             #\r
+#                                                                              #\r
+#   Unless required by applicable law or agreed to in writing, software        #\r
+#   distributed under the License is distributed on an "AS IS" BASIS,          #\r
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #\r
+#   See the License for the specific language governing permissions and        #\r
+#   limitations under the License.                                             #\r
+##############################################################################*/\r
+\r
+\r
+package org.oran.otf.common.utility.http;\r
+\r
+import org.oran.otf.common.model.local.OTFApiResponse;\r
+import javax.ws.rs.core.MediaType;\r
+import javax.ws.rs.core.Response;\r
+\r
+public class ResponseUtility {\r
+\r
+  public static class Build {\r
+\r
+    public static Response okRequest() {\r
+      return Response.ok().build();\r
+    }\r
+\r
+    public static Response badRequest() {\r
+      return Response.status(400).build();\r
+    }\r
+\r
+    public static Response okRequestWithMessage(String msg) {\r
+      return Response.status(200)\r
+          .type(MediaType.APPLICATION_JSON)\r
+          .entity(new OTFApiResponse(200, msg))\r
+          .build();\r
+    }\r
+\r
+    public static Response okRequestWithObject(Object obj) {\r
+      return Response.status(200).type(MediaType.APPLICATION_JSON).entity(obj).build();\r
+    }\r
+\r
+    public static Response badRequestWithMessage(String msg) {\r
+      return Response.status(400)\r
+          .type(MediaType.APPLICATION_JSON)\r
+          .entity(new OTFApiResponse(400, msg))\r
+          .build();\r
+    }\r
+\r
+    public static Response internalServerError() {\r
+      return Response.status(500).build();\r
+    }\r
+\r
+    public static Response internalServerErrorWithMessage(String msg) {\r
+      return Response.status(500)\r
+          .type(MediaType.APPLICATION_JSON)\r
+          .entity(new OTFApiResponse(500, msg))\r
+          .build();\r
+    }\r
+\r
+    public static Response unauthorized() {\r
+      return Response.status(401).build();\r
+    }\r
+    public static Response unauthorizedWithMessage(String msg) {\r
+      return Response.status(401)\r
+          .type(MediaType.APPLICATION_JSON)\r
+          .entity(new OTFApiResponse(401, msg))\r
+          .build();\r
+    }\r
+\r
+    public static Response notFoundWithMessage(String msg) {\r
+      return Response.status(404)\r
+          .type(MediaType.APPLICATION_JSON)\r
+          .entity(new OTFApiResponse(404, msg))\r
+          .build();\r
+    }\r
+\r
+    public static Response serviceUnavailableWithMessage(String msg) {\r
+      return Response.status(503)\r
+          .type(MediaType.APPLICATION_JSON)\r
+          .entity(new OTFApiResponse(503, msg))\r
+          .build();\r
+    }\r
+\r
+    public static Response serviceUnavailable() {\r
+      return Response.status(503).build();\r
+    }\r
+\r
+    public static Response genericWithCode(int code) {\r
+      return Response.status(code).build();\r
+    }\r
+\r
+    public static Response genericWithMessage(int code, String msg) {\r
+      return Response.status(code)\r
+          .type(MediaType.APPLICATION_JSON)\r
+          .entity(new OTFApiResponse(code, msg))\r
+          .build();\r
+    }\r
+\r
+    public static Response genericWithObject(int code, Object obj) {\r
+      return Response.status(code).type(MediaType.APPLICATION_JSON).entity(obj).build();\r
+    }\r
+  }\r
+}\r