27a430c7cc6f635548d2545344e4fa945b8bd878
[clamp.git] / src / main / java / org / onap / clamp / clds / model / CldsDictionary.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2018 AT&T Intellectual Property. All rights
6  *                             reserved.
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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  * ===================================================================
21  *
22  */
23
24 package org.onap.clamp.clds.model;
25
26 import java.util.ArrayList;
27 import java.util.List;
28
29 import org.onap.clamp.clds.dao.CldsDao;
30
31 import com.google.gson.annotations.Expose;
32
33 /**
34  * Represents a CLDS Dictionary.
35  */
36
37 public class CldsDictionary {
38
39     @Expose
40     private String dictionaryId;
41     @Expose
42     private String dictionaryName;
43
44     @Expose
45     private String createdBy;
46     @Expose
47     private String updatedBy;
48     @Expose
49     private String lastUpdatedDate;
50     @Expose
51     private List<CldsDictionaryItem> cldsDictionaryItems = new ArrayList<>();
52
53     /**
54      * Creates or updates dictionary item for a dictionary in DB.
55      *
56      * @param dictionaryName The dictionary name
57      * @param cldsDao        The CldsDao
58      * @param userId         The user ID
59      */
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());
67             } else {
68                 this.setDictionaryId(cldsDictionary.getDictionaryId());
69                 this.setCreatedBy(cldsDictionary.getCreatedBy());
70                 this.setUpdatedBy(cldsDictionary.getUpdatedBy());
71                 this.setLastUpdatedDate(cldsDictionary.getLastUpdatedDate());
72             }
73         } else {
74             this.setCreatedBy(userId);
75             this.setUpdatedBy(userId);
76             cldsDao.insDictionary(this);
77         }
78     }
79
80     /**
81      * Get the dictionary ID.
82      * 
83      * @return the dictionaryId
84      */
85     public String getDictionaryId() {
86         return dictionaryId;
87     }
88
89     /**
90      * Set the dictionary Id.
91      * 
92      * @param dictionaryId the dictionaryId to set
93      */
94     public void setDictionaryId(String dictionaryId) {
95         this.dictionaryId = dictionaryId;
96     }
97
98     /**
99      * Get the dictionary name.
100      * 
101      * @return the dictionaryName
102      */
103     public String getDictionaryName() {
104         return dictionaryName;
105     }
106
107     /**
108      * Set the dictionary name.
109      * 
110      * @param dictionaryName the dictionaryName to set
111      */
112     public void setDictionaryName(String dictionaryName) {
113         this.dictionaryName = dictionaryName;
114     }
115
116     /**
117      * Get the createdBy info.
118      * 
119      * @return the createdBy
120      */
121     public String getCreatedBy() {
122         return createdBy;
123     }
124
125     /**
126      * Set the createdBy info.
127      * 
128      * @param createdBy the createdBy to set
129      */
130     public void setCreatedBy(String createdBy) {
131         this.createdBy = createdBy;
132     }
133
134     /**
135      * Get the updatedBy info.
136      * 
137      * @return the updatedBy
138      */
139     public String getUpdatedBy() {
140         return updatedBy;
141     }
142
143     /**
144      * Set the updatedBy info.
145      * 
146      * @param updatedby the updatedBy to set
147      */
148     public void setUpdatedBy(String updatedby) {
149         updatedBy = updatedby;
150     }
151
152     /**
153      * Get the last updated date.
154      * 
155      * @return the lastUpdatedDate
156      */
157     public String getLastUpdatedDate() {
158         return lastUpdatedDate;
159     }
160
161     /**
162      * Set the last updated date.
163      * 
164      * @param lastUpdatedDate the lastUpdatedDate to set
165      */
166     public void setLastUpdatedDate(String lastUpdatedDate) {
167         this.lastUpdatedDate = lastUpdatedDate;
168     }
169
170     /**
171      * Get all the dictionary items.
172      * 
173      * @return the cldsDictionaryItems
174      */
175     public List<CldsDictionaryItem> getCldsDictionaryItems() {
176         return cldsDictionaryItems;
177     }
178
179     /**
180      * Set the whole dictionary items.
181      * 
182      * @param cldsDictionaryItems the cldsDictionaryItems to set
183      */
184     public void setCldsDictionaryItems(List<CldsDictionaryItem> cldsDictionaryItems) {
185         this.cldsDictionaryItems = cldsDictionaryItems;
186     }
187
188 }