Merge "Upload Tosca Model changes to remove policy model type parsing from UI. Dictio...
[clamp.git] / src / main / java / org / onap / clamp / tosca / Dictionary.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.CascadeType;
31 import javax.persistence.Column;
32 import javax.persistence.Entity;
33 import javax.persistence.FetchType;
34 import javax.persistence.Id;
35 import javax.persistence.JoinColumn;
36 import javax.persistence.JoinTable;
37 import javax.persistence.ManyToMany;
38 import javax.persistence.Table;
39 import org.onap.clamp.loop.common.AuditEntity;
40
41 /**
42  * Represents Dictionary.
43  */
44
45 @Entity
46 @Table(name = "dictionary")
47 public class Dictionary extends AuditEntity implements Serializable {
48
49     /**
50      * The serial version id.
51      */
52     private static final long serialVersionUID = -286522707701388645L;
53
54     @Id
55     @Expose
56     @Column(nullable = false, name = "name", unique = true)
57     private String name;
58
59     @Expose
60     @Column(name = "dictionary_second_level")
61     private int secondLevelDictionary = 0;
62
63     @Expose
64     @Column(name = "dictionary_type")
65     private String subDictionaryType;
66
67     @Expose
68     @ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.ALL})
69     @JoinTable(
70         name = "dictionary_to_dictionaryelements",
71         joinColumns = @JoinColumn(name = "dictionary_name", referencedColumnName = "name"),
72         inverseJoinColumns = {@JoinColumn(
73             name = "dictionary_element_short_name",
74             referencedColumnName = "short_name")})
75     private Set<DictionaryElement> dictionaryElements = new HashSet<>();
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      * secondLevelDictionary getter.
97      *
98      * @return the secondLevelDictionary
99      */
100     public int getSecondLevelDictionary() {
101         return secondLevelDictionary;
102     }
103
104     /**
105      * secondLevelDictionary setter.
106      *
107      * @param secondLevelDictionary the secondLevelDictionary to set
108      */
109     public void setSecondLevelDictionary(int secondLevelDictionary) {
110         this.secondLevelDictionary = secondLevelDictionary;
111     }
112
113     /**
114      * subDictionaryType getter.
115      *
116      * @return the subDictionaryType
117      */
118     public String getSubDictionaryType() {
119         return subDictionaryType;
120     }
121
122     /**
123      * subDictionaryType setter.
124      *
125      * @param subDictionaryType the subDictionaryType to set
126      */
127     public void setSubDictionaryType(String subDictionaryType) {
128         this.subDictionaryType = subDictionaryType;
129     }
130
131     /**
132      * dictionaryElements getter.
133      *
134      * @return the dictionaryElements List of dictionary element
135      */
136     public Set<DictionaryElement> getDictionaryElements() {
137         return dictionaryElements;
138     }
139
140     /**
141      * Method to add a new dictionaryElement to the list.
142      *
143      * @param dictionaryElement The dictionary element
144      */
145     public void addDictionaryElements(DictionaryElement dictionaryElement) {
146         dictionaryElements.add(dictionaryElement);
147         dictionaryElement.getUsedByDictionaries().add(this);
148     }
149
150     /**
151      * Method to set dictionaryElements.
152      *
153      * @param dictionaryElements The dictionary elements set
154      */
155     public void setDictionaryElements(Set<DictionaryElement> dictionaryElements) {
156         this.dictionaryElements = dictionaryElements;
157     }
158
159     /**
160      * Method to delete a dictionaryElement from the list.
161      *
162      * @param dictionaryElement The dictionary element
163      */
164     public void removeDictionaryElement(DictionaryElement dictionaryElement) {
165         dictionaryElements.remove(dictionaryElement);
166         dictionaryElement.getUsedByDictionaries().remove(this);
167     }
168
169     /**
170      * Default Constructor.
171      */
172     public Dictionary() {
173
174     }
175
176     /**
177      * Constructor.
178      *
179      * @param name The Dictionary name
180      * @param secondLevelDictionary defines if dictionary is a secondary level
181      * @param subDictionaryType defines the type of secondary level dictionary
182      */
183     public Dictionary(String name, int secondLevelDictionary, String subDictionaryType) {
184         this.name = name;
185         this.secondLevelDictionary = secondLevelDictionary;
186         this.subDictionaryType = subDictionaryType;
187     }
188
189     @Override
190     public int hashCode() {
191         final int prime = 31;
192         int result = 1;
193         result = prime * result + ((name == null) ? 0 : name.hashCode());
194         return result;
195     }
196
197     @Override
198     public boolean equals(Object obj) {
199         if (this == obj) {
200             return true;
201         }
202         if (obj == null) {
203             return false;
204         }
205         if (getClass() != obj.getClass()) {
206             return false;
207         }
208         Dictionary other = (Dictionary) obj;
209         if (name == null) {
210             if (other.name != null) {
211                 return false;
212             }
213         } else if (!name.equals(other.name)) {
214             return false;
215         }
216         return true;
217     }
218
219 }