b43a68abe1a46e24f63181050cac48469edfd197
[sdc.git] /
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   /**
54    * Every entity class must have a default constructor according to
55    * <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/object_mapper/creating/">
56    * Definition of mapped classes</a>.
57    */
58   public NetworkEntity() {
59     // Don't delete! Default constructor is required by DataStax driver
60   }
61
62   /**
63    * Instantiates a new Network entity.
64    *
65    * @param vspId   the vsp id
66    * @param version the version
67    * @param id      the id
68    */
69   public NetworkEntity(String vspId, Version version, String id) {
70     this.vspId = vspId;
71     this.version = version;
72     this.id = id;
73   }
74
75   @Override
76   public CompositionEntityType getType() {
77     return CompositionEntityType.network;
78   }
79
80   @Override
81   public CompositionEntityId getCompositionEntityId() {
82     return new CompositionEntityId(getId(), new CompositionEntityId(getVspId(), null));
83   }
84
85   @Override
86   public String getCompositionData() {
87     return compositionData;
88   }
89
90   @Override
91   public void setCompositionData(String compositionData) {
92     this.compositionData = compositionData;
93   }
94
95   @Override
96   public String getQuestionnaireData() {
97     return questionnaireData;
98   }
99
100   @Override
101   public void setQuestionnaireData(String questionnaireData) {
102     this.questionnaireData = questionnaireData;
103   }
104
105   public String getVspId() {
106     return vspId;
107   }
108
109   public void setVspId(String vspId) {
110     this.vspId = vspId;
111   }
112
113   @Override
114   public String getEntityType() {
115     return ENTITY_TYPE;
116   }
117
118   @Override
119   public String getFirstClassCitizenId() {
120     return getVspId();
121   }
122
123   @Override
124   public String getId() {
125     return id;
126   }
127
128   @Override
129   public void setId(String id) {
130     this.id = id;
131   }
132
133   @Override
134   public Version getVersion() {
135     return version;
136   }
137
138   @Override
139   public void setVersion(Version version) {
140     this.version = version;
141   }
142
143   public Network getNetworkCompositionData() {
144     return compositionData == null ? null : JsonUtil.json2Object(compositionData, Network.class);
145   }
146
147   public void setNetworkCompositionData(Network network) {
148     this.compositionData = network == null ? null : JsonUtil.object2Json(network);
149   }
150
151   @Override
152   public int hashCode() {
153     int result = vspId != null ? vspId.hashCode() : 0;
154     result = 31 * result + (version != null ? version.hashCode() : 0);
155     result = 31 * result + (id != null ? id.hashCode() : 0);
156     result = 31 * result + (compositionData != null ? compositionData.hashCode() : 0);
157     result = 31 * result + (questionnaireData != null ? questionnaireData.hashCode() : 0);
158     return result;
159   }
160
161   @Override
162   public boolean equals(Object object) {
163     if (this == object) {
164       return true;
165     }
166     if (object == null || getClass() != object.getClass()) {
167       return false;
168     }
169
170     NetworkEntity that = (NetworkEntity) object;
171
172     if (vspId != null ? !vspId.equals(that.vspId) : that.vspId != null) {
173       return false;
174     }
175     if (version != null ? !version.equals(that.version) : that.version != null) {
176       return false;
177     }
178     if (id != null ? !id.equals(that.id) : that.id != null) {
179       return false;
180     }
181     if (compositionData != null ? !compositionData.equals(that.compositionData)
182         : that.compositionData != null) {
183       return false;
184     }
185     return questionnaireData != null ? questionnaireData.equals(that.questionnaireData)
186         : that.questionnaireData == null;
187
188   }
189 }