Merge of new rebased code
[appc.git] / appc-oam / appc-oam-bundle / src / main / java / org / openecomp / appc / oam / OAMCommandStatus.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : APP-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
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
22 package org.openecomp.appc.oam;
23
24
25 import org.openecomp.appc.executor.objects.Params;
26 import org.openecomp.appc.util.MessageFormatter;
27
28 import java.util.Map;
29
30 public enum OAMCommandStatus {
31
32     ACCEPTED(100,"ACCEPTED - request accepted"),
33
34     //ERROR(2xx) – request can’t be handled due to some technical error
35     UNEXPECTED_ERROR(200,"UNEXPECTED ERROR - ${errorMsg}"),
36
37     SUCCESS(400,"SUCCESS - request has been processed successfully"),
38         ;
39
40
41     public static final String errorDgMessageParamName = "errorDgMessage";
42
43         private int responseCode;
44         private String responseMessage;
45
46
47
48
49     OAMCommandStatus(int responseCode, String responseMessage) {
50         this.responseCode = responseCode;
51         this.responseMessage = responseMessage;
52             }
53
54     public String getResponseMessage() {
55                 return responseMessage;
56         }
57
58         public int getResponseCode() {
59                 return responseCode;
60         }
61
62
63         /**
64      *
65      * @return  messageTemplate
66      */
67
68
69     public String getFormattedMessage(Params params){
70             Map<String,Object> paramsMap = params != null ? params.getParams() : null;
71             return MessageFormatter.format(getResponseMessage(),paramsMap);
72
73         }
74
75     public String getFormattedMessageWithCode(Params params){
76         return getResponseCode()+"-" + getFormattedMessage(params);
77     }
78
79     @Override
80     public String toString() {
81         return "OAMCommandStatus{" +
82                 "responseCode=" + responseCode +
83                 ", responseMessage='" + responseMessage + '\'' +
84                 '}';
85     }
86 }
87