Merge "Not logged or rethrow this exception."
[aai/data-router.git] / src / main / java / org / onap / aai / datarouter / exception / DataRouterError.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23 package org.onap.aai.datarouter.exception;
24
25 /*
26  * COPYRIGHT NOTICE: Copyright (c) 2016 Team Pacifica (Amdocs & AT&T) The contents and intellectual
27  * property contained herein, remain the property of Team Pacifica (Amdocs & AT&T).
28  */
29
30 import java.text.MessageFormat;
31
32 import javax.ws.rs.core.Response.Status;
33
34 /**
35  * DL enum for error conditions.
36  */
37 public enum DataRouterError {
38
39   /** Parsing exceptions - Range 100..199. */
40   DL_PARSE_100("DL-100", "Unable to find resource {0} in the model", Status.BAD_REQUEST), 
41   DL_PARSE_101("DL-101", "Unable to parse ", Status.BAD_REQUEST), 
42   DL_PARSE_102("DL-102", "Sot Filter error: {0} ", Status.INTERNAL_SERVER_ERROR), 
43   DL_PARSE_103("DL-103", "URL Parsing error: {0} ", Status.BAD_REQUEST), 
44   DL_PARSE_104("DL-104", "Missing Ids filter: {0} ", Status.BAD_REQUEST), 
45   DL_PARSE_105("DL-105", "Invalid Ids filter: {0} ", Status.BAD_REQUEST),
46
47   /** Validation exceptions - Range 200..299. */
48   DL_VALIDATION_200("DL-200", "Missing X-TransactionId in header ", Status.BAD_REQUEST),
49
50   /** Other components integration errors - Range 300..399. */
51   DL_INTEGRATION_300("DL-300", "Unable to decorate Graph ", Status.INTERNAL_SERVER_ERROR),
52
53   /** Environment related exceptions - Range 400..499. */
54   DL_ENV_400("DL-400", "Unable to find file {0} ", Status.INTERNAL_SERVER_ERROR), 
55   DL_ENV_401("DL-401", "Unable to Load OXM Models", Status.INTERNAL_SERVER_ERROR),
56
57   /** Other components integration errors - Range 500..599. */
58   DL_AUTH_500("DL-500", "Unable to authorize User ", Status.FORBIDDEN);
59
60   /** The error id. */
61   private String id;
62   /** The error message. */
63   private String message;
64   /** The error http return code. */
65   private Status status;
66
67   /**
68    * Constructor.
69    * 
70    * @param id the error id
71    * @param message the error message
72    */
73   DataRouterError(final String id, final String message, final Status status) {
74     this.id = id;
75     this.message = message;
76     this.status = status;
77   }
78
79   /**
80    * Get the id.
81    * 
82    * @return the error id
83    */
84   public String getId() {
85     return this.id;
86   }
87
88   /**
89    * Get the message.
90    * 
91    * @param args the error arguments
92    * @return the error message
93    */
94   public String getMessage(final Object... args) {
95     final MessageFormat formatter = new MessageFormat("");
96     formatter.applyPattern(this.message);
97     return formatter.format(args);
98   }
99
100   public Status getHttpStatus() {
101     return this.status;
102   }
103
104 }