Fixed the Policy API issues and Bugfixes
[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         private String id = UUID.randomUUID().toString();
30         private String name;
31         private String description;
32         private String actor;
33         private String recipe;
34         private LinkedList<Constraint> limit_constraints;
35         
36         public GuardPolicy() {
37                 //Do Nothing Empty Constructor. 
38         }
39         
40         public String getId() {
41                 return id;
42         }
43
44         public void setId(String id) {
45                 this.id = id;
46         }
47
48         public String getName() {
49                 return name;
50         }
51
52         public void setName(String name) {
53                 this.name = name;
54         }
55
56         public String getDescription() {
57                 return description;
58         }
59
60         public void setDescription(String description) {
61                 this.description = description;
62         }
63
64         public String getActor() {
65                 return actor;
66         }
67
68         public void setActor(String actor) {
69                 this.actor = actor;
70         }
71
72         public String getRecipe() {
73                 return recipe;
74         }
75
76         public void setRecipe(String recipe) {
77                 this.recipe = recipe;
78         }
79
80         public LinkedList<Constraint> getLimit_constraints() {
81                 return  limit_constraints;
82         }
83
84         public void setLimit_constraints(LinkedList<Constraint> limit_constraints) {
85                 this.limit_constraints = limit_constraints;
86         }
87
88         public GuardPolicy(String id) {
89                 this.id = id;
90         }
91         
92         public GuardPolicy(String name, String actor, String recipe) {
93                 this.name = name;
94                 this.actor = actor;
95                 this.recipe = recipe;
96         }
97         
98         public GuardPolicy(String id, String name, String description, String actor, String recipe) {
99                 this(name, actor, recipe);
100                 this.id = id;
101                 this.description = description;
102         }
103         
104         public GuardPolicy(String name, String actor, String recipe, List<Constraint> limit_constraints) {
105                 this(name, actor, recipe);
106                 if (limit_constraints != null) {
107                         this.limit_constraints = (LinkedList<Constraint>) Collections.unmodifiableList(limit_constraints);
108                 }
109         }
110         
111         public GuardPolicy(String name, String description, String actor, String recipe, List<Constraint> limit_constraints) {
112                 this(name, actor, recipe, limit_constraints);
113                 this.description = description;
114         }
115         
116         public GuardPolicy(String id, String name, String description, String actor, String recipe, List<Constraint> limit_constraints) {
117                 this(name, description, actor, recipe, limit_constraints);
118                 this.id = id;
119         }
120         
121         public GuardPolicy(GuardPolicy policy) {
122                 this.id = policy.id;
123                 this.name = policy.name;
124                 this.description = policy.description;
125                 this.actor = policy.actor;
126                 this.recipe = policy.recipe;
127                 if (policy.limit_constraints != null) {
128                         this.limit_constraints = (LinkedList<Constraint>) Collections.unmodifiableList(policy.limit_constraints);
129                 }
130         }
131         
132         public boolean isValid() {
133                 if(id==null || name ==null|| actor==null|| recipe==null){
134                         return false;
135                 }
136                 return true;
137         }
138         
139         @Override
140         public String toString() {
141                 return "Policy [id=" + id + ", name=" + name + ", description=" + description + ", actor=" + actor + ", recipe="
142                                 + recipe + ", limitConstraints=" + limit_constraints + "]";
143         }
144
145         @Override
146         public int hashCode() {
147                 final int prime = 31;
148                 int result = 1;
149                 result = prime * result + ((actor == null) ? 0 : actor.hashCode());
150                 result = prime * result + ((description == null) ? 0 : description.hashCode());
151                 result = prime * result + ((id == null) ? 0 : id.hashCode());
152                 result = prime * result + ((name == null) ? 0 : name.hashCode());
153                 result = prime * result + ((limit_constraints == null) ? 0 : limit_constraints.hashCode());
154                 result = prime * result + ((recipe == null) ? 0 : recipe.hashCode());
155                 return result;
156         }
157
158         @Override
159         public boolean equals(Object obj) {
160                 if (this == obj)
161                         return true;
162                 if (obj == null)
163                         return false;
164                 if (getClass() != obj.getClass())
165                         return false;
166                 GuardPolicy other = (GuardPolicy) obj;
167                 if (actor == null) {
168                         if (other.actor != null) 
169                                 return false;
170                 } else if (!actor.equals(other.actor))
171                         return false;
172                 if (description == null) {
173                         if (other.description != null)
174                                 return false;
175                 } else if (!description.equals(other.description))
176                         return false;
177                 if (id == null) {
178                         if (other.id != null)
179                                 return false;
180                 } else if (!id.equals(other.id))
181                         return false;
182                 if (name == null) {
183                         if (other.name != null)
184                                 return false;
185                 } else if (!name.equals(other.name))
186                         return false;
187                 if (limit_constraints == null) {
188                         if (other.limit_constraints != null)
189                                 return false;
190                 } else if (!limit_constraints.equals(other.limit_constraints))
191                         return false;
192                 if (recipe == null) {
193                         if (other.recipe != null)
194                                 return false;
195                 } else if (!recipe.equals(other.recipe))
196                         return false;
197                 return true;
198         }
199         
200         
201 }