Merge "Removal of dead code"
[clamp.git] / src / main / java / org / onap / clamp / clds / model / CldsEvent.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017-2019 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 org.onap.clamp.clds.dao.CldsDao;
27
28 /**
29  * Represent a CLDS Event.
30  */
31 public class CldsEvent {
32     /**
33      * The constant ACTION_TEST.
34      */
35     public static final String ACTION_TEST = "TEST";
36     /**
37      * The constant ACTION_CREATE.
38      */
39     public static final String ACTION_CREATE = "CREATE";
40     /**
41      * The constant ACTION_MODIFY.
42      */
43     public static final String ACTION_MODIFY = "MODIFY";
44     /**
45      * The constant ACTION_SUBMIT.
46      */
47     public static final String ACTION_SUBMIT = "SUBMIT";
48     /**
49      * The constant ACTION_RESUBMIT.
50      */
51     // an update before model is active
52     public static final String ACTION_RESUBMIT = "RESUBMIT";
53     /**
54      * The constant ACTION_SUBMITDCAE.
55      */
56     // For simplified models
57     public static final String ACTION_SUBMITDCAE = "SUBMITDCAE";
58     /**
59      * The constant ACTION_SUBMITPOLICY.
60      */
61     public static final String ACTION_SUBMITPOLICY = "SUBMITPOLICY";
62     /**
63      * The constant ACTION_DISTRIBUTE.
64      */
65     // only from dcae
66     public static final String ACTION_DISTRIBUTE = "DISTRIBUTE";
67     /**
68      * The constant ACTION_DEPLOY.
69      */
70     // only from dcae
71     public static final String ACTION_DEPLOY = "DEPLOY";
72     /**
73      * The constant ACTION_UNDEPLOY.
74      */
75     // only from dcae
76     public static final String ACTION_UNDEPLOY = "UNDEPLOY";
77     /**
78      * The constant ACTION_UPDATE.
79      */
80     public static final String ACTION_UPDATE = "UPDATE";
81     /**
82      * The constant ACTION_DELETE.
83      */
84     public static final String ACTION_DELETE = "DELETE";
85     /**
86      * The constant ACTION_STOP.
87      */
88     public static final String ACTION_STOP = "STOP";
89     /**
90      * The constant ACTION_RESTART.
91      */
92     public static final String ACTION_RESTART = "RESTART";
93
94     /**
95      * The constant ACTION_STATE_INITIATED.
96      */
97     public static final String ACTION_STATE_INITIATED = "INITIATED";
98     /**
99      * The constant ACTION_STATE_SENT.
100      */
101     public static final String ACTION_STATE_SENT = "SENT";
102     /**
103      * The constant ACTION_STATE_COMPLETED.
104      */
105     public static final String ACTION_STATE_COMPLETED = "COMPLETED";
106     /**
107      * The constant ACTION_STATE_RECEIVED.
108      */
109     public static final String ACTION_STATE_RECEIVED = "RECEIVED";
110     /**
111      * The constant ACTION_STATE_ERROR.
112      */
113     public static final String ACTION_STATE_ERROR = "ERROR";
114     /**
115      * The constant ACTION_STATE_ANY.
116      */
117     public static final String ACTION_STATE_ANY = null;
118
119     private String id;
120     private String actionCd;
121     private String actionStateCd;
122     private String processInstanceId;
123     private String userid;
124
125     /**
126      * Gets id.
127      *
128      * @return the id
129      */
130     public String getId() {
131         return id;
132     }
133
134     /**
135      * Sets id.
136      *
137      * @param id the id
138      */
139     public void setId(String id) {
140         this.id = id;
141     }
142
143     /**
144      * Ins event clds event.
145      *
146      * @param cldsDao           the clds dao
147      * @param controlName       the control name
148      * @param userid            the userid
149      * @param actionCd          the action cd
150      * @param actionStateCd     the action state cd
151      * @param processInstanceId the process instance id
152      * @return clds event
153      */
154     public static CldsEvent insEvent(CldsDao cldsDao, String controlName, String userid, String actionCd,
155         String actionStateCd, String processInstanceId) {
156         CldsModel model = CldsModel.createUsingControlName(controlName);
157         return insEvent(cldsDao, model, userid, actionCd, actionStateCd, processInstanceId);
158     }
159
160     /**
161      * Insert event using controlNameUuid to find the model. This method meant for
162      * processing events from dcae.
163      *
164      * @param cldsDao           the clds dao
165      * @param model             the model
166      * @param userId            the user id
167      * @param actionCd          the action cd
168      * @param actionStateCd     the action state cd
169      * @param processInstanceId the process instance id
170      * @return clds event
171      */
172     public static CldsEvent insEvent(CldsDao cldsDao, CldsModel model, String userId, String actionCd,
173         String actionStateCd, String processInstanceId) {
174         CldsEvent event = new CldsEvent();
175         event.setUserid(userId);
176         event.setActionCd(actionCd);
177         event.setActionStateCd(actionStateCd);
178         event.setProcessInstanceId(processInstanceId);
179         cldsDao.insEvent(null, model.getControlNamePrefix(), model.getControlNameUuid(), event);
180         return event;
181     }
182
183     /**
184      * Check if actionCd is equal to the supplied checkActionCd checkActionCd should
185      * not be null.
186      *
187      * @param checkActionCd the check action cd
188      * @return boolean
189      */
190     public boolean isActionCd(String checkActionCd) {
191         if (actionCd == null) {
192             return false;
193         }
194         return actionCd.equals(checkActionCd);
195     }
196
197     /**
198      * Check if actionCd and actionStateCd are equal to the supplied checkActionCd
199      * and checkActionStateCd. Treat checkActionStateCd == null as a wildcard
200      * checkActionCd should not be null.
201      *
202      * @param checkActionCd      the check action cd
203      * @param checkActionStateCd the check action state cd
204      * @return boolean
205      */
206     public boolean isActionAndStateCd(String checkActionCd, String checkActionStateCd) {
207         if (actionCd == null) {
208             return false;
209         }
210         // treat checkActionStateCd == null as a wildcard (same for
211         // actionStateCd, although it shouln't be null...)
212         if (checkActionStateCd == null || actionStateCd == null) {
213             return actionCd.equals(checkActionCd);
214         }
215         return actionCd.equals(checkActionCd) && actionStateCd.equals(checkActionStateCd);
216     }
217
218     /**
219      * Check if actionStateCd is equal to the supplied checkActionStateCd.
220      * checkActionCd should not be null.
221      *
222      * @param checkActionStateCd the check action state cd
223      * @return boolean
224      */
225     public boolean isActionStateCd(String checkActionStateCd) {
226         return !(checkActionStateCd == null || actionStateCd == null) && actionStateCd.equals(checkActionStateCd);
227     }
228
229     /**
230      * Gets action cd.
231      *
232      * @return the actionCd
233      */
234     public String getActionCd() {
235         return actionCd;
236     }
237
238     /**
239      * Sets action cd.
240      *
241      * @param actionCd the actionCd to set
242      */
243     public void setActionCd(String actionCd) {
244         this.actionCd = actionCd;
245     }
246
247     /**
248      * Gets action state cd.
249      *
250      * @return the actionStateCd
251      */
252     public String getActionStateCd() {
253         return actionStateCd;
254     }
255
256     /**
257      * Sets action state cd.
258      *
259      * @param actionStateCd the actionStateCd to set
260      */
261     public void setActionStateCd(String actionStateCd) {
262         this.actionStateCd = actionStateCd;
263     }
264
265     /**
266      * Gets process instance id.
267      *
268      * @return the processInstanceId
269      */
270     public String getProcessInstanceId() {
271         return processInstanceId;
272     }
273
274     /**
275      * Sets process instance id.
276      *
277      * @param processInstanceId the processInstanceId to set
278      */
279     public void setProcessInstanceId(String processInstanceId) {
280         this.processInstanceId = processInstanceId;
281     }
282
283     /**
284      * Gets userid.
285      *
286      * @return the userid
287      */
288     public String getUserid() {
289         return userid;
290     }
291
292     /**
293      * Sets userid.
294      *
295      * @param userid the userid to set
296      */
297     public void setUserid(String userid) {
298         this.userid = userid;
299     }
300 }