summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/events/Event.java
blob: 37c3c58169e397849be320bc7dadf543152fd303 (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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
/*
 * $Revision: 1.13 $
 *
 * $Date: 2004/11/22 09:12:28 $
 *
 * Copyright (C) 2001 CERN - European Organization for Nuclear Research
 * All rights reserved.
 */

package com.c2kernel.events;

import java.util.Calendar;

import com.c2kernel.common.GTimeStamp;
import com.c2kernel.common.InvalidDataException;
import com.c2kernel.entity.C2KLocalObject;
import com.c2kernel.persistency.ClusterStorage;


/**
 * The data structure of events, which are passed over the event service.
 *
 * Events are incrementaly numbered objects maintained by the History.
 *
 * @version $Revision: 1.13 $ $Date: 2004/11/22 09:12:28 $
 * @author  $Author: abranson $
 */
public class Event implements C2KLocalObject
{

	int mEntitySystemKey, mOriginState, mTransition, mTargetState;
	Integer mID, mSchemaVersion, mStateMachineVersion;
    String mName, mStepName, mStepPath, mStepType, mSchemaName, mStateMachineName, mViewName, mAgentName, mAgentRole;
    GTimeStamp mTimeStamp;

    public int getOriginState() {
		return mOriginState;
	}

	public void setOriginState(int originState) {
		this.mOriginState = originState;
	}

	public int getTargetState() {
		return mTargetState;
	}

	public void setTargetState(int targetState) {
		this.mTargetState = targetState;
	}

	public Integer getStateMachineVersion() {
		return mStateMachineVersion;
	}

	public void setStateMachineVersion(Integer stateMachineVersion) {
		this.mStateMachineVersion = stateMachineVersion;
	}

	public String getStateMachineName() {
		return mStateMachineName;
	}

	public void setStateMachineName(String stateMachineName) {
		this.mStateMachineName = stateMachineName;
	}

	public void setID( Integer id ) {
        mID = id;
        mName = String.valueOf(id);
    }
    
    /**
     */
    public void setEntitySystemKey( int systemKey )
    {
        mEntitySystemKey = systemKey;
    }

    /**
     * Set the Event Name, in parameter is a String
     */
    @Override
	public void setName(String name)
    {
        mName = name;
        try {
            mID = Integer.parseInt(name);
        } catch (NumberFormatException ex) {
            mID = -1;
        }
    }

    /**
     * Set the StepPath of the Event, in parameter is a String
     */
    public void setStepName(String name)
    {
        mStepName = name;
    }

    /**
     * Set the StepPath of the Event, in parameter is a String
     */
    public void setStepPath(String path)
    {
        mStepPath = path;
    }

	/**
	 * Set the StepType of the Event, in parameter is a String
	 */
	public void setStepType(String type)
	{
		mStepType = type;
	}
	
	/**
	 * @param viewName the viewName to set
	 */
	public void setViewName(String viewName) {
		this.mViewName = viewName;
	}

    /**
     * Set the AgentInfo in the Event, in parameter is an AgentInfo
     */
    public void setAgentName(String agentName)
    {
        mAgentName = agentName;
    }

	public void setAgentRole(String agentRole)
	{
		mAgentRole = agentRole;
	}

    /**
     * Set the TimeStamp in the Event, in parameter is an GTimeStamp
     */
    public void setTimeStamp(GTimeStamp inTimeStamp)
    {
        mTimeStamp = inTimeStamp;
    }


    /**
     * Return the Event's ID
     */
    public Integer getID()
    {
        return mID;
    }

    /**
     */
    public int getEntitySystemKey()
    {
        return mEntitySystemKey;
    }

    /**
     * Return the Event Name
     */
    @Override
	public String getName()
    {
        return mName;
    }

    /**
     * Return the StepPath of the Event.
     */
    public String getStepName()
    {
        return mStepName;
    }

    /**
     * Return the StepPath of the Event.
     */
    public String getStepPath()
    {
        return mStepPath;
    }

	/**
	 * Return the StepPath of the Event.
	 */
	public String getStepType()
	{
		return mStepType;
	}
	
    /**
	 * @return the mViewName
	 */
	public String getViewName() {
		return mViewName;
	}

    /**
     * Return the AgentInfo of the Event.
     */
    public String getAgentName()
    {
        return mAgentName;
    }

    public String getAgentRole()
    {
    	return mAgentRole;
    }

    /**
     * Return the Event's TimeStamp.
     */
    public GTimeStamp getTimeStamp()
    {
        return mTimeStamp;
    }

    /**
     *  Return the TimeStamp in a form that will
     *  convert nicely to a String
     *  YYYY-MM-DD HH:MI:SS
     */
    public String getTimeString()
    {
        return Event.timeToString(mTimeStamp);
    }

    public static String timeToString(GTimeStamp timeStamp) {
        StringBuffer time = new StringBuffer().append(timeStamp.mYear).append("-");

        if (timeStamp.mMonth<10) time.append("0");
        time.append(timeStamp.mMonth).append("-");

        if (timeStamp.mDay<10) time.append("0");
        time.append(timeStamp.mDay).append(" ");

        if (timeStamp.mHour<10) time.append("0");
        time.append(timeStamp.mHour).append(":");

        if (timeStamp.mMinute<10) time.append("0");
        time.append(timeStamp.mMinute).append(":");

        if (timeStamp.mSecond<10) time.append("0");
        time.append(timeStamp.mSecond);

        return time.toString();
    }

    public void setTimeString(String time) throws InvalidDataException
    {
    	if (time.length() == 19)
    	    mTimeStamp = new GTimeStamp(
        					Integer.parseInt(time.substring(0,4)),
        					Integer.parseInt(time.substring(5,7)),
        					Integer.parseInt(time.substring(8,10)),
        					Integer.parseInt(time.substring(11,13)),
        					Integer.parseInt(time.substring(14,16)),
    	    				Integer.parseInt(time.substring(17,19)),
    		   				Calendar.getInstance().get(Calendar.ZONE_OFFSET));
        else if (time.length() == 14) // support for some sql formats
            mTimeStamp = new GTimeStamp(
                            Integer.parseInt(time.substring(0,4)),
                            Integer.parseInt(time.substring(4,6)),
                            Integer.parseInt(time.substring(6,8)),
                            Integer.parseInt(time.substring(8,10)),
                            Integer.parseInt(time.substring(10,12)),
                            Integer.parseInt(time.substring(12,14)),
                            Calendar.getInstance().get(Calendar.ZONE_OFFSET));
        else
            throw new InvalidDataException("Unknown time format: "+time, "");
    }



   static public GTimeStamp getGMT()
    {
        java.util.Calendar now = Calendar.getInstance();

        return new GTimeStamp( now.get(Calendar.YEAR),
                               now.get(Calendar.MONTH)+1,
                               now.get(Calendar.DAY_OF_MONTH),
                               now.get(Calendar.HOUR_OF_DAY),
                               now.get(Calendar.MINUTE),
                               now.get(Calendar.SECOND),
                               now.get(Calendar.ZONE_OFFSET) );
    }
	/**
	 * @see com.c2kernel.entity.C2KLocalObject#getClusterType()
	 */
	@Override
	public String getClusterType() {
		return ClusterStorage.HISTORY;
	}

    /**
     * @return
     */
    public int getTransition() {
        return mTransition;
    }

    /**
     * @param i
     */
    public void setTransition(int i) {
        mTransition = i;
    }

	public Integer getSchemaVersion() {
		return mSchemaVersion;
	}

	public void setSchemaVersion(Integer schemaVersion) {
		this.mSchemaVersion = schemaVersion;
	}

	public String getSchemaName() {
		return mSchemaName;
	}

	public void setSchemaName(String schemaName) {
		this.mSchemaName = schemaName;
	}

}