bd49484bd7adf072ae78ec237bca04f9aa37bb36
[policy/models.git] / models-interactions / model-yaml / src / main / java / org / onap / policy / controlloop / policy / FinalResult.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * policy-yaml
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2019 Nordix Foundation.
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.onap.policy.controlloop.policy;
23
24 public enum FinalResult {
25     /**
26      * The Control Loop Policy successfully completed its Operations.
27      */
28     FINAL_SUCCESS("Final_Success"),
29     /**
30      * The Control Loop Policy was an Open Loop and is finished.
31      */
32     FINAL_OPENLOOP("Final_OpenLoop"),
33     /**
34      * The Control Loop Policy failed in its last Operation Policy. 
35      * NOTE: Previous Operation Policies may have been successful.
36      */
37     FINAL_FAILURE("Final_Failure"),
38     /**
39      * The Control Loop Policy failed because the overall timeout was met.
40      */
41     FINAL_FAILURE_TIMEOUT("Final_Failure_Timeout"),
42     /**
43      * The Control Loop Policy failed because an Operation Policy met its retry limit.
44      */
45     FINAL_FAILURE_RETRIES("Final_Failure_Retries"),
46     /**
47      * The Control Loop Policy failed due to an exception.
48      */
49     FINAL_FAILURE_EXCEPTION("Final_Failure_Exception"), 
50     /**
51      *  The Control Loop Policy failed due to guard denied.
52      */
53     FINAL_FAILURE_GUARD("Final_Failure_Guard")
54     ;
55     
56     String result;
57     
58     private FinalResult(String result) {
59         this.result = result;
60     }
61     
62     /**
63      * Converts to a result object.
64      * 
65      * @param result input string
66      * @return result object
67      */
68     public static FinalResult toResult(String result) {
69         if (result.equalsIgnoreCase(FINAL_SUCCESS.toString())) {
70             return FINAL_SUCCESS;
71         }
72         if (result.equalsIgnoreCase(FINAL_OPENLOOP.toString())) {
73             return FINAL_OPENLOOP;
74         }
75         if (result.equalsIgnoreCase(FINAL_FAILURE.toString())) {
76             return FINAL_FAILURE;
77         }
78         if (result.equalsIgnoreCase(FINAL_FAILURE_TIMEOUT.toString())) {
79             return FINAL_FAILURE_TIMEOUT;
80         }
81         if (result.equalsIgnoreCase(FINAL_FAILURE_RETRIES.toString())) {
82             return FINAL_FAILURE_RETRIES;
83         }
84         if (result.equalsIgnoreCase(FINAL_FAILURE_EXCEPTION.toString())) {
85             return FINAL_FAILURE_EXCEPTION;
86         }
87         if (result.equalsIgnoreCase(FINAL_FAILURE_GUARD.toString())) {
88             return FINAL_FAILURE_GUARD;
89         }
90         return null;
91     }
92     
93     /**
94      * Check if the result really is a result.
95      * 
96      * @param result string
97      * @param finalResult result object
98      * @return true if a result
99      */
100     public static boolean isResult(String result, FinalResult finalResult) {
101         FinalResult toResult = FinalResult.toResult(result);
102         if (toResult == null) {
103             return false;
104         }
105         return toResult.equals(finalResult);
106     }
107
108 }