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