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.LimitForXml;
32 import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitXml;
33 import org.openecomp.sdc.vendorlicense.dao.types.xml.OperationalScopeForXml;
34 import org.openecomp.sdc.vendorlicense.dao.types.xml.ThresholdForXml;
35 import org.openecomp.sdc.versioning.dao.types.Version;
36 import org.openecomp.sdc.versioning.dao.types.VersionableEntity;
38 import java.util.Collection;
39 import java.util.HashSet;
40 import java.util.Objects;
43 @Table(keyspace = "dox", name = "entitlement_pool")
44 public class EntitlementPoolEntity implements VersionableEntity {
45 private static final String ENTITY_TYPE = "Entitlement Pool";
48 @Column(name = "vlm_id")
49 private String vendorLicenseModelId;
51 @PartitionKey(value = 1)
53 private Version version;
56 @Column(name = "ep_id")
59 private String description;
61 @Column(name = "threshold")
62 private Integer thresholdValue;
64 @Column(name = "threshold_unit")
65 private ThresholdUnit thresholdUnit;
67 private String increments;
69 @Column(name = "operational_scope")
71 private MultiChoiceOrOther<OperationalScope> operationalScope;
73 @Column(name = "ref_fg_ids")
74 private Set<String> referencingFeatureGroups = new HashSet<>();
76 @Column(name = "version_uuid")
77 private String versionUuId;
80 private String startDate;
81 private String expiryDate;
83 private Collection<LimitEntity> limits;
85 //Defined and used only for License Artifcat XMLs
86 private String manufacturerReferenceNumber;
89 * Every entity class must have a default constructor according to
90 * <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/object_mapper/creating/">
91 * Definition of mapped classes</a>.
93 public EntitlementPoolEntity() {
94 // Don't delete! Default constructor is required by DataStax driver
98 * Instantiates a new Entitlement pool entity.
100 * @param vlmId the vlm id
101 * @param version the version
104 public EntitlementPoolEntity(String vlmId, Version version, String id) {
105 this.vendorLicenseModelId = vlmId;
106 this.version = version;
111 public String getEntityType() {
116 public String getFirstClassCitizenId() {
117 return getVendorLicenseModelId();
121 public String getId() {
126 public void setId(String id) {
131 public Version getVersion() {
136 public void setVersion(Version version) {
137 this.version = version;
141 public String getVersionUuId() {
146 public void setVersionUuId(String uuId) {
150 public String getVendorLicenseModelId() {
151 return vendorLicenseModelId;
154 public void setVendorLicenseModelId(String vendorLicenseModelId) {
155 this.vendorLicenseModelId = vendorLicenseModelId;
158 public Set<String> getReferencingFeatureGroups() {
159 return referencingFeatureGroups;
162 public void setReferencingFeatureGroups(Set<String> referencingFeatureGroups) {
163 this.referencingFeatureGroups = referencingFeatureGroups;
166 public String getName() {
170 public void setName(String name) {
174 public String getDescription() {
178 public void setDescription(String description) {
179 this.description = description;
182 public Integer getThresholdValue() {
183 return thresholdValue;
186 public void setThresholdValue(Integer thresholdValue) {
187 this.thresholdValue = thresholdValue;
190 public ThresholdUnit getThresholdUnit() {
191 return thresholdUnit;
194 public void setThresholdUnit(ThresholdUnit thresholdUnits) {
195 this.thresholdUnit = thresholdUnits;
198 public String getIncrements() {
202 public void setIncrements(String increments) {
203 this.increments = increments;
206 public MultiChoiceOrOther<OperationalScope> getOperationalScope() {
207 return operationalScope;
210 public void setOperationalScope(MultiChoiceOrOther<OperationalScope> operationalScope) {
211 if (operationalScope != null) {
212 operationalScope.resolveEnum(OperationalScope.class);
214 this.operationalScope = operationalScope;
218 * Gets threshold for artifact.
220 * @return the threshold for artifact
222 public ThresholdForXml getThresholdForArtifact() {
223 ThresholdForXml threshold = new ThresholdForXml();
224 threshold.setUnit(getThresholdUnit() == null ? null : getThresholdUnit().name());
225 threshold.setValue(getThresholdValue());
230 * Gets version for artifact.
232 * @return version in format suitable for artifact
234 public String getVersionForArtifact() {
235 return version.toString();
238 public String getStartDate() {
242 public void setStartDate(String startDate) {
243 this.startDate = startDate;
246 public String getExpiryDate() {
250 public void setExpiryDate(String expiryDate) {
251 this.expiryDate = expiryDate;
254 public Collection<LimitEntity> getLimits() {
258 public void setLimits(Collection<LimitEntity> limits) {
259 this.limits = limits;
262 public LimitForXml getSPLimits() {
263 if (limits != null) {
264 Set<LimitXml> hs = new HashSet<>();
265 for (LimitEntity obj : limits) {
266 if (obj.getType().equals(LimitType.ServiceProvider)) {
267 LimitXml xmlObj = new LimitXml();
268 xmlObj.setDescription(obj.getDescription());
269 xmlObj.setMetric(obj.getMetric());
270 xmlObj.setValues(obj.getValue());
271 xmlObj.setUnit(obj.getUnit());
272 xmlObj.setAggregationFunction(
273 obj.getAggregationFunction() != null ? obj.getAggregationFunction().name() : null);
274 xmlObj.setTime(obj.getTime());
278 LimitForXml spLimitForXml = new LimitForXml();
279 spLimitForXml.setLimits(hs);
280 return spLimitForXml;
286 public LimitForXml getVendorLimits() {
287 if (limits != null) {
288 Set<LimitXml> hs = new HashSet<>();
289 for (LimitEntity obj : limits) {
290 if (obj.getType().equals(LimitType.Vendor)) {
291 LimitXml xmlObj = new LimitXml();
292 xmlObj.setDescription(obj.getDescription());
293 xmlObj.setMetric(obj.getMetric());
294 xmlObj.setValues(obj.getValue());
295 xmlObj.setUnit(obj.getUnit());
296 xmlObj.setAggregationFunction(
297 obj.getAggregationFunction() != null ? obj.getAggregationFunction().name() : null);
298 xmlObj.setTime(obj.getTime());
302 LimitForXml vendorLimitForXml = new LimitForXml();
303 vendorLimitForXml.setLimits(hs);
304 return vendorLimitForXml;
312 public int hashCode() {
314 .hash(vendorLicenseModelId, version, id, name, description, thresholdValue, thresholdUnit,
315 increments, operationalScope, referencingFeatureGroups, startDate, expiryDate);
319 public boolean equals(Object obj) {
323 if (obj == null || getClass() != obj.getClass()) {
326 EntitlementPoolEntity that = (EntitlementPoolEntity) obj;
327 return Objects.equals(that.thresholdValue, thresholdValue)
328 && Objects.equals(vendorLicenseModelId, that.vendorLicenseModelId)
329 && Objects.equals(id, that.id)
330 && Objects.equals(name, that.name)
331 && Objects.equals(description, that.description)
332 && Objects.equals(thresholdUnit, that.thresholdUnit)
333 && Objects.equals(increments, that.increments)
334 && Objects.equals(operationalScope, that.operationalScope)
335 && Objects.equals(referencingFeatureGroups, that.referencingFeatureGroups)
336 && Objects.equals(startDate, that.startDate)
337 && Objects.equals(expiryDate, that.expiryDate)
338 && Objects.equals(manufacturerReferenceNumber, that.manufacturerReferenceNumber)
339 && Objects.equals(version, that.version);
343 public String toString() {
344 return "EntitlementPoolEntity{"
345 + "vendorLicenseModelId='" + vendorLicenseModelId + '\''
346 + ", version=" + version
347 + ", id='" + id + '\''
348 + ", name='" + name + '\''
349 + ", description='" + description + '\''
350 + ", thresholdValue=" + thresholdValue
351 + ", thresholdUnit='" + thresholdUnit + '\''
352 + ", increments='" + increments + '\''
353 + ", operationalScope=" + operationalScope
354 + ", referencingFeatureGroups=" + referencingFeatureGroups
355 + ", version_uuid=" + versionUuId
356 + ", startDate=" + startDate
357 + ", expiryDate=" + expiryDate
362 * Gets operational scope for artifact.
364 * @return the operational scope for artifact
366 public OperationalScopeForXml getOperationalScopeForArtifact() {
367 OperationalScopeForXml obj = new OperationalScopeForXml();
368 if (operationalScope != null) {
369 if (operationalScope.getResults().size() > 0) {
370 obj.setValue(operationalScope.getResults());
376 //Defined and used only for License Artifcat XMLs
377 public void setManufacturerReferenceNumber(String manufacturerReferenceNumber) {
378 this.manufacturerReferenceNumber = manufacturerReferenceNumber;
381 public String getManufacturerReferenceNumber() {
382 return manufacturerReferenceNumber;
385 public String getIsoFormatStartDate() {
386 String isoFormatStartDate = null;
387 if (!StringUtils.isEmpty(startDate)) {
388 isoFormatStartDate = VendorLicenseUtil.getIsoFormatDate(startDate);
390 return isoFormatStartDate;
394 public String getIsoFormatExpiryDate() {
395 String isoFormatExpDate = null;
396 if (!StringUtils.isEmpty(expiryDate)) {
397 isoFormatExpDate = VendorLicenseUtil.getIsoFormatDate(expiryDate);
399 return isoFormatExpDate;