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