dce2939ae58b4e8d0e63536a7bc4801fa684fd45
[sdc.git] /
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.openecomp.sdc.vendorlicense.dao.types.xml.LimitForXml;
30 import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitXml;
31 import org.openecomp.sdc.vendorlicense.dao.types.xml.OperationalScopeForXml;
32 import org.openecomp.sdc.vendorlicense.dao.types.xml.ThresholdForXml;
33 import org.openecomp.sdc.versioning.dao.types.Version;
34 import org.openecomp.sdc.versioning.dao.types.VersionableEntity;
35
36 import java.util.Collection;
37 import java.util.HashSet;
38 import java.util.Objects;
39 import java.util.Set;
40
41 @Table(keyspace = "dox", name = "entitlement_pool")
42 public class EntitlementPoolEntity implements VersionableEntity {
43   private static final String ENTITY_TYPE = "Entitlement Pool";
44
45   @PartitionKey
46   @Column(name = "vlm_id")
47   private String vendorLicenseModelId;
48
49   @PartitionKey(value = 1)
50   @Frozen
51   private Version version;
52
53   @ClusteringColumn
54   @Column(name = "ep_id")
55   private String id;
56   private String name;
57   private String description;
58
59   @Column(name = "threshold")
60   private Integer thresholdValue;
61
62   @Column(name = "threshold_unit")
63   @Enumerated
64   private ThresholdUnit thresholdUnit;
65
66   private String increments;
67
68   @Column(name = "operational_scope")
69   @Frozen
70   private MultiChoiceOrOther<OperationalScope> operationalScope;
71
72   @Column(name = "ref_fg_ids")
73   private Set<String> referencingFeatureGroups = new HashSet<>();
74
75   @Column(name = "version_uuid")
76   private String versionUuId;
77
78
79   private String startDate;
80   private String expiryDate;
81
82   private Collection<LimitEntity> limits;
83
84   //Defined and used only for License Artifcat XMLs
85   private String manufacturerReferenceNumber;
86
87   public EntitlementPoolEntity() {
88   }
89
90   /**
91    * Instantiates a new Entitlement pool entity.
92    *
93    * @param vlmId   the vlm id
94    * @param version the version
95    * @param id      the id
96    */
97   public EntitlementPoolEntity(String vlmId, Version version, String id) {
98     this.vendorLicenseModelId = vlmId;
99     this.version = version;
100     this.id = id;
101   }
102
103   @Override
104   public String getEntityType() {
105     return ENTITY_TYPE;
106   }
107
108   @Override
109   public String getFirstClassCitizenId() {
110     return getVendorLicenseModelId();
111   }
112
113   @Override
114   public String getId() {
115     return id;
116   }
117
118   @Override
119   public void setId(String id) {
120     this.id = id;
121   }
122
123   @Override
124   public Version getVersion() {
125     return version;
126   }
127
128   @Override
129   public void setVersion(Version version) {
130     this.version = version;
131   }
132
133   @Override
134   public String getVersionUuId() {
135     return versionUuId;
136   }
137
138   @Override
139   public void setVersionUuId(String uuId) {
140     versionUuId = uuId;
141   }
142
143   public String getVendorLicenseModelId() {
144     return vendorLicenseModelId;
145   }
146
147   public void setVendorLicenseModelId(String vendorLicenseModelId) {
148     this.vendorLicenseModelId = vendorLicenseModelId;
149   }
150
151   public Set<String> getReferencingFeatureGroups() {
152     return referencingFeatureGroups;
153   }
154
155   public void setReferencingFeatureGroups(Set<String> referencingFeatureGroups) {
156     this.referencingFeatureGroups = referencingFeatureGroups;
157   }
158
159   public String getName() {
160     return name;
161   }
162
163   public void setName(String name) {
164     this.name = name;
165   }
166
167   public String getDescription() {
168     return description;
169   }
170
171   public void setDescription(String description) {
172     this.description = description;
173   }
174
175   public Integer getThresholdValue() {
176     return thresholdValue;
177   }
178
179   public void setThresholdValue(Integer thresholdValue) {
180     this.thresholdValue = thresholdValue;
181   }
182
183   public ThresholdUnit getThresholdUnit() {
184     return thresholdUnit;
185   }
186
187   public void setThresholdUnit(ThresholdUnit thresholdUnits) {
188     this.thresholdUnit = thresholdUnits;
189   }
190
191   public String getIncrements() {
192     return increments;
193   }
194
195   public void setIncrements(String increments) {
196     this.increments = increments;
197   }
198
199   public MultiChoiceOrOther<OperationalScope> getOperationalScope() {
200     return operationalScope;
201   }
202
203   public void setOperationalScope(MultiChoiceOrOther<OperationalScope> operationalScope) {
204     if(operationalScope != null) {
205       operationalScope.resolveEnum(OperationalScope.class);
206     }
207     this.operationalScope = operationalScope;
208   }
209
210   /**
211    * Gets threshold for artifact.
212    *
213    * @return the threshold for artifact
214    */
215   public ThresholdForXml getThresholdForArtifact() {
216     ThresholdForXml threshold = new ThresholdForXml();
217     threshold.setUnit(getThresholdUnit() == null ? null : getThresholdUnit().name());
218     threshold.setValue(getThresholdValue());
219     return threshold;
220   }
221
222   /**
223    *  Gets version for artifact.
224    * @return version in format suitable for artifact
225    */
226   public String getVersionForArtifact() {
227     return version.toString();
228   }
229
230   public String getStartDate() {
231     return startDate;
232   }
233
234   public void setStartDate(String startDate) {
235     this.startDate = startDate;
236   }
237
238   public String getExpiryDate() {
239     return expiryDate;
240   }
241
242   public void setExpiryDate(String expiryDate) {
243     this.expiryDate = expiryDate;
244   }
245
246   public Collection<LimitEntity> getLimits() {
247     return limits;
248   }
249
250   public void setLimits(Collection<LimitEntity> limits) {
251     this.limits = limits;
252   }
253
254   public LimitForXml getSPLimits(){
255     if(limits != null){
256       Set<LimitXml> hs = new HashSet<>();
257       for(LimitEntity obj : limits){
258         if(obj.getType().equals(LimitType.ServiceProvider)){
259           LimitXml xmlObj = new LimitXml();
260           xmlObj.setDescription(obj.getDescription());
261           xmlObj.setMetric(obj.getMetric()!=null?obj.getMetric().name():null);
262           xmlObj.setValues(obj.getValue()!=null?Integer.toString(obj.getValue()):null);
263           xmlObj.setUnit(obj.getUnit()!=null?Integer.toString(obj.getUnit()):null);
264           xmlObj.setAggregationFunction(obj.getAggregationFunction()!=null?obj.getAggregationFunction().name():null);
265           xmlObj.setTime(obj.getTime()!=null?obj.getTime().name():null);
266           hs.add(xmlObj);
267         }
268       }
269       LimitForXml spLimitForXml = new LimitForXml();
270       spLimitForXml.setLimits(hs);
271       return spLimitForXml;
272     }
273
274     return null;
275   }
276
277   public LimitForXml getVendorLimits(){
278     if(limits != null){
279       Set<LimitXml> hs = new HashSet<>();
280       for(LimitEntity obj : limits){
281         if(obj.getType().equals(LimitType.Vendor)){
282           LimitXml xmlObj = new LimitXml();
283           xmlObj.setDescription(obj.getDescription());
284           xmlObj.setMetric(obj.getMetric()!=null?obj.getMetric().name():null);
285           xmlObj.setValues(obj.getValue()!=null?Integer.toString(obj.getValue()):null);
286           xmlObj.setUnit(obj.getUnit()!=null?Integer.toString(obj.getUnit()):null);
287           xmlObj.setAggregationFunction(obj.getAggregationFunction()!=null?obj.getAggregationFunction().name():null);
288           xmlObj.setTime(obj.getTime()!=null?obj.getTime().name():null);
289           hs.add(xmlObj);
290         }
291       }
292       LimitForXml vendorLimitForXml = new LimitForXml();
293       vendorLimitForXml.setLimits(hs);
294       return vendorLimitForXml;
295     }
296
297     return null;
298   }
299
300
301   @Override
302   public int hashCode() {
303     return Objects
304         .hash(vendorLicenseModelId, version, id, name, description, thresholdValue, thresholdUnit,
305             increments, operationalScope, referencingFeatureGroups, startDate, expiryDate);
306   }
307
308   @Override
309   public boolean equals(Object obj) {
310     if (this == obj) {
311       return true;
312     }
313     if (obj == null || getClass() != obj.getClass()) {
314       return false;
315     }
316     EntitlementPoolEntity that = (EntitlementPoolEntity) obj;
317     return Objects.equals(that.thresholdValue, thresholdValue)
318         && Objects.equals(vendorLicenseModelId, that.vendorLicenseModelId)
319         && Objects.equals(id, that.id)
320         && Objects.equals(name, that.name)
321         && Objects.equals(description, that.description)
322         && Objects.equals(thresholdUnit, that.thresholdUnit)
323         && Objects.equals(increments, that.increments)
324         && Objects.equals(operationalScope, that.operationalScope)
325         && Objects.equals(referencingFeatureGroups, that.referencingFeatureGroups)
326         && Objects.equals(startDate, that.startDate)
327         && Objects.equals(expiryDate, that.expiryDate);
328   }
329
330   @Override
331   public String toString() {
332     return "EntitlementPoolEntity{"
333         + "vendorLicenseModelId='" + vendorLicenseModelId + '\''
334         + ", version=" + version
335         + ", id='" + id + '\''
336         + ", name='" + name + '\''
337         + ", description='" + description + '\''
338         + ", thresholdValue=" + thresholdValue
339         + ", thresholdUnit='" + thresholdUnit + '\''
340         + ", increments='" + increments + '\''
341         + ", operationalScope=" + operationalScope
342         + ", referencingFeatureGroups=" + referencingFeatureGroups
343         + ", version_uuid=" + versionUuId
344         + ", startDate=" + startDate
345         + ", expiryDate=" + expiryDate
346         + '}';
347   }
348
349   /**
350    * Gets operational scope for artifact.
351    *
352    * @return the operational scope for artifact
353    */
354   public OperationalScopeForXml getOperationalScopeForArtifact() {
355     OperationalScopeForXml obj = new OperationalScopeForXml();
356     if (operationalScope != null) {
357       if(operationalScope.getResults().size() > 0) {
358         obj.setValue(operationalScope.getResults());
359       }
360     }
361     return obj;
362   }
363
364   //Defined and used only for License Artifcat XMLs
365   public void setManufacturerReferenceNumber(String manufacturerReferenceNumber) {
366     this.manufacturerReferenceNumber = manufacturerReferenceNumber;
367   }
368
369   public String getManufacturerReferenceNumber() {
370     return manufacturerReferenceNumber;
371   }
372 }