Introduce tosca saving
[clamp.git] / src / main / java / org / onap / clamp / clds / model / CldsDictionaryItem.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 com.fasterxml.jackson.annotation.JsonInclude;
27 import com.fasterxml.jackson.annotation.JsonInclude.Include;
28
29 import java.util.List;
30
31 import org.onap.clamp.clds.dao.CldsDao;
32
33 /**
34  * Represents a CLDS Dictionary Item.
35  */
36 @JsonInclude(Include.NON_NULL)
37 public class CldsDictionaryItem {
38
39     private String dictElementId;
40     private String dictionaryId;
41     private String dictElementName;
42     private String dictElementShortName;
43     private String dictElementDesc;
44     private String dictElementType;
45     private String createdBy;
46     private String updatedBy;
47     private String lastUpdatedDate;
48
49     public void save(String dictionaryName, CldsDao cldsDao, String userId) {
50         // Check if dictionary exists.
51         List<CldsDictionary> list = cldsDao.getDictionary(this.getDictionaryId(), dictionaryName);
52         if (list != null && !list.isEmpty()) {
53             // Dictionary found. We can add or update the dictionary element
54             CldsDictionary cldsDictionary = list.stream().findFirst().get();
55             List<CldsDictionaryItem> dictionaryItems = cldsDao.getDictionaryElements(dictionaryName,
56                 cldsDictionary.getDictionaryId(), this.getDictElementShortName());
57             if (dictionaryItems != null && !dictionaryItems.isEmpty()) {
58                 CldsDictionaryItem item = dictionaryItems.stream().findFirst().get();
59                 cldsDao.updateDictionaryElements(item.getDictElementId(), this, userId);
60                 this.setCreatedBy(item.getCreatedBy());
61
62             } else {
63                 this.setCreatedBy(userId);
64                 this.setUpdatedBy(userId);
65                 cldsDao.insDictionarElements(this, userId);
66             }
67         }
68     }
69
70     /**
71      * @return the dictElementId
72      */
73     public String getDictElementId() {
74         return dictElementId;
75     }
76
77     /**
78      * @param dictElementId
79      *        the dictElementId to set
80      */
81     public void setDictElementId(String dictElementId) {
82         this.dictElementId = dictElementId;
83     }
84
85     /**
86      * @return the dictionaryId
87      */
88     public String getDictionaryId() {
89         return dictionaryId;
90     }
91
92     /**
93      * @param dictionaryId
94      *        the dictionaryId to set
95      */
96     public void setDictionaryId(String dictionaryId) {
97         this.dictionaryId = dictionaryId;
98     }
99
100     /**
101      * @return the dictElementName
102      */
103     public String getDictElementName() {
104         return dictElementName;
105     }
106
107     /**
108      * @param dictElementName
109      *        the dictElementName to set
110      */
111     public void setDictElementName(String dictElementName) {
112         this.dictElementName = dictElementName;
113     }
114
115     /**
116      * @return the dictElementShortName
117      */
118     public String getDictElementShortName() {
119         return dictElementShortName;
120     }
121
122     /**
123      * @param dictElementShortName
124      *        the dictElementShortName to set
125      */
126     public void setDictElementShortName(String dictElementShortName) {
127         this.dictElementShortName = dictElementShortName;
128     }
129
130     /**
131      * @return the dictElementDesc
132      */
133     public String getDictElementDesc() {
134         return dictElementDesc;
135     }
136
137     /**
138      * @param dictElementDesc
139      *        the dictElementDesc to set
140      */
141     public void setDictElementDesc(String dictElementDesc) {
142         this.dictElementDesc = dictElementDesc;
143     }
144
145     /**
146      * @return the dictElementType
147      */
148     public String getDictElementType() {
149         return dictElementType;
150     }
151
152     /**
153      * @param dictElementType
154      *        the dictElementType to set
155      */
156     public void setDictElementType(String dictElementType) {
157         this.dictElementType = dictElementType;
158     }
159
160     /**
161      * @return the createdBy
162      */
163     public String getCreatedBy() {
164         return createdBy;
165     }
166
167     /**
168      * @param createdBy
169      *        the createdBy to set
170      */
171     public void setCreatedBy(String createdBy) {
172         this.createdBy = createdBy;
173     }
174
175     /**
176      * @return the updatedBy
177      */
178     public String getUpdatedBy() {
179         return updatedBy;
180     }
181
182     /**
183      * @param updatedby
184      *        the updatedBy to set
185      */
186     public void setUpdatedBy(String updatedby) {
187         updatedBy = updatedby;
188     }
189
190     /**
191      * @return the lastUpdatedDate
192      */
193     public String getLastUpdatedDate() {
194         return lastUpdatedDate;
195     }
196
197     /**
198      * @param lastUpdatedDate
199      *        the lastUpdatedDate to set
200      */
201     public void setLastUpdatedDate(String lastUpdatedDate) {
202         this.lastUpdatedDate = lastUpdatedDate;
203     }
204
205 }