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