+ private static final Map<StatusCode, Response.Status> ResponseStatusMapping = new HashMap<StatusCode, Response.Status>() {
+ private static final long serialVersionUID = 1L;
+ {
+ put(StatusCode.SUCCESS, Response.Status.OK);
+ put(StatusCode.BADREQUEST, Response.Status.BAD_REQUEST);
+ put(StatusCode.UNAUTHORIZED, Response.Status.UNAUTHORIZED);
+ put(StatusCode.FORBIDDEN, Response.Status.FORBIDDEN);
+ put(StatusCode.NOTFOUND, Response.Status.NOT_FOUND);
+ put(StatusCode.NOTALLOWED, Response.Status.FORBIDDEN);
+ put(StatusCode.NOTACCEPTABLE, Response.Status.NOT_ACCEPTABLE);
+ put(StatusCode.TIMEOUT, Response.Status.GONE);
+ put(StatusCode.CONFLICT, Response.Status.CONFLICT);
+ put(StatusCode.GONE, Response.Status.GONE);
+ put(StatusCode.UNSUPPORTED, Response.Status.BAD_REQUEST);
+ put(StatusCode.INTERNALERROR, Response.Status.INTERNAL_SERVER_ERROR);
+ put(StatusCode.NOTIMPLEMENTED, Response.Status.NOT_ACCEPTABLE);
+ put(StatusCode.NOSERVICE, Response.Status.SERVICE_UNAVAILABLE);
+ put(StatusCode.UNDEFINED, Response.Status.BAD_REQUEST);
+ }
+ };
+
+ private static final String AUDIT = "audit";
+
+ private static final Logger logger = LoggerFactory.getLogger(AUDIT);
+
+ // Suppress default constructor for noninstantiability
+ private NorthboundUtils() {
+ }
+
+ /**
+ * Returns Response.Status for a given status. If the status is null or if
+ * the corresponding StatusCode is not present in the ResponseStatusMapping,
+ * it returns null.
+ *
+ * @param status
+ * The Status
+ * @return The Response.Status for a given status
+ */
+ public static Response.Status getResponseStatus(Status status) {
+ return ResponseStatusMapping.get(status.getCode());
+ }
+
+ /**
+ * Returns Response for a given status. If the status provided is null or if
+ * the corresponding StatusCode is not present in the ResponseStatusMapping,
+ * it returns Response with StatusType as INTERNAL_SERVER_ERROR.
+ *
+ * @param status
+ * The Status
+ * @return The Response for a given status.
+ */
+ public static Response getResponse(Status status) {
+ if ((status == null) || (!ResponseStatusMapping.containsKey(status.getCode()))) {
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Action Result Unknown").build();
+ }
+ return Response.status(ResponseStatusMapping.get(status.getCode())).entity(status.getDescription()).build();
+ }