[SDC] Onboarding 1710 rebase.
[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.vendorlicense.dao.types.xml.LimitXml;
34 import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitForXml;
35 import org.openecomp.sdc.versioning.dao.types.Version;
36 import org.openecomp.sdc.versioning.dao.types.VersionableEntity;
37
38 import java.util.Collection;
39 import java.util.HashSet;
40 import java.util.Objects;
41 import java.util.Set;
42
43 @Table(keyspace = "dox", name = "entitlement_pool")
44 public class EntitlementPoolEntity implements VersionableEntity {
45   private static final String ENTITY_TYPE = "Entitlement Pool";
46
47   @PartitionKey
48   @Column(name = "vlm_id")
49   private String vendorLicenseModelId;
50
51   @PartitionKey(value = 1)
52   @Frozen
53   private Version version;
54
55   @ClusteringColumn
56   @Column(name = "ep_id")
57   private String id;
58   private String name;
59   private String description;
60
61   @Column(name = "threshold")
62   private Integer thresholdValue;
63
64   @Column(name = "threshold_unit")
65   @Enumerated
66   private ThresholdUnit thresholdUnit;
67
68   @Column(name = "entitlement_metric")
69   @Frozen
70   private ChoiceOrOther<EntitlementMetric> entitlementMetric;
71   private String increments;
72
73   @Column(name = "aggregation_func")
74   @Frozen
75   private ChoiceOrOther<AggregationFunction> aggregationFunction;
76
77   @Column(name = "operational_scope")
78   @Frozen
79   private MultiChoiceOrOther<OperationalScope> operationalScope;
80
81   @Frozen
82   private ChoiceOrOther<EntitlementTime> time;
83
84   @Column(name = "manufacturer_ref_num")
85   private String manufacturerReferenceNumber;
86
87   @Column(name = "ref_fg_ids")
88   private Set<String> referencingFeatureGroups = new HashSet<>();
89
90   @Column(name = "version_uuid")
91   private String versionUuId;
92
93
94   private String startDate;
95   private String expiryDate;
96
97   private Collection<LimitEntity> limits;
98
99   public EntitlementPoolEntity() {
100   }
101
102   /**
103    * Instantiates a new Entitlement pool entity.
104    *
105    * @param vlmId   the vlm id
106    * @param version the version
107    * @param id      the id
108    */
109   public EntitlementPoolEntity(String vlmId, Version version, String id) {
110     this.vendorLicenseModelId = vlmId;
111     this.version = version;
112     this.id = id;
113   }
114
115   @Override
116   public String getEntityType() {
117     return ENTITY_TYPE;
118   }
119
120   @Override
121   public String getFirstClassCitizenId() {
122     return getVendorLicenseModelId();
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   @Override
146   public String getVersionUuId() {
147     return versionUuId;
148   }
149
150   @Override
151   public void setVersionUuId(String uuId) {
152     versionUuId = uuId;
153   }
154
155   public String getVendorLicenseModelId() {
156     return vendorLicenseModelId;
157   }
158
159   public void setVendorLicenseModelId(String vendorLicenseModelId) {
160     this.vendorLicenseModelId = vendorLicenseModelId;
161   }
162
163   public Set<String> getReferencingFeatureGroups() {
164     return referencingFeatureGroups;
165   }
166
167   public void setReferencingFeatureGroups(Set<String> referencingFeatureGroups) {
168     this.referencingFeatureGroups = referencingFeatureGroups;
169   }
170
171   public String getName() {
172     return name;
173   }
174
175   public void setName(String name) {
176     this.name = name;
177   }
178
179   public String getDescription() {
180     return description;
181   }
182
183   public void setDescription(String description) {
184     this.description = description;
185   }
186
187   public Integer getThresholdValue() {
188     return thresholdValue;
189   }
190
191   public void setThresholdValue(Integer thresholdValue) {
192     this.thresholdValue = thresholdValue;
193   }
194
195   public ThresholdUnit getThresholdUnit() {
196     return thresholdUnit;
197   }
198
199   public void setThresholdUnit(ThresholdUnit thresholdUnits) {
200     this.thresholdUnit = thresholdUnits;
201   }
202
203   public ChoiceOrOther<EntitlementMetric> getEntitlementMetric() {
204     return entitlementMetric;
205   }
206
207   public void setEntitlementMetric(ChoiceOrOther<EntitlementMetric> entitlementMetric) {
208     entitlementMetric.resolveEnum(EntitlementMetric.class);
209     this.entitlementMetric = entitlementMetric;
210   }
211
212   public String getIncrements() {
213     return increments;
214   }
215
216   public void setIncrements(String increments) {
217     this.increments = increments;
218   }
219
220   public ChoiceOrOther<AggregationFunction> getAggregationFunction() {
221     return aggregationFunction;
222   }
223
224   public void setAggregationFunction(ChoiceOrOther<AggregationFunction> aggregationFunction) {
225     aggregationFunction.resolveEnum(AggregationFunction.class);
226     this.aggregationFunction = aggregationFunction;
227   }
228
229   public MultiChoiceOrOther<OperationalScope> getOperationalScope() {
230     return operationalScope;
231   }
232
233   public void setOperationalScope(MultiChoiceOrOther<OperationalScope> operationalScope) {
234     if(operationalScope != null) {
235       operationalScope.resolveEnum(OperationalScope.class);
236     }
237     this.operationalScope = operationalScope;
238   }
239
240   public ChoiceOrOther<EntitlementTime> getTime() {
241     return time;
242   }
243
244   public void setTime(ChoiceOrOther<EntitlementTime> time) {
245     time.resolveEnum(EntitlementTime.class);
246     this.time = time;
247   }
248
249   public String getManufacturerReferenceNumber() {
250     return manufacturerReferenceNumber;
251   }
252
253   public void setManufacturerReferenceNumber(String manufacturerReferenceNumber) {
254     this.manufacturerReferenceNumber = manufacturerReferenceNumber;
255   }
256
257   /**
258    * Gets threshold for artifact.
259    *
260    * @return the threshold for artifact
261    */
262   public ThresholdForXml getThresholdForArtifact() {
263     ThresholdForXml threshold = new ThresholdForXml();
264     threshold.setUnit(getThresholdUnit() == null ? null : getThresholdUnit().name());
265     threshold.setValue(getThresholdValue());
266     return threshold;
267   }
268
269   /**
270    *  Gets version for artifact.
271    * @return version in format suitable for artifact
272    */
273   public String getVersionForArtifact() {
274     return version.toString();
275   }
276
277   /**
278    * Gets entitlement metric for artifact.
279    *
280    * @return the entitlement metric for artifact
281    */
282   public EntitlementMetricForXml getEntitlementMetricForArtifact() {
283     EntitlementMetricForXml metric = new EntitlementMetricForXml();
284     if (entitlementMetric != null) {
285       metric.setValue(entitlementMetric.getResult());
286     } else {
287       metric.setValue(null);
288     }
289     return metric;
290   }
291
292   /**
293    * Gets time for artifact.
294    *
295    * @return the time for artifact
296    */
297   public EntitlementTimeForXml getTimeForArtifact() {
298     EntitlementTimeForXml timeForXml = new EntitlementTimeForXml();
299     if (time != null) {
300       timeForXml.setValue(time.getResult());
301     }
302
303     return timeForXml;
304   }
305
306   public String getStartDate() {
307     return startDate;
308   }
309
310   public void setStartDate(String startDate) {
311     this.startDate = startDate;
312   }
313
314   public String getExpiryDate() {
315     return expiryDate;
316   }
317
318   public void setExpiryDate(String expiryDate) {
319     this.expiryDate = expiryDate;
320   }
321
322   public Collection<LimitEntity> getLimits() {
323     return limits;
324   }
325
326   public void setLimits(Collection<LimitEntity> limits) {
327     this.limits = limits;
328   }
329
330   public LimitForXml getSPLimits(){
331     if(limits != null){
332       Set<LimitXml> hs = new HashSet<>();
333       for(LimitEntity obj : limits){
334         if(obj.getType().equals(LimitType.ServiceProvider)){
335           LimitXml xmlObj = new LimitXml();
336           xmlObj.setDescription(obj.getDescription());
337           xmlObj.setMetric(obj.getMetric().toString());
338           xmlObj.setValues(obj.getValue()!=null?Integer.toString(obj.getValue()):null);
339           xmlObj.setUnit(obj.getUnit()!=null?Integer.toString(obj.getUnit()):null);
340           xmlObj.setAggregationFunction(obj.getAggregationFunction()!=null?obj.getAggregationFunction().name():null);
341           xmlObj.setTime(obj.getTime()!=null?obj.getTime().name():null);
342           hs.add(xmlObj);
343         }
344       }
345       LimitForXml spLimitForXml = new LimitForXml();
346       spLimitForXml.setLimits(hs);
347       return spLimitForXml;
348     }
349
350     return null;
351   }
352
353   public LimitForXml getVendorLimits(){
354     if(limits != null){
355       Set<LimitXml> hs = new HashSet<>();
356       for(LimitEntity obj : limits){
357         if(obj.getType().equals(LimitType.Vendor)){
358           LimitXml xmlObj = new LimitXml();
359           xmlObj.setDescription(obj.getDescription());
360           xmlObj.setMetric(obj.getMetric().toString());
361           xmlObj.setValues(obj.getValue()!=null?Integer.toString(obj.getValue()):null);
362           xmlObj.setUnit(obj.getUnit()!=null?Integer.toString(obj.getUnit()):null);
363           xmlObj.setAggregationFunction(obj.getAggregationFunction()!=null?obj.getAggregationFunction().name():null);
364           xmlObj.setTime(obj.getTime()!=null?obj.getTime().name():null);
365           hs.add(xmlObj);
366         }
367       }
368       LimitForXml vendorLimitForXml = new LimitForXml();
369       vendorLimitForXml.setLimits(hs);
370       return vendorLimitForXml;
371     }
372
373     return null;
374   }
375
376
377   @Override
378   public int hashCode() {
379     return Objects
380         .hash(vendorLicenseModelId, version, id, name, description, thresholdValue, thresholdUnit,
381             entitlementMetric, increments, aggregationFunction, operationalScope, time,
382             manufacturerReferenceNumber, referencingFeatureGroups, startDate, expiryDate);
383   }
384
385   @Override
386   public boolean equals(Object obj) {
387     if (this == obj) {
388       return true;
389     }
390     if (obj == null || getClass() != obj.getClass()) {
391       return false;
392     }
393     EntitlementPoolEntity that = (EntitlementPoolEntity) obj;
394     return Objects.equals(that.thresholdValue, thresholdValue)
395         && Objects.equals(vendorLicenseModelId, that.vendorLicenseModelId)
396         && Objects.equals(id, that.id)
397         && Objects.equals(name, that.name)
398         && Objects.equals(description, that.description)
399         && Objects.equals(thresholdUnit, that.thresholdUnit)
400         && Objects.equals(entitlementMetric, that.entitlementMetric)
401         && Objects.equals(increments, that.increments)
402         && Objects.equals(aggregationFunction, that.aggregationFunction)
403         && Objects.equals(operationalScope, that.operationalScope)
404         && Objects.equals(time, that.time)
405         && Objects.equals(manufacturerReferenceNumber, that.manufacturerReferenceNumber)
406         && Objects.equals(referencingFeatureGroups, that.referencingFeatureGroups)
407         && Objects.equals(startDate, that.startDate)
408         && Objects.equals(expiryDate, that.expiryDate);
409   }
410
411   @Override
412   public String toString() {
413     return "EntitlementPoolEntity{"
414         + "vendorLicenseModelId='" + vendorLicenseModelId + '\''
415         + ", version=" + version
416         + ", id='" + id + '\''
417         + ", name='" + name + '\''
418         + ", description='" + description + '\''
419         + ", thresholdValue=" + thresholdValue
420         + ", thresholdUnit='" + thresholdUnit + '\''
421         + ", entitlementMetric=" + entitlementMetric
422         + ", increments='" + increments + '\''
423         + ", aggregationFunction=" + aggregationFunction
424         + ", operationalScope=" + operationalScope
425         + ", time=" + time
426         + ", manufacturerReferenceNumber='" + manufacturerReferenceNumber + '\''
427         + ", referencingFeatureGroups=" + referencingFeatureGroups
428         + ", version_uuid=" + versionUuId
429         + ", startDate=" + startDate
430         + ", expiryDate=" + expiryDate
431         + '}';
432   }
433
434   /**
435    * Gets aggregation function for artifact.
436    *
437    * @return the aggregation function for artifact
438    */
439   public AggregationFunctionForXml getAggregationFunctionForArtifact() {
440     AggregationFunctionForXml aggregationFunctionForXml = new AggregationFunctionForXml();
441     if (entitlementMetric != null) {
442       aggregationFunctionForXml.setValue(aggregationFunction.getResult());
443     } else {
444       aggregationFunctionForXml.setValue(null);
445     }
446     return aggregationFunctionForXml;
447   }
448
449   /**
450    * Gets operational scope for artifact.
451    *
452    * @return the operational scope for artifact
453    */
454   public Set<String> getOperationalScopeForArtifact() {
455     if (operationalScope != null) {
456       return operationalScope.getResults();
457     } else {
458       return null;
459     }
460   }
461 }