70f7b5aa23d22e3f7606adc6db40c897c0f492fb
[vid.git] / vid-app-common / src / main / java / org / onap / vid / model / CategoryParameterOption.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 - 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.onap.vid.model;
22
23 import java.io.Serializable;
24 import java.util.Date;
25 import java.util.Set;
26 import javax.persistence.Column;
27 import javax.persistence.Entity;
28 import javax.persistence.GeneratedValue;
29 import javax.persistence.GenerationType;
30 import javax.persistence.Id;
31 import javax.persistence.JoinColumn;
32 import javax.persistence.ManyToOne;
33 import javax.persistence.Table;
34 import javax.persistence.Transient;
35 import org.onap.portalsdk.core.domain.support.DomainVo;
36
37 @Entity
38 @Table(name = "vid_category_parameter_option")
39 public class CategoryParameterOption extends DomainVo {
40
41     private String appId;
42     private String name;
43
44     private CategoryParameter categoryParameter;
45
46     public CategoryParameterOption() {
47     }
48
49     public CategoryParameterOption(String appId, String name, CategoryParameter categoryParameter) {
50         setAppId(appId);
51         setName(name);
52         setCategoryParameter(categoryParameter);
53     }
54
55     @Id
56     @GeneratedValue(strategy = GenerationType.IDENTITY)
57     @Column(name = "CATEGORY_OPT_DB_ID")
58     public Long getId() {
59         return id;
60     }
61
62     @Column(name = "CATEGORY_OPT_APP_ID")
63     public String getAppId() {
64         return appId;
65     }
66
67     public void setAppId(String appId) {
68         this.appId = appId;
69     }
70
71     @Column(name = "NAME")
72     public String getName() {
73         return name;
74     }
75
76     public void setName(String name) {
77         this.name = name;
78     }
79
80     @ManyToOne
81     @JoinColumn(name="CATEGORY_ID", nullable=false)
82     public CategoryParameter getCategoryParameter() {
83         return categoryParameter;
84     }
85
86     public void setCategoryParameter(CategoryParameter categoryParameter) {
87         this.categoryParameter = categoryParameter;
88     }
89
90     @Override
91     @Column(name = "CREATED_DATE")
92     public Date getCreated() {
93         return super.getCreated();
94     }
95
96     @Override
97     @Column(name = "MODIFIED_DATE")
98     public Date getModified() {
99         return super.getModified();
100     }
101
102     @Override
103     @Transient
104     public Long getCreatedId() {
105         return super.getCreatedId();
106     }
107
108     @Override
109     @Transient
110     public Long getModifiedId() {
111         return super.getModifiedId();
112     }
113
114     @Override
115     @Transient
116     public Serializable getAuditUserId() {
117         return super.getAuditUserId();
118     }
119
120     @Override
121     @Transient
122     public Long getRowNum() {
123         return super.getRowNum();
124     }
125
126     @Override
127     @Transient
128     public Set getAuditTrail() {
129         return super.getAuditTrail();
130     }
131
132     @Override
133     public boolean equals(Object o) {
134         if (this == o) {
135             return true;
136         }
137         if (o == null || getClass() != o.getClass()) {
138             return false;
139         }
140
141         CategoryParameterOption that = (CategoryParameterOption) o;
142
143         if (getAppId() != null ? !getAppId().equals(that.getAppId()) : that.getAppId() != null) {
144             return false;
145         }
146         if (getName() != null ? !getName().equals(that.getName()) : that.getName() != null) {
147             return false;
148         }
149         return getCategoryParameter() != null ? getCategoryParameter().equals(that.getCategoryParameter())
150             : that.getCategoryParameter() == null;
151     }
152
153     @Override
154     public int hashCode() {
155         int result = getAppId() != null ? getAppId().hashCode() : 0;
156         result = 31 * result + (getName() != null ? getName().hashCode() : 0);
157         result = 31 * result + hashCodeOfParentCategoryParameter();
158         return result;
159     }
160
161     private int hashCodeOfParentCategoryParameter() {
162         // Don't use getCategoryParameter's hashCode, as it might loop back to self's hasCode
163         return (getCategoryParameter() == null || getCategoryParameter().getId() == null)
164                 ? 0 : getCategoryParameter().getId().hashCode();
165     }
166
167     @Override
168     public String toString() {
169         return "CategoryParameterOption{" +
170                 "id=" + id +
171                 ", key='" + appId + '\'' +
172                 ", value='" + name + '\'' +
173                 ", categoryParameterId=" + categoryParameter.getId() +
174                 '}';
175     }
176 }