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 com.fasterxml.jackson.annotation.JsonInclude;
27 import com.fasterxml.jackson.annotation.JsonInclude.Include;
29 import java.util.List;
31 import org.onap.clamp.clds.dao.CldsDao;
34 * Represents a CLDS Dictionary Item.
36 @JsonInclude(Include.NON_NULL)
37 public class CldsDictionaryItem {
39 private String dictElementId;
40 private String dictionaryId;
41 private String dictElementName;
42 private String dictElementShortName;
43 private String dictElementDesc;
44 private String dictElementType;
45 private String createdBy;
46 private String updatedBy;
47 private String lastUpdatedDate;
49 public void save(String dictionaryName, CldsDao cldsDao, String userId) {
50 // Check if dictionary exists.
51 List<CldsDictionary> list = cldsDao.getDictionary(this.getDictionaryId(), dictionaryName);
52 if (list != null && !list.isEmpty()) {
53 // Dictionary found. We can add or update the dictionary element
54 CldsDictionary cldsDictionary = list.stream().findFirst().get();
55 List<CldsDictionaryItem> dictionaryItems = cldsDao.getDictionaryElements(dictionaryName,
56 cldsDictionary.getDictionaryId(), this.getDictElementShortName());
57 if (dictionaryItems != null && !dictionaryItems.isEmpty()) {
58 CldsDictionaryItem item = dictionaryItems.stream().findFirst().get();
59 cldsDao.updateDictionaryElements(item.getDictElementId(), this, userId);
60 this.setCreatedBy(item.getCreatedBy());
63 this.setCreatedBy(userId);
64 this.setUpdatedBy(userId);
65 cldsDao.insDictionarElements(this, userId);
71 * @return the dictElementId
73 public String getDictElementId() {
78 * @param dictElementId
79 * the dictElementId to set
81 public void setDictElementId(String dictElementId) {
82 this.dictElementId = dictElementId;
86 * @return the dictionaryId
88 public String getDictionaryId() {
94 * the dictionaryId to set
96 public void setDictionaryId(String dictionaryId) {
97 this.dictionaryId = dictionaryId;
101 * @return the dictElementName
103 public String getDictElementName() {
104 return dictElementName;
108 * @param dictElementName
109 * the dictElementName to set
111 public void setDictElementName(String dictElementName) {
112 this.dictElementName = dictElementName;
116 * @return the dictElementShortName
118 public String getDictElementShortName() {
119 return dictElementShortName;
123 * @param dictElementShortName
124 * the dictElementShortName to set
126 public void setDictElementShortName(String dictElementShortName) {
127 this.dictElementShortName = dictElementShortName;
131 * @return the dictElementDesc
133 public String getDictElementDesc() {
134 return dictElementDesc;
138 * @param dictElementDesc
139 * the dictElementDesc to set
141 public void setDictElementDesc(String dictElementDesc) {
142 this.dictElementDesc = dictElementDesc;
146 * @return the dictElementType
148 public String getDictElementType() {
149 return dictElementType;
153 * @param dictElementType
154 * the dictElementType to set
156 public void setDictElementType(String dictElementType) {
157 this.dictElementType = dictElementType;
161 * @return the createdBy
163 public String getCreatedBy() {
169 * the createdBy to set
171 public void setCreatedBy(String createdBy) {
172 this.createdBy = createdBy;
176 * @return the updatedBy
178 public String getUpdatedBy() {
184 * the updatedBy to set
186 public void setUpdatedBy(String updatedby) {
187 updatedBy = updatedby;
191 * @return the lastUpdatedDate
193 public String getLastUpdatedDate() {
194 return lastUpdatedDate;
198 * @param lastUpdatedDate
199 * the lastUpdatedDate to set
201 public void setLastUpdatedDate(String lastUpdatedDate) {
202 this.lastUpdatedDate = lastUpdatedDate;