0195fac17217b7e2c38fd41f09f218c13890d442
[policy/engine.git] / ECOMP-ControlloopPolicy / src / main / java / org / openecomp / policy / controlloop / policy / guard / GuardPolicy.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.guard;
21
22 import java.util.Collections;
23 import java.util.LinkedList;
24 import java.util.List;
25 import java.util.UUID;
26
27 public class GuardPolicy {
28
29         public String id = UUID.randomUUID().toString();
30         public String name;
31         public String description;
32         public String actor;
33         public String recipe;
34         public LinkedList<Constraint> limit_constraints;
35         
36         public GuardPolicy() {
37                 
38         }
39         
40         public GuardPolicy(String id) {
41                 this.id = id;
42         }
43         
44         public GuardPolicy(String name, String actor, String recipe) {
45                 this.name = name;
46                 this.actor = actor;
47                 this.recipe = recipe;
48         }
49         
50         public GuardPolicy(String id, String name, String description, String actor, String recipe) {
51                 this(name, actor, recipe);
52                 this.id = id;
53                 this.description = description;
54         }
55         
56         public GuardPolicy(String name, String actor, String recipe, List<Constraint> limit_constraints) {
57                 this(name, actor, recipe);
58                 if (limit_constraints != null) {
59                         this.limit_constraints = (LinkedList<Constraint>) Collections.unmodifiableList(limit_constraints);
60                 }
61         }
62         
63         public GuardPolicy(String name, String description, String actor, String recipe, List<Constraint> limit_constraints) {
64                 this(name, actor, recipe, limit_constraints);
65                 this.description = description;
66         }
67         
68         public GuardPolicy(String id, String name, String description, String actor, String recipe, List<Constraint> limit_constraints) {
69                 this(name, description, actor, recipe, limit_constraints);
70                 this.id = id;
71         }
72         
73         public GuardPolicy(GuardPolicy policy) {
74                 this.id = policy.id;
75                 this.name = policy.name;
76                 this.description = policy.description;
77                 this.actor = policy.actor;
78                 this.recipe = policy.recipe;
79                 if (policy.limit_constraints != null) {
80                         this.limit_constraints = (LinkedList<Constraint>) Collections.unmodifiableList(policy.limit_constraints);
81                 }
82         }
83         
84         public boolean isValid() {
85                 try {
86                         if (id == null) {
87                                 throw new NullPointerException();
88                         }
89                         if (name == null) {
90                                 throw new NullPointerException();
91                         }
92                         if (actor == null) {
93                                 throw new NullPointerException();
94                         }
95                         if (recipe == null) {
96                                 throw new NullPointerException();
97                         }
98                 } catch (Exception e) {
99                         return false;
100                 }
101                 return true;
102         }
103         
104         @Override
105         public String toString() {
106                 return "Policy [id=" + id + ", name=" + name + ", description=" + description + ", actor=" + actor + ", recipe="
107                                 + recipe + ", limit_constraints=" + limit_constraints + "]";
108         }
109
110         @Override
111         public int hashCode() {
112                 final int prime = 31;
113                 int result = 1;
114                 result = prime * result + ((actor == null) ? 0 : actor.hashCode());
115                 result = prime * result + ((description == null) ? 0 : description.hashCode());
116                 result = prime * result + ((id == null) ? 0 : id.hashCode());
117                 result = prime * result + ((name == null) ? 0 : name.hashCode());
118                 result = prime * result + ((limit_constraints == null) ? 0 : limit_constraints.hashCode());
119                 result = prime * result + ((recipe == null) ? 0 : recipe.hashCode());
120                 return result;
121         }
122
123         @Override
124         public boolean equals(Object obj) {
125                 if (this == obj)
126                         return true;
127                 if (obj == null)
128                         return false;
129                 if (getClass() != obj.getClass())
130                         return false;
131                 GuardPolicy other = (GuardPolicy) obj;
132                 if (actor == null) {
133                         if (other.actor != null) 
134                                 return false;
135                 } else if (!actor.equals(other.actor))
136                         return false;
137                 if (description == null) {
138                         if (other.description != null)
139                                 return false;
140                 } else if (!description.equals(other.description))
141                         return false;
142                 if (id == null) {
143                         if (other.id != null)
144                                 return false;
145                 } else if (!id.equals(other.id))
146                         return false;
147                 if (name == null) {
148                         if (other.name != null)
149                                 return false;
150                 } else if (!name.equals(other.name))
151                         return false;
152                 if (limit_constraints == null) {
153                         if (other.limit_constraints != null)
154                                 return false;
155                 } else if (!limit_constraints.equals(other.limit_constraints))
156                         return false;
157                 if (recipe == null) {
158                         if (other.recipe != null)
159                                 return false;
160                 } else if (!recipe.equals(other.recipe))
161                         return false;
162                 return true;
163         }
164         
165         
166 }