602fd6d15c78960a9959460ce8fae502bff61b18
[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 / ComponentEntity.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 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   private 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   public ComponentEntity() {
60
61   }
62
63   /**
64    * Instantiates a new Component entity.
65    *
66    * @param vspId   the vsp id
67    * @param version the version
68    * @param id      the id
69    */
70   public ComponentEntity(String vspId, Version version, String id) {
71     this.vspId = vspId;
72     this.version = version;
73     this.id = id;
74   }
75
76   @Override
77   public CompositionEntityType getType() {
78     return CompositionEntityType.component;
79   }
80
81   @Override
82   public CompositionEntityId getCompositionEntityId() {
83     return new CompositionEntityId(getId(), new CompositionEntityId(getVspId(), null));
84   }
85
86   @Override
87   public String getCompositionData() {
88     return compositionData;
89   }
90
91   @Override
92   public void setCompositionData(String compositionData) {
93     this.compositionData = compositionData;
94   }
95
96   @Override
97   public String getQuestionnaireData() {
98     return questionnaireData;
99   }
100
101   @Override
102   public void setQuestionnaireData(String questionnaireData) {
103     this.questionnaireData = questionnaireData;
104   }
105
106   public String getVspId() {
107     return vspId;
108   }
109
110   public void setVspId(String vspId) {
111     this.vspId = vspId;
112   }
113
114   @Override
115   public String getEntityType() {
116     return ENTITY_TYPE;
117   }
118
119   @Override
120   public String getFirstClassCitizenId() {
121     return getVspId();
122   }
123
124   @Override
125   public String getId() {
126     return id;
127   }
128
129   @Override
130   public void setId(String id) {
131     this.id = id;
132   }
133
134   @Override
135   public Version getVersion() {
136     return version;
137   }
138
139   @Override
140   public void setVersion(Version version) {
141     this.version = version;
142   }
143
144   public ComponentData getComponentCompositionData() {
145     return compositionData == null ? null
146         : JsonUtil.json2Object(compositionData, ComponentData.class);
147   }
148
149   public void setComponentCompositionData(ComponentData component) {
150     this.compositionData = component == null ? null : JsonUtil.object2Json(component);
151   }
152
153   public List<NicEntity> getNics() {
154     return nics;
155   }
156
157   public void setNics(List<NicEntity> nics) {
158     this.nics = nics;
159   }
160
161   @Override
162   public int hashCode() {
163     int result = vspId != null ? vspId.hashCode() : 0;
164     result = 31 * result + (version != null ? version.hashCode() : 0);
165     result = 31 * result + (id != null ? id.hashCode() : 0);
166     result = 31 * result + (compositionData != null ? compositionData.hashCode() : 0);
167     result = 31 * result + (questionnaireData != null ? questionnaireData.hashCode() : 0);
168     return result;
169   }
170
171   @Override
172   public boolean equals(Object object) {
173     if (this == object) {
174       return true;
175     }
176     if (object == null || getClass() != object.getClass()) {
177       return false;
178     }
179
180     ComponentEntity that = (ComponentEntity) object;
181
182     if (vspId != null ? !vspId.equals(that.vspId) : that.vspId != null) {
183       return false;
184     }
185     if (version != null ? !version.equals(that.version) : that.version != null) {
186       return false;
187     }
188     if (id != null ? !id.equals(that.id) : that.id != null) {
189       return false;
190     }
191     if (compositionData != null ? !compositionData.equals(that.compositionData)
192         : that.compositionData != null) {
193       return false;
194     }
195     return questionnaireData != null ? questionnaireData.equals(that.questionnaireData)
196         : that.questionnaireData == null;
197
198   }
199 }