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.ArrayList;
30 import java.util.List;
32 import org.onap.clamp.clds.dao.CldsDao;
35 * Represents a CLDS Dictionary.
37 @JsonInclude(Include.NON_NULL)
38 public class CldsDictionary {
40 private String dictionaryId;
41 private String dictionaryName;
42 private String createdBy;
43 private String updatedBy;
44 private String lastUpdatedDate;
45 private List<CldsDictionaryItem> cldsDictionaryItems = new ArrayList<>();
48 * Creates or updates dictionary item for a dictionary in DB
50 * @param dictionaryName
54 public void save(String dictionaryName, CldsDao cldsDao, String userId) {
55 List<CldsDictionary> list = cldsDao.getDictionary(this.getDictionaryId(), dictionaryName);
56 if (list != null && !list.isEmpty()) {
57 CldsDictionary cldsDictionary = list.stream().findFirst().get();
58 if (!cldsDictionary.getDictionaryName().equalsIgnoreCase(this.getDictionaryName())) {
59 cldsDao.updateDictionary(cldsDictionary.getDictionaryId(), this, userId);
60 this.setCreatedBy(cldsDictionary.getCreatedBy());
62 this.setDictionaryId(cldsDictionary.getDictionaryId());
63 this.setCreatedBy(cldsDictionary.getCreatedBy());
64 this.setUpdatedBy(cldsDictionary.getUpdatedBy());
65 this.setLastUpdatedDate(cldsDictionary.getLastUpdatedDate());
68 this.setCreatedBy(userId);
69 this.setUpdatedBy(userId);
70 cldsDao.insDictionary(this);
75 * @return the dictionaryId
77 public String getDictionaryId() {
83 * the dictionaryId to set
85 public void setDictionaryId(String dictionaryId) {
86 this.dictionaryId = dictionaryId;
90 * @return the dictionaryName
92 public String getDictionaryName() {
93 return dictionaryName;
97 * @param dictionaryName
98 * the dictionaryName to set
100 public void setDictionaryName(String dictionaryName) {
101 this.dictionaryName = dictionaryName;
105 * @return the createdBy
107 public String getCreatedBy() {
113 * the createdBy to set
115 public void setCreatedBy(String createdBy) {
116 this.createdBy = createdBy;
120 * @return the updatedBy
122 public String getUpdatedBy() {
128 * the updatedBy to set
130 public void setUpdatedBy(String updatedby) {
131 updatedBy = updatedby;
135 * @return the lastUpdatedDate
137 public String getLastUpdatedDate() {
138 return lastUpdatedDate;
142 * @param lastUpdatedDate
143 * the lastUpdatedDate to set
145 public void setLastUpdatedDate(String lastUpdatedDate) {
146 this.lastUpdatedDate = lastUpdatedDate;
150 * @return the cldsDictionaryItems
152 public List<CldsDictionaryItem> getCldsDictionaryItems() {
153 return cldsDictionaryItems;
157 * @param cldsDictionaryItems
158 * the cldsDictionaryItems to set
160 public void setCldsDictionaryItems(List<CldsDictionaryItem> cldsDictionaryItems) {
161 this.cldsDictionaryItems = cldsDictionaryItems;