Changes include Metadata support, Upload tosca policy model and Loop Template
[clamp.git] / src / main / java / org / onap / clamp / tosca / DictionaryElement.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2020 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 import java.io.Serializable;
28 import java.util.HashSet;
29 import java.util.Set;
30 import javax.persistence.Column;
31 import javax.persistence.Entity;
32 import javax.persistence.FetchType;
33 import javax.persistence.Id;
34 import javax.persistence.ManyToMany;
35 import javax.persistence.Table;
36 import org.onap.clamp.loop.common.AuditEntity;
37
38 /**
39  * Represents a Dictionary Item.
40  */
41 @Entity
42 @Table(name = "dictionary_elements")
43 public class DictionaryElement extends AuditEntity implements Serializable {
44
45     /**
46      * The serial version id.
47      */
48     private static final long serialVersionUID = -286522707701388644L;
49
50     @Id
51     @Expose
52     @Column(nullable = false, name = "short_name")
53     private String shortName;
54
55     @Expose
56     @Column(nullable = false, name = "name")
57     private String name;
58
59     @Expose
60     @Column(nullable = false, name = "description")
61     private String description;
62
63     @Expose
64     @Column(nullable = false, name = "type")
65     private String type;
66
67     @Expose
68     @Column(nullable = true, name = "subdictionary_name")
69     private String subDictionary;
70
71     @ManyToMany(mappedBy = "dictionaryElements", fetch = FetchType.EAGER)
72     private Set<Dictionary> usedByDictionaries = new HashSet<>();
73
74     /**
75      * name getter.
76      *
77      * @return the name
78      */
79     public String getName() {
80         return name;
81     }
82
83     /**
84      * name setter.
85      *
86      * @param name the name to set
87      */
88     public void setName(String name) {
89         this.name = name;
90     }
91
92     /**
93      * shortName getter.
94      *
95      * @return the shortName
96      */
97     public String getShortName() {
98         return shortName;
99     }
100
101     /**
102      * shortName setter.
103      *
104      * @param shortName the shortName to set
105      */
106     public void setShortName(String shortName) {
107         this.shortName = shortName;
108     }
109
110     /**
111      * description getter.
112      *
113      * @return the description
114      */
115     public String getDescription() {
116         return description;
117     }
118
119     /**
120      * description setter.
121      *
122      * @param description the description to set
123      */
124     public void setDescription(String description) {
125         this.description = description;
126     }
127
128     /**
129      * type getter.
130      *
131      * @return the type
132      */
133     public String getType() {
134         return type;
135     }
136
137     /**
138      * type setter.
139      *
140      * @param type the type to set
141      */
142     public void setType(String type) {
143         this.type = type;
144     }
145
146     /**
147      * subDictionary getter.
148      *
149      * @return the subDictionary
150      */
151     public String getSubDictionary() {
152         return subDictionary;
153     }
154
155     /**
156      * subDictionary setter.
157      *
158      * @param subDictionary the subDictionary to set
159      */
160     public void setSubDictionary(String subDictionary) {
161         this.subDictionary = subDictionary;
162     }
163
164     /**
165      * usedByDictionaries getter.
166      *
167      * @return the usedByDictionaries
168      */
169     public Set<Dictionary> getUsedByDictionaries() {
170         return usedByDictionaries;
171     }
172
173     /**
174      * usedByDictionaries setter.
175      *
176      * @param usedByDictionaries the usedByDictionaries to set
177      */
178     public void setUsedByDictionaries(Set<Dictionary> usedByDictionaries) {
179         this.usedByDictionaries = usedByDictionaries;
180     }
181
182     /**
183      * Default Constructor.
184      */
185     public DictionaryElement() {
186     }
187
188     /**
189      * Constructor.
190      *
191      * @param name The Dictionary element name
192      * @param shortName The short name
193      * @param description The description
194      * @param type The type of element
195      * @param subDictionary The sub type
196      */
197     public DictionaryElement(String name, String shortName, String description, String type,
198         String subDictionary) {
199         this.name = name;
200         this.shortName = shortName;
201         this.description = description;
202         this.type = type;
203         this.subDictionary = subDictionary;
204     }
205
206     /**
207      * Constructor.
208      *
209      * @param name The Dictionary element name
210      * @param shortName The short name
211      * @param description The description
212      * @param type The type of element
213      * @param subDictionary The sub type
214      */
215     public DictionaryElement(String name, String shortName, String description, String type,
216         String subDictionary, Set<Dictionary> usedByDictionaries) {
217         this.name = name;
218         this.shortName = shortName;
219         this.description = description;
220         this.type = type;
221         this.subDictionary = subDictionary;
222         this.usedByDictionaries = usedByDictionaries;
223     }
224
225     @Override
226     public int hashCode() {
227         final int prime = 31;
228         int result = 1;
229         result = prime * result + ((shortName == null) ? 0 : shortName.hashCode());
230         return result;
231     }
232
233     @Override
234     public boolean equals(Object obj) {
235         if (this == obj) {
236             return true;
237         }
238         if (obj == null) {
239             return false;
240         }
241         if (getClass() != obj.getClass()) {
242             return false;
243         }
244         DictionaryElement other = (DictionaryElement) obj;
245         if (shortName == null) {
246             if (other.shortName != null) {
247                 return false;
248             }
249         } else if (!shortName.equals(other.shortName)) {
250             return false;
251         }
252         return true;
253     }
254 }