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.LimitForXml;
30 import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitXml;
31 import org.openecomp.sdc.vendorlicense.dao.types.xml.OperationalScopeForXml;
32 import org.openecomp.sdc.vendorlicense.dao.types.xml.ThresholdForXml;
33 import org.openecomp.sdc.versioning.dao.types.Version;
34 import org.openecomp.sdc.versioning.dao.types.VersionableEntity;
36 import java.util.Collection;
37 import java.util.HashSet;
38 import java.util.Objects;
41 @Table(keyspace = "dox", name = "entitlement_pool")
42 public class EntitlementPoolEntity implements VersionableEntity {
43 private static final String ENTITY_TYPE = "Entitlement Pool";
46 @Column(name = "vlm_id")
47 private String vendorLicenseModelId;
49 @PartitionKey(value = 1)
51 private Version version;
54 @Column(name = "ep_id")
57 private String description;
59 @Column(name = "threshold")
60 private Integer thresholdValue;
62 @Column(name = "threshold_unit")
64 private ThresholdUnit thresholdUnit;
66 private String increments;
68 @Column(name = "operational_scope")
70 private MultiChoiceOrOther<OperationalScope> operationalScope;
72 @Column(name = "ref_fg_ids")
73 private Set<String> referencingFeatureGroups = new HashSet<>();
75 @Column(name = "version_uuid")
76 private String versionUuId;
79 private String startDate;
80 private String expiryDate;
82 private Collection<LimitEntity> limits;
84 //Defined and used only for License Artifcat XMLs
85 private String manufacturerReferenceNumber;
87 public EntitlementPoolEntity() {
91 * Instantiates a new Entitlement pool entity.
93 * @param vlmId the vlm id
94 * @param version the version
97 public EntitlementPoolEntity(String vlmId, Version version, String id) {
98 this.vendorLicenseModelId = vlmId;
99 this.version = version;
104 public String getEntityType() {
109 public String getFirstClassCitizenId() {
110 return getVendorLicenseModelId();
114 public String getId() {
119 public void setId(String id) {
124 public Version getVersion() {
129 public void setVersion(Version version) {
130 this.version = version;
134 public String getVersionUuId() {
139 public void setVersionUuId(String uuId) {
143 public String getVendorLicenseModelId() {
144 return vendorLicenseModelId;
147 public void setVendorLicenseModelId(String vendorLicenseModelId) {
148 this.vendorLicenseModelId = vendorLicenseModelId;
151 public Set<String> getReferencingFeatureGroups() {
152 return referencingFeatureGroups;
155 public void setReferencingFeatureGroups(Set<String> referencingFeatureGroups) {
156 this.referencingFeatureGroups = referencingFeatureGroups;
159 public String getName() {
163 public void setName(String name) {
167 public String getDescription() {
171 public void setDescription(String description) {
172 this.description = description;
175 public Integer getThresholdValue() {
176 return thresholdValue;
179 public void setThresholdValue(Integer thresholdValue) {
180 this.thresholdValue = thresholdValue;
183 public ThresholdUnit getThresholdUnit() {
184 return thresholdUnit;
187 public void setThresholdUnit(ThresholdUnit thresholdUnits) {
188 this.thresholdUnit = thresholdUnits;
191 public String getIncrements() {
195 public void setIncrements(String increments) {
196 this.increments = increments;
199 public MultiChoiceOrOther<OperationalScope> getOperationalScope() {
200 return operationalScope;
203 public void setOperationalScope(MultiChoiceOrOther<OperationalScope> operationalScope) {
204 if(operationalScope != null) {
205 operationalScope.resolveEnum(OperationalScope.class);
207 this.operationalScope = operationalScope;
211 * Gets threshold for artifact.
213 * @return the threshold for artifact
215 public ThresholdForXml getThresholdForArtifact() {
216 ThresholdForXml threshold = new ThresholdForXml();
217 threshold.setUnit(getThresholdUnit() == null ? null : getThresholdUnit().name());
218 threshold.setValue(getThresholdValue());
223 * Gets version for artifact.
224 * @return version in format suitable for artifact
226 public String getVersionForArtifact() {
227 return version.toString();
230 public String getStartDate() {
234 public void setStartDate(String startDate) {
235 this.startDate = startDate;
238 public String getExpiryDate() {
242 public void setExpiryDate(String expiryDate) {
243 this.expiryDate = expiryDate;
246 public Collection<LimitEntity> getLimits() {
250 public void setLimits(Collection<LimitEntity> limits) {
251 this.limits = limits;
254 public LimitForXml getSPLimits(){
256 Set<LimitXml> hs = new HashSet<>();
257 for(LimitEntity obj : limits){
258 if(obj.getType().equals(LimitType.ServiceProvider)){
259 LimitXml xmlObj = new LimitXml();
260 xmlObj.setDescription(obj.getDescription());
261 xmlObj.setMetric(obj.getMetric()!=null?obj.getMetric().name():null);
262 xmlObj.setValues(obj.getValue()!=null?Integer.toString(obj.getValue()):null);
263 xmlObj.setUnit(obj.getUnit()!=null?Integer.toString(obj.getUnit()):null);
264 xmlObj.setAggregationFunction(obj.getAggregationFunction()!=null?obj.getAggregationFunction().name():null);
265 xmlObj.setTime(obj.getTime()!=null?obj.getTime().name():null);
269 LimitForXml spLimitForXml = new LimitForXml();
270 spLimitForXml.setLimits(hs);
271 return spLimitForXml;
277 public LimitForXml getVendorLimits(){
279 Set<LimitXml> hs = new HashSet<>();
280 for(LimitEntity obj : limits){
281 if(obj.getType().equals(LimitType.Vendor)){
282 LimitXml xmlObj = new LimitXml();
283 xmlObj.setDescription(obj.getDescription());
284 xmlObj.setMetric(obj.getMetric()!=null?obj.getMetric().name():null);
285 xmlObj.setValues(obj.getValue()!=null?Integer.toString(obj.getValue()):null);
286 xmlObj.setUnit(obj.getUnit()!=null?Integer.toString(obj.getUnit()):null);
287 xmlObj.setAggregationFunction(obj.getAggregationFunction()!=null?obj.getAggregationFunction().name():null);
288 xmlObj.setTime(obj.getTime()!=null?obj.getTime().name():null);
292 LimitForXml vendorLimitForXml = new LimitForXml();
293 vendorLimitForXml.setLimits(hs);
294 return vendorLimitForXml;
302 public int hashCode() {
304 .hash(vendorLicenseModelId, version, id, name, description, thresholdValue, thresholdUnit,
305 increments, operationalScope, referencingFeatureGroups, startDate, expiryDate);
309 public boolean equals(Object obj) {
313 if (obj == null || getClass() != obj.getClass()) {
316 EntitlementPoolEntity that = (EntitlementPoolEntity) obj;
317 return Objects.equals(that.thresholdValue, thresholdValue)
318 && Objects.equals(vendorLicenseModelId, that.vendorLicenseModelId)
319 && Objects.equals(id, that.id)
320 && Objects.equals(name, that.name)
321 && Objects.equals(description, that.description)
322 && Objects.equals(thresholdUnit, that.thresholdUnit)
323 && Objects.equals(increments, that.increments)
324 && Objects.equals(operationalScope, that.operationalScope)
325 && Objects.equals(referencingFeatureGroups, that.referencingFeatureGroups)
326 && Objects.equals(startDate, that.startDate)
327 && Objects.equals(expiryDate, that.expiryDate);
331 public String toString() {
332 return "EntitlementPoolEntity{"
333 + "vendorLicenseModelId='" + vendorLicenseModelId + '\''
334 + ", version=" + version
335 + ", id='" + id + '\''
336 + ", name='" + name + '\''
337 + ", description='" + description + '\''
338 + ", thresholdValue=" + thresholdValue
339 + ", thresholdUnit='" + thresholdUnit + '\''
340 + ", increments='" + increments + '\''
341 + ", operationalScope=" + operationalScope
342 + ", referencingFeatureGroups=" + referencingFeatureGroups
343 + ", version_uuid=" + versionUuId
344 + ", startDate=" + startDate
345 + ", expiryDate=" + expiryDate
350 * Gets operational scope for artifact.
352 * @return the operational scope for artifact
354 public OperationalScopeForXml getOperationalScopeForArtifact() {
355 OperationalScopeForXml obj = new OperationalScopeForXml();
356 if (operationalScope != null) {
357 if(operationalScope.getResults().size() > 0) {
358 obj.setValue(operationalScope.getResults());
364 //Defined and used only for License Artifcat XMLs
365 public void setManufacturerReferenceNumber(String manufacturerReferenceNumber) {
366 this.manufacturerReferenceNumber = manufacturerReferenceNumber;
369 public String getManufacturerReferenceNumber() {
370 return manufacturerReferenceNumber;