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;
28 import org.apache.commons.lang3.StringUtils;
29 import org.openecomp.sdc.vendorlicense.VendorLicenseUtil;
30 import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitForXml;
31 import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitXml;
32 import org.openecomp.sdc.vendorlicense.dao.types.xml.OperationalScopeForXml;
33 import org.openecomp.sdc.vendorlicense.dao.types.xml.ThresholdForXml;
34 import org.openecomp.sdc.versioning.dao.types.Version;
35 import org.openecomp.sdc.versioning.dao.types.VersionableEntity;
37 import java.util.Collection;
38 import java.util.HashSet;
39 import java.util.Objects;
42 @Table(keyspace = "dox", name = "entitlement_pool")
43 public class EntitlementPoolEntity implements VersionableEntity {
44 private static final String ENTITY_TYPE = "Entitlement Pool";
47 @Column(name = "vlm_id")
48 private String vendorLicenseModelId;
50 @PartitionKey(value = 1)
52 private Version version;
55 @Column(name = "ep_id")
58 private String description;
60 @Column(name = "threshold")
61 private Integer thresholdValue;
63 @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;
88 * Every entity class must have a default constructor according to
89 * <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/object_mapper/creating/">
90 * Definition of mapped classes</a>.
92 public EntitlementPoolEntity() {
93 // Don't delete! Default constructor is required by DataStax driver
97 * Instantiates a new Entitlement pool entity.
99 * @param vlmId the vlm id
100 * @param version the version
103 public EntitlementPoolEntity(String vlmId, Version version, String id) {
104 this.vendorLicenseModelId = vlmId;
105 this.version = version;
110 public String getEntityType() {
115 public String getFirstClassCitizenId() {
116 return getVendorLicenseModelId();
120 public String getId() {
125 public void setId(String id) {
130 public Version getVersion() {
135 public void setVersion(Version version) {
136 this.version = version;
140 public String getVersionUuId() {
145 public void setVersionUuId(String uuId) {
149 public String getVendorLicenseModelId() {
150 return vendorLicenseModelId;
153 public void setVendorLicenseModelId(String vendorLicenseModelId) {
154 this.vendorLicenseModelId = vendorLicenseModelId;
157 public Set<String> getReferencingFeatureGroups() {
158 return referencingFeatureGroups;
161 public void setReferencingFeatureGroups(Set<String> referencingFeatureGroups) {
162 this.referencingFeatureGroups = referencingFeatureGroups;
165 public String getName() {
169 public void setName(String name) {
173 public String getDescription() {
177 public void setDescription(String description) {
178 this.description = description;
181 public Integer getThresholdValue() {
182 return thresholdValue;
185 public void setThresholdValue(Integer thresholdValue) {
186 this.thresholdValue = thresholdValue;
189 public ThresholdUnit getThresholdUnit() {
190 return thresholdUnit;
193 public void setThresholdUnit(ThresholdUnit thresholdUnits) {
194 this.thresholdUnit = thresholdUnits;
197 public String getIncrements() {
201 public void setIncrements(String increments) {
202 this.increments = increments;
205 public MultiChoiceOrOther<OperationalScope> getOperationalScope() {
206 return operationalScope;
209 public void setOperationalScope(MultiChoiceOrOther<OperationalScope> operationalScope) {
210 if (operationalScope != null) {
211 operationalScope.resolveEnum(OperationalScope.class);
213 this.operationalScope = operationalScope;
217 * Gets threshold for artifact.
219 * @return the threshold for artifact
221 public ThresholdForXml getThresholdForArtifact() {
222 ThresholdForXml threshold = new ThresholdForXml();
223 threshold.setUnit(getThresholdUnit() == null ? null : getThresholdUnit().name());
224 threshold.setValue(getThresholdValue());
229 * Gets version for artifact.
231 * @return version in format suitable for artifact
233 public String getVersionForArtifact() {
234 return version.toString();
237 public String getStartDate() {
241 public void setStartDate(String startDate) {
242 this.startDate = startDate;
245 public String getExpiryDate() {
249 public void setExpiryDate(String expiryDate) {
250 this.expiryDate = expiryDate;
253 public Collection<LimitEntity> getLimits() {
257 public void setLimits(Collection<LimitEntity> limits) {
258 this.limits = limits;
261 public LimitForXml getSPLimits() {
262 if (limits != null) {
263 Set<LimitXml> hs = new HashSet<>();
264 for (LimitEntity obj : limits) {
265 if (obj.getType().equals(LimitType.ServiceProvider)) {
266 LimitXml xmlObj = new LimitXml();
267 xmlObj.setDescription(obj.getDescription());
268 xmlObj.setMetric(obj.getMetric());
269 xmlObj.setValues(obj.getValue());
270 xmlObj.setUnit(obj.getUnit());
271 xmlObj.setAggregationFunction(
272 obj.getAggregationFunction() != null ? obj.getAggregationFunction().name() : null);
273 xmlObj.setTime(obj.getTime());
277 LimitForXml spLimitForXml = new LimitForXml();
278 spLimitForXml.setLimits(hs);
279 return spLimitForXml;
285 public LimitForXml getVendorLimits() {
286 if (limits != null) {
287 Set<LimitXml> hs = new HashSet<>();
288 for (LimitEntity obj : limits) {
289 if (obj.getType().equals(LimitType.Vendor)) {
290 LimitXml xmlObj = new LimitXml();
291 xmlObj.setDescription(obj.getDescription());
292 xmlObj.setMetric(obj.getMetric());
293 xmlObj.setValues(obj.getValue());
294 xmlObj.setUnit(obj.getUnit());
295 xmlObj.setAggregationFunction(
296 obj.getAggregationFunction() != null ? obj.getAggregationFunction().name() : null);
297 xmlObj.setTime(obj.getTime());
301 LimitForXml vendorLimitForXml = new LimitForXml();
302 vendorLimitForXml.setLimits(hs);
303 return vendorLimitForXml;
311 public int hashCode() {
313 .hash(vendorLicenseModelId, version, id, name, description, thresholdValue, thresholdUnit,
314 increments, operationalScope, referencingFeatureGroups, startDate, expiryDate);
318 public boolean equals(Object obj) {
322 if (obj == null || getClass() != obj.getClass()) {
325 EntitlementPoolEntity that = (EntitlementPoolEntity) obj;
326 return Objects.equals(that.thresholdValue, thresholdValue)
327 && Objects.equals(vendorLicenseModelId, that.vendorLicenseModelId)
328 && Objects.equals(id, that.id)
329 && Objects.equals(name, that.name)
330 && Objects.equals(description, that.description)
331 && Objects.equals(thresholdUnit, that.thresholdUnit)
332 && Objects.equals(increments, that.increments)
333 && Objects.equals(operationalScope, that.operationalScope)
334 && Objects.equals(referencingFeatureGroups, that.referencingFeatureGroups)
335 && Objects.equals(startDate, that.startDate)
336 && Objects.equals(expiryDate, that.expiryDate)
337 && Objects.equals(manufacturerReferenceNumber, that.manufacturerReferenceNumber)
338 && Objects.equals(version, that.version);
342 public String toString() {
343 return "EntitlementPoolEntity{"
344 + "vendorLicenseModelId='" + vendorLicenseModelId + '\''
345 + ", version=" + version
346 + ", id='" + id + '\''
347 + ", name='" + name + '\''
348 + ", description='" + description + '\''
349 + ", thresholdValue=" + thresholdValue
350 + ", thresholdUnit='" + thresholdUnit + '\''
351 + ", increments='" + increments + '\''
352 + ", operationalScope=" + operationalScope
353 + ", referencingFeatureGroups=" + referencingFeatureGroups
354 + ", version_uuid=" + versionUuId
355 + ", startDate=" + startDate
356 + ", expiryDate=" + expiryDate
361 * Gets operational scope for artifact.
363 * @return the operational scope for artifact
365 public OperationalScopeForXml getOperationalScopeForArtifact() {
366 OperationalScopeForXml obj = new OperationalScopeForXml();
367 if (operationalScope != null) {
368 if (operationalScope.getResults().size() > 0) {
369 obj.setValue(operationalScope.getResults());
375 //Defined and used only for License Artifcat XMLs
376 public void setManufacturerReferenceNumber(String manufacturerReferenceNumber) {
377 this.manufacturerReferenceNumber = manufacturerReferenceNumber;
380 public String getManufacturerReferenceNumber() {
381 return manufacturerReferenceNumber;
384 public String getIsoFormatStartDate() {
385 String isoFormatStartDate = null;
386 if (!StringUtils.isEmpty(startDate)) {
387 isoFormatStartDate = VendorLicenseUtil.getIsoFormatDate(startDate);
389 return isoFormatStartDate;
393 public String getIsoFormatExpiryDate() {
394 String isoFormatExpDate = null;
395 if (!StringUtils.isEmpty(expiryDate)) {
396 isoFormatExpDate = VendorLicenseUtil.getIsoFormatDate(expiryDate);
398 return isoFormatExpDate;