Merge "Add debugging of REST call"
[policy/drools-applications.git] / controlloop / common / policy-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  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.controlloop.policy;
22
23 public enum FinalResult {
24     /**
25      * The Control Loop Policy successfully completed its Operations.
26      */
27     FINAL_SUCCESS("Final_Success"),
28     /**
29      * The Control Loop Policy was an Open Loop and is finished.
30      */
31     FINAL_OPENLOOP("Final_OpenLoop"),
32     /**
33      * The Control Loop Policy failed in its last Operation Policy. 
34      * NOTE: Previous Operation Policies may have been successful.
35      */
36     FINAL_FAILURE("Final_Failure"),
37     /**
38      * The Control Loop Policy failed because the overall timeout was met.
39      */
40     FINAL_FAILURE_TIMEOUT("Final_Failure_Timeout"),
41     /**
42      * The Control Loop Policy failed because an Operation Policy met its retry limit.
43      */
44     FINAL_FAILURE_RETRIES("Final_Failure_Retries"),
45     /**
46      * The Control Loop Policy failed due to an exception.
47      */
48     FINAL_FAILURE_EXCEPTION("Final_Failure_Exception"), 
49     /**
50      *  The Control Loop Policy failed due to guard denied.
51      */
52     FINAL_FAILURE_GUARD("Final_Failure_Guard")
53     ;
54     
55     String result;
56     
57     private FinalResult(String result) {
58         this.result = result;
59     }
60     
61     /**
62      * Converts to a result object.
63      * 
64      * @param result input string
65      * @return result object
66      */
67     public static FinalResult toResult(String result) {
68         if (result.equalsIgnoreCase(FINAL_SUCCESS.toString())) {
69             return FINAL_SUCCESS;
70         }
71         if (result.equalsIgnoreCase(FINAL_OPENLOOP.toString())) {
72             return FINAL_OPENLOOP;
73         }
74         if (result.equalsIgnoreCase(FINAL_FAILURE.toString())) {
75             return FINAL_FAILURE;
76         }
77         if (result.equalsIgnoreCase(FINAL_FAILURE_TIMEOUT.toString())) {
78             return FINAL_FAILURE_TIMEOUT;
79         }
80         if (result.equalsIgnoreCase(FINAL_FAILURE_RETRIES.toString())) {
81             return FINAL_FAILURE_RETRIES;
82         }
83         if (result.equalsIgnoreCase(FINAL_FAILURE_EXCEPTION.toString())) {
84             return FINAL_FAILURE_EXCEPTION;
85         }
86         if (result.equalsIgnoreCase(FINAL_FAILURE_GUARD.toString())) {
87             return FINAL_FAILURE_GUARD;
88         }
89         return null;
90     }
91     
92     /**
93      * Check if the result really is a result.
94      * 
95      * @param result string
96      * @param finalResult result object
97      * @return true if a result
98      */
99     public static boolean isResult(String result, FinalResult finalResult) {
100         FinalResult toResult = FinalResult.toResult(result);
101         if (toResult == null) {
102             return false;
103         }
104         return toResult.equals(finalResult);
105     }
106
107 }