e81885f3eeb1b01ab572a093ba8241cc8c17de2b
[clamp.git] / src / main / java / org / onap / clamp / tosca / DictionaryElement.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ===================================================================
21  *
22  */
23
24 package org.onap.clamp.tosca;
25
26 import com.google.gson.annotations.Expose;
27
28 import java.io.Serializable;
29
30 import javax.persistence.CascadeType;
31 import javax.persistence.Column;
32 import javax.persistence.Entity;
33 import javax.persistence.Id;
34 import javax.persistence.JoinColumn;
35 import javax.persistence.ManyToOne;
36 import javax.persistence.Table;
37
38 import org.onap.clamp.loop.common.AuditEntity;
39
40 /**
41  * Represents a Dictionary Item.
42  */
43 @Entity
44 @Table(name = "dictionary_elements")
45 public class DictionaryElement extends AuditEntity implements Serializable {
46
47     /**
48      * The serial version id.
49      */
50     private static final long serialVersionUID = -286522707701388644L;
51
52     @Id
53     @Expose
54     @Column(nullable = false, name = "name", unique = true)
55     private String name;
56
57     @Expose
58     @Column(nullable = false, name = "short_name", unique = true)
59     private String shortName;
60
61     @Expose
62     @Column(name = "description")
63     private String description;
64
65     @Expose
66     @Column(nullable = false, name = "type")
67     private String type;
68
69     @Column(name = "subdictionary_id", nullable = false)
70     @Expose
71     private String subDictionary;
72
73     @ManyToOne(cascade = CascadeType.ALL)
74     @JoinColumn(name = "dictionary_id")
75     private Dictionary dictionary;
76
77     /**
78      * name getter.
79      * 
80      * @return the name
81      */
82     public String getName() {
83         return name;
84     }
85
86     /**
87      * name setter.
88      * 
89      * @param name the name to set
90      */
91     public void setName(String name) {
92         this.name = name;
93     }
94
95     /**
96      * shortName getter.
97      * 
98      * @return the shortName
99      */
100     public String getShortName() {
101         return shortName;
102     }
103
104     /**
105      * shortName setter.
106      * 
107      * @param shortName the shortName to set
108      */
109     public void setShortName(String shortName) {
110         this.shortName = shortName;
111     }
112
113     /**
114      * description getter.
115      * 
116      * @return the description
117      */
118     public String getDescription() {
119         return description;
120     }
121
122     /**
123      * description setter.
124      * 
125      * @param description the description to set
126      */
127     public void setDescription(String description) {
128         this.description = description;
129     }
130
131     /**
132      * type getter.
133      * 
134      * @return the type
135      */
136     public String getType() {
137         return type;
138     }
139
140     /**
141      * type setter.
142      * 
143      * @param type the type to set
144      */
145     public void setType(String type) {
146         this.type = type;
147     }
148
149     /**
150      * subDictionary getter.
151      * 
152      * @return the subDictionary
153      */
154     public String getSubDictionary() {
155         return subDictionary;
156     }
157
158     /**
159      * subDictionary setter.
160      * 
161      * @param subDictionary the subDictionary to set
162      */
163     public void setSubDictionary(String subDictionary) {
164         this.subDictionary = subDictionary;
165     }
166
167     /**
168      * dictionary getter.
169      * 
170      * @return the dictionary
171      */
172     public Dictionary getDictionary() {
173         return dictionary;
174     }
175
176     /**
177      * dictionary setter.
178      * 
179      * @param dictionary the dictionary to set
180      */
181     public void setDictionary(Dictionary dictionary) {
182         this.dictionary = dictionary;
183     }
184
185     /**
186      * Default Constructor.
187      */
188     public DictionaryElement() {
189     }
190
191     /**
192      * Constructor.
193      * 
194      * @param name          The Dictionary element name
195      * @param shortName     The short name
196      * @param description   The description
197      * @param type          The type of element
198      * @param subDictionary The sub type
199      * @param dictionary    The parent dictionary
200      */
201     public DictionaryElement(String name, String shortName, String description, String type, String subDictionary,
202             Dictionary dictionary) {
203         this.name = name;
204         this.shortName = shortName;
205         this.description = description;
206         this.type = type;
207         this.subDictionary = subDictionary;
208         this.dictionary = dictionary;
209     }
210
211     @Override
212     public int hashCode() {
213         final int prime = 31;
214         int result = 1;
215         result = prime * result + ((dictionary == null) ? 0 : dictionary.hashCode());
216         result = prime * result + ((name == null) ? 0 : name.hashCode());
217         return result;
218     }
219
220     @Override
221     public boolean equals(Object obj) {
222         if (this == obj) {
223             return true;
224         }
225         if (obj == null) {
226             return false;
227         }
228         if (getClass() != obj.getClass()) {
229             return false;
230         }
231         DictionaryElement other = (DictionaryElement) obj;
232         if (dictionary == null) {
233             if (other.dictionary != null) {
234                 return false;
235             }
236         } else if (!dictionary.equals(other.dictionary)) {
237             return false;
238         }
239         if (name == null) {
240             if (other.name != null) {
241                 return false;
242             }
243         } else if (!name.equals(other.name)) {
244             return false;
245         }
246         return true;
247     }
248
249 }