219b4893ca509e039dd27fded1773adccf90b59d
[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     @Override
59     public Long getId() {
60         return id;
61     }
62
63     @Column(name = "CATEGORY_OPT_APP_ID")
64     public String getAppId() {
65         return appId;
66     }
67
68     public void setAppId(String appId) {
69         this.appId = appId;
70     }
71
72     @Column(name = "NAME")
73     public String getName() {
74         return name;
75     }
76
77     public void setName(String name) {
78         this.name = name;
79     }
80
81     @ManyToOne
82     @JoinColumn(name="CATEGORY_ID", nullable=false)
83     public CategoryParameter getCategoryParameter() {
84         return categoryParameter;
85     }
86
87     public void setCategoryParameter(CategoryParameter categoryParameter) {
88         this.categoryParameter = categoryParameter;
89     }
90
91     @Override
92     @Column(name = "CREATED_DATE")
93     public Date getCreated() {
94         return super.getCreated();
95     }
96
97     @Override
98     @Column(name = "MODIFIED_DATE")
99     public Date getModified() {
100         return super.getModified();
101     }
102
103     @Override
104     @Transient
105     public Long getCreatedId() {
106         return super.getCreatedId();
107     }
108
109     @Override
110     @Transient
111     public Long getModifiedId() {
112         return super.getModifiedId();
113     }
114
115     @Override
116     @Transient
117     public Serializable getAuditUserId() {
118         return super.getAuditUserId();
119     }
120
121     @Override
122     @Transient
123     public Long getRowNum() {
124         return super.getRowNum();
125     }
126
127     @Override
128     @Transient
129     public Set getAuditTrail() {
130         return super.getAuditTrail();
131     }
132
133     @Override
134     public boolean equals(Object o) {
135         if (this == o) {
136             return true;
137         }
138         if (o == null || getClass() != o.getClass()) {
139             return false;
140         }
141
142         CategoryParameterOption that = (CategoryParameterOption) o;
143
144         if (getAppId() != null ? !getAppId().equals(that.getAppId()) : that.getAppId() != null) {
145             return false;
146         }
147         if (getName() != null ? !getName().equals(that.getName()) : that.getName() != null) {
148             return false;
149         }
150         return getCategoryParameter() != null ? getCategoryParameter().equals(that.getCategoryParameter())
151             : that.getCategoryParameter() == null;
152     }
153
154     @Override
155     public int hashCode() {
156         int result = getAppId() != null ? getAppId().hashCode() : 0;
157         result = 31 * result + (getName() != null ? getName().hashCode() : 0);
158         result = 31 * result + hashCodeOfParentCategoryParameter();
159         return result;
160     }
161
162     private int hashCodeOfParentCategoryParameter() {
163         // Don't use getCategoryParameter's hashCode, as it might loop back to self's hasCode
164         return (getCategoryParameter() == null || getCategoryParameter().getId() == null)
165                 ? 0 : getCategoryParameter().getId().hashCode();
166     }
167
168     @Override
169     public String toString() {
170         return "CategoryParameterOption{" +
171                 "id=" + id +
172                 ", key='" + appId + '\'' +
173                 ", value='" + name + '\'' +
174                 ", categoryParameterId=" + categoryParameter.getId() +
175                 '}';
176     }
177 }