Fix check style issues
[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 /**
32  * Represents a CLDS Dictionary.
33  */
34
35 public class CldsDictionary {
36
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<>();
43
44     /**
45      * Creates or updates dictionary item for a dictionary in DB.
46      *
47      * @param dictionaryName The dictionary name
48      * @param cldsDao The CldsDao
49      * @param userId The user ID
50      */
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());
58             } else {
59                 this.setDictionaryId(cldsDictionary.getDictionaryId());
60                 this.setCreatedBy(cldsDictionary.getCreatedBy());
61                 this.setUpdatedBy(cldsDictionary.getUpdatedBy());
62                 this.setLastUpdatedDate(cldsDictionary.getLastUpdatedDate());
63             }
64         } else {
65             this.setCreatedBy(userId);
66             this.setUpdatedBy(userId);
67             cldsDao.insDictionary(this);
68         }
69     }
70
71     /**
72      * Get the dictionary ID.
73      * @return the dictionaryId
74      */
75     public String getDictionaryId() {
76         return dictionaryId;
77     }
78
79     /**
80      * Set the dictionary Id.
81      * @param dictionaryId
82      *        the dictionaryId to set
83      */
84     public void setDictionaryId(String dictionaryId) {
85         this.dictionaryId = dictionaryId;
86     }
87
88     /**
89      * Get the dictionary name.
90      * @return the dictionaryName
91      */
92     public String getDictionaryName() {
93         return dictionaryName;
94     }
95
96     /**
97      * Set the dictionary name.
98      * @param dictionaryName
99      *        the dictionaryName to set
100      */
101     public void setDictionaryName(String dictionaryName) {
102         this.dictionaryName = dictionaryName;
103     }
104
105     /**
106      * Get the createdBy info.
107      * @return the createdBy
108      */
109     public String getCreatedBy() {
110         return createdBy;
111     }
112
113     /**
114      * Set the createdBy info.
115      * @param createdBy
116      *        the createdBy to set
117      */
118     public void setCreatedBy(String createdBy) {
119         this.createdBy = createdBy;
120     }
121
122     /**
123      * Get the updatedBy info.
124      * @return the updatedBy
125      */
126     public String getUpdatedBy() {
127         return updatedBy;
128     }
129
130     /**
131      * Set the updatedBy info.
132      * @param updatedby
133      *        the updatedBy to set
134      */
135     public void setUpdatedBy(String updatedby) {
136         updatedBy = updatedby;
137     }
138
139     /**
140      * Get the last updated date.
141      * @return the lastUpdatedDate
142      */
143     public String getLastUpdatedDate() {
144         return lastUpdatedDate;
145     }
146
147     /**
148      * Set the last updated date.
149      * @param lastUpdatedDate
150      *        the lastUpdatedDate to set
151      */
152     public void setLastUpdatedDate(String lastUpdatedDate) {
153         this.lastUpdatedDate = lastUpdatedDate;
154     }
155
156     /**
157      * Get all the dictionary items.
158      * @return the cldsDictionaryItems
159      */
160     public List<CldsDictionaryItem> getCldsDictionaryItems() {
161         return cldsDictionaryItems;
162     }
163
164     /**
165      * Set the whole dictionary items.
166      * @param cldsDictionaryItems
167      *        the cldsDictionaryItems to set
168      */
169     public void setCldsDictionaryItems(List<CldsDictionaryItem> cldsDictionaryItems) {
170         this.cldsDictionaryItems = cldsDictionaryItems;
171     }
172
173 }