cb051b81035330d20113c3cb1ec3f5a8644d595b
[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     public void save(String dictionaryName, CldsDao cldsDao, String userId) {
46         // Check if dictionary exists.
47         List<CldsDictionary> list = cldsDao.getDictionary(this.getDictionaryId(), dictionaryName);
48         if (list != null && !list.isEmpty()) {
49             // Dictionary found. We can add or update the dictionary element
50             CldsDictionary cldsDictionary = list.stream().findFirst().get();
51             List<CldsDictionaryItem> dictionaryItems = cldsDao.getDictionaryElements(dictionaryName,
52                 cldsDictionary.getDictionaryId(), this.getDictElementShortName());
53             if (dictionaryItems != null && !dictionaryItems.isEmpty()) {
54                 CldsDictionaryItem item = dictionaryItems.stream().findFirst().get();
55                 cldsDao.updateDictionaryElements(item.getDictElementId(), this, userId);
56                 this.setCreatedBy(item.getCreatedBy());
57
58             } else {
59                 this.setCreatedBy(userId);
60                 this.setUpdatedBy(userId);
61                 cldsDao.insDictionarElements(this, userId);
62             }
63         }
64     }
65
66     /**
67      * @return the dictElementId
68      */
69     public String getDictElementId() {
70         return dictElementId;
71     }
72
73     /**
74      * @param dictElementId
75      *        the dictElementId to set
76      */
77     public void setDictElementId(String dictElementId) {
78         this.dictElementId = dictElementId;
79     }
80
81     /**
82      * @return the dictionaryId
83      */
84     public String getDictionaryId() {
85         return dictionaryId;
86     }
87
88     /**
89      * @param dictionaryId
90      *        the dictionaryId to set
91      */
92     public void setDictionaryId(String dictionaryId) {
93         this.dictionaryId = dictionaryId;
94     }
95
96     /**
97      * @return the dictElementName
98      */
99     public String getDictElementName() {
100         return dictElementName;
101     }
102
103     /**
104      * @param dictElementName
105      *        the dictElementName to set
106      */
107     public void setDictElementName(String dictElementName) {
108         this.dictElementName = dictElementName;
109     }
110
111     /**
112      * @return the dictElementShortName
113      */
114     public String getDictElementShortName() {
115         return dictElementShortName;
116     }
117
118     /**
119      * @param dictElementShortName
120      *        the dictElementShortName to set
121      */
122     public void setDictElementShortName(String dictElementShortName) {
123         this.dictElementShortName = dictElementShortName;
124     }
125
126     /**
127      * @return the dictElementDesc
128      */
129     public String getDictElementDesc() {
130         return dictElementDesc;
131     }
132
133     /**
134      * @param dictElementDesc
135      *        the dictElementDesc to set
136      */
137     public void setDictElementDesc(String dictElementDesc) {
138         this.dictElementDesc = dictElementDesc;
139     }
140
141     /**
142      * @return the dictElementType
143      */
144     public String getDictElementType() {
145         return dictElementType;
146     }
147
148     /**
149      * @param dictElementType
150      *        the dictElementType to set
151      */
152     public void setDictElementType(String dictElementType) {
153         this.dictElementType = dictElementType;
154     }
155
156     /**
157      * @return the createdBy
158      */
159     public String getCreatedBy() {
160         return createdBy;
161     }
162
163     /**
164      * @param createdBy
165      *        the createdBy to set
166      */
167     public void setCreatedBy(String createdBy) {
168         this.createdBy = createdBy;
169     }
170
171     /**
172      * @return the updatedBy
173      */
174     public String getUpdatedBy() {
175         return updatedBy;
176     }
177
178     /**
179      * @param updatedby
180      *        the updatedBy to set
181      */
182     public void setUpdatedBy(String updatedby) {
183         updatedBy = updatedby;
184     }
185
186     /**
187      * @return the lastUpdatedDate
188      */
189     public String getLastUpdatedDate() {
190         return lastUpdatedDate;
191     }
192
193     /**
194      * @param lastUpdatedDate
195      *        the lastUpdatedDate to set
196      */
197     public void setLastUpdatedDate(String lastUpdatedDate) {
198         this.lastUpdatedDate = lastUpdatedDate;
199     }
200
201 }