[SDC] Onboarding 1710 rebase.
[sdc.git] / openecomp-be / lib / openecomp-sdc-vendor-software-product-lib / openecomp-sdc-vendor-software-product-api / src / main / java / org / openecomp / sdc / vendorsoftwareproduct / dao / type / NicEntity.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.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   public NicEntity() {
57
58   }
59
60   /**
61    * Instantiates a new Nic entity.
62    *
63    * @param vspId       the vsp id
64    * @param version     the version
65    * @param componentId the component id
66    * @param id          the id
67    */
68   public NicEntity(String vspId, Version version, String componentId, String id) {
69     this.vspId = vspId;
70     this.version = version;
71     this.componentId = componentId;
72     this.id = id;
73   }
74
75   @Override
76   public CompositionEntityType getType() {
77     return CompositionEntityType.nic;
78   }
79
80   @Override
81   public CompositionEntityId getCompositionEntityId() {
82     return new CompositionEntityId(getId(),
83         new CompositionEntityId(getComponentId(), new CompositionEntityId(getVspId(), null)));
84   }
85
86   @Override
87   public String getCompositionData() {
88     return compositionData;
89   }
90
91   @Override
92   public void setCompositionData(String compositionData) {
93     this.compositionData = compositionData;
94   }
95
96   @Override
97   public String getQuestionnaireData() {
98     return questionnaireData;
99   }
100
101   @Override
102   public void setQuestionnaireData(String questionnaireData) {
103     this.questionnaireData = questionnaireData;
104   }
105
106   public String getVspId() {
107     return vspId;
108   }
109
110   public void setVspId(String vspId) {
111     this.vspId = vspId;
112   }
113
114   @Override
115   public String getEntityType() {
116     return ENTITY_TYPE;
117   }
118
119   @Override
120   public String getFirstClassCitizenId() {
121     return getVspId();
122   }
123
124   @Override
125   public String getId() {
126     return id;
127   }
128
129   @Override
130   public void setId(String id) {
131     this.id = id;
132   }
133
134   @Override
135   public Version getVersion() {
136     return version;
137   }
138
139   @Override
140   public void setVersion(Version version) {
141     this.version = version;
142   }
143
144   public String getComponentId() {
145     return componentId;
146   }
147
148   public void setComponentId(String componentId) {
149     this.componentId = componentId;
150   }
151
152   public Nic getNicCompositionData() {
153     return compositionData == null ? null : JsonUtil.json2Object(compositionData, Nic.class);
154   }
155
156   public void setNicCompositionData(Nic nic) {
157     this.compositionData = nic == null ? null : JsonUtil.object2Json(nic);
158   }
159
160   @Override
161   public int hashCode() {
162     int result = vspId != null ? vspId.hashCode() : 0;
163     result = 31 * result + (version != null ? version.hashCode() : 0);
164     result = 31 * result + (componentId != null ? componentId.hashCode() : 0);
165     result = 31 * result + (id != null ? id.hashCode() : 0);
166     result = 31 * result + (compositionData != null ? compositionData.hashCode() : 0);
167     result = 31 * result + (questionnaireData != null ? questionnaireData.hashCode() : 0);
168     return result;
169   }
170
171   @Override
172   public boolean equals(Object object) {
173     if (this == object) {
174       return true;
175     }
176     if (object == null || getClass() != object.getClass()) {
177       return false;
178     }
179
180     NicEntity nicEntity = (NicEntity) object;
181
182     if (vspId != null ? !vspId.equals(nicEntity.vspId) : nicEntity.vspId != null) {
183       return false;
184     }
185     if (version != null ? !version.equals(nicEntity.version) : nicEntity.version != null) {
186       return false;
187     }
188     if (componentId != null ? !componentId.equals(nicEntity.componentId)
189         : nicEntity.componentId != null) {
190       return false;
191     }
192     if (id != null ? !id.equals(nicEntity.id) : nicEntity.id != null) {
193       return false;
194     }
195     if (compositionData != null ? !compositionData.equals(nicEntity.compositionData)
196         : nicEntity.compositionData != null) {
197       return false;
198     }
199     return questionnaireData != null ? questionnaireData.equals(nicEntity.questionnaireData)
200         : nicEntity.questionnaireData == null;
201
202   }
203 }