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