[SDC-29] rebase continue work to align source
[sdc.git] / catalog-model / src / main / java / org / openecomp / sdc / be / model / PropertyDefinition.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
21 package org.openecomp.sdc.be.model;
22
23 import java.io.Serializable;
24 import java.util.List;
25 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
26
27
28 public class PropertyDefinition extends PropertyDataDefinition
29                 implements IOperationParameter, IComplexDefaultValue, Serializable {
30
31         
32         /**The enumeration presents the list of property names with specific behavior 
33          * @author rbetzer
34          *
35          */
36         public enum PropertyNames {
37                 
38                 MIN_INSTANCES("min_vf_module_instances", GroupInstancePropertyValueUpdateBehavior.UPDATABLE_ON_SERVICE_LEVEL),
39                 MAX_INSTANCES("max_vf_module_instances", GroupInstancePropertyValueUpdateBehavior.UPDATABLE_ON_SERVICE_LEVEL),
40                 INITIAL_COUNT("initial_count", GroupInstancePropertyValueUpdateBehavior.UPDATABLE_ON_SERVICE_LEVEL),
41                 VF_MODULE_LABEL("vf_module_label", GroupInstancePropertyValueUpdateBehavior.UPDATABLE_ON_RESOURCE_LEVEL),
42                 VF_MODULE_DESCRIPTION("vf_module_description", GroupInstancePropertyValueUpdateBehavior.UPDATABLE_ON_RESOURCE_LEVEL),
43                 NETWORK_ROLE("network_role", GroupInstancePropertyValueUpdateBehavior.NOT_RELEVANT),
44                 AVAILABILTY_ZONE_COUNT("availability_zone_count", GroupInstancePropertyValueUpdateBehavior.UPDATABLE_ON_SERVICE_LEVEL),
45                 VFC_LIST("vfc_list", GroupInstancePropertyValueUpdateBehavior.UPDATABLE_ON_SERVICE_LEVEL);
46                 
47                 private String propertyName;
48                 private GroupInstancePropertyValueUpdateBehavior updateBehavior;
49                 
50                 private PropertyNames(String propertyName,GroupInstancePropertyValueUpdateBehavior updateBehavior){
51                         this.propertyName = propertyName;
52                         this.updateBehavior = updateBehavior;
53                 }
54                 
55                 public String getPropertyName() {
56                         return propertyName;
57                 }
58                 
59                 public GroupInstancePropertyValueUpdateBehavior getUpdateBehavior() {
60                         return updateBehavior;
61                 }
62                 /**
63                  * finds PropertyNames according received string name
64                  * @param name
65                  * @return
66                  */
67                 public static PropertyNames findName(String name){
68                         for (PropertyNames e : PropertyNames.values()) {
69                                 if (e.getPropertyName().equals(name)) {
70                                         return e;
71                                 }
72                         }
73                         return null;
74                 }
75         }
76         /**
77          * The enumeration presents the list of highest levels for which update property value is allowed
78          * @author nsheshukov
79          *
80          */
81         public enum GroupInstancePropertyValueUpdateBehavior{
82                 NOT_RELEVANT("NOT_RELEVANT", -1),
83                 UPDATABLE_ON_RESOURCE_LEVEL("UPDATABLE_ON_VF_LEVEL", 0),
84                 UPDATABLE_ON_SERVICE_LEVEL("UPDATABLE_ON_SERVICE_LEVEL", 1);
85                 
86                 String levelName;
87                 int levelNumber;
88                 
89                 private GroupInstancePropertyValueUpdateBehavior(String name, int levelNumber){
90                         this.levelName = name;
91                         this.levelNumber = levelNumber;
92                 }
93
94                 public String getLevelName() {
95                         return levelName;
96                 }
97
98                 public int getLevelNumber() {
99                         return levelNumber;
100                 }
101         }
102         
103         private static final long serialVersionUID = 188403656600317269L;
104
105         private List<PropertyConstraint> constraints;
106         // private Schema schema;
107         // private String status;
108
109
110
111         
112         public PropertyDefinition() {
113                 super();
114         }
115
116         public PropertyDefinition(PropertyDataDefinition p) {
117                 super(p);
118         }
119
120         public PropertyDefinition(PropertyDefinition pd) {
121                 super(pd);      
122                 this.setConstraints(pd.getConstraints());               
123                 //status = pd.status;
124                 
125         }
126
127         public List<PropertyConstraint> getConstraints() {
128                 return constraints;
129         }
130
131         public void setConstraints(List<PropertyConstraint> constraints) {
132                 this.constraints = constraints;
133         }
134
135
136
137         @Override
138         public String toString() {
139                 return super.toString() + " [name=" + getName() + ", constraints="
140                                 + constraints + "]]";
141         }
142
143         // public void setSchema(Schema entrySchema) {
144         // this.schema = entrySchema;
145         //
146         // }
147         //
148         // public Schema getSchema() {
149         // return schema;
150         // }
151
152 //      public String getStatus() {
153 //              return status;
154 //      }
155 //
156 //      public void setStatus(String status) {
157 //              this.status = status;
158 //      }
159
160         
161
162         @Override
163         public boolean isDefinition() {
164                 return false;
165         }
166
167         public void setDefinition(boolean definition) {
168                 super.setDefinition(definition);
169         }
170
171         @Override
172         public int hashCode() {
173                 final int prime = 31;
174                 int result = super.hashCode();
175                 result = prime * result + ((constraints == null) ? 0 : constraints.hashCode());
176                 result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
177                 //result = prime * result + ((status == null) ? 0 : status.hashCode());
178                 return result;
179         }
180
181         @Override
182         public boolean equals(Object obj) {
183                 if (this == obj)
184                         return true;
185                 if (!super.equals(obj))
186                         return false;
187                 if (getClass() != obj.getClass())
188                         return false;
189                 PropertyDefinition other = (PropertyDefinition) obj;
190                 if (constraints == null) {
191                         if (other.constraints != null)
192                                 return false;
193                 } else if (!constraints.equals(other.constraints))
194                         return false;
195                 if (getName() == null) {
196                         if (other.getName() != null)
197                                 return false;
198                 } else if (!getName().equals(other.getName()))
199                         return false;
200 //              if (status == null) {
201 //                      if (other.status != null)
202 //                              return false;
203 //              } else if (!status.equals(other.status))
204 //                      return false;
205                 return true;
206         }
207
208 }