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;
60 private EntitlementPoolType type;
62 @Column(name = "threshold")
63 private Integer thresholdValue;
65 @Column(name = "threshold_unit")
66 private ThresholdUnit thresholdUnit;
68 private String increments;
70 @Column(name = "operational_scope")
72 private MultiChoiceOrOther<OperationalScope> operationalScope;
74 @Column(name = "ref_fg_ids")
75 private Set<String> referencingFeatureGroups = new HashSet<>();
77 @Column(name = "version_uuid")
78 private String versionUuId;
81 private String startDate;
82 private String expiryDate;
84 private Collection<LimitEntity> limits;
86 //Defined and used only for License Artifcat XMLs
87 private String manufacturerReferenceNumber;
90 * Every entity class must have a default constructor according to
91 * <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/object_mapper/creating/">
92 * Definition of mapped classes</a>.
94 public EntitlementPoolEntity() {
95 // Don't delete! Default constructor is required by DataStax driver
99 * Instantiates a new Entitlement pool entity.
101 * @param vlmId the vlm id
102 * @param version the version
105 public EntitlementPoolEntity(String vlmId, Version version, String id) {
106 this.vendorLicenseModelId = vlmId;
107 this.version = version;
112 public String getEntityType() {
117 public String getFirstClassCitizenId() {
118 return getVendorLicenseModelId();
122 public String getId() {
127 public void setId(String id) {
132 public Version getVersion() {
137 public void setVersion(Version version) {
138 this.version = version;
142 public String getVersionUuId() {
147 public void setVersionUuId(String uuId) {
151 public String getVendorLicenseModelId() {
152 return vendorLicenseModelId;
155 public void setVendorLicenseModelId(String vendorLicenseModelId) {
156 this.vendorLicenseModelId = vendorLicenseModelId;
159 public Set<String> getReferencingFeatureGroups() {
160 return referencingFeatureGroups;
163 public void setReferencingFeatureGroups(Set<String> referencingFeatureGroups) {
164 this.referencingFeatureGroups = referencingFeatureGroups;
167 public String getName() {
171 public void setName(String name) {
175 public String getDescription() {
179 public void setDescription(String description) {
180 this.description = description;
183 public EntitlementPoolType getType() {
187 public void setType(EntitlementPoolType type) {
191 public Integer getThresholdValue() {
192 return thresholdValue;
195 public void setThresholdValue(Integer thresholdValue) {
196 this.thresholdValue = thresholdValue;
199 public ThresholdUnit getThresholdUnit() {
200 return thresholdUnit;
203 public void setThresholdUnit(ThresholdUnit thresholdUnits) {
204 this.thresholdUnit = thresholdUnits;
207 public String getIncrements() {
211 public void setIncrements(String increments) {
212 this.increments = increments;
215 public MultiChoiceOrOther<OperationalScope> getOperationalScope() {
216 return operationalScope;
219 public void setOperationalScope(MultiChoiceOrOther<OperationalScope> operationalScope) {
220 if (operationalScope != null) {
221 operationalScope.resolveEnum(OperationalScope.class);
223 this.operationalScope = operationalScope;
227 * Gets threshold for artifact.
229 * @return the threshold for artifact
231 public ThresholdForXml getThresholdForArtifact() {
232 ThresholdForXml threshold = new ThresholdForXml();
233 threshold.setUnit(getThresholdUnit() == null ? null : getThresholdUnit().name());
234 threshold.setValue(getThresholdValue());
239 * Gets version for artifact.
241 * @return version in format suitable for artifact
243 public String getVersionForArtifact() {
244 return version.toString();
247 public String getStartDate() {
251 public void setStartDate(String startDate) {
252 this.startDate = startDate;
255 public String getExpiryDate() {
259 public void setExpiryDate(String expiryDate) {
260 this.expiryDate = expiryDate;
263 public Collection<LimitEntity> getLimits() {
267 public void setLimits(Collection<LimitEntity> limits) {
268 this.limits = limits;
271 public LimitForXml getSPLimits() {
272 if (limits != null) {
273 Set<LimitXml> hs = new HashSet<>();
274 for (LimitEntity obj : limits) {
275 if (obj.getType().equals(LimitType.ServiceProvider)) {
276 LimitXml xmlObj = new LimitXml();
277 xmlObj.setDescription(obj.getDescription());
278 xmlObj.setMetric(obj.getMetric());
279 xmlObj.setValues(obj.getValue());
280 xmlObj.setUnit(obj.getUnit());
281 xmlObj.setAggregationFunction(
282 obj.getAggregationFunction() != null ? obj.getAggregationFunction().name() : null);
283 xmlObj.setTime(obj.getTime());
287 LimitForXml spLimitForXml = new LimitForXml();
288 spLimitForXml.setLimits(hs);
289 return spLimitForXml;
295 public LimitForXml getVendorLimits() {
296 if (limits != null) {
297 Set<LimitXml> hs = new HashSet<>();
298 for (LimitEntity obj : limits) {
299 if (obj.getType().equals(LimitType.Vendor)) {
300 LimitXml xmlObj = new LimitXml();
301 xmlObj.setDescription(obj.getDescription());
302 xmlObj.setMetric(obj.getMetric());
303 xmlObj.setValues(obj.getValue());
304 xmlObj.setUnit(obj.getUnit());
305 xmlObj.setAggregationFunction(
306 obj.getAggregationFunction() != null ? obj.getAggregationFunction().name() : null);
307 xmlObj.setTime(obj.getTime());
311 LimitForXml vendorLimitForXml = new LimitForXml();
312 vendorLimitForXml.setLimits(hs);
313 return vendorLimitForXml;
321 public int hashCode() {
323 .hash(vendorLicenseModelId, version, id, name, description, type, thresholdValue, thresholdUnit,
324 increments, operationalScope, referencingFeatureGroups, startDate, expiryDate);
328 public boolean equals(Object obj) {
332 if (obj == null || getClass() != obj.getClass()) {
335 EntitlementPoolEntity that = (EntitlementPoolEntity) obj;
336 return Objects.equals(that.thresholdValue, thresholdValue)
337 && Objects.equals(vendorLicenseModelId, that.vendorLicenseModelId)
338 && Objects.equals(id, that.id)
339 && Objects.equals(name, that.name)
340 && Objects.equals(description, that.description)
342 && Objects.equals(thresholdUnit, that.thresholdUnit)
343 && Objects.equals(increments, that.increments)
344 && Objects.equals(that.operationalScope, operationalScope)
345 && Objects.equals(startDate, that.startDate)
346 && Objects.equals(expiryDate, that.expiryDate)
347 && Objects.equals(manufacturerReferenceNumber, that.manufacturerReferenceNumber)
348 && Objects.equals(version, that.version);
352 public String toString() {
353 return "EntitlementPoolEntity{"
354 + "vendorLicenseModelId='" + vendorLicenseModelId + '\''
355 + ", version=" + version
356 + ", id='" + id + '\''
357 + ", name='" + name + '\''
358 + ", description='" + description + '\''
360 + ", thresholdValue=" + thresholdValue
361 + ", thresholdUnit='" + thresholdUnit + '\''
362 + ", increments='" + increments + '\''
363 + ", operationalScope=" + operationalScope
364 + ", referencingFeatureGroups=" + referencingFeatureGroups
365 + ", version_uuid=" + versionUuId
366 + ", startDate=" + startDate
367 + ", expiryDate=" + expiryDate
372 * Gets operational scope for artifact.
374 * @return the operational scope for artifact
376 public OperationalScopeForXml getOperationalScopeForArtifact() {
377 OperationalScopeForXml obj = new OperationalScopeForXml();
378 if (operationalScope != null) {
379 if (operationalScope.getResults().size() > 0) {
380 obj.setValue(operationalScope.getResults());
386 //Defined and used only for License Artifcat XMLs
387 public void setManufacturerReferenceNumber(String manufacturerReferenceNumber) {
388 this.manufacturerReferenceNumber = manufacturerReferenceNumber;
391 public String getManufacturerReferenceNumber() {
392 return manufacturerReferenceNumber;
395 public String getIsoFormatStartDate() {
396 String isoFormatStartDate = null;
397 if (!StringUtils.isEmpty(startDate)) {
398 isoFormatStartDate = VendorLicenseUtil.getIsoFormatDate(startDate);
400 return isoFormatStartDate;
404 public String getIsoFormatExpiryDate() {
405 String isoFormatExpDate = null;
406 if (!StringUtils.isEmpty(expiryDate)) {
407 isoFormatExpDate = VendorLicenseUtil.getIsoFormatDate(expiryDate);
409 return isoFormatExpDate;