07641594c28dca0b5d80d7b6dfc928e078e821d6
[sdc.git] / openecomp-be / lib / openecomp-sdc-vendor-license-lib / openecomp-sdc-vendor-license-api / src / main / java / org / openecomp / sdc / vendorlicense / dao / types / LicenseKeyGroupEntity.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.openecomp.sdc.vendorlicense.dao.types.xml.LicenseKeyTypeForXml;
30 import org.openecomp.sdc.versioning.dao.types.Version;
31 import org.openecomp.sdc.versioning.dao.types.VersionableEntity;
32
33 import java.util.HashSet;
34 import java.util.Objects;
35 import java.util.Set;
36
37 @Table(keyspace = "dox", name = "license_key_group")
38 public class LicenseKeyGroupEntity implements VersionableEntity {
39   private static final String ENTITY_TYPE = "License Key Group";
40
41   @PartitionKey
42   @Column(name = "vlm_id")
43   private String vendorLicenseModelId;
44   @PartitionKey(value = 1)
45   @Frozen
46   private Version version;
47   @ClusteringColumn
48   @Column(name = "lkg_id")
49   private String id;
50   private String name;
51   private String description;
52   @Enumerated
53   private LicenseKeyType type;
54   @Column(name = "operational_scope")
55   @Frozen
56   private MultiChoiceOrOther<OperationalScope> operationalScope;
57   @Column(name = "ref_fg_ids")
58   private Set<String> referencingFeatureGroups = new HashSet<>();
59   @Column(name = "version_uuid")
60   private String versionUuId;
61
62
63   public LicenseKeyGroupEntity() {
64   }
65
66   /**
67    * Instantiates a new License key group entity.
68    *
69    * @param vendorLicenseModelId the vendor license model id
70    * @param version              the version
71    * @param id                   the id
72    */
73   public LicenseKeyGroupEntity(String vendorLicenseModelId, Version version, String id) {
74     this.vendorLicenseModelId = vendorLicenseModelId;
75     this.version = version;
76     this.id = id;
77   }
78
79   @Override
80   public String getEntityType() {
81     return ENTITY_TYPE;
82   }
83
84   @Override
85   public String getFirstClassCitizenId() {
86     return getVendorLicenseModelId();
87   }
88
89   public String getId() {
90     return id;
91   }
92
93   public void setId(String id) {
94     this.id = id;
95   }
96
97   public Version getVersion() {
98     return version;
99   }
100
101   public void setVersion(Version version) {
102     this.version = version;
103   }
104
105   @Override
106   public String getVersionUuId() {
107     return versionUuId;
108   }
109
110   @Override
111   public void setVersionUuId(String uuId) {
112     versionUuId = uuId;
113   }
114
115   public String getVendorLicenseModelId() {
116     return vendorLicenseModelId;
117   }
118
119   public void setVendorLicenseModelId(String vendorLicenseModelId) {
120     this.vendorLicenseModelId = vendorLicenseModelId;
121   }
122
123   public String getName() {
124     return name;
125   }
126
127   public void setName(String name) {
128     this.name = name;
129   }
130
131   public String getDescription() {
132     return description;
133   }
134
135   public void setDescription(String description) {
136     this.description = description;
137   }
138
139   public LicenseKeyType getType() {
140     return type;
141   }
142
143   public void setType(LicenseKeyType type) {
144     this.type = type;
145   }
146
147   public MultiChoiceOrOther<OperationalScope> getOperationalScope() {
148     return operationalScope;
149   }
150
151   public void setOperationalScope(MultiChoiceOrOther<OperationalScope> operationalScope) {
152     operationalScope.resolveEnum(OperationalScope.class);
153     this.operationalScope = operationalScope;
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   @Override
165   public int hashCode() {
166     return Objects
167         .hash(vendorLicenseModelId, version, id, name, description, type, operationalScope,
168             referencingFeatureGroups);
169   }
170
171   @Override
172   public boolean equals(Object obj) {
173     if (this == obj) {
174       return true;
175     }
176     if (obj == null || getClass() != obj.getClass()) {
177       return false;
178     }
179     LicenseKeyGroupEntity that = (LicenseKeyGroupEntity) obj;
180     return Objects.equals(vendorLicenseModelId, that.vendorLicenseModelId)
181         && Objects.equals(id, that.id)
182         && Objects.equals(name, that.name)
183         && Objects.equals(description, that.description)
184         && type == that.type
185         && Objects.equals(operationalScope, that.operationalScope)
186         && Objects.equals(referencingFeatureGroups, that.referencingFeatureGroups);
187   }
188
189   @Override
190   public String toString() {
191     return "LicenseKeyGroupEntity{" + "vendorLicenseModelId='" + vendorLicenseModelId + '\''
192         + ", version=" + version
193         + ", id='" + id + '\''
194         + ", name='" + name + '\''
195         + ", description='" + description + '\''
196         + ", type=" + type
197         + ", operationalScope=" + operationalScope
198         + ", referencingFeatureGroups=" + referencingFeatureGroups
199         + ", versionUuId='" + versionUuId + '\''
200         + '}';
201   }
202
203   /**
204    * Gets operational scope for artifact.
205    *
206    * @return the operational scope for artifact
207    */
208   public Set<String> getOperationalScopeForArtifact() {
209     if (operationalScope != null) {
210       return operationalScope.getResults();
211     } else {
212       return null;
213     }
214   }
215
216   /**
217    * Gets version for artifact.
218    * @return version in format suitable for artifact
219    */
220   public String getVersionForArtifact() {
221     return version.toString();
222   }
223
224   /**
225    * Gets type for artifact.
226    *
227    * @return the type for artifact
228    */
229   public LicenseKeyTypeForXml getTypeForArtifact() {
230     LicenseKeyTypeForXml typeXml = new LicenseKeyTypeForXml();
231     if (type != null) {
232       typeXml.setValue(type.toString());
233     } else {
234       typeXml.setValue(null);
235     }
236     return typeXml;
237   }
238 }