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.openecomp.sdc.vendorlicense.dao.types.xml.AggregationFunctionForXml;
30 import org.openecomp.sdc.vendorlicense.dao.types.xml.EntitlementMetricForXml;
31 import org.openecomp.sdc.vendorlicense.dao.types.xml.EntitlementTimeForXml;
32 import org.openecomp.sdc.vendorlicense.dao.types.xml.ThresholdForXml;
33 import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitXml;
34 import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitForXml;
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;
61 @Column(name = "threshold")
62 private Integer thresholdValue;
64 @Column(name = "threshold_unit")
66 private ThresholdUnit thresholdUnit;
68 @Column(name = "entitlement_metric")
70 private ChoiceOrOther<EntitlementMetric> entitlementMetric;
71 private String increments;
73 @Column(name = "aggregation_func")
75 private ChoiceOrOther<AggregationFunction> aggregationFunction;
77 @Column(name = "operational_scope")
79 private MultiChoiceOrOther<OperationalScope> operationalScope;
82 private ChoiceOrOther<EntitlementTime> time;
84 @Column(name = "manufacturer_ref_num")
85 private String manufacturerReferenceNumber;
87 @Column(name = "ref_fg_ids")
88 private Set<String> referencingFeatureGroups = new HashSet<>();
90 @Column(name = "version_uuid")
91 private String versionUuId;
94 private String startDate;
95 private String expiryDate;
97 private Collection<LimitEntity> limits;
99 public EntitlementPoolEntity() {
103 * Instantiates a new Entitlement pool entity.
105 * @param vlmId the vlm id
106 * @param version the version
109 public EntitlementPoolEntity(String vlmId, Version version, String id) {
110 this.vendorLicenseModelId = vlmId;
111 this.version = version;
116 public String getEntityType() {
121 public String getFirstClassCitizenId() {
122 return getVendorLicenseModelId();
126 public String getId() {
131 public void setId(String id) {
136 public Version getVersion() {
141 public void setVersion(Version version) {
142 this.version = version;
146 public String getVersionUuId() {
151 public void setVersionUuId(String uuId) {
155 public String getVendorLicenseModelId() {
156 return vendorLicenseModelId;
159 public void setVendorLicenseModelId(String vendorLicenseModelId) {
160 this.vendorLicenseModelId = vendorLicenseModelId;
163 public Set<String> getReferencingFeatureGroups() {
164 return referencingFeatureGroups;
167 public void setReferencingFeatureGroups(Set<String> referencingFeatureGroups) {
168 this.referencingFeatureGroups = referencingFeatureGroups;
171 public String getName() {
175 public void setName(String name) {
179 public String getDescription() {
183 public void setDescription(String description) {
184 this.description = description;
187 public Integer getThresholdValue() {
188 return thresholdValue;
191 public void setThresholdValue(Integer thresholdValue) {
192 this.thresholdValue = thresholdValue;
195 public ThresholdUnit getThresholdUnit() {
196 return thresholdUnit;
199 public void setThresholdUnit(ThresholdUnit thresholdUnits) {
200 this.thresholdUnit = thresholdUnits;
203 public ChoiceOrOther<EntitlementMetric> getEntitlementMetric() {
204 return entitlementMetric;
207 public void setEntitlementMetric(ChoiceOrOther<EntitlementMetric> entitlementMetric) {
208 entitlementMetric.resolveEnum(EntitlementMetric.class);
209 this.entitlementMetric = entitlementMetric;
212 public String getIncrements() {
216 public void setIncrements(String increments) {
217 this.increments = increments;
220 public ChoiceOrOther<AggregationFunction> getAggregationFunction() {
221 return aggregationFunction;
224 public void setAggregationFunction(ChoiceOrOther<AggregationFunction> aggregationFunction) {
225 aggregationFunction.resolveEnum(AggregationFunction.class);
226 this.aggregationFunction = aggregationFunction;
229 public MultiChoiceOrOther<OperationalScope> getOperationalScope() {
230 return operationalScope;
233 public void setOperationalScope(MultiChoiceOrOther<OperationalScope> operationalScope) {
234 if(operationalScope != null) {
235 operationalScope.resolveEnum(OperationalScope.class);
237 this.operationalScope = operationalScope;
240 public ChoiceOrOther<EntitlementTime> getTime() {
244 public void setTime(ChoiceOrOther<EntitlementTime> time) {
245 time.resolveEnum(EntitlementTime.class);
249 public String getManufacturerReferenceNumber() {
250 return manufacturerReferenceNumber;
253 public void setManufacturerReferenceNumber(String manufacturerReferenceNumber) {
254 this.manufacturerReferenceNumber = manufacturerReferenceNumber;
258 * Gets threshold for artifact.
260 * @return the threshold for artifact
262 public ThresholdForXml getThresholdForArtifact() {
263 ThresholdForXml threshold = new ThresholdForXml();
264 threshold.setUnit(getThresholdUnit() == null ? null : getThresholdUnit().name());
265 threshold.setValue(getThresholdValue());
270 * Gets version for artifact.
271 * @return version in format suitable for artifact
273 public String getVersionForArtifact() {
274 return version.toString();
278 * Gets entitlement metric for artifact.
280 * @return the entitlement metric for artifact
282 public EntitlementMetricForXml getEntitlementMetricForArtifact() {
283 EntitlementMetricForXml metric = new EntitlementMetricForXml();
284 if (entitlementMetric != null) {
285 metric.setValue(entitlementMetric.getResult());
287 metric.setValue(null);
293 * Gets time for artifact.
295 * @return the time for artifact
297 public EntitlementTimeForXml getTimeForArtifact() {
298 EntitlementTimeForXml timeForXml = new EntitlementTimeForXml();
300 timeForXml.setValue(time.getResult());
306 public String getStartDate() {
310 public void setStartDate(String startDate) {
311 this.startDate = startDate;
314 public String getExpiryDate() {
318 public void setExpiryDate(String expiryDate) {
319 this.expiryDate = expiryDate;
322 public Collection<LimitEntity> getLimits() {
326 public void setLimits(Collection<LimitEntity> limits) {
327 this.limits = limits;
330 public LimitForXml getSPLimits(){
332 Set<LimitXml> hs = new HashSet<>();
333 for(LimitEntity obj : limits){
334 if(obj.getType().equals(LimitType.ServiceProvider)){
335 LimitXml xmlObj = new LimitXml();
336 xmlObj.setDescription(obj.getDescription());
337 xmlObj.setMetric(obj.getMetric().toString());
338 xmlObj.setValues(obj.getValue()!=null?Integer.toString(obj.getValue()):null);
339 xmlObj.setUnit(obj.getUnit()!=null?Integer.toString(obj.getUnit()):null);
340 xmlObj.setAggregationFunction(obj.getAggregationFunction()!=null?obj.getAggregationFunction().name():null);
341 xmlObj.setTime(obj.getTime()!=null?obj.getTime().name():null);
345 LimitForXml spLimitForXml = new LimitForXml();
346 spLimitForXml.setLimits(hs);
347 return spLimitForXml;
353 public LimitForXml getVendorLimits(){
355 Set<LimitXml> hs = new HashSet<>();
356 for(LimitEntity obj : limits){
357 if(obj.getType().equals(LimitType.Vendor)){
358 LimitXml xmlObj = new LimitXml();
359 xmlObj.setDescription(obj.getDescription());
360 xmlObj.setMetric(obj.getMetric().toString());
361 xmlObj.setValues(obj.getValue()!=null?Integer.toString(obj.getValue()):null);
362 xmlObj.setUnit(obj.getUnit()!=null?Integer.toString(obj.getUnit()):null);
363 xmlObj.setAggregationFunction(obj.getAggregationFunction()!=null?obj.getAggregationFunction().name():null);
364 xmlObj.setTime(obj.getTime()!=null?obj.getTime().name():null);
368 LimitForXml vendorLimitForXml = new LimitForXml();
369 vendorLimitForXml.setLimits(hs);
370 return vendorLimitForXml;
378 public int hashCode() {
380 .hash(vendorLicenseModelId, version, id, name, description, thresholdValue, thresholdUnit,
381 entitlementMetric, increments, aggregationFunction, operationalScope, time,
382 manufacturerReferenceNumber, referencingFeatureGroups, startDate, expiryDate);
386 public boolean equals(Object obj) {
390 if (obj == null || getClass() != obj.getClass()) {
393 EntitlementPoolEntity that = (EntitlementPoolEntity) obj;
394 return Objects.equals(that.thresholdValue, thresholdValue)
395 && Objects.equals(vendorLicenseModelId, that.vendorLicenseModelId)
396 && Objects.equals(id, that.id)
397 && Objects.equals(name, that.name)
398 && Objects.equals(description, that.description)
399 && Objects.equals(thresholdUnit, that.thresholdUnit)
400 && Objects.equals(entitlementMetric, that.entitlementMetric)
401 && Objects.equals(increments, that.increments)
402 && Objects.equals(aggregationFunction, that.aggregationFunction)
403 && Objects.equals(operationalScope, that.operationalScope)
404 && Objects.equals(time, that.time)
405 && Objects.equals(manufacturerReferenceNumber, that.manufacturerReferenceNumber)
406 && Objects.equals(referencingFeatureGroups, that.referencingFeatureGroups)
407 && Objects.equals(startDate, that.startDate)
408 && Objects.equals(expiryDate, that.expiryDate);
412 public String toString() {
413 return "EntitlementPoolEntity{"
414 + "vendorLicenseModelId='" + vendorLicenseModelId + '\''
415 + ", version=" + version
416 + ", id='" + id + '\''
417 + ", name='" + name + '\''
418 + ", description='" + description + '\''
419 + ", thresholdValue=" + thresholdValue
420 + ", thresholdUnit='" + thresholdUnit + '\''
421 + ", entitlementMetric=" + entitlementMetric
422 + ", increments='" + increments + '\''
423 + ", aggregationFunction=" + aggregationFunction
424 + ", operationalScope=" + operationalScope
426 + ", manufacturerReferenceNumber='" + manufacturerReferenceNumber + '\''
427 + ", referencingFeatureGroups=" + referencingFeatureGroups
428 + ", version_uuid=" + versionUuId
429 + ", startDate=" + startDate
430 + ", expiryDate=" + expiryDate
435 * Gets aggregation function for artifact.
437 * @return the aggregation function for artifact
439 public AggregationFunctionForXml getAggregationFunctionForArtifact() {
440 AggregationFunctionForXml aggregationFunctionForXml = new AggregationFunctionForXml();
441 if (entitlementMetric != null) {
442 aggregationFunctionForXml.setValue(aggregationFunction.getResult());
444 aggregationFunctionForXml.setValue(null);
446 return aggregationFunctionForXml;
450 * Gets operational scope for artifact.
452 * @return the operational scope for artifact
454 public Set<String> getOperationalScopeForArtifact() {
455 if (operationalScope != null) {
456 return operationalScope.getResults();