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