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