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