2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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 * ===================================================================
24 package org.onap.clamp.clds.model;
26 import java.util.List;
28 import org.onap.clamp.clds.dao.CldsDao;
30 import com.google.gson.annotations.Expose;
33 * Represents a CLDS Dictionary Item.
35 public class CldsDictionaryItem {
38 private String dictElementId;
40 private String dictionaryId;
42 private String dictElementName;
44 private String dictElementShortName;
46 private String dictElementDesc;
48 private String dictElementType;
50 private String createdBy;
52 private String updatedBy;
54 private String lastUpdatedDate;
57 * Save the dictionary item.
59 * @param dictionaryName The name of the dictionary
60 * @param cldsDao The cldsDao
61 * @param userId The user id
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());
77 this.setCreatedBy(userId);
78 this.setUpdatedBy(userId);
79 cldsDao.insDictionarElements(this, userId);
85 * Get the dictionary element id.
87 * @return the dictElementId
89 public String getDictElementId() {
94 * Set the dictionary element id.
96 * @param dictElementId the dictElementId to set
98 public void setDictElementId(String dictElementId) {
99 this.dictElementId = dictElementId;
103 * Get the dictionary id.
105 * @return the dictionaryId
107 public String getDictionaryId() {
112 * Set the dictionary id.
114 * @param dictionaryId the dictionaryId to set
116 public void setDictionaryId(String dictionaryId) {
117 this.dictionaryId = dictionaryId;
121 * Get the dictionary name.
123 * @return the dictElementName
125 public String getDictElementName() {
126 return dictElementName;
130 * Set the dictionary name.
132 * @param dictElementName the dictElementName to set
134 public void setDictElementName(String dictElementName) {
135 this.dictElementName = dictElementName;
139 * Get the dictionary element short name.
141 * @return the dictElementShortName
143 public String getDictElementShortName() {
144 return dictElementShortName;
148 * Set the dictionary element short name.
150 * @param dictElementShortName the dictElementShortName to set
152 public void setDictElementShortName(String dictElementShortName) {
153 this.dictElementShortName = dictElementShortName;
157 * Get the dictionary element description.
159 * @return the dictElementDesc
161 public String getDictElementDesc() {
162 return dictElementDesc;
166 * Set the dictionary element description.
168 * @param dictElementDesc the dictElementDesc to set
170 public void setDictElementDesc(String dictElementDesc) {
171 this.dictElementDesc = dictElementDesc;
175 * Get the dictionary element type.
177 * @return the dictElementType
179 public String getDictElementType() {
180 return dictElementType;
184 * Set the dictionary element type.
186 * @param dictElementType the dictElementType to set
188 public void setDictElementType(String dictElementType) {
189 this.dictElementType = dictElementType;
193 * Get the createdBy info.
195 * @return the createdBy
197 public String getCreatedBy() {
202 * Set the createdBy info.
204 * @param createdBy the createdBy to set
206 public void setCreatedBy(String createdBy) {
207 this.createdBy = createdBy;
211 * Get the updatedBy info.
213 * @return the updatedBy
215 public String getUpdatedBy() {
220 * Set the updatedBy info.
222 * @param updatedby the updatedBy to set
224 public void setUpdatedBy(String updatedby) {
225 updatedBy = updatedby;
229 * Get the last updated date.
231 * @return the lastUpdatedDate
233 public String getLastUpdatedDate() {
234 return lastUpdatedDate;
238 * Set the last updated date.
240 * @param lastUpdatedDate the lastUpdatedDate to set
242 public void setLastUpdatedDate(String lastUpdatedDate) {
243 this.lastUpdatedDate = lastUpdatedDate;