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.Frozen;
26 import com.datastax.driver.mapping.annotations.PartitionKey;
27 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.*;
32 import org.openecomp.sdc.versioning.dao.types.Version;
33 import org.openecomp.sdc.versioning.dao.types.VersionableEntity;
35 import java.util.Collection;
36 import java.util.HashSet;
37 import java.util.Objects;
40 @Table(keyspace = "dox", name = "license_key_group")
41 public class LicenseKeyGroupEntity implements VersionableEntity {
42 private static final String ENTITY_TYPE = "License Key Group";
45 @Column(name = "vlm_id")
46 private String vendorLicenseModelId;
47 @PartitionKey(value = 1)
49 private Version version;
51 @Column(name = "lkg_id")
54 private String description;
55 private LicenseKeyType type;
56 @Column(name = "operational_scope")
58 private MultiChoiceOrOther<OperationalScope> operationalScope;
59 @Column(name = "ref_fg_ids")
60 private Set<String> referencingFeatureGroups = new HashSet<>();
61 @Column(name = "version_uuid")
62 private String versionUuId;
63 private Integer thresholdValue;
64 private ThresholdUnit thresholdUnits;
65 private String increments;
67 private Collection<LimitEntity> limits;
68 private String startDate;
69 private String expiryDate;
71 //Defined and used only for License Artifcat XMLs
72 private String manufacturerReferenceNumber;
75 * Every entity class must have a default constructor according to
76 * <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/object_mapper/creating/">
77 * Definition of mapped classes</a>.
79 public LicenseKeyGroupEntity() {
80 // Don't delete! Default constructor is required by DataStax driver
84 * Instantiates a new License key group entity.
86 * @param vendorLicenseModelId the vendor license model id
87 * @param version the version
90 public LicenseKeyGroupEntity(String vendorLicenseModelId, Version version, String id) {
91 this.vendorLicenseModelId = vendorLicenseModelId;
92 this.version = version;
97 public String getEntityType() {
102 public String getFirstClassCitizenId() {
103 return getVendorLicenseModelId();
106 public String getId() {
110 public void setId(String id) {
114 public Version getVersion() {
118 public void setVersion(Version version) {
119 this.version = version;
123 public String getVersionUuId() {
128 public void setVersionUuId(String uuId) {
132 public String getVendorLicenseModelId() {
133 return vendorLicenseModelId;
136 public void setVendorLicenseModelId(String vendorLicenseModelId) {
137 this.vendorLicenseModelId = vendorLicenseModelId;
140 public String getName() {
144 public void setName(String name) {
148 public String getDescription() {
152 public void setDescription(String description) {
153 this.description = description;
156 public LicenseKeyType getType() {
160 public void setType(LicenseKeyType type) {
164 public MultiChoiceOrOther<OperationalScope> getOperationalScope() {
165 return operationalScope;
168 public void setOperationalScope(MultiChoiceOrOther<OperationalScope> operationalScope) {
169 if (operationalScope != null) {
170 operationalScope.resolveEnum(OperationalScope.class);
172 this.operationalScope = operationalScope;
175 public Set<String> getReferencingFeatureGroups() {
176 return referencingFeatureGroups;
179 public void setReferencingFeatureGroups(Set<String> referencingFeatureGroups) {
180 this.referencingFeatureGroups = referencingFeatureGroups;
183 public Integer getThresholdValue() {
184 return thresholdValue;
187 public void setThresholdValue(Integer thresholdValue) {
188 this.thresholdValue = thresholdValue;
191 public ThresholdUnit getThresholdUnits() {
192 return thresholdUnits;
195 public void setThresholdUnits(ThresholdUnit thresholdUnit) {
196 this.thresholdUnits = thresholdUnit;
199 public String getIncrements() {
203 public void setIncrements(String increments) {
204 this.increments = increments;
207 public ThresholdForXml getThresholdForArtifact() {
208 ThresholdForXml threshold = new ThresholdForXml();
209 threshold.setUnit(getThresholdUnits() == null ? null : getThresholdUnits().name());
210 threshold.setValue(getThresholdValue());
214 public Collection<LimitEntity> getLimits() {
218 public void setLimits(Collection<LimitEntity> limits) {
219 this.limits = limits;
222 public LimitForXml getSPLimits() {
223 if (limits != null) {
224 Set<LimitXml> hs = new HashSet<>();
225 for (LimitEntity obj : limits) {
226 if (obj.getType().equals(LimitType.ServiceProvider)) {
227 LimitXml xmlObj = new LimitXml();
228 xmlObj.setDescription(obj.getDescription());
229 xmlObj.setMetric(obj.getMetric());
230 xmlObj.setValues(obj.getValue());
231 xmlObj.setUnit(obj.getUnit());
232 xmlObj.setAggregationFunction(
233 obj.getAggregationFunction() != null ? obj.getAggregationFunction().name() : null);
234 xmlObj.setTime(obj.getTime());
238 LimitForXml spLimitForXml = new LimitForXml();
239 spLimitForXml.setLimits(hs);
240 return spLimitForXml;
246 public LimitForXml getVendorLimits() {
247 if (limits != null) {
248 Set<LimitXml> hs = new HashSet<>();
249 for (LimitEntity obj : limits) {
250 if (obj.getType().equals(LimitType.Vendor)) {
251 LimitXml xmlObj = new LimitXml();
252 xmlObj.setDescription(obj.getDescription());
253 xmlObj.setMetric(obj.getMetric());
254 xmlObj.setValues(obj.getValue());
255 xmlObj.setUnit(obj.getUnit());
256 xmlObj.setAggregationFunction(
257 obj.getAggregationFunction() != null ? obj.getAggregationFunction().name() : null);
258 xmlObj.setTime(obj.getTime());
262 LimitForXml vendorLimitForXml = new LimitForXml();
263 vendorLimitForXml.setLimits(hs);
264 return vendorLimitForXml;
270 public String getStartDate() {
274 public void setStartDate(String startDate) {
275 this.startDate = startDate;
278 public String getExpiryDate() {
282 public void setExpiryDate(String expiryDate) {
283 this.expiryDate = expiryDate;
287 public int hashCode() {
289 .hash(vendorLicenseModelId, version, id, name, description, type, operationalScope,
290 referencingFeatureGroups, startDate, expiryDate,
291 thresholdValue, thresholdUnits, increments);
295 public boolean equals(Object obj) {
299 if (obj == null || getClass() != obj.getClass()) {
302 LicenseKeyGroupEntity that = (LicenseKeyGroupEntity) obj;
303 return Objects.equals(vendorLicenseModelId, that.vendorLicenseModelId)
304 && Objects.equals(version, that.version)
305 && Objects.equals(id, that.id)
306 && Objects.equals(name, that.name)
307 && Objects.equals(description, that.description)
309 && Objects.equals(operationalScope, that.operationalScope)
310 && Objects.equals(referencingFeatureGroups, that.referencingFeatureGroups)
311 && Objects.equals(startDate, that.startDate)
312 && Objects.equals(expiryDate, that.expiryDate)
313 && Objects.equals(thresholdValue, that.thresholdValue)
314 && Objects.equals(thresholdUnits, that.thresholdUnits)
315 && Objects.equals(increments, that.increments)
316 && Objects.equals(manufacturerReferenceNumber, that.manufacturerReferenceNumber);
320 public String toString() {
321 return "LicenseKeyGroupEntity{" + "vendorLicenseModelId='" + vendorLicenseModelId + '\''
322 + ", version=" + version
323 + ", id='" + id + '\''
324 + ", name='" + name + '\''
325 + ", description='" + description + '\''
327 + ", operationalScope=" + operationalScope
328 + ", referencingFeatureGroups=" + referencingFeatureGroups
329 + ", versionUuId='" + versionUuId + '\''
330 + ", startDate=" + startDate
331 + ", expiryDate=" + expiryDate
332 + ", thresholdValue='" + thresholdValue + '\''
333 + ", thresholdUnits='" + thresholdUnits + '\''
334 + ", increments='" + increments + '\''
339 * Gets operational scope for artifact.
341 * @return the operational scope for artifact
343 public OperationalScopeForXml getOperationalScopeForArtifact() {
344 OperationalScopeForXml obj = new OperationalScopeForXml();
345 if (operationalScope != null) {
346 if (operationalScope.getResults().size() > 0) {
347 obj.setValue(operationalScope.getResults());
354 * Gets version for artifact.
356 * @return version in format suitable for artifact
358 public String getVersionForArtifact() {
359 return version.toString();
363 * Gets type for artifact.
365 * @return the type for artifact
367 public LicenseKeyTypeForXml getTypeForArtifact() {
368 LicenseKeyTypeForXml typeXml = new LicenseKeyTypeForXml();
370 typeXml.setValue(type.toString());
372 typeXml.setValue(null);
377 //Defined and used only for License Artifcat XMLs
378 public String getManufacturerReferenceNumber() {
379 return manufacturerReferenceNumber;
382 public void setManufacturerReferenceNumber(String manufacturerReferenceNumber) {
383 this.manufacturerReferenceNumber = manufacturerReferenceNumber;
386 public String getIsoFormatStartDate() {
387 String isoFormatStartDate = null;
388 if (!StringUtils.isEmpty(startDate)) {
389 isoFormatStartDate = VendorLicenseUtil.getIsoFormatDate(startDate);
391 return isoFormatStartDate;
395 public String getIsoFormatExpiryDate() {
396 String isoFormatExpDate = null;
397 if (!StringUtils.isEmpty(expiryDate)) {
398 isoFormatExpDate = VendorLicenseUtil.getIsoFormatDate(expiryDate);
400 return isoFormatExpDate;