d76b434f291bce14d26b002974f70554fc976ae6
[sdc.git] /
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.apache.commons.lang3.StringUtils;
30 import org.openecomp.sdc.vendorlicense.VendorLicenseUtil;
31 import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitForXml;
32 import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitXml;
33 import org.openecomp.sdc.vendorlicense.dao.types.xml.OperationalScopeForXml;
34 import org.openecomp.sdc.vendorlicense.dao.types.xml.ThresholdForXml;
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   private String increments;
69
70   @Column(name = "operational_scope")
71   @Frozen
72   private MultiChoiceOrOther<OperationalScope> operationalScope;
73
74   @Column(name = "ref_fg_ids")
75   private Set<String> referencingFeatureGroups = new HashSet<>();
76
77   @Column(name = "version_uuid")
78   private String versionUuId;
79
80
81   private String startDate;
82   private String expiryDate;
83
84   private Collection<LimitEntity> limits;
85
86   //Defined and used only for License Artifcat XMLs
87   private String manufacturerReferenceNumber;
88
89   /**
90    * Every entity class must have a default constructor according to
91    * <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/object_mapper/creating/">
92    * Definition of mapped classes</a>.
93    */
94   public EntitlementPoolEntity() {
95     // Don't delete! Default constructor is required by DataStax driver
96   }
97
98   /**
99    * Instantiates a new Entitlement pool entity.
100    *
101    * @param vlmId   the vlm id
102    * @param version the version
103    * @param id      the id
104    */
105   public EntitlementPoolEntity(String vlmId, Version version, String id) {
106     this.vendorLicenseModelId = vlmId;
107     this.version = version;
108     this.id = id;
109   }
110
111   @Override
112   public String getEntityType() {
113     return ENTITY_TYPE;
114   }
115
116   @Override
117   public String getFirstClassCitizenId() {
118     return getVendorLicenseModelId();
119   }
120
121   @Override
122   public String getId() {
123     return id;
124   }
125
126   @Override
127   public void setId(String id) {
128     this.id = id;
129   }
130
131   @Override
132   public Version getVersion() {
133     return version;
134   }
135
136   @Override
137   public void setVersion(Version version) {
138     this.version = version;
139   }
140
141   @Override
142   public String getVersionUuId() {
143     return versionUuId;
144   }
145
146   @Override
147   public void setVersionUuId(String uuId) {
148     versionUuId = uuId;
149   }
150
151   public String getVendorLicenseModelId() {
152     return vendorLicenseModelId;
153   }
154
155   public void setVendorLicenseModelId(String vendorLicenseModelId) {
156     this.vendorLicenseModelId = vendorLicenseModelId;
157   }
158
159   public Set<String> getReferencingFeatureGroups() {
160     return referencingFeatureGroups;
161   }
162
163   public void setReferencingFeatureGroups(Set<String> referencingFeatureGroups) {
164     this.referencingFeatureGroups = referencingFeatureGroups;
165   }
166
167   public String getName() {
168     return name;
169   }
170
171   public void setName(String name) {
172     this.name = name;
173   }
174
175   public String getDescription() {
176     return description;
177   }
178
179   public void setDescription(String description) {
180     this.description = description;
181   }
182
183   public Integer getThresholdValue() {
184     return thresholdValue;
185   }
186
187   public void setThresholdValue(Integer thresholdValue) {
188     this.thresholdValue = thresholdValue;
189   }
190
191   public ThresholdUnit getThresholdUnit() {
192     return thresholdUnit;
193   }
194
195   public void setThresholdUnit(ThresholdUnit thresholdUnits) {
196     this.thresholdUnit = thresholdUnits;
197   }
198
199   public String getIncrements() {
200     return increments;
201   }
202
203   public void setIncrements(String increments) {
204     this.increments = increments;
205   }
206
207   public MultiChoiceOrOther<OperationalScope> getOperationalScope() {
208     return operationalScope;
209   }
210
211   public void setOperationalScope(MultiChoiceOrOther<OperationalScope> operationalScope) {
212     if (operationalScope != null) {
213       operationalScope.resolveEnum(OperationalScope.class);
214     }
215     this.operationalScope = operationalScope;
216   }
217
218   /**
219    * Gets threshold for artifact.
220    *
221    * @return the threshold for artifact
222    */
223   public ThresholdForXml getThresholdForArtifact() {
224     ThresholdForXml threshold = new ThresholdForXml();
225     threshold.setUnit(getThresholdUnit() == null ? null : getThresholdUnit().name());
226     threshold.setValue(getThresholdValue());
227     return threshold;
228   }
229
230   /**
231    * Gets version for artifact.
232    *
233    * @return version in format suitable for artifact
234    */
235   public String getVersionForArtifact() {
236     return version.toString();
237   }
238
239   public String getStartDate() {
240     return startDate;
241   }
242
243   public void setStartDate(String startDate) {
244     this.startDate = startDate;
245   }
246
247   public String getExpiryDate() {
248     return expiryDate;
249   }
250
251   public void setExpiryDate(String expiryDate) {
252     this.expiryDate = expiryDate;
253   }
254
255   public Collection<LimitEntity> getLimits() {
256     return limits;
257   }
258
259   public void setLimits(Collection<LimitEntity> limits) {
260     this.limits = limits;
261   }
262
263   public LimitForXml getSPLimits() {
264     if (limits != null) {
265       Set<LimitXml> hs = new HashSet<>();
266       for (LimitEntity obj : limits) {
267         if (obj.getType().equals(LimitType.ServiceProvider)) {
268           LimitXml xmlObj = new LimitXml();
269           xmlObj.setDescription(obj.getDescription());
270           xmlObj.setMetric(obj.getMetric());
271           xmlObj.setValues(obj.getValue());
272           xmlObj.setUnit(obj.getUnit());
273           xmlObj.setAggregationFunction(
274               obj.getAggregationFunction() != null ? obj.getAggregationFunction().name() : null);
275           xmlObj.setTime(obj.getTime());
276           hs.add(xmlObj);
277         }
278       }
279       LimitForXml spLimitForXml = new LimitForXml();
280       spLimitForXml.setLimits(hs);
281       return spLimitForXml;
282     }
283
284     return null;
285   }
286
287   public LimitForXml getVendorLimits() {
288     if (limits != null) {
289       Set<LimitXml> hs = new HashSet<>();
290       for (LimitEntity obj : limits) {
291         if (obj.getType().equals(LimitType.Vendor)) {
292           LimitXml xmlObj = new LimitXml();
293           xmlObj.setDescription(obj.getDescription());
294           xmlObj.setMetric(obj.getMetric());
295           xmlObj.setValues(obj.getValue());
296           xmlObj.setUnit(obj.getUnit());
297           xmlObj.setAggregationFunction(
298               obj.getAggregationFunction() != null ? obj.getAggregationFunction().name() : null);
299           xmlObj.setTime(obj.getTime());
300           hs.add(xmlObj);
301         }
302       }
303       LimitForXml vendorLimitForXml = new LimitForXml();
304       vendorLimitForXml.setLimits(hs);
305       return vendorLimitForXml;
306     }
307
308     return null;
309   }
310
311
312   @Override
313   public int hashCode() {
314     return Objects
315         .hash(vendorLicenseModelId, version, id, name, description, thresholdValue, thresholdUnit,
316             increments, operationalScope, referencingFeatureGroups, startDate, expiryDate);
317   }
318
319   @Override
320   public boolean equals(Object obj) {
321     if (this == obj) {
322       return true;
323     }
324     if (obj == null || getClass() != obj.getClass()) {
325       return false;
326     }
327     EntitlementPoolEntity that = (EntitlementPoolEntity) obj;
328     return Objects.equals(that.thresholdValue, thresholdValue)
329         && Objects.equals(vendorLicenseModelId, that.vendorLicenseModelId)
330         && Objects.equals(id, that.id)
331         && Objects.equals(name, that.name)
332         && Objects.equals(description, that.description)
333         && Objects.equals(thresholdUnit, that.thresholdUnit)
334         && Objects.equals(increments, that.increments)
335         && Objects.equals(operationalScope, that.operationalScope)
336         && Objects.equals(referencingFeatureGroups, that.referencingFeatureGroups)
337         && Objects.equals(startDate, that.startDate)
338         && Objects.equals(expiryDate, that.expiryDate)
339         && Objects.equals(manufacturerReferenceNumber, that.manufacturerReferenceNumber)
340         && Objects.equals(version, that.version);
341   }
342
343   @Override
344   public String toString() {
345     return "EntitlementPoolEntity{"
346         + "vendorLicenseModelId='" + vendorLicenseModelId + '\''
347         + ", version=" + version
348         + ", id='" + id + '\''
349         + ", name='" + name + '\''
350         + ", description='" + description + '\''
351         + ", thresholdValue=" + thresholdValue
352         + ", thresholdUnit='" + thresholdUnit + '\''
353         + ", increments='" + increments + '\''
354         + ", operationalScope=" + operationalScope
355         + ", referencingFeatureGroups=" + referencingFeatureGroups
356         + ", version_uuid=" + versionUuId
357         + ", startDate=" + startDate
358         + ", expiryDate=" + expiryDate
359         + '}';
360   }
361
362   /**
363    * Gets operational scope for artifact.
364    *
365    * @return the operational scope for artifact
366    */
367   public OperationalScopeForXml getOperationalScopeForArtifact() {
368     OperationalScopeForXml obj = new OperationalScopeForXml();
369     if (operationalScope != null) {
370       if (operationalScope.getResults().size() > 0) {
371         obj.setValue(operationalScope.getResults());
372       }
373     }
374     return obj;
375   }
376
377   //Defined and used only for License Artifcat XMLs
378   public void setManufacturerReferenceNumber(String manufacturerReferenceNumber) {
379     this.manufacturerReferenceNumber = manufacturerReferenceNumber;
380   }
381
382   public String getManufacturerReferenceNumber() {
383     return manufacturerReferenceNumber;
384   }
385
386   public String getIsoFormatStartDate() {
387     String isoFormatStartDate = null;
388     if (!StringUtils.isEmpty(startDate)) {
389       isoFormatStartDate = VendorLicenseUtil.getIsoFormatDate(startDate);
390     }
391     return isoFormatStartDate;
392   }
393
394
395   public String getIsoFormatExpiryDate() {
396     String isoFormatExpDate = null;
397     if (!StringUtils.isEmpty(expiryDate)) {
398       isoFormatExpDate = VendorLicenseUtil.getIsoFormatDate(expiryDate);
399     }
400     return isoFormatExpDate;
401   }
402 }