5452c03d2249ed3ceb6dcd398941f002a5397478
[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.vendorsoftwareproduct.dao.type;
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.core.utilities.json.JsonUtil;
29 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId;
30 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType;
31 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic;
32 import org.openecomp.sdc.versioning.dao.types.Version;
33
34
35 @Table(keyspace = "dox", name = "vsp_component_nic")
36 public class NicEntity implements CompositionEntity {
37   private static final String ENTITY_TYPE = "Vendor Software Product NIC";
38
39   @PartitionKey
40   @Column(name = "vsp_id")
41   private String vspId;
42   @PartitionKey(value = 1)
43   @Frozen
44   private Version version;
45   @ClusteringColumn
46   @Column(name = "component_id")
47   private String componentId;
48   @ClusteringColumn(value = 1)
49   @Column(name = "nic_id")
50   private String id;
51   @Column(name = "composition_data")
52   private String compositionData;
53   @Column(name = "questionnaire_data")
54   private String questionnaireData;
55
56   /**
57    * Every entity class must have a default constructor according to
58    * <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/object_mapper/creating/">
59    * Definition of mapped classes</a>.
60    */
61   public NicEntity() {
62     // Don't delete! Default constructor is required by DataStax driver
63   }
64
65   /**
66    * Instantiates a new Nic entity.
67    *
68    * @param vspId       the vsp id
69    * @param version     the version
70    * @param componentId the component id
71    * @param id          the id
72    */
73   public NicEntity(String vspId, Version version, String componentId, String id) {
74     this.vspId = vspId;
75     this.version = version;
76     this.componentId = componentId;
77     this.id = id;
78   }
79
80   @Override
81   public CompositionEntityType getType() {
82     return CompositionEntityType.nic;
83   }
84
85   @Override
86   public CompositionEntityId getCompositionEntityId() {
87     return new CompositionEntityId(getId(),
88         new CompositionEntityId(getComponentId(), new CompositionEntityId(getVspId(), null)));
89   }
90
91   @Override
92   public String getCompositionData() {
93     return compositionData;
94   }
95
96   @Override
97   public void setCompositionData(String compositionData) {
98     this.compositionData = compositionData;
99   }
100
101   @Override
102   public String getQuestionnaireData() {
103     return questionnaireData;
104   }
105
106   @Override
107   public void setQuestionnaireData(String questionnaireData) {
108     this.questionnaireData = questionnaireData;
109   }
110
111   public String getVspId() {
112     return vspId;
113   }
114
115   public void setVspId(String vspId) {
116     this.vspId = vspId;
117   }
118
119   @Override
120   public String getEntityType() {
121     return ENTITY_TYPE;
122   }
123
124   @Override
125   public String getFirstClassCitizenId() {
126     return getVspId();
127   }
128
129   @Override
130   public String getId() {
131     return id;
132   }
133
134   @Override
135   public void setId(String id) {
136     this.id = id;
137   }
138
139   @Override
140   public Version getVersion() {
141     return version;
142   }
143
144   @Override
145   public void setVersion(Version version) {
146     this.version = version;
147   }
148
149   public String getComponentId() {
150     return componentId;
151   }
152
153   public void setComponentId(String componentId) {
154     this.componentId = componentId;
155   }
156
157   public Nic getNicCompositionData() {
158     return compositionData == null ? null : JsonUtil.json2Object(compositionData, Nic.class);
159   }
160
161   public void setNicCompositionData(Nic nic) {
162     this.compositionData = nic == null ? null : JsonUtil.object2Json(nic);
163   }
164
165   @Override
166   public int hashCode() {
167     int result = vspId != null ? vspId.hashCode() : 0;
168     result = 31 * result + (version != null ? version.hashCode() : 0);
169     result = 31 * result + (componentId != null ? componentId.hashCode() : 0);
170     result = 31 * result + (id != null ? id.hashCode() : 0);
171     result = 31 * result + (compositionData != null ? compositionData.hashCode() : 0);
172     result = 31 * result + (questionnaireData != null ? questionnaireData.hashCode() : 0);
173     return result;
174   }
175
176   @Override
177   public boolean equals(Object object) {
178     if (this == object) {
179       return true;
180     }
181     if (object == null || getClass() != object.getClass()) {
182       return false;
183     }
184
185     NicEntity nicEntity = (NicEntity) object;
186
187     if (vspId != null ? !vspId.equals(nicEntity.vspId) : nicEntity.vspId != null) {
188       return false;
189     }
190     if (version != null ? !version.equals(nicEntity.version) : nicEntity.version != null) {
191       return false;
192     }
193     if (componentId != null ? !componentId.equals(nicEntity.componentId)
194         : nicEntity.componentId != null) {
195       return false;
196     }
197     if (id != null ? !id.equals(nicEntity.id) : nicEntity.id != null) {
198       return false;
199     }
200     if (compositionData != null ? !compositionData.equals(nicEntity.compositionData)
201         : nicEntity.compositionData != null) {
202       return false;
203     }
204     return questionnaireData != null ? questionnaireData.equals(nicEntity.questionnaireData)
205         : nicEntity.questionnaireData == null;
206
207   }
208 }