Add collaboration feature
[sdc.git] / openecomp-be / lib / openecomp-sdc-vendor-license-lib / openecomp-sdc-vendor-license-api / src / main / java / org / openecomp / sdc / vendorlicense / dao / types / EntitlementPoolEntity.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.vendorlicense.dao.types;
22
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;
38
39 import java.util.Collection;
40 import java.util.HashSet;
41 import java.util.Objects;
42 import java.util.Set;
43
44 @Table(keyspace = "dox", name = "entitlement_pool")
45 public class EntitlementPoolEntity implements VersionableEntity {
46
47   private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
48   private static final String ENTITY_TYPE = "Entitlement Pool";
49
50   @PartitionKey
51   @Column(name = "vlm_id")
52   private String vendorLicenseModelId;
53
54   @PartitionKey(value = 1)
55   @Frozen
56   private Version version;
57
58   @ClusteringColumn
59   @Column(name = "ep_id")
60   private String id;
61   private String name;
62   private String description;
63
64   @Column(name = "threshold")
65   private Integer thresholdValue;
66
67   @Column(name = "threshold_unit")
68   @Enumerated
69   private ThresholdUnit thresholdUnit;
70
71   private String increments;
72
73   @Column(name = "operational_scope")
74   @Frozen
75   private MultiChoiceOrOther<OperationalScope> operationalScope;
76
77   @Column(name = "ref_fg_ids")
78   private Set<String> referencingFeatureGroups = new HashSet<>();
79
80   @Column(name = "version_uuid")
81   private String versionUuId;
82
83
84   private String startDate;
85   private String expiryDate;
86
87   private Collection<LimitEntity> limits;
88
89   //Defined and used only for License Artifcat XMLs
90   private String manufacturerReferenceNumber;
91
92   public EntitlementPoolEntity() {
93   }
94
95   /**
96    * Instantiates a new Entitlement pool entity.
97    *
98    * @param vlmId   the vlm id
99    * @param version the version
100    * @param id      the id
101    */
102   public EntitlementPoolEntity(String vlmId, Version version, String id) {
103     this.vendorLicenseModelId = vlmId;
104     this.version = version;
105     this.id = id;
106   }
107
108   @Override
109   public String getEntityType() {
110     return ENTITY_TYPE;
111   }
112
113   @Override
114   public String getFirstClassCitizenId() {
115     return getVendorLicenseModelId();
116   }
117
118   @Override
119   public String getId() {
120     return id;
121   }
122
123   @Override
124   public void setId(String id) {
125     this.id = id;
126   }
127
128   @Override
129   public Version getVersion() {
130     return version;
131   }
132
133   @Override
134   public void setVersion(Version version) {
135     this.version = version;
136   }
137
138   @Override
139   public String getVersionUuId() {
140     return versionUuId;
141   }
142
143   @Override
144   public void setVersionUuId(String uuId) {
145     versionUuId = uuId;
146   }
147
148   public String getVendorLicenseModelId() {
149     return vendorLicenseModelId;
150   }
151
152   public void setVendorLicenseModelId(String vendorLicenseModelId) {
153     this.vendorLicenseModelId = vendorLicenseModelId;
154   }
155
156   public Set<String> getReferencingFeatureGroups() {
157     return referencingFeatureGroups;
158   }
159
160   public void setReferencingFeatureGroups(Set<String> referencingFeatureGroups) {
161     this.referencingFeatureGroups = referencingFeatureGroups;
162   }
163
164   public String getName() {
165     return name;
166   }
167
168   public void setName(String name) {
169     this.name = name;
170   }
171
172   public String getDescription() {
173     return description;
174   }
175
176   public void setDescription(String description) {
177     this.description = description;
178   }
179
180   public Integer getThresholdValue() {
181     return thresholdValue;
182   }
183
184   public void setThresholdValue(Integer thresholdValue) {
185     this.thresholdValue = thresholdValue;
186   }
187
188   public ThresholdUnit getThresholdUnit() {
189     return thresholdUnit;
190   }
191
192   public void setThresholdUnit(ThresholdUnit thresholdUnits) {
193     this.thresholdUnit = thresholdUnits;
194   }
195
196   public String getIncrements() {
197     return increments;
198   }
199
200   public void setIncrements(String increments) {
201     this.increments = increments;
202   }
203
204   public MultiChoiceOrOther<OperationalScope> getOperationalScope() {
205     return operationalScope;
206   }
207
208   public void setOperationalScope(MultiChoiceOrOther<OperationalScope> operationalScope) {
209     if (operationalScope != null) {
210       operationalScope.resolveEnum(OperationalScope.class);
211     }
212     this.operationalScope = operationalScope;
213   }
214
215   /**
216    * Gets threshold for artifact.
217    *
218    * @return the threshold for artifact
219    */
220   public ThresholdForXml getThresholdForArtifact() {
221     ThresholdForXml threshold = new ThresholdForXml();
222     threshold.setUnit(getThresholdUnit() == null ? null : getThresholdUnit().name());
223     threshold.setValue(getThresholdValue());
224     return threshold;
225   }
226
227   /**
228    * Gets version for artifact.
229    *
230    * @return version in format suitable for artifact
231    */
232   public String getVersionForArtifact() {
233     return version.toString();
234   }
235
236   public String getStartDate() {
237     return startDate;
238   }
239
240   public void setStartDate(String startDate) {
241     this.startDate = startDate;
242   }
243
244   public String getExpiryDate() {
245     return expiryDate;
246   }
247
248   public void setExpiryDate(String expiryDate) {
249     this.expiryDate = expiryDate;
250   }
251
252   public Collection<LimitEntity> getLimits() {
253     return limits;
254   }
255
256   public void setLimits(Collection<LimitEntity> limits) {
257     this.limits = limits;
258   }
259
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());
273           hs.add(xmlObj);
274         }
275       }
276       LimitForXml spLimitForXml = new LimitForXml();
277       spLimitForXml.setLimits(hs);
278       return spLimitForXml;
279     }
280
281     return null;
282   }
283
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());
297           hs.add(xmlObj);
298         }
299       }
300       LimitForXml vendorLimitForXml = new LimitForXml();
301       vendorLimitForXml.setLimits(hs);
302       return vendorLimitForXml;
303     }
304
305     return null;
306   }
307
308
309   @Override
310   public int hashCode() {
311     return Objects
312         .hash(vendorLicenseModelId, version, id, name, description, thresholdValue, thresholdUnit,
313             increments, operationalScope, referencingFeatureGroups, startDate, expiryDate);
314   }
315
316   @Override
317   public boolean equals(Object obj) {
318     if (this == obj) {
319       return true;
320     }
321     if (obj == null || getClass() != obj.getClass()) {
322       return false;
323     }
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);
338   }
339
340   @Override
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
356         + '}';
357   }
358
359   /**
360    * Gets operational scope for artifact.
361    *
362    * @return the operational scope for artifact
363    */
364   public OperationalScopeForXml getOperationalScopeForArtifact() {
365     OperationalScopeForXml obj = new OperationalScopeForXml();
366     if (operationalScope != null) {
367       if (operationalScope.getResults().size() > 0) {
368         obj.setValue(operationalScope.getResults());
369       }
370     }
371     return obj;
372   }
373
374   //Defined and used only for License Artifcat XMLs
375   public void setManufacturerReferenceNumber(String manufacturerReferenceNumber) {
376     this.manufacturerReferenceNumber = manufacturerReferenceNumber;
377   }
378
379   public String getManufacturerReferenceNumber() {
380     return manufacturerReferenceNumber;
381   }
382
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,
389           isoFormatStartDate);
390     }
391     return isoFormatStartDate;
392   }
393
394
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,
401           isoFormatExpDate);
402     }
403     return isoFormatExpDate;
404   }
405 }