Remove checkstyle issues
[clamp.git] / src / main / java / org / onap / clamp / clds / model / CldsDictionaryItem.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2018 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.clds.model;
25
26 import com.google.gson.annotations.Expose;
27
28 import java.util.List;
29
30 import org.onap.clamp.clds.dao.CldsDao;
31
32 /**
33  * Represents a CLDS Dictionary Item.
34  */
35 public class CldsDictionaryItem {
36
37     @Expose
38     private String dictElementId;
39     @Expose
40     private String dictionaryId;
41     @Expose
42     private String dictElementName;
43     @Expose
44     private String dictElementShortName;
45     @Expose
46     private String dictElementDesc;
47     @Expose
48     private String dictElementType;
49     @Expose
50     private String createdBy;
51     @Expose
52     private String updatedBy;
53     @Expose
54     private String lastUpdatedDate;
55
56     /**
57      * Save the dictionary item.
58      *
59      * @param dictionaryName The name of the dictionary
60      * @param cldsDao        The cldsDao
61      * @param userId         The user id
62      */
63     public void save(String dictionaryName, CldsDao cldsDao, String userId) {
64         // Check if dictionary exists.
65         List<CldsDictionary> list = cldsDao.getDictionary(this.getDictionaryId(), dictionaryName);
66         if (list != null && !list.isEmpty()) {
67             // Dictionary found. We can add or update the dictionary element
68             CldsDictionary cldsDictionary = list.stream().findFirst().get();
69             List<CldsDictionaryItem> dictionaryItems = cldsDao.getDictionaryElements(dictionaryName,
70                     cldsDictionary.getDictionaryId(), this.getDictElementShortName());
71             if (dictionaryItems != null && !dictionaryItems.isEmpty()) {
72                 CldsDictionaryItem item = dictionaryItems.stream().findFirst().get();
73                 cldsDao.updateDictionaryElements(item.getDictElementId(), this, userId);
74                 this.setCreatedBy(item.getCreatedBy());
75
76             } else {
77                 this.setCreatedBy(userId);
78                 this.setUpdatedBy(userId);
79                 cldsDao.insDictionarElements(this, userId);
80             }
81         }
82     }
83
84     /**
85      * Get the dictionary element id.
86      *
87      * @return the dictElementId
88      */
89     public String getDictElementId() {
90         return dictElementId;
91     }
92
93     /**
94      * Set the dictionary element id.
95      *
96      * @param dictElementId the dictElementId to set
97      */
98     public void setDictElementId(String dictElementId) {
99         this.dictElementId = dictElementId;
100     }
101
102     /**
103      * Get the dictionary id.
104      *
105      * @return the dictionaryId
106      */
107     public String getDictionaryId() {
108         return dictionaryId;
109     }
110
111     /**
112      * Set the dictionary id.
113      *
114      * @param dictionaryId the dictionaryId to set
115      */
116     public void setDictionaryId(String dictionaryId) {
117         this.dictionaryId = dictionaryId;
118     }
119
120     /**
121      * Get the dictionary name.
122      *
123      * @return the dictElementName
124      */
125     public String getDictElementName() {
126         return dictElementName;
127     }
128
129     /**
130      * Set the dictionary name.
131      *
132      * @param dictElementName the dictElementName to set
133      */
134     public void setDictElementName(String dictElementName) {
135         this.dictElementName = dictElementName;
136     }
137
138     /**
139      * Get the dictionary element short name.
140      *
141      * @return the dictElementShortName
142      */
143     public String getDictElementShortName() {
144         return dictElementShortName;
145     }
146
147     /**
148      * Set the dictionary element short name.
149      *
150      * @param dictElementShortName the dictElementShortName to set
151      */
152     public void setDictElementShortName(String dictElementShortName) {
153         this.dictElementShortName = dictElementShortName;
154     }
155
156     /**
157      * Get the dictionary element description.
158      *
159      * @return the dictElementDesc
160      */
161     public String getDictElementDesc() {
162         return dictElementDesc;
163     }
164
165     /**
166      * Set the dictionary element description.
167      *
168      * @param dictElementDesc the dictElementDesc to set
169      */
170     public void setDictElementDesc(String dictElementDesc) {
171         this.dictElementDesc = dictElementDesc;
172     }
173
174     /**
175      * Get the dictionary element type.
176      *
177      * @return the dictElementType
178      */
179     public String getDictElementType() {
180         return dictElementType;
181     }
182
183     /**
184      * Set the dictionary element type.
185      *
186      * @param dictElementType the dictElementType to set
187      */
188     public void setDictElementType(String dictElementType) {
189         this.dictElementType = dictElementType;
190     }
191
192     /**
193      * Get the createdBy info.
194      *
195      * @return the createdBy
196      */
197     public String getCreatedBy() {
198         return createdBy;
199     }
200
201     /**
202      * Set the createdBy info.
203      *
204      * @param createdBy the createdBy to set
205      */
206     public void setCreatedBy(String createdBy) {
207         this.createdBy = createdBy;
208     }
209
210     /**
211      * Get the updatedBy info.
212      *
213      * @return the updatedBy
214      */
215     public String getUpdatedBy() {
216         return updatedBy;
217     }
218
219     /**
220      * Set the updatedBy info.
221      *
222      * @param updatedby the updatedBy to set
223      */
224     public void setUpdatedBy(String updatedby) {
225         updatedBy = updatedby;
226     }
227
228     /**
229      * Get the last updated date.
230      *
231      * @return the lastUpdatedDate
232      */
233     public String getLastUpdatedDate() {
234         return lastUpdatedDate;
235     }
236
237     /**
238      * Set the last updated date.
239      *
240      * @param lastUpdatedDate the lastUpdatedDate to set
241      */
242     public void setLastUpdatedDate(String lastUpdatedDate) {
243         this.lastUpdatedDate = lastUpdatedDate;
244     }
245
246 }