aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/clamp/clds/model/CldsEvent.java
blob: 8379e5024b6d2b877d2dc23e856409cef8cc543e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*-
 * ============LICENSE_START=======================================================
 * ONAP CLAMP
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights
 *                             reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 * ============LICENSE_END============================================
 * ===================================================================
 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
 */

package org.onap.clamp.clds.model;

import org.onap.clamp.clds.dao.CldsDao;

/**
 * Represent a CLDS Event.
 */
public class CldsEvent {
    public static final String ACTION_CREATE = "CREATE";
    public static final String ACTION_SUBMIT = "SUBMIT";
    public static final String ACTION_RESUBMIT = "RESUBMIT"; // an update before model is active
    public static final String ACTION_DISTRIBUTE = "DISTRIBUTE"; // only from dcae
    public static final String ACTION_DEPLOY = "DEPLOY"; // only from dcae
    public static final String ACTION_UNDEPLOY = "UNDEPLOY"; // only from dcae
    public static final String ACTION_UPDATE = "UPDATE";
    public static final String ACTION_DELETE = "DELETE";
    public static final String ACTION_STOP = "STOP";
    public static final String ACTION_RESTART = "RESTART";

    public static final String ACTION_STATE_INITIATED = "INITIATED";
    public static final String ACTION_STATE_SENT = "SENT";
    public static final String ACTION_STATE_COMPLETED = "COMPLETED";
    public static final String ACTION_STATE_RECEIVED = "RECEIVED";
    public static final String ACTION_STATE_ERROR = "ERROR";
    public static final String ACTION_STATE_ANY = null;

    private String id;
    private String actionCd;
    private String actionStateCd;
    private String processInstanceId;
    private String userid;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    /**
     * @param cldsDao
     * @param controlName
     * @param userid
     * @param actionCd
     * @param actionStateCd
     * @param processInstanceId
     * @return
     */
    public static CldsEvent insEvent(CldsDao cldsDao, String controlName, String userid, String actionCd, String actionStateCd, String processInstanceId) {
        CldsModel model = CldsModel.createUsingControlName(controlName);
        return insEvent(cldsDao, model, actionCd, actionStateCd, processInstanceId);
    }

    /**
     * Insert event using controlNameUuid to find the model.
     * This method meant for processing events from dcae.
     * @param cldsDao
     * @param model
     * @param actionCd
     * @param actionStateCd
     * @param processInstanceId
     * @return
     */
    public static CldsEvent insEvent(CldsDao cldsDao, CldsModel model, String actionCd, String actionStateCd, String processInstanceId) {
        CldsEvent event = new CldsEvent();
        event.setActionCd(actionCd);
        event.setActionStateCd(actionStateCd);
        event.setProcessInstanceId(processInstanceId);
        cldsDao.insEvent(null, model.getControlNamePrefix(), model.getControlNameUuid(), event);
        return event;
    }

    /**
     * Check if actionCd  and actionStateCd are equal to the supplied checkActionCd and checkActionStateCd.
     * Treat checkActionStateCd == null as a wildcard
     * checkActionCd should not be null.
     *
     * @param checkActionCd
     * @param checkActionStateCd
     * @return
     */
    public boolean isActionAndStateCd(String checkActionCd, String checkActionStateCd) {
        if (actionCd == null) {
            return false;
        }
        // treat checkActionStateCd == null as a wildcard (same for actionStateCd, although it shouln't be null...)
        if (checkActionStateCd == null || actionStateCd == null) {
            return actionCd.equals(checkActionCd);
        }
        return actionCd.equals(checkActionCd) && actionStateCd.equals(checkActionStateCd);
    }

    /**
     * Check if actionStateCd is equal to the supplied checkActionStateCd.
     * checkActionCd should not be null.
     *
     * @param checkActionStateCd
     * @return
     */
    public boolean isActionStateCd(String checkActionStateCd) {
        return !(checkActionStateCd == null || actionStateCd == null) && actionStateCd.equals(checkActionStateCd);
    }

    /**
     * @return the actionCd
     */
    public String getActionCd() {
        return actionCd;
    }

    /**
     * @param actionCd the actionCd to set
     */
    public void setActionCd(String actionCd) {
        this.actionCd = actionCd;
    }

    /**
     * @return the actionStateCd
     */
    public String getActionStateCd() {
        return actionStateCd;
    }

    /**
     * @param actionStateCd the actionStateCd to set
     */
    public void setActionStateCd(String actionStateCd) {
        this.actionStateCd = actionStateCd;
    }

    /**
     * @return the processInstanceId
     */
    public String getProcessInstanceId() {
        return processInstanceId;
    }

    /**
     * @param processInstanceId the processInstanceId to set
     */
    public void setProcessInstanceId(String processInstanceId) {
        this.processInstanceId = processInstanceId;
    }

    /**
     * @return the userid
     */
    public String getUserid() {
        return userid;
    }

    /**
     * @param userid the userid to set
     */
    public void setUserid(String userid) {
        this.userid = userid;
    }
}