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