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