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