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