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