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.logging.context.impl.MdcDataDebugMessage;
31 import org.openecomp.sdc.vendorlicense.VendorLicenseUtil;
32 import org.openecomp.sdc.vendorlicense.dao.types.xml.LicenseKeyTypeForXml;
33 import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitForXml;
34 import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitXml;
35 import org.openecomp.sdc.vendorlicense.dao.types.xml.OperationalScopeForXml;
36 import org.openecomp.sdc.vendorlicense.dao.types.xml.ThresholdForXml;
37 import org.openecomp.sdc.versioning.dao.types.Version;
38 import org.openecomp.sdc.versioning.dao.types.VersionableEntity;
40 import java.util.Collection;
41 import java.util.HashSet;
42 import java.util.Objects;
45 @Table(keyspace = "dox", name = "license_key_group")
46 public class LicenseKeyGroupEntity implements VersionableEntity {
48 private static final MdcDataDebugMessage MDC_DATA_DEBUG_MESSAGE = new MdcDataDebugMessage();
49 private static final String ENTITY_TYPE = "License Key Group";
52 @Column(name = "vlm_id")
53 private String vendorLicenseModelId;
54 @PartitionKey(value = 1)
56 private Version version;
58 @Column(name = "lkg_id")
61 private String description;
63 private LicenseKeyType type;
64 @Column(name = "operational_scope")
66 private MultiChoiceOrOther<OperationalScope> operationalScope;
67 @Column(name = "ref_fg_ids")
68 private Set<String> referencingFeatureGroups = new HashSet<>();
69 @Column(name = "version_uuid")
70 private String versionUuId;
71 private Integer thresholdValue;
72 private ThresholdUnit thresholdUnits;
73 private String increments;
75 private Collection<LimitEntity> limits;
76 private String startDate;
77 private String expiryDate;
79 //Defined and used only for License Artifcat XMLs
80 private String manufacturerReferenceNumber;
83 * Every entity class must have a default constructor according to
84 * <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/object_mapper/creating/">
85 * Definition of mapped classes</a>.
87 public LicenseKeyGroupEntity() {
88 // Don't delete! Default constructor is required by DataStax driver
92 * Instantiates a new License key group entity.
94 * @param vendorLicenseModelId the vendor license model id
95 * @param version the version
98 public LicenseKeyGroupEntity(String vendorLicenseModelId, Version version, String id) {
99 this.vendorLicenseModelId = vendorLicenseModelId;
100 this.version = version;
105 public String getEntityType() {
110 public String getFirstClassCitizenId() {
111 return getVendorLicenseModelId();
114 public String getId() {
118 public void setId(String id) {
122 public Version getVersion() {
126 public void setVersion(Version version) {
127 this.version = version;
131 public String getVersionUuId() {
136 public void setVersionUuId(String uuId) {
140 public String getVendorLicenseModelId() {
141 return vendorLicenseModelId;
144 public void setVendorLicenseModelId(String vendorLicenseModelId) {
145 this.vendorLicenseModelId = vendorLicenseModelId;
148 public String getName() {
152 public void setName(String name) {
156 public String getDescription() {
160 public void setDescription(String description) {
161 this.description = description;
164 public LicenseKeyType getType() {
168 public void setType(LicenseKeyType type) {
172 public MultiChoiceOrOther<OperationalScope> getOperationalScope() {
173 return operationalScope;
176 public void setOperationalScope(MultiChoiceOrOther<OperationalScope> operationalScope) {
177 if (operationalScope != null) {
178 operationalScope.resolveEnum(OperationalScope.class);
180 this.operationalScope = operationalScope;
183 public Set<String> getReferencingFeatureGroups() {
184 return referencingFeatureGroups;
187 public void setReferencingFeatureGroups(Set<String> referencingFeatureGroups) {
188 this.referencingFeatureGroups = referencingFeatureGroups;
191 public Integer getThresholdValue() {
192 return thresholdValue;
195 public void setThresholdValue(Integer thresholdValue) {
196 this.thresholdValue = thresholdValue;
199 public ThresholdUnit getThresholdUnits() {
200 return thresholdUnits;
203 public void setThresholdUnits(ThresholdUnit thresholdUnit) {
204 this.thresholdUnits = thresholdUnit;
207 public String getIncrements() {
211 public void setIncrements(String increments) {
212 this.increments = increments;
215 public ThresholdForXml getThresholdForArtifact() {
216 ThresholdForXml threshold = new ThresholdForXml();
217 threshold.setUnit(getThresholdUnits() == null ? null : getThresholdUnits().name());
218 threshold.setValue(getThresholdValue());
222 public Collection<LimitEntity> getLimits() {
226 public void setLimits(Collection<LimitEntity> limits) {
227 this.limits = limits;
230 public LimitForXml getSPLimits() {
231 if (limits != null) {
232 Set<LimitXml> hs = new HashSet<>();
233 for (LimitEntity obj : limits) {
234 if (obj.getType().equals(LimitType.ServiceProvider)) {
235 LimitXml xmlObj = new LimitXml();
236 xmlObj.setDescription(obj.getDescription());
237 xmlObj.setMetric(obj.getMetric());
238 xmlObj.setValues(obj.getValue());
239 xmlObj.setUnit(obj.getUnit());
240 xmlObj.setAggregationFunction(
241 obj.getAggregationFunction() != null ? obj.getAggregationFunction().name() : null);
242 xmlObj.setTime(obj.getTime());
246 LimitForXml spLimitForXml = new LimitForXml();
247 spLimitForXml.setLimits(hs);
248 return spLimitForXml;
254 public LimitForXml getVendorLimits() {
255 if (limits != null) {
256 Set<LimitXml> hs = new HashSet<>();
257 for (LimitEntity obj : limits) {
258 if (obj.getType().equals(LimitType.Vendor)) {
259 LimitXml xmlObj = new LimitXml();
260 xmlObj.setDescription(obj.getDescription());
261 xmlObj.setMetric(obj.getMetric());
262 xmlObj.setValues(obj.getValue());
263 xmlObj.setUnit(obj.getUnit());
264 xmlObj.setAggregationFunction(
265 obj.getAggregationFunction() != null ? obj.getAggregationFunction().name() : null);
266 xmlObj.setTime(obj.getTime());
270 LimitForXml vendorLimitForXml = new LimitForXml();
271 vendorLimitForXml.setLimits(hs);
272 return vendorLimitForXml;
278 public String getStartDate() {
282 public void setStartDate(String startDate) {
283 this.startDate = startDate;
286 public String getExpiryDate() {
290 public void setExpiryDate(String expiryDate) {
291 this.expiryDate = expiryDate;
295 public int hashCode() {
297 .hash(vendorLicenseModelId, version, id, name, description, type, operationalScope,
298 referencingFeatureGroups, startDate, expiryDate,
299 thresholdValue, thresholdUnits, increments);
303 public boolean equals(Object obj) {
307 if (obj == null || getClass() != obj.getClass()) {
310 LicenseKeyGroupEntity that = (LicenseKeyGroupEntity) obj;
311 return Objects.equals(vendorLicenseModelId, that.vendorLicenseModelId)
312 && Objects.equals(version, that.version)
313 && Objects.equals(id, that.id)
314 && Objects.equals(name, that.name)
315 && Objects.equals(description, that.description)
317 && Objects.equals(operationalScope, that.operationalScope)
318 && Objects.equals(referencingFeatureGroups, that.referencingFeatureGroups)
319 && Objects.equals(startDate, that.startDate)
320 && Objects.equals(expiryDate, that.expiryDate)
321 && Objects.equals(thresholdValue, that.thresholdValue)
322 && Objects.equals(thresholdUnits, that.thresholdUnits)
323 && Objects.equals(increments, that.increments)
324 && Objects.equals(manufacturerReferenceNumber, that.manufacturerReferenceNumber);
328 public String toString() {
329 return "LicenseKeyGroupEntity{" + "vendorLicenseModelId='" + vendorLicenseModelId + '\''
330 + ", version=" + version
331 + ", id='" + id + '\''
332 + ", name='" + name + '\''
333 + ", description='" + description + '\''
335 + ", operationalScope=" + operationalScope
336 + ", referencingFeatureGroups=" + referencingFeatureGroups
337 + ", versionUuId='" + versionUuId + '\''
338 + ", startDate=" + startDate
339 + ", expiryDate=" + expiryDate
340 + ", thresholdValue='" + thresholdValue + '\''
341 + ", thresholdUnits='" + thresholdUnits + '\''
342 + ", increments='" + increments + '\''
347 * Gets operational scope for artifact.
349 * @return the operational scope for artifact
351 public OperationalScopeForXml getOperationalScopeForArtifact() {
352 OperationalScopeForXml obj = new OperationalScopeForXml();
353 if (operationalScope != null) {
354 if (operationalScope.getResults().size() > 0) {
355 obj.setValue(operationalScope.getResults());
362 * Gets version for artifact.
364 * @return version in format suitable for artifact
366 public String getVersionForArtifact() {
367 return version.toString();
371 * Gets type for artifact.
373 * @return the type for artifact
375 public LicenseKeyTypeForXml getTypeForArtifact() {
376 LicenseKeyTypeForXml typeXml = new LicenseKeyTypeForXml();
378 typeXml.setValue(type.toString());
380 typeXml.setValue(null);
385 //Defined and used only for License Artifcat XMLs
386 public String getManufacturerReferenceNumber() {
387 return manufacturerReferenceNumber;
390 public void setManufacturerReferenceNumber(String manufacturerReferenceNumber) {
391 this.manufacturerReferenceNumber = manufacturerReferenceNumber;
394 public String getIsoFormatStartDate() {
395 MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("start date", startDate);
396 String isoFormatStartDate = null;
397 if (!StringUtils.isEmpty(startDate)) {
398 isoFormatStartDate = VendorLicenseUtil.getIsoFormatDate(startDate);
399 MDC_DATA_DEBUG_MESSAGE.debugExitMessage("start date", "iso format start date", startDate,
402 return isoFormatStartDate;
406 public String getIsoFormatExpiryDate() {
407 MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("expiry date", expiryDate);
408 String isoFormatExpDate = null;
409 if (!StringUtils.isEmpty(expiryDate)) {
410 isoFormatExpDate = VendorLicenseUtil.getIsoFormatDate(expiryDate);
411 MDC_DATA_DEBUG_MESSAGE.debugExitMessage("expiry date", "iso format expiry date", expiryDate,
414 return isoFormatExpDate;