push addional code
[sdc.git] / openecomp-be / lib / openecomp-sdc-vendor-license-lib / openecomp-sdc-vendor-license-api / src / main / java / org / openecomp / sdc / vendorlicense / dao / types / EntitlementPoolEntity.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.vendorlicense.dao.types;
22
23 import com.datastax.driver.mapping.annotations.ClusteringColumn;
24 import com.datastax.driver.mapping.annotations.Column;
25 import com.datastax.driver.mapping.annotations.Enumerated;
26 import com.datastax.driver.mapping.annotations.Frozen;
27 import com.datastax.driver.mapping.annotations.PartitionKey;
28 import com.datastax.driver.mapping.annotations.Table;
29 import org.openecomp.sdc.vendorlicense.dao.types.xml.AggregationFunctionForXml;
30 import org.openecomp.sdc.vendorlicense.dao.types.xml.EntitlementMetricForXml;
31 import org.openecomp.sdc.vendorlicense.dao.types.xml.EntitlementTimeForXml;
32 import org.openecomp.sdc.vendorlicense.dao.types.xml.ThresholdForXml;
33 import org.openecomp.sdc.versioning.dao.types.Version;
34 import org.openecomp.sdc.versioning.dao.types.VersionableEntity;
35
36 import java.util.HashSet;
37 import java.util.Objects;
38 import java.util.Set;
39
40 @Table(keyspace = "dox", name = "entitlement_pool")
41 public class EntitlementPoolEntity implements VersionableEntity {
42   private static final String ENTITY_TYPE = "Entitlement Pool";
43
44   @PartitionKey
45   @Column(name = "vlm_id")
46   private String vendorLicenseModelId;
47
48   @PartitionKey(value = 1)
49   @Frozen
50   private Version version;
51
52   @ClusteringColumn
53   @Column(name = "ep_id")
54   private String id;
55   private String name;
56   private String description;
57
58
59   @Column(name = "threshold")
60   private int thresholdValue;
61
62   @Column(name = "threshold_unit")
63   @Enumerated
64   private ThresholdUnit thresholdUnit;
65
66   @Column(name = "entitlement_metric")
67   @Frozen
68   private ChoiceOrOther<EntitlementMetric> entitlementMetric;
69   private String increments;
70
71   @Column(name = "aggregation_func")
72   @Frozen
73   private ChoiceOrOther<AggregationFunction> aggregationFunction;
74
75   @Column(name = "operational_scope")
76   @Frozen
77   private MultiChoiceOrOther<OperationalScope> operationalScope;
78
79   @Frozen
80   private ChoiceOrOther<EntitlementTime> time;
81
82   @Column(name = "manufacturer_ref_num")
83   private String manufacturerReferenceNumber;
84
85   @Column(name = "ref_fg_ids")
86   private Set<String> referencingFeatureGroups = new HashSet<>();
87
88   @Column(name = "version_uuid")
89   private String versionUuId;
90
91   public EntitlementPoolEntity() {
92   }
93
94   /**
95    * Instantiates a new Entitlement pool entity.
96    *
97    * @param vlmId   the vlm id
98    * @param version the version
99    * @param id      the id
100    */
101   public EntitlementPoolEntity(String vlmId, Version version, String id) {
102     this.vendorLicenseModelId = vlmId;
103     this.version = version;
104     this.id = id;
105   }
106
107   @Override
108   public String getEntityType() {
109     return ENTITY_TYPE;
110   }
111
112   @Override
113   public String getFirstClassCitizenId() {
114     return getVendorLicenseModelId();
115   }
116
117   public String getVendorLicenseModelId() {
118     return vendorLicenseModelId;
119   }
120
121   public void setVendorLicenseModelId(String vendorLicenseModelId) {
122     this.vendorLicenseModelId = vendorLicenseModelId;
123   }
124
125   @Override
126   public String getId() {
127     return id;
128   }
129
130   @Override
131   public void setId(String id) {
132     this.id = id;
133   }
134
135   @Override
136   public Version getVersion() {
137     return version;
138   }
139
140   @Override
141   public void setVersion(Version version) {
142     this.version = version;
143   }
144
145   public Set<String> getReferencingFeatureGroups() {
146     return referencingFeatureGroups;
147   }
148
149   public void setReferencingFeatureGroups(Set<String> referencingFeatureGroups) {
150     this.referencingFeatureGroups = referencingFeatureGroups;
151   }
152
153   public String getName() {
154     return name;
155   }
156
157   public void setName(String name) {
158     this.name = name;
159   }
160
161   public String getDescription() {
162     return description;
163   }
164
165   public void setDescription(String description) {
166     this.description = description;
167   }
168
169   public int getThresholdValue() {
170     return thresholdValue;
171   }
172
173   public void setThresholdValue(int thresholdValue) {
174     this.thresholdValue = thresholdValue;
175   }
176
177   public ThresholdUnit getThresholdUnit() {
178     return thresholdUnit;
179   }
180
181   public void setThresholdUnit(ThresholdUnit thresholdUnits) {
182     this.thresholdUnit = thresholdUnits;
183   }
184
185   public ChoiceOrOther<EntitlementMetric> getEntitlementMetric() {
186     return entitlementMetric;
187   }
188
189   public void setEntitlementMetric(ChoiceOrOther<EntitlementMetric> entitlementMetric) {
190     entitlementMetric.resolveEnum(EntitlementMetric.class);
191     this.entitlementMetric = entitlementMetric;
192   }
193
194   public String getIncrements() {
195     return increments;
196   }
197
198   public void setIncrements(String increments) {
199     this.increments = increments;
200   }
201
202   public ChoiceOrOther<AggregationFunction> getAggregationFunction() {
203     return aggregationFunction;
204   }
205
206   public void setAggregationFunction(ChoiceOrOther<AggregationFunction> aggregationFunction) {
207     aggregationFunction.resolveEnum(AggregationFunction.class);
208     this.aggregationFunction = aggregationFunction;
209   }
210
211   public MultiChoiceOrOther<OperationalScope> getOperationalScope() {
212     return operationalScope;
213   }
214
215   public void setOperationalScope(MultiChoiceOrOther<OperationalScope> operationalScope) {
216     operationalScope.resolveEnum(OperationalScope.class);
217     this.operationalScope = operationalScope;
218   }
219
220   public ChoiceOrOther<EntitlementTime> getTime() {
221     return time;
222   }
223
224   public void setTime(ChoiceOrOther<EntitlementTime> time) {
225     time.resolveEnum(EntitlementTime.class);
226     this.time = time;
227   }
228
229   public String getManufacturerReferenceNumber() {
230     return manufacturerReferenceNumber;
231   }
232
233   public void setManufacturerReferenceNumber(String manufacturerReferenceNumber) {
234     this.manufacturerReferenceNumber = manufacturerReferenceNumber;
235   }
236
237
238   /**
239    * Gets threshold for artifact.
240    *
241    * @return the threshold for artifact
242    */
243   //util methods for XML
244   public ThresholdForXml getThresholdForArtifact() {
245     ThresholdForXml threshold = new ThresholdForXml();
246     threshold.setUnit(getThresholdUnit() == null ? null : getThresholdUnit().name());
247     threshold.setValue(getThresholdValue());
248     return threshold;
249   }
250
251   /**
252    * Gets entitlement metric for artifact.
253    *
254    * @return the entitlement metric for artifact
255    */
256   public EntitlementMetricForXml getEntitlementMetricForArtifact() {
257     EntitlementMetricForXml metric = new EntitlementMetricForXml();
258     if (entitlementMetric != null) {
259       metric.setValue(entitlementMetric.getResult());
260     } else {
261       metric.setValue(null);
262     }
263     return metric;
264   }
265
266   /**
267    * Gets time for artifact.
268    *
269    * @return the time for artifact
270    */
271   public EntitlementTimeForXml getTimeForArtifact() {
272     EntitlementTimeForXml timeForXml = new EntitlementTimeForXml();
273     if (time != null) {
274       timeForXml.setValue(time.getResult());
275     }
276
277     return timeForXml;
278   }
279
280
281   @Override
282   public String toString() {
283     return "EntitlementPoolEntity{"
284         + "vendorLicenseModelId='" + vendorLicenseModelId + '\''
285         + ", version=" + version
286         + ", id='" + id + '\''
287         + ", name='" + name + '\''
288         + ", description='" + description + '\''
289         + ", thresholdValue=" + thresholdValue
290         + ", thresholdUnit='" + thresholdUnit + '\''
291         + ", entitlementMetric=" + entitlementMetric
292         + ", increments='" + increments + '\''
293         + ", aggregationFunction=" + aggregationFunction
294         + ", operationalScope=" + operationalScope
295         + ", time=" + time
296         + ", manufacturerReferenceNumber='" + manufacturerReferenceNumber + '\''
297         + ", referencingFeatureGroups=" + referencingFeatureGroups
298         + ", version_uuid=" + versionUuId
299         + '}';
300   }
301
302   @Override
303   public boolean equals(Object obj) {
304     if (this == obj) {
305       return true;
306     }
307     if (obj == null || getClass() != obj.getClass()) {
308       return false;
309     }
310     EntitlementPoolEntity that = (EntitlementPoolEntity) obj;
311     return Float.compare(that.thresholdValue, thresholdValue) == 0
312         && Objects.equals(vendorLicenseModelId, that.vendorLicenseModelId)
313         && Objects.equals(version, that.version)
314         && Objects.equals(id, that.id)
315         && Objects.equals(name, that.name)
316         && Objects.equals(description, that.description)
317         && Objects.equals(thresholdUnit, that.thresholdUnit)
318         && Objects.equals(entitlementMetric, that.entitlementMetric)
319         && Objects.equals(increments, that.increments)
320         && Objects.equals(aggregationFunction, that.aggregationFunction)
321         && Objects.equals(operationalScope, that.operationalScope)
322         && Objects.equals(time, that.time)
323         && Objects.equals(manufacturerReferenceNumber, that.manufacturerReferenceNumber)
324         && Objects.equals(referencingFeatureGroups, that.referencingFeatureGroups);
325   }
326
327   @Override
328   public int hashCode() {
329     return Objects
330         .hash(vendorLicenseModelId, version, id, name, description, thresholdValue, thresholdUnit,
331             entitlementMetric, increments, aggregationFunction, operationalScope, time,
332             manufacturerReferenceNumber, referencingFeatureGroups);
333   }
334
335   /**
336    * Gets aggregation function for artifact.
337    *
338    * @return the aggregation function for artifact
339    */
340   public AggregationFunctionForXml getAggregationFunctionForArtifact() {
341     AggregationFunctionForXml aggregationFunctionForXml = new AggregationFunctionForXml();
342     if (entitlementMetric != null) {
343       aggregationFunctionForXml.setValue(aggregationFunction.getResult());
344     } else {
345       aggregationFunctionForXml.setValue(null);
346     }
347     return aggregationFunctionForXml;
348   }
349
350   /**
351    * Gets operational scope for artifact.
352    *
353    * @return the operational scope for artifact
354    */
355   public Set<String> getOperationalScopeForArtifact() {
356     if (operationalScope != null) {
357       return operationalScope.getResults();
358     } else {
359       return null;
360     }
361   }
362
363   public String getVersionUuId() {
364     return versionUuId;
365   }
366
367   public void setVersionUuId(String uuId) {
368     versionUuId = uuId;
369   }
370 }