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