push addional 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 / 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 ComponentData";
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   public String getVspId() {
87     return vspId;
88   }
89
90   public void setVspId(String vspId) {
91     this.vspId = vspId;
92   }
93
94   @Override
95   public Version getVersion() {
96     return version;
97   }
98
99   @Override
100   public void setVersion(Version version) {
101     this.version = version;
102   }
103
104   @Override
105   public String getEntityType() {
106     return ENTITY_TYPE;
107   }
108
109   @Override
110   public String getFirstClassCitizenId() {
111     return getVspId();
112   }
113
114   @Override
115   public String getId() {
116     return id;
117   }
118
119   @Override
120   public void setId(String id) {
121     this.id = id;
122   }
123
124   @Override
125   public String getCompositionData() {
126     return compositionData;
127   }
128
129   @Override
130   public void setCompositionData(String compositionData) {
131     this.compositionData = compositionData;
132   }
133
134   public ComponentData getComponentCompositionData() {
135     return compositionData == null ? null
136         : JsonUtil.json2Object(compositionData, ComponentData.class);
137   }
138
139   public void setComponentCompositionData(ComponentData component) {
140     this.compositionData = component == null ? null : JsonUtil.object2Json(component);
141   }
142
143   @Override
144   public String getQuestionnaireData() {
145     return questionnaireData;
146   }
147
148   @Override
149   public void setQuestionnaireData(String questionnaireData) {
150     this.questionnaireData = questionnaireData;
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 boolean equals(Object obj) {
163     if (this == obj) {
164       return true;
165     }
166     if (obj == null || getClass() != obj.getClass()) {
167       return false;
168     }
169
170     ComponentEntity that = (ComponentEntity) obj;
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
190   @Override
191   public int hashCode() {
192     int result = vspId != null ? vspId.hashCode() : 0;
193     result = 31 * result + (version != null ? version.hashCode() : 0);
194     result = 31 * result + (id != null ? id.hashCode() : 0);
195     result = 31 * result + (compositionData != null ? compositionData.hashCode() : 0);
196     result = 31 * result + (questionnaireData != null ? questionnaireData.hashCode() : 0);
197     return result;
198   }
199 }