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