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.ArrayList;
27 import java.util.List;
29 import org.onap.clamp.clds.dao.CldsDao;
31 import com.google.gson.annotations.Expose;
34 * Represents a CLDS Dictionary.
37 public class CldsDictionary {
40 private String dictionaryId;
42 private String dictionaryName;
45 private String createdBy;
47 private String updatedBy;
49 private String lastUpdatedDate;
51 private List<CldsDictionaryItem> cldsDictionaryItems = new ArrayList<>();
54 * Creates or updates dictionary item for a dictionary in DB.
56 * @param dictionaryName The dictionary name
57 * @param cldsDao The CldsDao
58 * @param userId The user ID
60 public void save(String dictionaryName, CldsDao cldsDao, String userId) {
61 List<CldsDictionary> list = cldsDao.getDictionary(this.getDictionaryId(), dictionaryName);
62 if (list != null && !list.isEmpty()) {
63 CldsDictionary cldsDictionary = list.stream().findFirst().get();
64 if (!cldsDictionary.getDictionaryName().equalsIgnoreCase(this.getDictionaryName())) {
65 cldsDao.updateDictionary(cldsDictionary.getDictionaryId(), this, userId);
66 this.setCreatedBy(cldsDictionary.getCreatedBy());
68 this.setDictionaryId(cldsDictionary.getDictionaryId());
69 this.setCreatedBy(cldsDictionary.getCreatedBy());
70 this.setUpdatedBy(cldsDictionary.getUpdatedBy());
71 this.setLastUpdatedDate(cldsDictionary.getLastUpdatedDate());
74 this.setCreatedBy(userId);
75 this.setUpdatedBy(userId);
76 cldsDao.insDictionary(this);
81 * Get the dictionary ID.
83 * @return the dictionaryId
85 public String getDictionaryId() {
90 * Set the dictionary Id.
92 * @param dictionaryId the dictionaryId to set
94 public void setDictionaryId(String dictionaryId) {
95 this.dictionaryId = dictionaryId;
99 * Get the dictionary name.
101 * @return the dictionaryName
103 public String getDictionaryName() {
104 return dictionaryName;
108 * Set the dictionary name.
110 * @param dictionaryName the dictionaryName to set
112 public void setDictionaryName(String dictionaryName) {
113 this.dictionaryName = dictionaryName;
117 * Get the createdBy info.
119 * @return the createdBy
121 public String getCreatedBy() {
126 * Set the createdBy info.
128 * @param createdBy the createdBy to set
130 public void setCreatedBy(String createdBy) {
131 this.createdBy = createdBy;
135 * Get the updatedBy info.
137 * @return the updatedBy
139 public String getUpdatedBy() {
144 * Set the updatedBy info.
146 * @param updatedby the updatedBy to set
148 public void setUpdatedBy(String updatedby) {
149 updatedBy = updatedby;
153 * Get the last updated date.
155 * @return the lastUpdatedDate
157 public String getLastUpdatedDate() {
158 return lastUpdatedDate;
162 * Set the last updated date.
164 * @param lastUpdatedDate the lastUpdatedDate to set
166 public void setLastUpdatedDate(String lastUpdatedDate) {
167 this.lastUpdatedDate = lastUpdatedDate;
171 * Get all the dictionary items.
173 * @return the cldsDictionaryItems
175 public List<CldsDictionaryItem> getCldsDictionaryItems() {
176 return cldsDictionaryItems;
180 * Set the whole dictionary items.
182 * @param cldsDictionaryItems the cldsDictionaryItems to set
184 public void setCldsDictionaryItems(List<CldsDictionaryItem> cldsDictionaryItems) {
185 this.cldsDictionaryItems = cldsDictionaryItems;