364a240498b816ee4c5a25c3286231c5eabb2acc
[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.openecomp.sdc.vendorlicense.dao.types.xml.LicenseKeyTypeForXml;
30 import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitXml;
31 import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitForXml;
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 = "license_key_group")
43 public class LicenseKeyGroupEntity implements VersionableEntity {
44   private static final String ENTITY_TYPE = "License Key Group";
45
46   @PartitionKey
47   @Column(name = "vlm_id")
48   private String vendorLicenseModelId;
49   @PartitionKey(value = 1)
50   @Frozen
51   private Version version;
52   @ClusteringColumn
53   @Column(name = "lkg_id")
54   private String id;
55   private String name;
56   private String description;
57   @Enumerated
58   private LicenseKeyType type;
59   @Column(name = "operational_scope")
60   @Frozen
61   private MultiChoiceOrOther<OperationalScope> operationalScope;
62   @Column(name = "ref_fg_ids")
63   private Set<String> referencingFeatureGroups = new HashSet<>();
64   @Column(name = "version_uuid")
65   private String versionUuId;
66   private Integer thresholdValue;
67   private ThresholdUnit thresholdUnits;
68   private String increments;
69
70   private Collection<LimitEntity> limits;
71   private String startDate;
72   private String expiryDate;
73
74   //Defined and used only for License Artifcat XMLs
75   private String manufacturerReferenceNumber;
76
77
78   public LicenseKeyGroupEntity() {
79   }
80
81   /**
82    * Instantiates a new License key group entity.
83    *
84    * @param vendorLicenseModelId the vendor license model id
85    * @param version              the version
86    * @param id                   the id
87    */
88   public LicenseKeyGroupEntity(String vendorLicenseModelId, Version version, String id) {
89     this.vendorLicenseModelId = vendorLicenseModelId;
90     this.version = version;
91     this.id = id;
92   }
93
94   @Override
95   public String getEntityType() {
96     return ENTITY_TYPE;
97   }
98
99   @Override
100   public String getFirstClassCitizenId() {
101     return getVendorLicenseModelId();
102   }
103
104   public String getId() {
105     return id;
106   }
107
108   public void setId(String id) {
109     this.id = id;
110   }
111
112   public Version getVersion() {
113     return version;
114   }
115
116   public void setVersion(Version version) {
117     this.version = version;
118   }
119
120   @Override
121   public String getVersionUuId() {
122     return versionUuId;
123   }
124
125   @Override
126   public void setVersionUuId(String uuId) {
127     versionUuId = uuId;
128   }
129
130   public String getVendorLicenseModelId() {
131     return vendorLicenseModelId;
132   }
133
134   public void setVendorLicenseModelId(String vendorLicenseModelId) {
135     this.vendorLicenseModelId = vendorLicenseModelId;
136   }
137
138   public String getName() {
139     return name;
140   }
141
142   public void setName(String name) {
143     this.name = name;
144   }
145
146   public String getDescription() {
147     return description;
148   }
149
150   public void setDescription(String description) {
151     this.description = description;
152   }
153
154   public LicenseKeyType getType() {
155     return type;
156   }
157
158   public void setType(LicenseKeyType type) {
159     this.type = type;
160   }
161
162   public MultiChoiceOrOther<OperationalScope> getOperationalScope() {
163     return operationalScope;
164   }
165
166   public void setOperationalScope(MultiChoiceOrOther<OperationalScope> operationalScope) {
167     if(operationalScope != null)  {
168       operationalScope.resolveEnum(OperationalScope.class);
169     }
170     this.operationalScope = operationalScope;
171   }
172
173   public Set<String> getReferencingFeatureGroups() {
174     return referencingFeatureGroups;
175   }
176
177   public void setReferencingFeatureGroups(Set<String> referencingFeatureGroups) {
178     this.referencingFeatureGroups = referencingFeatureGroups;
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 getThresholdUnits() {
190     return thresholdUnits;
191   }
192
193   public void setThresholdUnits(ThresholdUnit thresholdUnit) {
194     this.thresholdUnits = thresholdUnit;
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 ThresholdForXml getThresholdForArtifact() {
206     ThresholdForXml threshold = new ThresholdForXml();
207     threshold.setUnit(getThresholdUnits() == null ? null : getThresholdUnits().name());
208     threshold.setValue(getThresholdValue());
209     return threshold;
210   }
211
212   public Collection<LimitEntity> getLimits() {
213     return limits;
214   }
215
216   public void setLimits(Collection<LimitEntity> limits) {
217     this.limits = limits;
218   }
219
220   public LimitForXml getSPLimits(){
221     if(limits != null){
222       Set<LimitXml> hs = new HashSet<>();
223       for(LimitEntity obj : limits){
224         if(obj.getType().equals(LimitType.ServiceProvider)){
225           LimitXml xmlObj = new LimitXml();
226           xmlObj.setDescription(obj.getDescription());
227           xmlObj.setMetric(obj.getMetric());
228           xmlObj.setValues(obj.getValue());
229           xmlObj.setUnit(obj.getUnit());
230           xmlObj.setAggregationFunction(obj.getAggregationFunction()!=null?obj.getAggregationFunction().name():null);
231           xmlObj.setTime(obj.getTime());
232           hs.add(xmlObj);
233         }
234       }
235       LimitForXml spLimitForXml = new LimitForXml();
236       spLimitForXml.setLimits(hs);
237       return spLimitForXml;
238     }
239
240     return null;
241   }
242
243   public LimitForXml getVendorLimits(){
244     if(limits != null){
245       Set<LimitXml> hs = new HashSet<>();
246       for(LimitEntity obj : limits){
247         if(obj.getType().equals(LimitType.Vendor)){
248           LimitXml xmlObj = new LimitXml();
249           xmlObj.setDescription(obj.getDescription());
250           xmlObj.setMetric(obj.getMetric());
251           xmlObj.setValues(obj.getValue());
252           xmlObj.setUnit(obj.getUnit());
253           xmlObj.setAggregationFunction(obj.getAggregationFunction()!=null?obj.getAggregationFunction().name():null);
254           xmlObj.setTime(obj.getTime());
255           hs.add(xmlObj);
256         }
257       }
258       LimitForXml vendorLimitForXml = new LimitForXml();
259       vendorLimitForXml.setLimits(hs);
260       return vendorLimitForXml;
261     }
262
263     return null;
264   }
265
266   public String getStartDate() {
267     return startDate;
268   }
269
270   public void setStartDate(String startDate) {
271     this.startDate = startDate;
272   }
273
274   public String getExpiryDate() {
275     return expiryDate;
276   }
277
278   public void setExpiryDate(String expiryDate) {
279     this.expiryDate = expiryDate;
280   }
281
282   @Override
283   public int hashCode() {
284     return Objects
285         .hash(vendorLicenseModelId, version, id, name, description, type, operationalScope,
286             referencingFeatureGroups, startDate, expiryDate,
287             thresholdValue, thresholdUnits, increments);
288   }
289
290   @Override
291   public boolean equals(Object obj) {
292     if (this == obj) {
293       return true;
294     }
295     if (obj == null || getClass() != obj.getClass()) {
296       return false;
297     }
298     LicenseKeyGroupEntity that = (LicenseKeyGroupEntity) obj;
299     return Objects.equals(vendorLicenseModelId, that.vendorLicenseModelId)
300         && Objects.equals(id, that.id)
301         && Objects.equals(name, that.name)
302         && Objects.equals(description, that.description)
303         && type == that.type
304         && Objects.equals(operationalScope, that.operationalScope)
305         && Objects.equals(referencingFeatureGroups, that.referencingFeatureGroups)
306         && Objects.equals(startDate, that.startDate)
307         && Objects.equals(expiryDate, that.expiryDate)
308         && Objects.equals(thresholdValue, that.thresholdValue)
309         && Objects.equals(thresholdUnits, that.thresholdUnits)
310         && Objects.equals(increments, that.increments);
311   }
312
313   @Override
314   public String toString() {
315     return "LicenseKeyGroupEntity{" + "vendorLicenseModelId='" + vendorLicenseModelId + '\''
316         + ", version=" + version
317         + ", id='" + id + '\''
318         + ", name='" + name + '\''
319         + ", description='" + description + '\''
320         + ", type=" + type
321         + ", operationalScope=" + operationalScope
322         + ", referencingFeatureGroups=" + referencingFeatureGroups
323         + ", versionUuId='" + versionUuId + '\''
324         + ", startDate=" + startDate
325         + ", expiryDate=" + expiryDate
326         + ", thresholdValue='" + thresholdValue + '\''
327         + ", thresholdUnits='" + thresholdUnits + '\''
328         + ", increments='" + increments + '\''
329         + '}';
330   }
331
332   /**
333    * Gets operational scope for artifact.
334    *
335    * @return the operational scope for artifact
336    */
337   public OperationalScopeForXml getOperationalScopeForArtifact() {
338     OperationalScopeForXml obj = new OperationalScopeForXml();
339     if (operationalScope != null) {
340       if(operationalScope.getResults().size() > 0) {
341         obj.setValue(operationalScope.getResults());
342       }
343     }
344     return obj;
345   }
346
347   /**
348    * Gets version for artifact.
349    * @return version in format suitable for artifact
350    */
351   public String getVersionForArtifact() {
352     return version.toString();
353   }
354
355   /**
356    * Gets type for artifact.
357    *
358    * @return the type for artifact
359    */
360   public LicenseKeyTypeForXml getTypeForArtifact() {
361     LicenseKeyTypeForXml typeXml = new LicenseKeyTypeForXml();
362     if (type != null) {
363       typeXml.setValue(type.toString());
364     } else {
365       typeXml.setValue(null);
366     }
367     return typeXml;
368   }
369
370   //Defined and used only for License Artifcat XMLs
371   public String getManufacturerReferenceNumber() {
372     return manufacturerReferenceNumber;
373   }
374
375   public void setManufacturerReferenceNumber(String manufacturerReferenceNumber) {
376     this.manufacturerReferenceNumber = manufacturerReferenceNumber;
377   }
378 }