KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workflow > CmsTask


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workflow/CmsTask.java,v $
3  * Date : $Date: 2006/03/28 12:14:36 $
4  * Version: $Revision: 1.15 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.workflow;
33
34 import org.opencms.db.CmsDbUtil;
35 import org.opencms.main.CmsIllegalArgumentException;
36 import org.opencms.util.CmsStringUtil;
37 import org.opencms.util.CmsUUID;
38
39 /**
40  * Describes an OpenCms task.<p>
41  *
42  * @author Alexander Kandzior
43  *
44  * @version $Revision: 1.15 $
45  *
46  * @since 6.0.0
47  */

48 public class CmsTask {
49
50     /** The name constraints when generating new tasks. */
51     public static final String JavaDoc NAME_CONSTRAINTS = "äöüÄÖÜ -._~?/()\\#&:;";
52
53     /** The id of the user who is the agent of this task. */
54     private CmsUUID m_agentUserId;
55
56     /** The auto finish value of this task. */
57     private int m_autoFinish;
58
59     /** Timestamp when the task has been ended. */
60     private java.sql.Timestamp JavaDoc m_endTime;
61
62     /** Escalation type of this task. */
63     private int m_escalationType;
64
65     /** Link to the html page which handles this task. */
66     private String JavaDoc m_htmlLink;
67
68     /** The id of this task. */
69     private int m_id;
70
71     /** The id of the user who initiated this task. */
72     private CmsUUID m_initiatorUserId;
73
74     /** The id of the milestone to which this task belongs. */
75     private int m_milestone;
76
77     /** The name of this task. */
78     private String JavaDoc m_name;
79
80     /** The id of the user who was the original agent. */
81     private CmsUUID m_originalUserId;
82
83     /** The id of the task which is the parent of this task. */
84     private int m_parent;
85
86     /** Percentage value of this task. */
87     private int m_percentage;
88
89     /** Permission flag of this task. */
90     private String JavaDoc m_permission;
91
92     /** Priority of this task. */
93     private int m_priority;
94
95     /** The id of the role which is set for this task. */
96     private CmsUUID m_roleId;
97
98     /** The id of the task which is the root task of this task. */
99     private int m_root;
100
101     /** Timestamp when this task has been started. */
102     private java.sql.Timestamp JavaDoc m_startTime;
103
104     /** State of this task. */
105     private int m_state;
106
107     /** Type of this task. */
108     private int m_taskType;
109
110     /** Timestamp when this task has to be completed. */
111     private java.sql.Timestamp JavaDoc m_timeOut;
112
113     /** Timestamp when this task has to be activated. */
114     private java.sql.Timestamp JavaDoc m_wakeupTime;
115
116     /**
117      * Creates a new CmsTask object with default values for all members.<p>
118      */

119     public CmsTask() {
120
121         m_id = CmsDbUtil.UNKNOWN_ID;
122         m_name = null;
123         m_state = 0;
124         m_taskType = CmsDbUtil.UNKNOWN_ID;
125         m_root = CmsDbUtil.UNKNOWN_ID;
126         m_parent = CmsDbUtil.UNKNOWN_ID;
127         m_initiatorUserId = CmsUUID.getNullUUID();
128         m_roleId = CmsUUID.getNullUUID();
129         m_agentUserId = CmsUUID.getNullUUID();
130         m_originalUserId = CmsUUID.getNullUUID();
131         m_startTime = null;
132         m_wakeupTime = null;
133         m_timeOut = null;
134         m_endTime = null;
135         m_percentage = 0;
136         m_permission = "-rw-rw-rw";
137         m_priority = CmsDbUtil.UNKNOWN_ID;
138         m_escalationType = 0;
139         m_htmlLink = null;
140         m_milestone = CmsDbUtil.UNKNOWN_ID;
141         m_autoFinish = 0;
142     }
143
144     /**
145      * Creates a new CmsTask object.<p>
146      *
147      * @param id the id of this task
148      * @param name the name of this task
149      * @param state state of this task
150      * @param taskType type of this task
151      * @param root the id of the task which is the root task of this task
152      * @param parent the id of the task which is the parent of this task
153      * @param initiatorUserId the id of the user who initiated this task
154      * @param roleId the id of the role which is set for this task
155      * @param agentUserId the id of the user who is the agent of this task
156      * @param originalUserId the id of the user who was the original agent
157      * @param startTime timestamp when this task has been started
158      * @param wakeupTime timestamp when this task has to be activated
159      * @param timeOut timestamp when this task has to be completed
160      * @param endTime timestamp when the task has been ended
161      * @param percentage percentage value of this task
162      * @param permission permission flag of this task
163      * @param priority priority of this task
164      * @param escalationType escalation type of this task
165      * @param htmlLink link to the html page which handles this task
166      * @param milestone the id of the milstone to which this task belongs
167      * @param autofinish the auto finish value of this task
168      */

169     public CmsTask(
170         int id,
171         String JavaDoc name,
172         int state,
173         int taskType,
174         int root,
175         int parent,
176         CmsUUID initiatorUserId,
177         CmsUUID roleId,
178         CmsUUID agentUserId,
179         CmsUUID originalUserId,
180         java.sql.Timestamp JavaDoc startTime,
181         java.sql.Timestamp JavaDoc wakeupTime,
182         java.sql.Timestamp JavaDoc timeOut,
183         java.sql.Timestamp JavaDoc endTime,
184         int percentage,
185         String JavaDoc permission,
186         int priority,
187         int escalationType,
188         String JavaDoc htmlLink,
189         int milestone,
190         int autofinish) {
191
192         m_id = id;
193         m_name = name;
194         m_state = state;
195         m_taskType = taskType;
196         m_root = root;
197         m_parent = parent;
198         m_initiatorUserId = initiatorUserId;
199         m_roleId = roleId;
200         m_agentUserId = agentUserId;
201         m_originalUserId = originalUserId;
202         m_startTime = startTime;
203         m_wakeupTime = wakeupTime;
204         m_timeOut = timeOut;
205         m_endTime = endTime;
206         m_percentage = percentage;
207         m_permission = permission;
208         m_priority = priority;
209         m_escalationType = escalationType;
210         m_htmlLink = htmlLink;
211         m_milestone = milestone;
212         m_autoFinish = autofinish;
213     }
214
215     /**
216      *
217      * Checks if the provided task name is a valid task name,
218      * that is contains only valid characters.<p>
219      *
220      * A task name can only be composed of digits,
221      * standard ASCII letters and the symbols defined in {@link #NAME_CONSTRAINTS}.<p>
222      *
223      * @param name the task name to check
224      *
225      * @throws CmsIllegalArgumentException if the given task name is not valid
226      */

227     public static void checkTaskName(String JavaDoc name) throws CmsIllegalArgumentException {
228
229         if (CmsStringUtil.isEmptyOrWhitespaceOnly(name)) {
230             throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_BAD_TASKNAME_EMPTY_0, name));
231         }
232
233         CmsStringUtil.checkName(name, NAME_CONSTRAINTS, Messages.ERR_BAD_TASKNAME_4, Messages.get());
234     }
235
236     /**
237      * @see java.lang.Object#equals(java.lang.Object)
238      */

239     public boolean equals(Object JavaDoc obj) {
240
241         if (obj == this) {
242             return true;
243         }
244         if (obj instanceof CmsTask) {
245             return ((CmsTask)obj).m_id == m_id;
246         }
247         return false;
248     }
249
250     /**
251      * Returns the agent user id of this task.<p>
252      *
253      * @return the agent user id of this task
254      */

255     public CmsUUID getAgentUser() {
256
257         return m_agentUserId;
258     }
259
260     /**
261      * Returns the autofinish flag of this task.<p>
262      *
263      * @return the autofinish flag of this task
264      */

265     public int getAutoFinish() {
266
267         return m_autoFinish;
268     }
269
270     /**
271      * Returns the endtime of this task.<p>
272      *
273      * @return the endtime of this task
274      */

275     public java.sql.Timestamp JavaDoc getEndTime() {
276
277         return m_endTime;
278     }
279
280     /**
281      * Returns the escalation type of this task.<p>
282      *
283      * @return the escalation type of this task
284      */

285     public int getEscalationType() {
286
287         return m_escalationType;
288     }
289
290     /**
291      * Returns the html link of this task.<p>
292      *
293      * @return the htmllink of this task
294      */

295     public String JavaDoc getHtmlLink() {
296
297         return m_htmlLink;
298     }
299
300     /**
301      * Returns the id of this task.<p>
302      *
303      * @return the id of this task
304      */

305     public int getId() {
306
307         return m_id;
308     }
309
310     /**
311      * Returns the initiator user id of this task.<p>
312      *
313      * @return the initiator user id of this task
314      */

315     public CmsUUID getInitiatorUser() {
316
317         return m_initiatorUserId;
318     }
319
320     /**
321      * Returns the milestone value of this task.<p>
322      *
323      * @return the milestone value of this task
324      */

325     public int getMilestone() {
326
327         return m_milestone;
328     }
329
330     /**
331      * Returns the name of this task.<p>
332      *
333      * @return the name of this task
334      */

335     public String JavaDoc getName() {
336
337         return m_name;
338     }
339
340     /**
341      * Returns the original agent user id of this task.<p>
342      *
343      * @return the original agent user id of this task
344      */

345     public CmsUUID getOriginalUser() {
346
347         return m_originalUserId;
348     }
349
350     /**
351      * Returns the parent id of this task.<p>
352      *
353      * @return the parent id of this task
354      */

355     public int getParent() {
356
357         return m_parent;
358     }
359
360     /**
361      * Returns the percentage of this task.<p>
362      *
363      * @return the percentage of this task
364      */

365     public int getPercentage() {
366
367         return m_percentage;
368     }
369
370     /**
371      * Returns the permission of this task.<p>
372      *
373      * @return the permission of this task
374      */

375     public String JavaDoc getPermission() {
376
377         return m_permission;
378     }
379
380     /**
381      * Returns the priority of this task.<p>
382      *
383      * @return the priority of this task
384      */

385     public int getPriority() {
386
387         return m_priority;
388     }
389
390     /**
391      * Returns the role group id of this task.<p>
392      *
393      * @return the role group id of this task
394      */

395     public CmsUUID getRole() {
396
397         return m_roleId;
398     }
399
400     /**
401      * Returns the root id of this task.<p>
402      *
403      * @return the root id of this task
404      */

405     public int getRoot() {
406
407         return m_root;
408     }
409
410     /**
411      * Returns the starttime of this task.<p>
412      *
413      * @return the starttime of this task
414      */

415     public java.sql.Timestamp JavaDoc getStartTime() {
416
417         return m_startTime;
418     }
419
420     /**
421      * Returns the state of this task.<p>
422      *
423      * @return the state of this task
424      */

425     public int getState() {
426
427         return m_state;
428     }
429
430     /**
431      * Returns the state of this task as String.<p>
432      *
433      * @return the state of this task as String
434      */

435     public String JavaDoc getStateString() {
436
437         return State2String(m_state);
438     }
439
440     /**
441      * Returns the type of this task.<p>
442      *
443      * @return the type of this task
444      */

445     public int getTaskType() {
446
447         return m_taskType;
448     }
449
450     /**
451      *
452      * Returns the timeout date of this task.<p>
453      *
454      * @return the timeout date of this task
455      */

456     public java.sql.Timestamp JavaDoc getTimeOut() {
457
458         return m_timeOut;
459     }
460
461     /**
462      * Returns the wakeup time of this task.<p>
463      *
464      * @return the wakeup time of this task
465      */

466     public java.sql.Timestamp JavaDoc getWakeupTime() {
467
468         return m_wakeupTime;
469     }
470
471     /**
472      * @see java.lang.Object#hashCode()
473      */

474     public int hashCode() {
475
476         return (new Integer JavaDoc(m_id)).hashCode();
477     }
478
479     /**
480      * Sets the agent user id for this task.<p>
481      *
482      * @param agentUserId the agent user id for this task
483      */

484     public void setAgentUser(CmsUUID agentUserId) {
485
486         m_agentUserId = agentUserId;
487     }
488
489     /**
490      * Sets the initiator user id for this task.<p>
491      *
492      * @param initiatorUserId the initiator user id for this task
493      */

494     public void setInitiatorUser(CmsUUID initiatorUserId) {
495
496         m_initiatorUserId = initiatorUserId;
497     }
498
499     /**
500      * Sets the milestone value of this task.<p>
501      *
502      * @param milestone the milestone value of this task
503      */

504     public void setMilestone(int milestone) {
505
506         m_milestone = milestone;
507     }
508
509     /**
510      * Sets the name of this task.<p>
511      *
512      * @param taskname the name of this task
513      */

514     public void setName(String JavaDoc taskname) {
515
516         m_name = taskname;
517     }
518
519     /**
520      * Sets the original user id of this task.<p>
521      *
522      * @param originalUserId the original user id of this task
523      */

524     public void setOriginalUser(CmsUUID originalUserId) {
525
526         m_originalUserId = originalUserId;
527     }
528
529     /**
530      * Sets the parent id of this task.<p>
531      *
532      * @param parent the parent id of this task
533      */

534     public void setParent(int parent) {
535
536         m_parent = parent;
537     }
538
539     /**
540      * Sets the percentage for this task.<p>
541      *
542      * @param percentage the percentage for this task
543      */

544     public void setPercentage(int percentage) {
545
546         m_percentage = percentage;
547     }
548
549     /**
550      * Sets the priority for this task.<p>
551      *
552      * @param priority the priority for this task
553      */

554     public void setPriority(int priority) {
555
556         m_priority = priority;
557     }
558
559     /**
560      * Sets the role id for this task.<p>
561      *
562      * @param roleId the role id for this task
563      */

564     public void setRole(CmsUUID roleId) {
565
566         m_roleId = roleId;
567     }
568
569     /**
570      * Sets the root value for this task.<p>
571      *
572      * @param root the root value for this task
573      */

574     public void setRoot(int root) {
575
576         m_root = root;
577     }
578
579     /**
580      * Sets the start time of this task.<p>
581      *
582      * @param starttime the start time of this task
583      */

584     public void setStartTime(java.sql.Timestamp JavaDoc starttime) {
585
586         m_startTime = starttime;
587     }
588
589     /**
590      * Sets the state of this task.<p>
591      *
592      * @param state the state of this task
593      */

594     public void setState(int state) {
595
596         m_state = state;
597     }
598
599     /**
600      * Sets the type of this task.<p>
601      *
602      * @param tasktype the type of this task
603      */

604     public void setTaskType(int tasktype) {
605
606         m_taskType = tasktype;
607     }
608
609     /**
610      * Sets the timeout value for this task.<p>
611      *
612      * @param timeout the timeout value for this task
613      */

614     public void setTimeOut(java.sql.Timestamp JavaDoc timeout) {
615
616         m_timeOut = timeout;
617     }
618
619     /**
620      * Sets the wakeup time for this task.<p>
621      *
622      * @param wakeuptime the wakeup time for this task
623      */

624     public void setWakeupTime(java.sql.Timestamp JavaDoc wakeuptime) {
625
626         m_wakeupTime = wakeuptime;
627     }
628
629     /**
630      * @see java.lang.Object#toString()
631      */

632     public String JavaDoc toString() {
633
634         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
635         result.append("[Task]");
636         result.append(" id:");
637         result.append(this.getId());
638         result.append(" name:");
639         result.append(this.getName());
640         result.append(" root:");
641         result.append(this.getRoot());
642         result.append(" state:");
643         result.append(this.getStateString());
644         result.append(" owner:");
645         result.append(this.getInitiatorUser());
646         result.append(" agent:");
647         result.append(this.getAgentUser());
648         result.append(" role:");
649         result.append(this.getRole());
650         return result.toString();
651     }
652
653     /**
654      * Returns a String representation for the task state.<p>
655      *
656      * @param state the state to get a String representtion for
657      * @return a String representation for the task state
658      */

659     private String JavaDoc State2String(int state) {
660
661         String JavaDoc result = null;
662
663         switch (state) {
664             case CmsTaskService.TASK_STATE_PREPARE:
665                 result = Messages.get().getBundle().key(Messages.GUI_TASK_STATE_PREPARED_0);
666                 break;
667             case CmsTaskService.TASK_STATE_START:
668                 result = Messages.get().getBundle().key(Messages.GUI_TASK_STATE_START_0);
669                 break;
670             case CmsTaskService.TASK_STATE_STARTED:
671                 result = Messages.get().getBundle().key(Messages.GUI_TASK_STATE_STARTED_0);
672                 break;
673             case CmsTaskService.TASK_STATE_NOTENDED:
674                 result = Messages.get().getBundle().key(Messages.GUI_TASK_STATE_RUNNING_0);
675                 break;
676             case CmsTaskService.TASK_STATE_ENDED:
677                 result = Messages.get().getBundle().key(Messages.GUI_TASK_STATE_ENDED_0);
678                 break;
679             case CmsTaskService.TASK_STATE_HALTED:
680                 result = Messages.get().getBundle().key(Messages.GUI_TASK_STATE_HALTED_0);
681                 break;
682             default:
683                 result = Messages.get().getBundle().key(Messages.GUI_TASK_STATE_UNKNOWN_0);
684         }
685         return result;
686     }
687 }
Popular Tags