2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.vendorlicense.dao.types;
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.LicenseKeyTypeForXml;
32 import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitForXml;
33 import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitXml;
34 import org.openecomp.sdc.vendorlicense.dao.types.xml.OperationalScopeForXml;
35 import org.openecomp.sdc.vendorlicense.dao.types.xml.ThresholdForXml;
36 import org.openecomp.sdc.versioning.dao.types.Version;
37 import org.openecomp.sdc.versioning.dao.types.VersionableEntity;
39 import java.util.Collection;
40 import java.util.HashSet;
41 import java.util.Objects;
44 @Table(keyspace = "dox", name = "license_key_group")
45 public class LicenseKeyGroupEntity implements VersionableEntity {
46 private static final String ENTITY_TYPE = "License Key Group";
49 @Column(name = "vlm_id")
50 private String vendorLicenseModelId;
51 @PartitionKey(value = 1)
53 private Version version;
55 @Column(name = "lkg_id")
58 private String description;
60 private LicenseKeyType type;
61 @Column(name = "operational_scope")
63 private MultiChoiceOrOther<OperationalScope> operationalScope;
64 @Column(name = "ref_fg_ids")
65 private Set<String> referencingFeatureGroups = new HashSet<>();
66 @Column(name = "version_uuid")
67 private String versionUuId;
68 private Integer thresholdValue;
69 private ThresholdUnit thresholdUnits;
70 private String increments;
72 private Collection<LimitEntity> limits;
73 private String startDate;
74 private String expiryDate;
76 //Defined and used only for License Artifcat XMLs
77 private String manufacturerReferenceNumber;
80 * Every entity class must have a default constructor according to
81 * <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/object_mapper/creating/">
82 * Definition of mapped classes</a>.
84 public LicenseKeyGroupEntity() {
85 // Don't delete! Default constructor is required by DataStax driver
89 * Instantiates a new License key group entity.
91 * @param vendorLicenseModelId the vendor license model id
92 * @param version the version
95 public LicenseKeyGroupEntity(String vendorLicenseModelId, Version version, String id) {
96 this.vendorLicenseModelId = vendorLicenseModelId;
97 this.version = version;
102 public String getEntityType() {
107 public String getFirstClassCitizenId() {
108 return getVendorLicenseModelId();
111 public String getId() {
115 public void setId(String id) {
119 public Version getVersion() {
123 public void setVersion(Version version) {
124 this.version = version;
128 public String getVersionUuId() {
133 public void setVersionUuId(String uuId) {
137 public String getVendorLicenseModelId() {
138 return vendorLicenseModelId;
141 public void setVendorLicenseModelId(String vendorLicenseModelId) {
142 this.vendorLicenseModelId = vendorLicenseModelId;
145 public String getName() {
149 public void setName(String name) {
153 public String getDescription() {
157 public void setDescription(String description) {
158 this.description = description;
161 public LicenseKeyType getType() {
165 public void setType(LicenseKeyType type) {
169 public MultiChoiceOrOther<OperationalScope> getOperationalScope() {
170 return operationalScope;
173 public void setOperationalScope(MultiChoiceOrOther<OperationalScope> operationalScope) {
174 if (operationalScope != null) {
175 operationalScope.resolveEnum(OperationalScope.class);
177 this.operationalScope = operationalScope;
180 public Set<String> getReferencingFeatureGroups() {
181 return referencingFeatureGroups;
184 public void setReferencingFeatureGroups(Set<String> referencingFeatureGroups) {
185 this.referencingFeatureGroups = referencingFeatureGroups;
188 public Integer getThresholdValue() {
189 return thresholdValue;
192 public void setThresholdValue(Integer thresholdValue) {
193 this.thresholdValue = thresholdValue;
196 public ThresholdUnit getThresholdUnits() {
197 return thresholdUnits;
200 public void setThresholdUnits(ThresholdUnit thresholdUnit) {
201 this.thresholdUnits = thresholdUnit;
204 public String getIncrements() {
208 public void setIncrements(String increments) {
209 this.increments = increments;
212 public ThresholdForXml getThresholdForArtifact() {
213 ThresholdForXml threshold = new ThresholdForXml();
214 threshold.setUnit(getThresholdUnits() == null ? null : getThresholdUnits().name());
215 threshold.setValue(getThresholdValue());
219 public Collection<LimitEntity> getLimits() {
223 public void setLimits(Collection<LimitEntity> limits) {
224 this.limits = limits;
227 public LimitForXml getSPLimits() {
228 if (limits != null) {
229 Set<LimitXml> hs = new HashSet<>();
230 for (LimitEntity obj : limits) {
231 if (obj.getType().equals(LimitType.ServiceProvider)) {
232 LimitXml xmlObj = new LimitXml();
233 xmlObj.setDescription(obj.getDescription());
234 xmlObj.setMetric(obj.getMetric());
235 xmlObj.setValues(obj.getValue());
236 xmlObj.setUnit(obj.getUnit());
237 xmlObj.setAggregationFunction(
238 obj.getAggregationFunction() != null ? obj.getAggregationFunction().name() : null);
239 xmlObj.setTime(obj.getTime());
243 LimitForXml spLimitForXml = new LimitForXml();
244 spLimitForXml.setLimits(hs);
245 return spLimitForXml;
251 public LimitForXml getVendorLimits() {
252 if (limits != null) {
253 Set<LimitXml> hs = new HashSet<>();
254 for (LimitEntity obj : limits) {
255 if (obj.getType().equals(LimitType.Vendor)) {
256 LimitXml xmlObj = new LimitXml();
257 xmlObj.setDescription(obj.getDescription());
258 xmlObj.setMetric(obj.getMetric());
259 xmlObj.setValues(obj.getValue());
260 xmlObj.setUnit(obj.getUnit());
261 xmlObj.setAggregationFunction(
262 obj.getAggregationFunction() != null ? obj.getAggregationFunction().name() : null);
263 xmlObj.setTime(obj.getTime());
267 LimitForXml vendorLimitForXml = new LimitForXml();
268 vendorLimitForXml.setLimits(hs);
269 return vendorLimitForXml;
275 public String getStartDate() {
279 public void setStartDate(String startDate) {
280 this.startDate = startDate;
283 public String getExpiryDate() {
287 public void setExpiryDate(String expiryDate) {
288 this.expiryDate = expiryDate;
292 public int hashCode() {
294 .hash(vendorLicenseModelId, version, id, name, description, type, operationalScope,
295 referencingFeatureGroups, startDate, expiryDate,
296 thresholdValue, thresholdUnits, increments);
300 public boolean equals(Object obj) {
304 if (obj == null || getClass() != obj.getClass()) {
307 LicenseKeyGroupEntity that = (LicenseKeyGroupEntity) obj;
308 return Objects.equals(vendorLicenseModelId, that.vendorLicenseModelId)
309 && Objects.equals(version, that.version)
310 && Objects.equals(id, that.id)
311 && Objects.equals(name, that.name)
312 && Objects.equals(description, that.description)
314 && Objects.equals(operationalScope, that.operationalScope)
315 && Objects.equals(referencingFeatureGroups, that.referencingFeatureGroups)
316 && Objects.equals(startDate, that.startDate)
317 && Objects.equals(expiryDate, that.expiryDate)
318 && Objects.equals(thresholdValue, that.thresholdValue)
319 && Objects.equals(thresholdUnits, that.thresholdUnits)
320 && Objects.equals(increments, that.increments)
321 && Objects.equals(manufacturerReferenceNumber, that.manufacturerReferenceNumber);
325 public String toString() {
326 return "LicenseKeyGroupEntity{" + "vendorLicenseModelId='" + vendorLicenseModelId + '\''
327 + ", version=" + version
328 + ", id='" + id + '\''
329 + ", name='" + name + '\''
330 + ", description='" + description + '\''
332 + ", operationalScope=" + operationalScope
333 + ", referencingFeatureGroups=" + referencingFeatureGroups
334 + ", versionUuId='" + versionUuId + '\''
335 + ", startDate=" + startDate
336 + ", expiryDate=" + expiryDate
337 + ", thresholdValue='" + thresholdValue + '\''
338 + ", thresholdUnits='" + thresholdUnits + '\''
339 + ", increments='" + increments + '\''
344 * Gets operational scope for artifact.
346 * @return the operational scope for artifact
348 public OperationalScopeForXml getOperationalScopeForArtifact() {
349 OperationalScopeForXml obj = new OperationalScopeForXml();
350 if (operationalScope != null) {
351 if (operationalScope.getResults().size() > 0) {
352 obj.setValue(operationalScope.getResults());
359 * Gets version for artifact.
361 * @return version in format suitable for artifact
363 public String getVersionForArtifact() {
364 return version.toString();
368 * Gets type for artifact.
370 * @return the type for artifact
372 public LicenseKeyTypeForXml getTypeForArtifact() {
373 LicenseKeyTypeForXml typeXml = new LicenseKeyTypeForXml();
375 typeXml.setValue(type.toString());
377 typeXml.setValue(null);
382 //Defined and used only for License Artifcat XMLs
383 public String getManufacturerReferenceNumber() {
384 return manufacturerReferenceNumber;
387 public void setManufacturerReferenceNumber(String manufacturerReferenceNumber) {
388 this.manufacturerReferenceNumber = manufacturerReferenceNumber;
391 public String getIsoFormatStartDate() {
392 String isoFormatStartDate = null;
393 if (!StringUtils.isEmpty(startDate)) {
394 isoFormatStartDate = VendorLicenseUtil.getIsoFormatDate(startDate);
396 return isoFormatStartDate;
400 public String getIsoFormatExpiryDate() {
401 String isoFormatExpDate = null;
402 if (!StringUtils.isEmpty(expiryDate)) {
403 isoFormatExpDate = VendorLicenseUtil.getIsoFormatDate(expiryDate);
405 return isoFormatExpDate;