push addional code
[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 ComponentData 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   public String getVspId() {
87     return vspId;
88   }
89
90   public void setVspId(String vspId) {
91     this.vspId = vspId;
92   }
93
94   @Override
95   public Version getVersion() {
96     return version;
97   }
98
99   @Override
100   public void setVersion(Version version) {
101     this.version = version;
102   }
103
104   @Override
105   public String getEntityType() {
106     return ENTITY_TYPE;
107   }
108
109   @Override
110   public String getFirstClassCitizenId() {
111     return getVspId();
112   }
113
114   public String getComponentId() {
115     return componentId;
116   }
117
118   public void setComponentId(String componentId) {
119     this.componentId = componentId;
120   }
121
122   @Override
123   public String getId() {
124     return id;
125   }
126
127   @Override
128   public void setId(String id) {
129     this.id = id;
130   }
131
132   @Override
133   public String getCompositionData() {
134     return compositionData;
135   }
136
137   @Override
138   public void setCompositionData(String compositionData) {
139     this.compositionData = compositionData;
140   }
141
142   public Nic getNicCompositionData() {
143     return compositionData == null ? null : JsonUtil.json2Object(compositionData, Nic.class);
144   }
145
146   public void setNicCompositionData(Nic nic) {
147     this.compositionData = nic == null ? null : JsonUtil.object2Json(nic);
148   }
149
150   @Override
151   public String getQuestionnaireData() {
152     return questionnaireData;
153   }
154
155   @Override
156   public void setQuestionnaireData(String questionnaireData) {
157     this.questionnaireData = questionnaireData;
158   }
159
160   @Override
161   public boolean equals(Object obj) {
162     if (this == obj) {
163       return true;
164     }
165     if (obj == null || getClass() != obj.getClass()) {
166       return false;
167     }
168
169     NicEntity nicEntity = (NicEntity) obj;
170
171     if (vspId != null ? !vspId.equals(nicEntity.vspId) : nicEntity.vspId != null) {
172       return false;
173     }
174     if (version != null ? !version.equals(nicEntity.version) : nicEntity.version != null) {
175       return false;
176     }
177     if (componentId != null ? !componentId.equals(nicEntity.componentId)
178         : nicEntity.componentId != null) {
179       return false;
180     }
181     if (id != null ? !id.equals(nicEntity.id) : nicEntity.id != null) {
182       return false;
183     }
184     if (compositionData != null ? !compositionData.equals(nicEntity.compositionData)
185         : nicEntity.compositionData != null) {
186       return false;
187     }
188     return questionnaireData != null ? questionnaireData.equals(nicEntity.questionnaireData)
189         : nicEntity.questionnaireData == null;
190
191   }
192
193   @Override
194   public int hashCode() {
195     int result = vspId != null ? vspId.hashCode() : 0;
196     result = 31 * result + (version != null ? version.hashCode() : 0);
197     result = 31 * result + (componentId != null ? componentId.hashCode() : 0);
198     result = 31 * result + (id != null ? id.hashCode() : 0);
199     result = 31 * result + (compositionData != null ? compositionData.hashCode() : 0);
200     result = 31 * result + (questionnaireData != null ? questionnaireData.hashCode() : 0);
201     return result;
202   }
203 }