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;
32 * Represents a CLDS Dictionary.
35 public class CldsDictionary {
37 private String dictionaryId;
38 private String dictionaryName;
39 private String createdBy;
40 private String updatedBy;
41 private String lastUpdatedDate;
42 private List<CldsDictionaryItem> cldsDictionaryItems = new ArrayList<>();
45 * Creates or updates dictionary item for a dictionary in DB.
47 * @param dictionaryName The dictionary name
48 * @param cldsDao The CldsDao
49 * @param userId The user ID
51 public void save(String dictionaryName, CldsDao cldsDao, String userId) {
52 List<CldsDictionary> list = cldsDao.getDictionary(this.getDictionaryId(), dictionaryName);
53 if (list != null && !list.isEmpty()) {
54 CldsDictionary cldsDictionary = list.stream().findFirst().get();
55 if (!cldsDictionary.getDictionaryName().equalsIgnoreCase(this.getDictionaryName())) {
56 cldsDao.updateDictionary(cldsDictionary.getDictionaryId(), this, userId);
57 this.setCreatedBy(cldsDictionary.getCreatedBy());
59 this.setDictionaryId(cldsDictionary.getDictionaryId());
60 this.setCreatedBy(cldsDictionary.getCreatedBy());
61 this.setUpdatedBy(cldsDictionary.getUpdatedBy());
62 this.setLastUpdatedDate(cldsDictionary.getLastUpdatedDate());
65 this.setCreatedBy(userId);
66 this.setUpdatedBy(userId);
67 cldsDao.insDictionary(this);
72 * Get the dictionary ID.
73 * @return the dictionaryId
75 public String getDictionaryId() {
80 * Set the dictionary Id.
82 * the dictionaryId to set
84 public void setDictionaryId(String dictionaryId) {
85 this.dictionaryId = dictionaryId;
89 * Get the dictionary name.
90 * @return the dictionaryName
92 public String getDictionaryName() {
93 return dictionaryName;
97 * Set the dictionary name.
98 * @param dictionaryName
99 * the dictionaryName to set
101 public void setDictionaryName(String dictionaryName) {
102 this.dictionaryName = dictionaryName;
106 * Get the createdBy info.
107 * @return the createdBy
109 public String getCreatedBy() {
114 * Set the createdBy info.
116 * the createdBy to set
118 public void setCreatedBy(String createdBy) {
119 this.createdBy = createdBy;
123 * Get the updatedBy info.
124 * @return the updatedBy
126 public String getUpdatedBy() {
131 * Set the updatedBy info.
133 * the updatedBy to set
135 public void setUpdatedBy(String updatedby) {
136 updatedBy = updatedby;
140 * Get the last updated date.
141 * @return the lastUpdatedDate
143 public String getLastUpdatedDate() {
144 return lastUpdatedDate;
148 * Set the last updated date.
149 * @param lastUpdatedDate
150 * the lastUpdatedDate to set
152 public void setLastUpdatedDate(String lastUpdatedDate) {
153 this.lastUpdatedDate = lastUpdatedDate;
157 * Get all the dictionary items.
158 * @return the cldsDictionaryItems
160 public List<CldsDictionaryItem> getCldsDictionaryItems() {
161 return cldsDictionaryItems;
165 * Set the whole dictionary items.
166 * @param cldsDictionaryItems
167 * the cldsDictionaryItems to set
169 public void setCldsDictionaryItems(List<CldsDictionaryItem> cldsDictionaryItems) {
170 this.cldsDictionaryItems = cldsDictionaryItems;