73f959008b6621297c7e8821a2d842d312cece01
[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
48      * @param cldsDao
49      * @param userId
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      * @return the dictionaryId
73      */
74     public String getDictionaryId() {
75         return dictionaryId;
76     }
77
78     /**
79      * @param dictionaryId
80      *        the dictionaryId to set
81      */
82     public void setDictionaryId(String dictionaryId) {
83         this.dictionaryId = dictionaryId;
84     }
85
86     /**
87      * @return the dictionaryName
88      */
89     public String getDictionaryName() {
90         return dictionaryName;
91     }
92
93     /**
94      * @param dictionaryName
95      *        the dictionaryName to set
96      */
97     public void setDictionaryName(String dictionaryName) {
98         this.dictionaryName = dictionaryName;
99     }
100
101     /**
102      * @return the createdBy
103      */
104     public String getCreatedBy() {
105         return createdBy;
106     }
107
108     /**
109      * @param createdBy
110      *        the createdBy to set
111      */
112     public void setCreatedBy(String createdBy) {
113         this.createdBy = createdBy;
114     }
115
116     /**
117      * @return the updatedBy
118      */
119     public String getUpdatedBy() {
120         return updatedBy;
121     }
122
123     /**
124      * @param updatedby
125      *        the updatedBy to set
126      */
127     public void setUpdatedBy(String updatedby) {
128         updatedBy = updatedby;
129     }
130
131     /**
132      * @return the lastUpdatedDate
133      */
134     public String getLastUpdatedDate() {
135         return lastUpdatedDate;
136     }
137
138     /**
139      * @param lastUpdatedDate
140      *        the lastUpdatedDate to set
141      */
142     public void setLastUpdatedDate(String lastUpdatedDate) {
143         this.lastUpdatedDate = lastUpdatedDate;
144     }
145
146     /**
147      * @return the cldsDictionaryItems
148      */
149     public List<CldsDictionaryItem> getCldsDictionaryItems() {
150         return cldsDictionaryItems;
151     }
152
153     /**
154      * @param cldsDictionaryItems
155      *        the cldsDictionaryItems to set
156      */
157     public void setCldsDictionaryItems(List<CldsDictionaryItem> cldsDictionaryItems) {
158         this.cldsDictionaryItems = cldsDictionaryItems;
159     }
160
161 }