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