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 / NetworkEntity.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.Network;
32 import org.openecomp.sdc.versioning.dao.types.Version;
33
34 @Table(keyspace = "dox", name = "vsp_network")
35 public class NetworkEntity implements CompositionEntity {
36   private static final String ENTITY_TYPE = "Vendor Software Product Network";
37
38   @PartitionKey
39   @Column(name = "vsp_id")
40   private String vspId;
41   @PartitionKey(value = 1)
42   @Frozen
43   private Version version;
44   @ClusteringColumn
45   @Column(name = "network_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   public NetworkEntity() {
53
54   }
55
56   /**
57    * Instantiates a new Network entity.
58    *
59    * @param vspId   the vsp id
60    * @param version the version
61    * @param id      the id
62    */
63   public NetworkEntity(String vspId, Version version, String id) {
64     this.vspId = vspId;
65     this.version = version;
66     this.id = id;
67   }
68
69   @Override
70   public CompositionEntityType getType() {
71     return CompositionEntityType.network;
72   }
73
74   @Override
75   public CompositionEntityId getCompositionEntityId() {
76     return new CompositionEntityId(getId(), new CompositionEntityId(getVspId(), null));
77   }
78
79   public String getVspId() {
80     return vspId;
81   }
82
83   public void setVspId(String vspId) {
84     this.vspId = vspId;
85   }
86
87   @Override
88   public Version getVersion() {
89     return version;
90   }
91
92   @Override
93   public void setVersion(Version version) {
94     this.version = version;
95   }
96
97   @Override
98   public String getEntityType() {
99     return ENTITY_TYPE;
100   }
101
102   @Override
103   public String getFirstClassCitizenId() {
104     return getVspId();
105   }
106
107   @Override
108   public String getId() {
109     return id;
110   }
111
112   @Override
113   public void setId(String id) {
114     this.id = id;
115   }
116
117   @Override
118   public String getCompositionData() {
119     return compositionData;
120   }
121
122   @Override
123   public void setCompositionData(String compositionData) {
124     this.compositionData = compositionData;
125   }
126
127   public Network getNetworkCompositionData() {
128     return compositionData == null ? null : JsonUtil.json2Object(compositionData, Network.class);
129   }
130
131   public void setNetworkCompositionData(Network network) {
132     this.compositionData = network == null ? null : JsonUtil.object2Json(network);
133   }
134
135   @Override
136   public String getQuestionnaireData() {
137     return questionnaireData;
138   }
139
140   @Override
141   public void setQuestionnaireData(String questionnaireData) {
142     this.questionnaireData = questionnaireData;
143   }
144
145   @Override
146   public boolean equals(Object obj) {
147     if (this == obj) {
148       return true;
149     }
150     if (obj == null || getClass() != obj.getClass()) {
151       return false;
152     }
153
154     NetworkEntity that = (NetworkEntity) obj;
155
156     if (vspId != null ? !vspId.equals(that.vspId) : that.vspId != null) {
157       return false;
158     }
159     if (version != null ? !version.equals(that.version) : that.version != null) {
160       return false;
161     }
162     if (id != null ? !id.equals(that.id) : that.id != null) {
163       return false;
164     }
165     if (compositionData != null ? !compositionData.equals(that.compositionData)
166         : that.compositionData != null) {
167       return false;
168     }
169     return questionnaireData != null ? questionnaireData.equals(that.questionnaireData)
170         : that.questionnaireData == null;
171
172   }
173
174   @Override
175   public int hashCode() {
176     int result = vspId != null ? vspId.hashCode() : 0;
177     result = 31 * result + (version != null ? version.hashCode() : 0);
178     result = 31 * result + (id != null ? id.hashCode() : 0);
179     result = 31 * result + (compositionData != null ? compositionData.hashCode() : 0);
180     result = 31 * result + (questionnaireData != null ? questionnaireData.hashCode() : 0);
181     return result;
182   }
183 }