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