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 final MdcDataDebugMessage MDC_DATA_DEBUG_MESSAGE = 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;
93 * Every entity class must have a default constructor according to
94 * <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/object_mapper/creating/">
95 * Definition of mapped classes</a>.
97 public EntitlementPoolEntity() {
98 // Don't delete! Default constructor is required by DataStax driver
102 * Instantiates a new Entitlement pool entity.
104 * @param vlmId the vlm id
105 * @param version the version
108 public EntitlementPoolEntity(String vlmId, Version version, String id) {
109 this.vendorLicenseModelId = vlmId;
110 this.version = version;
115 public String getEntityType() {
120 public String getFirstClassCitizenId() {
121 return getVendorLicenseModelId();
125 public String getId() {
130 public void setId(String id) {
135 public Version getVersion() {
140 public void setVersion(Version version) {
141 this.version = version;
145 public String getVersionUuId() {
150 public void setVersionUuId(String uuId) {
154 public String getVendorLicenseModelId() {
155 return vendorLicenseModelId;
158 public void setVendorLicenseModelId(String vendorLicenseModelId) {
159 this.vendorLicenseModelId = vendorLicenseModelId;
162 public Set<String> getReferencingFeatureGroups() {
163 return referencingFeatureGroups;
166 public void setReferencingFeatureGroups(Set<String> referencingFeatureGroups) {
167 this.referencingFeatureGroups = referencingFeatureGroups;
170 public String getName() {
174 public void setName(String name) {
178 public String getDescription() {
182 public void setDescription(String description) {
183 this.description = description;
186 public Integer getThresholdValue() {
187 return thresholdValue;
190 public void setThresholdValue(Integer thresholdValue) {
191 this.thresholdValue = thresholdValue;
194 public ThresholdUnit getThresholdUnit() {
195 return thresholdUnit;
198 public void setThresholdUnit(ThresholdUnit thresholdUnits) {
199 this.thresholdUnit = thresholdUnits;
202 public String getIncrements() {
206 public void setIncrements(String increments) {
207 this.increments = increments;
210 public MultiChoiceOrOther<OperationalScope> getOperationalScope() {
211 return operationalScope;
214 public void setOperationalScope(MultiChoiceOrOther<OperationalScope> operationalScope) {
215 if (operationalScope != null) {
216 operationalScope.resolveEnum(OperationalScope.class);
218 this.operationalScope = operationalScope;
222 * Gets threshold for artifact.
224 * @return the threshold for artifact
226 public ThresholdForXml getThresholdForArtifact() {
227 ThresholdForXml threshold = new ThresholdForXml();
228 threshold.setUnit(getThresholdUnit() == null ? null : getThresholdUnit().name());
229 threshold.setValue(getThresholdValue());
234 * Gets version for artifact.
236 * @return version in format suitable for artifact
238 public String getVersionForArtifact() {
239 return version.toString();
242 public String getStartDate() {
246 public void setStartDate(String startDate) {
247 this.startDate = startDate;
250 public String getExpiryDate() {
254 public void setExpiryDate(String expiryDate) {
255 this.expiryDate = expiryDate;
258 public Collection<LimitEntity> getLimits() {
262 public void setLimits(Collection<LimitEntity> limits) {
263 this.limits = limits;
266 public LimitForXml getSPLimits() {
267 if (limits != null) {
268 Set<LimitXml> hs = new HashSet<>();
269 for (LimitEntity obj : limits) {
270 if (obj.getType().equals(LimitType.ServiceProvider)) {
271 LimitXml xmlObj = new LimitXml();
272 xmlObj.setDescription(obj.getDescription());
273 xmlObj.setMetric(obj.getMetric());
274 xmlObj.setValues(obj.getValue());
275 xmlObj.setUnit(obj.getUnit());
276 xmlObj.setAggregationFunction(
277 obj.getAggregationFunction() != null ? obj.getAggregationFunction().name() : null);
278 xmlObj.setTime(obj.getTime());
282 LimitForXml spLimitForXml = new LimitForXml();
283 spLimitForXml.setLimits(hs);
284 return spLimitForXml;
290 public LimitForXml getVendorLimits() {
291 if (limits != null) {
292 Set<LimitXml> hs = new HashSet<>();
293 for (LimitEntity obj : limits) {
294 if (obj.getType().equals(LimitType.Vendor)) {
295 LimitXml xmlObj = new LimitXml();
296 xmlObj.setDescription(obj.getDescription());
297 xmlObj.setMetric(obj.getMetric());
298 xmlObj.setValues(obj.getValue());
299 xmlObj.setUnit(obj.getUnit());
300 xmlObj.setAggregationFunction(
301 obj.getAggregationFunction() != null ? obj.getAggregationFunction().name() : null);
302 xmlObj.setTime(obj.getTime());
306 LimitForXml vendorLimitForXml = new LimitForXml();
307 vendorLimitForXml.setLimits(hs);
308 return vendorLimitForXml;
316 public int hashCode() {
318 .hash(vendorLicenseModelId, version, id, name, description, thresholdValue, thresholdUnit,
319 increments, operationalScope, referencingFeatureGroups, startDate, expiryDate);
323 public boolean equals(Object obj) {
327 if (obj == null || getClass() != obj.getClass()) {
330 EntitlementPoolEntity that = (EntitlementPoolEntity) obj;
331 return Objects.equals(that.thresholdValue, thresholdValue)
332 && Objects.equals(vendorLicenseModelId, that.vendorLicenseModelId)
333 && Objects.equals(id, that.id)
334 && Objects.equals(name, that.name)
335 && Objects.equals(description, that.description)
336 && Objects.equals(thresholdUnit, that.thresholdUnit)
337 && Objects.equals(increments, that.increments)
338 && Objects.equals(operationalScope, that.operationalScope)
339 && Objects.equals(referencingFeatureGroups, that.referencingFeatureGroups)
340 && Objects.equals(startDate, that.startDate)
341 && Objects.equals(expiryDate, that.expiryDate)
342 && Objects.equals(manufacturerReferenceNumber, that.manufacturerReferenceNumber)
343 && Objects.equals(version, that.version);
347 public String toString() {
348 return "EntitlementPoolEntity{"
349 + "vendorLicenseModelId='" + vendorLicenseModelId + '\''
350 + ", version=" + version
351 + ", id='" + id + '\''
352 + ", name='" + name + '\''
353 + ", description='" + description + '\''
354 + ", thresholdValue=" + thresholdValue
355 + ", thresholdUnit='" + thresholdUnit + '\''
356 + ", increments='" + increments + '\''
357 + ", operationalScope=" + operationalScope
358 + ", referencingFeatureGroups=" + referencingFeatureGroups
359 + ", version_uuid=" + versionUuId
360 + ", startDate=" + startDate
361 + ", expiryDate=" + expiryDate
366 * Gets operational scope for artifact.
368 * @return the operational scope for artifact
370 public OperationalScopeForXml getOperationalScopeForArtifact() {
371 OperationalScopeForXml obj = new OperationalScopeForXml();
372 if (operationalScope != null) {
373 if (operationalScope.getResults().size() > 0) {
374 obj.setValue(operationalScope.getResults());
380 //Defined and used only for License Artifcat XMLs
381 public void setManufacturerReferenceNumber(String manufacturerReferenceNumber) {
382 this.manufacturerReferenceNumber = manufacturerReferenceNumber;
385 public String getManufacturerReferenceNumber() {
386 return manufacturerReferenceNumber;
389 public String getIsoFormatStartDate() {
390 MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("start date", startDate);
391 String isoFormatStartDate = null;
392 if (!StringUtils.isEmpty(startDate)) {
393 isoFormatStartDate = VendorLicenseUtil.getIsoFormatDate(startDate);
394 MDC_DATA_DEBUG_MESSAGE.debugExitMessage("start date", "iso format start date", startDate,
397 return isoFormatStartDate;
401 public String getIsoFormatExpiryDate() {
402 MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("expiry date", expiryDate);
403 String isoFormatExpDate = null;
404 if (!StringUtils.isEmpty(expiryDate)) {
405 isoFormatExpDate = VendorLicenseUtil.getIsoFormatDate(expiryDate);
406 MDC_DATA_DEBUG_MESSAGE.debugExitMessage("expiry date", "iso format expiry date", expiryDate,
409 return isoFormatExpDate;