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