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