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.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;
37 import java.util.Collection;
38 import java.util.HashSet;
39 import java.util.Objects;
42 @Table(keyspace = "dox", name = "license_key_group")
43 public class LicenseKeyGroupEntity implements VersionableEntity {
44 private static final String ENTITY_TYPE = "License Key Group";
47 @Column(name = "vlm_id")
48 private String vendorLicenseModelId;
49 @PartitionKey(value = 1)
51 private Version version;
53 @Column(name = "lkg_id")
56 private String description;
58 private LicenseKeyType type;
59 @Column(name = "operational_scope")
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;
70 private Collection<LimitEntity> limits;
71 private String startDate;
72 private String expiryDate;
74 //Defined and used only for License Artifcat XMLs
75 private String manufacturerReferenceNumber;
78 public LicenseKeyGroupEntity() {
82 * Instantiates a new License key group entity.
84 * @param vendorLicenseModelId the vendor license model id
85 * @param version the version
88 public LicenseKeyGroupEntity(String vendorLicenseModelId, Version version, String id) {
89 this.vendorLicenseModelId = vendorLicenseModelId;
90 this.version = version;
95 public String getEntityType() {
100 public String getFirstClassCitizenId() {
101 return getVendorLicenseModelId();
104 public String getId() {
108 public void setId(String id) {
112 public Version getVersion() {
116 public void setVersion(Version version) {
117 this.version = version;
121 public String getVersionUuId() {
126 public void setVersionUuId(String uuId) {
130 public String getVendorLicenseModelId() {
131 return vendorLicenseModelId;
134 public void setVendorLicenseModelId(String vendorLicenseModelId) {
135 this.vendorLicenseModelId = vendorLicenseModelId;
138 public String getName() {
142 public void setName(String name) {
146 public String getDescription() {
150 public void setDescription(String description) {
151 this.description = description;
154 public LicenseKeyType getType() {
158 public void setType(LicenseKeyType type) {
162 public MultiChoiceOrOther<OperationalScope> getOperationalScope() {
163 return operationalScope;
166 public void setOperationalScope(MultiChoiceOrOther<OperationalScope> operationalScope) {
167 if(operationalScope != null) {
168 operationalScope.resolveEnum(OperationalScope.class);
170 this.operationalScope = operationalScope;
173 public Set<String> getReferencingFeatureGroups() {
174 return referencingFeatureGroups;
177 public void setReferencingFeatureGroups(Set<String> referencingFeatureGroups) {
178 this.referencingFeatureGroups = referencingFeatureGroups;
181 public Integer getThresholdValue() {
182 return thresholdValue;
185 public void setThresholdValue(Integer thresholdValue) {
186 this.thresholdValue = thresholdValue;
189 public ThresholdUnit getThresholdUnits() {
190 return thresholdUnits;
193 public void setThresholdUnits(ThresholdUnit thresholdUnit) {
194 this.thresholdUnits = thresholdUnit;
197 public String getIncrements() {
201 public void setIncrements(String increments) {
202 this.increments = increments;
205 public ThresholdForXml getThresholdForArtifact() {
206 ThresholdForXml threshold = new ThresholdForXml();
207 threshold.setUnit(getThresholdUnits() == null ? null : getThresholdUnits().name());
208 threshold.setValue(getThresholdValue());
212 public Collection<LimitEntity> getLimits() {
216 public void setLimits(Collection<LimitEntity> limits) {
217 this.limits = limits;
220 public LimitForXml getSPLimits(){
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());
235 LimitForXml spLimitForXml = new LimitForXml();
236 spLimitForXml.setLimits(hs);
237 return spLimitForXml;
243 public LimitForXml getVendorLimits(){
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;
266 public String getStartDate() {
270 public void setStartDate(String startDate) {
271 this.startDate = startDate;
274 public String getExpiryDate() {
278 public void setExpiryDate(String expiryDate) {
279 this.expiryDate = expiryDate;
283 public int hashCode() {
285 .hash(vendorLicenseModelId, version, id, name, description, type, operationalScope,
286 referencingFeatureGroups, startDate, expiryDate,
287 thresholdValue, thresholdUnits, increments);
291 public boolean equals(Object obj) {
295 if (obj == null || getClass() != obj.getClass()) {
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)
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);
314 public String toString() {
315 return "LicenseKeyGroupEntity{" + "vendorLicenseModelId='" + vendorLicenseModelId + '\''
316 + ", version=" + version
317 + ", id='" + id + '\''
318 + ", name='" + name + '\''
319 + ", description='" + description + '\''
321 + ", operationalScope=" + operationalScope
322 + ", referencingFeatureGroups=" + referencingFeatureGroups
323 + ", versionUuId='" + versionUuId + '\''
324 + ", startDate=" + startDate
325 + ", expiryDate=" + expiryDate
326 + ", thresholdValue='" + thresholdValue + '\''
327 + ", thresholdUnits='" + thresholdUnits + '\''
328 + ", increments='" + increments + '\''
333 * Gets operational scope for artifact.
335 * @return the operational scope for artifact
337 public OperationalScopeForXml getOperationalScopeForArtifact() {
338 OperationalScopeForXml obj = new OperationalScopeForXml();
339 if (operationalScope != null) {
340 if(operationalScope.getResults().size() > 0) {
341 obj.setValue(operationalScope.getResults());
348 * Gets version for artifact.
349 * @return version in format suitable for artifact
351 public String getVersionForArtifact() {
352 return version.toString();
356 * Gets type for artifact.
358 * @return the type for artifact
360 public LicenseKeyTypeForXml getTypeForArtifact() {
361 LicenseKeyTypeForXml typeXml = new LicenseKeyTypeForXml();
363 typeXml.setValue(type.toString());
365 typeXml.setValue(null);
370 //Defined and used only for License Artifcat XMLs
371 public String getManufacturerReferenceNumber() {
372 return manufacturerReferenceNumber;
375 public void setManufacturerReferenceNumber(String manufacturerReferenceNumber) {
376 this.manufacturerReferenceNumber = manufacturerReferenceNumber;