Commit includes ControlLoopPolicy API and bugfixes
[policy/engine.git] / ECOMP-ControlloopPolicy / src / main / java / org / openecomp / policy / controlloop / policy / PolicyResult.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2017 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 package org.openecomp.policy.controlloop.policy;
21
22 public enum PolicyResult {
23         /**
24          * Operation was successful.
25          */
26         SUCCESS("Success"),
27         /**
28          * Operation failed.
29          */
30         FAILURE("Failure"),
31         /**
32          * Operation failed due to maximum retries being met.
33          */
34         FAILURE_RETRIES("Failure_Retries"),
35         /**
36          * Operation failed due to timeout occurring.
37          */
38         FAILURE_TIMEOUT("Failure_Timeout"),
39         /**
40          * Operation failed due to an exception.
41          */
42         FAILURE_EXCEPTION("Failure_Exception"), 
43         /**
44          * Operation failed since Guard did not permit.
45          */
46         FAILURE_GUARD("Failure_Guard")
47         ;
48         
49         private String result;
50         
51         private PolicyResult(String result) {
52                 this.result = result;
53         }
54         
55         @Override
56         public String toString() {
57                 return this.result;
58         }
59         
60         public static PolicyResult toResult(String result) {
61                 if (result.equalsIgnoreCase(SUCCESS.toString())) {
62                         return SUCCESS;
63                 }
64                 if (result.equalsIgnoreCase(FAILURE.toString())) {
65                         return FAILURE;
66                 }
67                 if (result.equalsIgnoreCase(FAILURE_RETRIES.toString())) {
68                         return FAILURE_RETRIES;
69                 }
70                 if (result.equalsIgnoreCase(FAILURE_TIMEOUT.toString())) {
71                         return FAILURE_TIMEOUT;
72                 }
73                 if (result.equalsIgnoreCase(FAILURE_EXCEPTION.toString())) {
74                         return FAILURE_EXCEPTION;
75                 }
76                 if (result.equalsIgnoreCase(FAILURE_GUARD.toString())) {
77                         return FAILURE_GUARD;
78                 }
79                 return null;
80         }
81
82 }