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.apache.commons.lang3.StringUtils;
30 import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
31 import org.openecomp.sdc.vendorlicense.VendorLicenseUtil;
32 import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitForXml;
33 import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitXml;
34 import org.openecomp.sdc.vendorlicense.dao.types.xml.OperationalScopeForXml;
35 import org.openecomp.sdc.vendorlicense.dao.types.xml.ThresholdForXml;
36 import org.openecomp.sdc.versioning.dao.types.Version;
37 import org.openecomp.sdc.versioning.dao.types.VersionableEntity;
39 import java.util.Collection;
40 import java.util.HashSet;
41 import java.util.Objects;
44 @Table(keyspace = "dox", name = "entitlement_pool")
45 public class EntitlementPoolEntity implements VersionableEntity {
47 private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
48 private static final String ENTITY_TYPE = "Entitlement Pool";
51 @Column(name = "vlm_id")
52 private String vendorLicenseModelId;
54 @PartitionKey(value = 1)
56 private Version version;
59 @Column(name = "ep_id")
62 private String description;
64 @Column(name = "threshold")
65 private Integer thresholdValue;
67 @Column(name = "threshold_unit")
69 private ThresholdUnit thresholdUnit;
71 private String increments;
73 @Column(name = "operational_scope")
75 private MultiChoiceOrOther<OperationalScope> operationalScope;
77 @Column(name = "ref_fg_ids")
78 private Set<String> referencingFeatureGroups = new HashSet<>();
80 @Column(name = "version_uuid")
81 private String versionUuId;
84 private String startDate;
85 private String expiryDate;
87 private Collection<LimitEntity> limits;
89 //Defined and used only for License Artifcat XMLs
90 private String manufacturerReferenceNumber;
92 public EntitlementPoolEntity() {
96 * Instantiates a new Entitlement pool entity.
98 * @param vlmId the vlm id
99 * @param version the version
102 public EntitlementPoolEntity(String vlmId, Version version, String id) {
103 this.vendorLicenseModelId = vlmId;
104 this.version = version;
109 public String getEntityType() {
114 public String getFirstClassCitizenId() {
115 return getVendorLicenseModelId();
119 public String getId() {
124 public void setId(String id) {
129 public Version getVersion() {
134 public void setVersion(Version version) {
135 this.version = version;
139 public String getVersionUuId() {
144 public void setVersionUuId(String uuId) {
148 public String getVendorLicenseModelId() {
149 return vendorLicenseModelId;
152 public void setVendorLicenseModelId(String vendorLicenseModelId) {
153 this.vendorLicenseModelId = vendorLicenseModelId;
156 public Set<String> getReferencingFeatureGroups() {
157 return referencingFeatureGroups;
160 public void setReferencingFeatureGroups(Set<String> referencingFeatureGroups) {
161 this.referencingFeatureGroups = referencingFeatureGroups;
164 public String getName() {
168 public void setName(String name) {
172 public String getDescription() {
176 public void setDescription(String description) {
177 this.description = description;
180 public Integer getThresholdValue() {
181 return thresholdValue;
184 public void setThresholdValue(Integer thresholdValue) {
185 this.thresholdValue = thresholdValue;
188 public ThresholdUnit getThresholdUnit() {
189 return thresholdUnit;
192 public void setThresholdUnit(ThresholdUnit thresholdUnits) {
193 this.thresholdUnit = thresholdUnits;
196 public String getIncrements() {
200 public void setIncrements(String increments) {
201 this.increments = increments;
204 public MultiChoiceOrOther<OperationalScope> getOperationalScope() {
205 return operationalScope;
208 public void setOperationalScope(MultiChoiceOrOther<OperationalScope> operationalScope) {
209 if (operationalScope != null) {
210 operationalScope.resolveEnum(OperationalScope.class);
212 this.operationalScope = operationalScope;
216 * Gets threshold for artifact.
218 * @return the threshold for artifact
220 public ThresholdForXml getThresholdForArtifact() {
221 ThresholdForXml threshold = new ThresholdForXml();
222 threshold.setUnit(getThresholdUnit() == null ? null : getThresholdUnit().name());
223 threshold.setValue(getThresholdValue());
228 * Gets version for artifact.
230 * @return version in format suitable for artifact
232 public String getVersionForArtifact() {
233 return version.toString();
236 public String getStartDate() {
240 public void setStartDate(String startDate) {
241 this.startDate = startDate;
244 public String getExpiryDate() {
248 public void setExpiryDate(String expiryDate) {
249 this.expiryDate = expiryDate;
252 public Collection<LimitEntity> getLimits() {
256 public void setLimits(Collection<LimitEntity> limits) {
257 this.limits = limits;
260 public LimitForXml getSPLimits() {
261 if (limits != null) {
262 Set<LimitXml> hs = new HashSet<>();
263 for (LimitEntity obj : limits) {
264 if (obj.getType().equals(LimitType.ServiceProvider)) {
265 LimitXml xmlObj = new LimitXml();
266 xmlObj.setDescription(obj.getDescription());
267 xmlObj.setMetric(obj.getMetric());
268 xmlObj.setValues(obj.getValue());
269 xmlObj.setUnit(obj.getUnit());
270 xmlObj.setAggregationFunction(
271 obj.getAggregationFunction() != null ? obj.getAggregationFunction().name() : null);
272 xmlObj.setTime(obj.getTime());
276 LimitForXml spLimitForXml = new LimitForXml();
277 spLimitForXml.setLimits(hs);
278 return spLimitForXml;
284 public LimitForXml getVendorLimits() {
285 if (limits != null) {
286 Set<LimitXml> hs = new HashSet<>();
287 for (LimitEntity obj : limits) {
288 if (obj.getType().equals(LimitType.Vendor)) {
289 LimitXml xmlObj = new LimitXml();
290 xmlObj.setDescription(obj.getDescription());
291 xmlObj.setMetric(obj.getMetric());
292 xmlObj.setValues(obj.getValue());
293 xmlObj.setUnit(obj.getUnit());
294 xmlObj.setAggregationFunction(
295 obj.getAggregationFunction() != null ? obj.getAggregationFunction().name() : null);
296 xmlObj.setTime(obj.getTime());
300 LimitForXml vendorLimitForXml = new LimitForXml();
301 vendorLimitForXml.setLimits(hs);
302 return vendorLimitForXml;
310 public int hashCode() {
312 .hash(vendorLicenseModelId, version, id, name, description, thresholdValue, thresholdUnit,
313 increments, operationalScope, referencingFeatureGroups, startDate, expiryDate);
317 public boolean equals(Object obj) {
321 if (obj == null || getClass() != obj.getClass()) {
324 EntitlementPoolEntity that = (EntitlementPoolEntity) obj;
325 return Objects.equals(that.thresholdValue, thresholdValue)
326 && Objects.equals(vendorLicenseModelId, that.vendorLicenseModelId)
327 && Objects.equals(id, that.id)
328 && Objects.equals(name, that.name)
329 && Objects.equals(description, that.description)
330 && Objects.equals(thresholdUnit, that.thresholdUnit)
331 && Objects.equals(increments, that.increments)
332 && Objects.equals(operationalScope, that.operationalScope)
333 && Objects.equals(referencingFeatureGroups, that.referencingFeatureGroups)
334 && Objects.equals(startDate, that.startDate)
335 && Objects.equals(expiryDate, that.expiryDate)
336 && Objects.equals(manufacturerReferenceNumber, that.manufacturerReferenceNumber)
337 && Objects.equals(version, that.version);
341 public String toString() {
342 return "EntitlementPoolEntity{"
343 + "vendorLicenseModelId='" + vendorLicenseModelId + '\''
344 + ", version=" + version
345 + ", id='" + id + '\''
346 + ", name='" + name + '\''
347 + ", description='" + description + '\''
348 + ", thresholdValue=" + thresholdValue
349 + ", thresholdUnit='" + thresholdUnit + '\''
350 + ", increments='" + increments + '\''
351 + ", operationalScope=" + operationalScope
352 + ", referencingFeatureGroups=" + referencingFeatureGroups
353 + ", version_uuid=" + versionUuId
354 + ", startDate=" + startDate
355 + ", expiryDate=" + expiryDate
360 * Gets operational scope for artifact.
362 * @return the operational scope for artifact
364 public OperationalScopeForXml getOperationalScopeForArtifact() {
365 OperationalScopeForXml obj = new OperationalScopeForXml();
366 if (operationalScope != null) {
367 if (operationalScope.getResults().size() > 0) {
368 obj.setValue(operationalScope.getResults());
374 //Defined and used only for License Artifcat XMLs
375 public void setManufacturerReferenceNumber(String manufacturerReferenceNumber) {
376 this.manufacturerReferenceNumber = manufacturerReferenceNumber;
379 public String getManufacturerReferenceNumber() {
380 return manufacturerReferenceNumber;
383 public String getIsoFormatStartDate() {
384 mdcDataDebugMessage.debugEntryMessage("start date", startDate);
385 String isoFormatStartDate = null;
386 if (!StringUtils.isEmpty(startDate)) {
387 isoFormatStartDate = VendorLicenseUtil.getIsoFormatDate(startDate);
388 mdcDataDebugMessage.debugExitMessage("start date", "iso format start date", startDate,
391 return isoFormatStartDate;
395 public String getIsoFormatExpiryDate() {
396 mdcDataDebugMessage.debugEntryMessage("expiry date", expiryDate);
397 String isoFormatExpDate = null;
398 if (!StringUtils.isEmpty(expiryDate)) {
399 isoFormatExpDate = VendorLicenseUtil.getIsoFormatDate(expiryDate);
400 mdcDataDebugMessage.debugExitMessage("expiry date", "iso format expiry date", expiryDate,
403 return isoFormatExpDate;