Changes include Metadata support, Upload tosca policy model and Loop Template
[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(
69         fetch = FetchType.EAGER,
70         cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
71     @JoinTable(
72         name = "dictionary_to_dictionaryelements",
73         joinColumns = @JoinColumn(name = "dictionary_name", referencedColumnName = "name"),
74         inverseJoinColumns = {@JoinColumn(
75             name = "dictionary_element_short_name",
76             referencedColumnName = "short_name")})
77     private Set<DictionaryElement> dictionaryElements = new HashSet<>();
78
79     /**
80      * name getter.
81      *
82      * @return the name
83      */
84     public String getName() {
85         return name;
86     }
87
88     /**
89      * name setter.
90      *
91      * @param name the name to set
92      */
93     public void setName(String name) {
94         this.name = name;
95     }
96
97     /**
98      * secondLevelDictionary getter.
99      *
100      * @return the secondLevelDictionary
101      */
102     public int getSecondLevelDictionary() {
103         return secondLevelDictionary;
104     }
105
106     /**
107      * secondLevelDictionary setter.
108      *
109      * @param secondLevelDictionary the secondLevelDictionary to set
110      */
111     public void setSecondLevelDictionary(int secondLevelDictionary) {
112         this.secondLevelDictionary = secondLevelDictionary;
113     }
114
115     /**
116      * subDictionaryType getter.
117      *
118      * @return the subDictionaryType
119      */
120     public String getSubDictionaryType() {
121         return subDictionaryType;
122     }
123
124     /**
125      * subDictionaryType setter.
126      *
127      * @param subDictionaryType the subDictionaryType to set
128      */
129     public void setSubDictionaryType(String subDictionaryType) {
130         this.subDictionaryType = subDictionaryType;
131     }
132
133     /**
134      * dictionaryElements getter.
135      *
136      * @return the dictionaryElements List of dictionary element
137      */
138     public Set<DictionaryElement> getDictionaryElements() {
139         return dictionaryElements;
140     }
141
142     /**
143      * Method to add a new dictionaryElement to the list.
144      *
145      * @param dictionaryElement The dictionary element
146      */
147     public void addDictionaryElements(DictionaryElement dictionaryElement) {
148         dictionaryElements.add(dictionaryElement);
149         dictionaryElement.getUsedByDictionaries().add(this);
150     }
151
152     /**
153      * Method to delete a dictionaryElement from the list.
154      *
155      * @param dictionaryElement The dictionary element
156      */
157     public void removeDictionaryElement(DictionaryElement dictionaryElement) {
158         dictionaryElements.remove(dictionaryElement);
159         dictionaryElement.getUsedByDictionaries().remove(this);
160     }
161
162     /**
163      * Default Constructor.
164      */
165     public Dictionary() {
166
167     }
168
169     /**
170      * Constructor.
171      *
172      * @param name The Dictionary name
173      * @param secondLevelDictionary defines if dictionary is a secondary level
174      * @param subDictionaryType defines the type of secondary level dictionary
175      */
176     public Dictionary(String name, int secondLevelDictionary, String subDictionaryType) {
177         this.name = name;
178         this.secondLevelDictionary = secondLevelDictionary;
179         this.subDictionaryType = subDictionaryType;
180     }
181
182     @Override
183     public int hashCode() {
184         final int prime = 31;
185         int result = 1;
186         result = prime * result + ((name == null) ? 0 : name.hashCode());
187         return result;
188     }
189
190     @Override
191     public boolean equals(Object obj) {
192         if (this == obj) {
193             return true;
194         }
195         if (obj == null) {
196             return false;
197         }
198         if (getClass() != obj.getClass()) {
199             return false;
200         }
201         Dictionary other = (Dictionary) obj;
202         if (name == null) {
203             if (other.name != null) {
204                 return false;
205             }
206         } else if (!name.equals(other.name)) {
207             return false;
208         }
209         return true;
210     }
211
212 }