e0caf7e38b908917a80f9cf2715c0409e480ca7f
[clamp.git] / src / main / java / org / onap / clamp / clds / model / CldsEvent.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017-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 org.onap.clamp.clds.dao.CldsDao;
27
28 /**
29  * Represent a CLDS Event.
30  */
31 public class CldsEvent {
32     public static final String ACTION_TEST            = "TEST";
33     public static final String ACTION_CREATE          = "CREATE";
34     public static final String ACTION_SUBMIT          = "SUBMIT";
35     // an update before model is active
36     public static final String ACTION_RESUBMIT        = "RESUBMIT";
37     // For simplified models
38     public static final String ACTION_SUBMITDCAE      = "SUBMITDCAE";
39     // only from dcae
40     public static final String ACTION_DISTRIBUTE      = "DISTRIBUTE";
41     // only from dcae
42     public static final String ACTION_DEPLOY          = "DEPLOY";
43     // only from dcae
44     public static final String ACTION_UNDEPLOY        = "UNDEPLOY";
45     public static final String ACTION_UPDATE          = "UPDATE";
46     public static final String ACTION_DELETE          = "DELETE";
47     public static final String ACTION_STOP            = "STOP";
48     public static final String ACTION_RESTART         = "RESTART";
49
50     public static final String ACTION_STATE_INITIATED = "INITIATED";
51     public static final String ACTION_STATE_SENT      = "SENT";
52     public static final String ACTION_STATE_COMPLETED = "COMPLETED";
53     public static final String ACTION_STATE_RECEIVED  = "RECEIVED";
54     public static final String ACTION_STATE_ERROR     = "ERROR";
55     public static final String ACTION_STATE_ANY       = null;
56
57     private String             id;
58     private String             actionCd;
59     private String             actionStateCd;
60     private String             processInstanceId;
61     private String             userid;
62
63     public String getId() {
64         return id;
65     }
66
67     public void setId(String id) {
68         this.id = id;
69     }
70
71     /**
72      * @param cldsDao
73      * @param controlName
74      * @param userid
75      * @param actionCd
76      * @param actionStateCd
77      * @param processInstanceId
78      * @return
79      */
80     public static CldsEvent insEvent(CldsDao cldsDao, String controlName, String userid, String actionCd,
81             String actionStateCd, String processInstanceId) {
82         CldsModel model = CldsModel.createUsingControlName(controlName);
83         return insEvent(cldsDao, model, userid, actionCd, actionStateCd, processInstanceId);
84     }
85
86     /**
87      * Insert event using controlNameUuid to find the model. This method meant
88      * for processing events from dcae.
89      * 
90      * @param cldsDao
91      * @param model
92      * @param userId
93      * @param actionCd
94      * @param actionStateCd
95      * @param processInstanceId
96      * @return
97      */
98     public static CldsEvent insEvent(CldsDao cldsDao, CldsModel model, String userId, String actionCd,
99             String actionStateCd, String processInstanceId) {
100         CldsEvent event = new CldsEvent();
101         event.setUserid(userId);
102         event.setActionCd(actionCd);
103         event.setActionStateCd(actionStateCd);
104         event.setProcessInstanceId(processInstanceId);
105         cldsDao.insEvent(null, model.getControlNamePrefix(), model.getControlNameUuid(), event);
106         return event;
107     }
108
109     /**
110      * Check if actionCd is equal to the supplied checkActionCd checkActionCd
111      * should not be null.
112      * 
113      * @param checkActionCd
114      * @return
115      */
116     public boolean isActionCd(String checkActionCd) {
117         if (actionCd == null) {
118             return false;
119         }
120         return actionCd.equals(checkActionCd);
121     }
122
123     /**
124      * Check if actionCd and actionStateCd are equal to the supplied
125      * checkActionCd and checkActionStateCd. Treat checkActionStateCd == null as
126      * a wildcard checkActionCd should not be null.
127      *
128      * @param checkActionCd
129      * @param checkActionStateCd
130      * @return
131      */
132     public boolean isActionAndStateCd(String checkActionCd, String checkActionStateCd) {
133         if (actionCd == null) {
134             return false;
135         }
136         // treat checkActionStateCd == null as a wildcard (same for
137         // actionStateCd, although it shouln't be null...)
138         if (checkActionStateCd == null || actionStateCd == null) {
139             return actionCd.equals(checkActionCd);
140         }
141         return actionCd.equals(checkActionCd) && actionStateCd.equals(checkActionStateCd);
142     }
143
144     /**
145      * Check if actionStateCd is equal to the supplied checkActionStateCd.
146      * checkActionCd should not be null.
147      *
148      * @param checkActionStateCd
149      * @return
150      */
151     public boolean isActionStateCd(String checkActionStateCd) {
152         return !(checkActionStateCd == null || actionStateCd == null) && actionStateCd.equals(checkActionStateCd);
153     }
154
155     /**
156      * @return the actionCd
157      */
158     public String getActionCd() {
159         return actionCd;
160     }
161
162     /**
163      * @param actionCd
164      *            the actionCd to set
165      */
166     public void setActionCd(String actionCd) {
167         this.actionCd = actionCd;
168     }
169
170     /**
171      * @return the actionStateCd
172      */
173     public String getActionStateCd() {
174         return actionStateCd;
175     }
176
177     /**
178      * @param actionStateCd
179      *            the actionStateCd to set
180      */
181     public void setActionStateCd(String actionStateCd) {
182         this.actionStateCd = actionStateCd;
183     }
184
185     /**
186      * @return the processInstanceId
187      */
188     public String getProcessInstanceId() {
189         return processInstanceId;
190     }
191
192     /**
193      * @param processInstanceId
194      *            the processInstanceId to set
195      */
196     public void setProcessInstanceId(String processInstanceId) {
197         this.processInstanceId = processInstanceId;
198     }
199
200     /**
201      * @return the userid
202      */
203     public String getUserid() {
204         return userid;
205     }
206
207     /**
208      * @param userid
209      *            the userid to set
210      */
211     public void setUserid(String userid) {
212         this.userid = userid;
213     }
214 }