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=========================================================
20 package org.openecomp.sdc.vendorlicense.dao.types;
22 import com.datastax.driver.mapping.annotations.ClusteringColumn;
23 import com.datastax.driver.mapping.annotations.Column;
24 import com.datastax.driver.mapping.annotations.Frozen;
25 import com.datastax.driver.mapping.annotations.PartitionKey;
26 import com.datastax.driver.mapping.annotations.Table;
27 import java.util.Collection;
28 import java.util.HashSet;
29 import java.util.Objects;
31 import org.apache.commons.lang3.StringUtils;
32 import org.openecomp.sdc.vendorlicense.VendorLicenseUtil;
33 import org.openecomp.sdc.vendorlicense.dao.types.xml.LicenseKeyTypeForXml;
34 import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitForXml;
35 import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitXml;
36 import org.openecomp.sdc.vendorlicense.dao.types.xml.OperationalScopeForXml;
37 import org.openecomp.sdc.vendorlicense.dao.types.xml.ThresholdForXml;
38 import org.openecomp.sdc.versioning.dao.types.Version;
39 import org.openecomp.sdc.versioning.dao.types.VersionableEntity;
41 @Table(keyspace = "dox", name = "license_key_group")
42 public class LicenseKeyGroupEntity implements VersionableEntity {
44 private static final String ENTITY_TYPE = "License Key Group";
46 @Column(name = "vlm_id")
47 private String vendorLicenseModelId;
48 @PartitionKey(value = 1)
50 private Version version;
52 @Column(name = "lkg_id")
55 private String description;
56 private LicenseKeyType type;
57 @Column(name = "operational_scope")
59 private MultiChoiceOrOther<OperationalScope> operationalScope;
60 @Column(name = "ref_fg_ids")
61 private Set<String> referencingFeatureGroups = new HashSet<>();
62 @Column(name = "version_uuid")
63 private String versionUuId;
64 private Integer thresholdValue;
65 private ThresholdUnit thresholdUnits;
66 private String increments;
67 private Collection<LimitEntity> limits;
68 private String startDate;
69 private String expiryDate;
70 //Defined and used only for License Artifcat XMLs
71 private String manufacturerReferenceNumber;
74 * Every entity class must have a default constructor according to
75 * <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/object_mapper/creating/">
76 * Definition of mapped classes</a>.
78 public LicenseKeyGroupEntity() {
79 // Don't delete! Default constructor is required by DataStax driver
83 * Instantiates a new License key group entity.
85 * @param vendorLicenseModelId the vendor license model id
86 * @param version the version
89 public LicenseKeyGroupEntity(String vendorLicenseModelId, Version version, String id) {
90 this.vendorLicenseModelId = vendorLicenseModelId;
91 this.version = version;
96 public String getEntityType() {
101 public String getFirstClassCitizenId() {
102 return getVendorLicenseModelId();
105 public String getId() {
109 public void setId(String id) {
113 public Version getVersion() {
117 public void setVersion(Version version) {
118 this.version = version;
122 public String getVersionUuId() {
127 public void setVersionUuId(String uuId) {
131 public String getVendorLicenseModelId() {
132 return vendorLicenseModelId;
135 public void setVendorLicenseModelId(String vendorLicenseModelId) {
136 this.vendorLicenseModelId = vendorLicenseModelId;
139 public String getName() {
143 public void setName(String name) {
147 public String getDescription() {
151 public void setDescription(String description) {
152 this.description = description;
155 public LicenseKeyType getType() {
159 public void setType(LicenseKeyType type) {
163 public MultiChoiceOrOther<OperationalScope> getOperationalScope() {
164 return operationalScope;
167 public void setOperationalScope(MultiChoiceOrOther<OperationalScope> operationalScope) {
168 if (operationalScope != null) {
169 operationalScope.resolveEnum(OperationalScope.class);
171 this.operationalScope = operationalScope;
174 public Set<String> getReferencingFeatureGroups() {
175 return referencingFeatureGroups;
178 public void setReferencingFeatureGroups(Set<String> referencingFeatureGroups) {
179 this.referencingFeatureGroups = referencingFeatureGroups;
182 public Integer getThresholdValue() {
183 return thresholdValue;
186 public void setThresholdValue(Integer thresholdValue) {
187 this.thresholdValue = thresholdValue;
190 public ThresholdUnit getThresholdUnits() {
191 return thresholdUnits;
194 public void setThresholdUnits(ThresholdUnit thresholdUnit) {
195 this.thresholdUnits = thresholdUnit;
198 public String getIncrements() {
202 public void setIncrements(String increments) {
203 this.increments = increments;
206 public ThresholdForXml getThresholdForArtifact() {
207 ThresholdForXml threshold = new ThresholdForXml();
208 threshold.setUnit(getThresholdUnits() == null ? null : getThresholdUnits().name());
209 threshold.setValue(getThresholdValue());
213 public Collection<LimitEntity> getLimits() {
217 public void setLimits(Collection<LimitEntity> limits) {
218 this.limits = limits;
221 public LimitForXml getSPLimits() {
222 if (limits != null) {
223 Set<LimitXml> hs = new HashSet<>();
224 for (LimitEntity obj : limits) {
225 if (obj.getType().equals(LimitType.ServiceProvider)) {
226 LimitXml xmlObj = new LimitXml();
227 xmlObj.setDescription(obj.getDescription());
228 xmlObj.setMetric(obj.getMetric());
229 xmlObj.setValues(obj.getValue());
230 xmlObj.setUnit(obj.getUnit());
231 xmlObj.setAggregationFunction(obj.getAggregationFunction() != null ? obj.getAggregationFunction().name() : null);
232 xmlObj.setTime(obj.getTime());
236 LimitForXml spLimitForXml = new LimitForXml();
237 spLimitForXml.setLimits(hs);
238 return spLimitForXml;
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());
258 LimitForXml vendorLimitForXml = new LimitForXml();
259 vendorLimitForXml.setLimits(hs);
260 return vendorLimitForXml;
265 public String getStartDate() {
269 public void setStartDate(String startDate) {
270 this.startDate = startDate;
273 public String getExpiryDate() {
277 public void setExpiryDate(String expiryDate) {
278 this.expiryDate = expiryDate;
282 public int hashCode() {
284 .hash(vendorLicenseModelId, version, id, name, description, type, operationalScope, referencingFeatureGroups, startDate, expiryDate,
285 thresholdValue, thresholdUnits, increments);
289 public boolean equals(Object obj) {
293 if (obj == null || getClass() != obj.getClass()) {
296 LicenseKeyGroupEntity that = (LicenseKeyGroupEntity) obj;
297 return Objects.equals(vendorLicenseModelId, that.vendorLicenseModelId) && Objects.equals(version, that.version) && Objects.equals(id, that.id)
298 && Objects.equals(name, that.name) && Objects.equals(description, that.description) && type == that.type && Objects
299 .equals(that.operationalScope, operationalScope) && Objects.equals(startDate, that.startDate) && Objects
300 .equals(expiryDate, that.expiryDate) && Objects.equals(thresholdValue, that.thresholdValue) && Objects
301 .equals(thresholdUnits, that.thresholdUnits) && Objects.equals(increments, that.increments) && Objects
302 .equals(manufacturerReferenceNumber, that.manufacturerReferenceNumber);
306 public String toString() {
307 return "LicenseKeyGroupEntity{" + "vendorLicenseModelId='" + vendorLicenseModelId + '\'' + ", version=" + version + ", id='" + id + '\''
308 + ", name='" + name + '\'' + ", description='" + description + '\'' + ", type=" + type + ", operationalScope=" + operationalScope
309 + ", referencingFeatureGroups=" + referencingFeatureGroups + ", versionUuId='" + versionUuId + '\'' + ", startDate=" + startDate
310 + ", expiryDate=" + expiryDate + ", thresholdValue='" + thresholdValue + '\'' + ", thresholdUnits='" + thresholdUnits + '\''
311 + ", increments='" + increments + '\'' + '}';
315 * Gets operational scope for artifact.
317 * @return the operational scope for artifact
319 public OperationalScopeForXml getOperationalScopeForArtifact() {
320 OperationalScopeForXml obj = new OperationalScopeForXml();
321 if (operationalScope != null) {
322 if (operationalScope.getResults().size() > 0) {
323 obj.setValue(operationalScope.getResults());
330 * Gets version for artifact.
332 * @return version in format suitable for artifact
334 public String getVersionForArtifact() {
335 return version.toString();
339 * Gets type for artifact.
341 * @return the type for artifact
343 public LicenseKeyTypeForXml getTypeForArtifact() {
344 LicenseKeyTypeForXml typeXml = new LicenseKeyTypeForXml();
346 typeXml.setValue(type.toString());
348 typeXml.setValue(null);
353 //Defined and used only for License Artifcat XMLs
354 public String getManufacturerReferenceNumber() {
355 return manufacturerReferenceNumber;
358 public void setManufacturerReferenceNumber(String manufacturerReferenceNumber) {
359 this.manufacturerReferenceNumber = manufacturerReferenceNumber;
362 public String getIsoFormatStartDate() {
363 String isoFormatStartDate = null;
364 if (!StringUtils.isEmpty(startDate)) {
365 isoFormatStartDate = VendorLicenseUtil.getIsoFormatDate(startDate);
367 return isoFormatStartDate;
370 public String getIsoFormatExpiryDate() {
371 String isoFormatExpDate = null;
372 if (!StringUtils.isEmpty(expiryDate)) {
373 isoFormatExpDate = VendorLicenseUtil.getIsoFormatDate(expiryDate);
375 return isoFormatExpDate;