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=========================================================
20 package org.openecomp.sdc.vendorlicense.dao.types;
22 import com.datastax.driver.mapping.annotations.ClusteringColumn;
23 import com.datastax.driver.mapping.annotations.Column;
24 import com.datastax.driver.mapping.annotations.Frozen;
25 import com.datastax.driver.mapping.annotations.PartitionKey;
26 import com.datastax.driver.mapping.annotations.Table;
27 import java.util.Collection;
28 import java.util.HashSet;
29 import java.util.Objects;
31 import org.apache.commons.lang3.StringUtils;
32 import org.openecomp.sdc.vendorlicense.VendorLicenseUtil;
33 import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitForXml;
34 import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitXml;
35 import org.openecomp.sdc.vendorlicense.dao.types.xml.OperationalScopeForXml;
36 import org.openecomp.sdc.vendorlicense.dao.types.xml.ThresholdForXml;
37 import org.openecomp.sdc.versioning.dao.types.Version;
38 import org.openecomp.sdc.versioning.dao.types.VersionableEntity;
40 @Table(keyspace = "dox", name = "entitlement_pool")
41 public class EntitlementPoolEntity implements VersionableEntity {
43 private static final String ENTITY_TYPE = "Entitlement Pool";
45 @Column(name = "vlm_id")
46 private String vendorLicenseModelId;
47 @PartitionKey(value = 1)
49 private Version version;
51 @Column(name = "ep_id")
54 private String description;
55 private EntitlementPoolType type;
56 @Column(name = "threshold")
57 private Integer thresholdValue;
58 @Column(name = "threshold_unit")
59 private ThresholdUnit thresholdUnit;
60 private String increments;
61 @Column(name = "operational_scope")
63 private MultiChoiceOrOther<OperationalScope> operationalScope;
64 @Column(name = "ref_fg_ids")
65 private Set<String> referencingFeatureGroups = new HashSet<>();
66 @Column(name = "version_uuid")
67 private String versionUuId;
68 private String startDate;
69 private String expiryDate;
70 private Collection<LimitEntity> limits;
71 //Defined and used only for License Artifcat XMLs
72 private String manufacturerReferenceNumber;
75 * Every entity class must have a default constructor according to
76 * <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/object_mapper/creating/">
77 * Definition of mapped classes</a>.
79 public EntitlementPoolEntity() {
80 // Don't delete! Default constructor is required by DataStax driver
84 * Instantiates a new Entitlement pool entity.
86 * @param vlmId the vlm id
87 * @param version the version
90 public EntitlementPoolEntity(String vlmId, Version version, String id) {
91 this.vendorLicenseModelId = vlmId;
92 this.version = version;
97 public String getEntityType() {
102 public String getFirstClassCitizenId() {
103 return getVendorLicenseModelId();
107 public String getId() {
112 public void setId(String id) {
117 public Version getVersion() {
122 public void setVersion(Version version) {
123 this.version = version;
127 public String getVersionUuId() {
132 public void setVersionUuId(String uuId) {
136 public String getVendorLicenseModelId() {
137 return vendorLicenseModelId;
140 public void setVendorLicenseModelId(String vendorLicenseModelId) {
141 this.vendorLicenseModelId = vendorLicenseModelId;
144 public Set<String> getReferencingFeatureGroups() {
145 return referencingFeatureGroups;
148 public void setReferencingFeatureGroups(Set<String> referencingFeatureGroups) {
149 this.referencingFeatureGroups = referencingFeatureGroups;
152 public String getName() {
156 public void setName(String name) {
160 public String getDescription() {
164 public void setDescription(String description) {
165 this.description = description;
168 public EntitlementPoolType getType() {
172 public void setType(EntitlementPoolType type) {
176 public Integer getThresholdValue() {
177 return thresholdValue;
180 public void setThresholdValue(Integer thresholdValue) {
181 this.thresholdValue = thresholdValue;
184 public ThresholdUnit getThresholdUnit() {
185 return thresholdUnit;
188 public void setThresholdUnit(ThresholdUnit thresholdUnits) {
189 this.thresholdUnit = thresholdUnits;
192 public String getIncrements() {
196 public void setIncrements(String increments) {
197 this.increments = increments;
200 public MultiChoiceOrOther<OperationalScope> getOperationalScope() {
201 return operationalScope;
204 public void setOperationalScope(MultiChoiceOrOther<OperationalScope> operationalScope) {
205 if (operationalScope != null) {
206 operationalScope.resolveEnum(OperationalScope.class);
208 this.operationalScope = operationalScope;
212 * Gets threshold for artifact.
214 * @return the threshold for artifact
216 public ThresholdForXml getThresholdForArtifact() {
217 ThresholdForXml threshold = new ThresholdForXml();
218 threshold.setUnit(getThresholdUnit() == null ? null : getThresholdUnit().name());
219 threshold.setValue(getThresholdValue());
224 * Gets version for artifact.
226 * @return version in format suitable for artifact
228 public String getVersionForArtifact() {
229 return version.toString();
232 public String getStartDate() {
236 public void setStartDate(String startDate) {
237 this.startDate = startDate;
240 public String getExpiryDate() {
244 public void setExpiryDate(String expiryDate) {
245 this.expiryDate = expiryDate;
248 public Collection<LimitEntity> getLimits() {
252 public void setLimits(Collection<LimitEntity> limits) {
253 this.limits = limits;
256 public LimitForXml getSPLimits() {
257 if (limits != null) {
258 Set<LimitXml> hs = new HashSet<>();
259 for (LimitEntity obj : limits) {
260 if (obj.getType().equals(LimitType.ServiceProvider)) {
261 LimitXml xmlObj = new LimitXml();
262 xmlObj.setDescription(obj.getDescription());
263 xmlObj.setMetric(obj.getMetric());
264 xmlObj.setValues(obj.getValue());
265 xmlObj.setUnit(obj.getUnit());
266 xmlObj.setAggregationFunction(obj.getAggregationFunction() != null ? obj.getAggregationFunction().name() : null);
267 xmlObj.setTime(obj.getTime());
271 LimitForXml spLimitForXml = new LimitForXml();
272 spLimitForXml.setLimits(hs);
273 return spLimitForXml;
278 public LimitForXml getVendorLimits() {
279 if (limits != null) {
280 Set<LimitXml> hs = new HashSet<>();
281 for (LimitEntity obj : limits) {
282 if (obj.getType().equals(LimitType.Vendor)) {
283 LimitXml xmlObj = new LimitXml();
284 xmlObj.setDescription(obj.getDescription());
285 xmlObj.setMetric(obj.getMetric());
286 xmlObj.setValues(obj.getValue());
287 xmlObj.setUnit(obj.getUnit());
288 xmlObj.setAggregationFunction(obj.getAggregationFunction() != null ? obj.getAggregationFunction().name() : null);
289 xmlObj.setTime(obj.getTime());
293 LimitForXml vendorLimitForXml = new LimitForXml();
294 vendorLimitForXml.setLimits(hs);
295 return vendorLimitForXml;
301 public int hashCode() {
302 return Objects.hash(vendorLicenseModelId, version, id, name, description, type, thresholdValue, thresholdUnit, increments, operationalScope,
303 referencingFeatureGroups, startDate, expiryDate);
307 public boolean equals(Object obj) {
311 if (obj == null || getClass() != obj.getClass()) {
314 EntitlementPoolEntity that = (EntitlementPoolEntity) obj;
315 return Objects.equals(that.thresholdValue, thresholdValue) && Objects.equals(vendorLicenseModelId, that.vendorLicenseModelId) && Objects
316 .equals(id, that.id) && Objects.equals(name, that.name) && Objects.equals(description, that.description) && type == that.type && Objects
317 .equals(thresholdUnit, that.thresholdUnit) && Objects.equals(increments, that.increments) && Objects
318 .equals(that.operationalScope, operationalScope) && Objects.equals(startDate, that.startDate) && Objects
319 .equals(expiryDate, that.expiryDate) && Objects.equals(manufacturerReferenceNumber, that.manufacturerReferenceNumber) && Objects
320 .equals(version, that.version);
324 public String toString() {
325 return "EntitlementPoolEntity{" + "vendorLicenseModelId='" + vendorLicenseModelId + '\'' + ", version=" + version + ", id='" + id + '\''
326 + ", name='" + name + '\'' + ", description='" + description + '\'' + ", type=" + type + ", thresholdValue=" + thresholdValue
327 + ", thresholdUnit='" + thresholdUnit + '\'' + ", increments='" + increments + '\'' + ", operationalScope=" + operationalScope
328 + ", referencingFeatureGroups=" + referencingFeatureGroups + ", version_uuid=" + versionUuId + ", startDate=" + startDate
329 + ", expiryDate=" + expiryDate + '}';
333 * Gets operational scope for artifact.
335 * @return the operational scope for artifact
337 public OperationalScopeForXml getOperationalScopeForArtifact() {
338 OperationalScopeForXml obj = new OperationalScopeForXml();
339 if (operationalScope != null) {
340 if (operationalScope.getResults().size() > 0) {
341 obj.setValue(operationalScope.getResults());
347 public String getManufacturerReferenceNumber() {
348 return manufacturerReferenceNumber;
351 //Defined and used only for License Artifcat XMLs
352 public void setManufacturerReferenceNumber(String manufacturerReferenceNumber) {
353 this.manufacturerReferenceNumber = manufacturerReferenceNumber;
356 public String getIsoFormatStartDate() {
357 String isoFormatStartDate = null;
358 if (!StringUtils.isEmpty(startDate)) {
359 isoFormatStartDate = VendorLicenseUtil.getIsoFormatDate(startDate);
361 return isoFormatStartDate;
364 public String getIsoFormatExpiryDate() {
365 String isoFormatExpDate = null;
366 if (!StringUtils.isEmpty(expiryDate)) {
367 isoFormatExpDate = VendorLicenseUtil.getIsoFormatDate(expiryDate);
369 return isoFormatExpDate;