re base code
[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 org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
24
25 import java.util.List;
26
27
28 public class PropertyDefinition extends PropertyDataDefinition
29         implements IOperationParameter, IComplexDefaultValue {
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 List<PropertyConstraint> constraints;
104
105     public PropertyDefinition() {
106         super();
107     }
108
109     public PropertyDefinition(PropertyDataDefinition p) {
110         super(p);
111     }
112
113     public PropertyDefinition(PropertyDefinition pd) {
114         super(pd);
115         this.setConstraints(pd.getConstraints());
116     }
117
118     public List<PropertyConstraint> getConstraints() {
119         return constraints;
120     }
121
122     public void setConstraints(List<PropertyConstraint> constraints) {
123         this.constraints = constraints;
124     }
125
126
127
128     @Override
129     public String toString() {
130         return  "PropertyDefinition [ " + super.toString() + ", name=" + getName() + ", constraints="
131                 + constraints + "]]";
132     }
133
134     @Override
135     public boolean isDefinition() {
136         return false;
137     }
138
139     @Override
140     public int hashCode() {
141         final int prime = 31;
142         int result = super.hashCode();
143         result = prime * result + ((constraints == null) ? 0 : constraints.hashCode());
144         result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
145         return result;
146     }
147
148     @Override
149     public boolean equals(Object obj) {
150         if (this == obj)
151             return true;
152         if (!super.equals(obj))
153             return false;
154         if (getClass() != obj.getClass())
155             return false;
156         PropertyDefinition other = (PropertyDefinition) obj;
157         if (constraints == null) {
158             if (other.constraints != null)
159                 return false;
160         } else if (!constraints.equals(other.constraints))
161             return false;
162         if (getName() == null) {
163             if (other.getName() != null)
164                 return false;
165         } else if (!getName().equals(other.getName()))
166             return false;
167         return true;
168     }
169
170 }