re base 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 / LicenseAgreementEntity.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.Frozen;
26 import com.datastax.driver.mapping.annotations.PartitionKey;
27 import com.datastax.driver.mapping.annotations.Table;
28
29 import org.openecomp.sdc.versioning.dao.types.Version;
30 import org.openecomp.sdc.versioning.dao.types.VersionableEntity;
31
32 import java.util.HashSet;
33 import java.util.Objects;
34 import java.util.Set;
35
36 @Table(keyspace = "dox", name = "license_agreement")
37 public class LicenseAgreementEntity implements VersionableEntity {
38   public static final String ENTITY_TYPE = "License Agreement";
39
40   @PartitionKey(value = 0)
41   @Column(name = "vlm_id")
42   private String vendorLicenseModelId;
43
44   @PartitionKey(value = 1)
45   @Frozen
46   private Version version;
47
48   @ClusteringColumn
49   @Column(name = "la_id")
50   private String id;
51   private String name;
52   private String description;
53
54   @Column(name = "lic_term")
55   @Frozen
56   private ChoiceOrOther<LicenseTerm> licenseTerm;
57
58   @Column(name = "req_const")
59   private String requirementsAndConstrains;
60
61   @Column(name = "fg_ids")
62   private Set<String> featureGroupIds = new HashSet<>();
63
64   /**
65    * Every entity class must have a default constructor according to
66    * <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/object_mapper/creating/">
67    * Definition of mapped classes</a>.
68    */
69   public LicenseAgreementEntity() {
70     // Don't delete! Default constructor is required by DataStax driver
71   }
72
73   /**
74    * Instantiates a new License agreement entity.
75    *
76    * @param vlmId   the vlm id
77    * @param version the version
78    * @param id      the id
79    */
80   public LicenseAgreementEntity(String vlmId, Version version, String id) {
81     this.vendorLicenseModelId = vlmId;
82     this.id = id;
83     this.version = version;
84   }
85
86   @Override
87   public String getEntityType() {
88     return ENTITY_TYPE;
89   }
90
91   @Override
92   public String getFirstClassCitizenId() {
93     return getVendorLicenseModelId();
94   }
95
96   @Override
97   public String getId() {
98     return id;
99   }
100
101   @Override
102   public void setId(String id) {
103     this.id = id;
104   }
105
106   @Override
107   public Version getVersion() {
108     return version;
109   }
110
111   @Override
112   public void setVersion(Version version) {
113     this.version = version;
114   }
115
116   public String getVendorLicenseModelId() {
117     return vendorLicenseModelId;
118   }
119
120   public void setVendorLicenseModelId(String vendorLicenseModelId) {
121     this.vendorLicenseModelId = vendorLicenseModelId;
122   }
123
124   public String getName() {
125     return name;
126   }
127
128   public void setName(String name) {
129     this.name = name;
130   }
131
132   public String getDescription() {
133     return description;
134   }
135
136   public void setDescription(String description) {
137     this.description = description;
138   }
139
140   public ChoiceOrOther<LicenseTerm> getLicenseTerm() {
141     return licenseTerm;
142   }
143
144   public void setLicenseTerm(ChoiceOrOther<LicenseTerm> licenseTerm) {
145     licenseTerm.resolveEnum(LicenseTerm.class);
146     this.licenseTerm = licenseTerm;
147   }
148
149   public String getRequirementsAndConstrains() {
150     return requirementsAndConstrains;
151   }
152
153   public void setRequirementsAndConstrains(String requirementsAndConstrains) {
154     this.requirementsAndConstrains = requirementsAndConstrains;
155   }
156
157   public Set<String> getFeatureGroupIds() {
158     return featureGroupIds;
159   }
160
161   public void setFeatureGroupIds(Set<String> featureGroupIds) {
162     this.featureGroupIds = featureGroupIds;
163   }
164
165   @Override
166   public int hashCode() {
167     return Objects.hash(vendorLicenseModelId, version, id, name, description, licenseTerm,
168         requirementsAndConstrains, featureGroupIds);
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     LicenseAgreementEntity that = (LicenseAgreementEntity) obj;
180     return Objects.equals(vendorLicenseModelId, that.vendorLicenseModelId)
181         && Objects.equals(version, that.version)
182         && Objects.equals(id, that.id)
183         && Objects.equals(name, that.name)
184         && Objects.equals(description, that.description)
185         && Objects.equals(licenseTerm, that.licenseTerm)
186         && Objects.equals(requirementsAndConstrains, that.requirementsAndConstrains)
187         && Objects.equals(featureGroupIds, that.featureGroupIds);
188   }
189 }