KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workflow/CmsTaskService.java,v $
3  * Date : $Date: 2005/06/23 11:11:44 $
4  * Version: $Revision: 1.11 $
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.CmsSecurityManager;
35 import org.opencms.file.CmsGroup;
36 import org.opencms.file.CmsProject;
37 import org.opencms.file.CmsRequestContext;
38 import org.opencms.file.CmsUser;
39 import org.opencms.main.CmsException;
40
41 import java.util.List JavaDoc;
42
43 /**
44  * Just a convenience wrapper for
45  * workflow related methods.<p>
46  *
47  * @author Michael Moossen
48  *
49  * @version $Revision: 1.11 $
50  *
51  * @since 6.0.0
52  */

53 public class CmsTaskService {
54
55     /** Task preferences filter. */
56     public static final String JavaDoc TASK_FILTER = "task.filter.";
57
58     /** Task preferences message flags. */
59     public static final String JavaDoc TASK_MESSAGES = "TaskMessages";
60
61     /** state values of task messages when accepted. */
62     public static final int TASK_MESSAGES_ACCEPTED = 1;
63
64     /** state values of task messages when completed. */
65     public static final int TASK_MESSAGES_COMPLETED = 4;
66
67     /** state values of task messages when forwarded. */
68     public static final int TASK_MESSAGES_FORWARDED = 2;
69
70     /** state values of task messages when members. */
71     public static final int TASK_MESSAGES_MEMBERS = 8;
72
73     /** Task priority high. */
74     public static final int TASK_PRIORITY_HIGH = 1;
75
76     /** Task priority low. */
77     public static final int TASK_PRIORITY_LOW = 3;
78
79     /**
80      * Task priority normal.
81      **/

82     public static final int TASK_PRIORITY_NORMAL = 2;
83
84     /** state values of a task ended. */
85     public static final int TASK_STATE_ENDED = 4;
86
87     /** state values of a task halted. */
88     public static final int TASK_STATE_HALTED = 5;
89
90     /** state values of a task ready to end. */
91     public static final int TASK_STATE_NOTENDED = 3;
92
93     /** state values of a task prepared to start. */
94     public static final int TASK_STATE_PREPARE = 0;
95
96     /** state values of a task ready to start. */
97     public static final int TASK_STATE_START = 1;
98
99     /** state values of a task started. */
100     public static final int TASK_STATE_STARTED = 2;
101
102     /**System type values for the task log. */
103     public static final int TASKLOG_SYSTEM = 0;
104
105     /**User type value for the task log. */
106     public static final int TASKLOG_USER = 1;
107
108     /** Task type value of getting active tasks. */
109     public static final int TASKS_ACTIVE = 4;
110
111     /** Task type value of getting all tasks. */
112     public static final int TASKS_ALL = 1;
113
114     /** Task type value of getting done tasks. */
115     public static final int TASKS_DONE = 5;
116
117     /** Task type value of getting new tasks. */
118     public static final int TASKS_NEW = 2;
119
120     /** Task type value of getting open tasks. */
121     public static final int TASKS_OPEN = 3;
122
123     /** The request context. */
124     protected CmsRequestContext m_context;
125
126     /** The security manager to access the cms. */
127     protected CmsSecurityManager m_securityManager;
128
129     /**
130      * Creates a new <code>{@link CmsTaskService}</code>.<p>
131      *
132      * @param context the request context that contains the user authentification
133      * @param securityManager the security manager
134      */

135     public CmsTaskService(CmsRequestContext context, CmsSecurityManager securityManager) {
136
137         m_context = context;
138         m_securityManager = securityManager;
139     }
140
141     /**
142      * Updates the state of the given task as accepted by the current user.<p>
143      *
144      * @param taskId the id of the task to accept
145      *
146      * @throws CmsException if operation was not successful
147      */

148     public void acceptTask(int taskId) throws CmsException {
149
150         m_securityManager.acceptTask(m_context, taskId);
151     }
152
153     /**
154      * Creates a new task.<p>
155      *
156      * @param projectid the id of the current project task of the user
157      * @param agentName the user who will edit the task
158      * @param roleName a usergroup for the task
159      * @param taskname a name of the task
160      * @param tasktype the type of the task
161      * @param taskcomment a description of the task, which is written as task log entry
162      * @param timeout the time when the task must finished
163      * @param priority the id for the priority of the task
164      *
165      * @return the created task
166      *
167      * @throws CmsException if something goes wrong
168      */

169     public CmsTask createTask(
170         int projectid,
171         String JavaDoc agentName,
172         String JavaDoc roleName,
173         String JavaDoc taskname,
174         String JavaDoc taskcomment,
175         int tasktype,
176         long timeout,
177         int priority) throws CmsException {
178
179         return m_securityManager.createTask(
180             m_context,
181             m_context.currentUser(),
182             projectid,
183             agentName,
184             roleName,
185             taskname,
186             taskcomment,
187             tasktype,
188             timeout,
189             priority);
190     }
191
192     /**
193      * Creates a new task.<p>
194      *
195      * This is just a more limited version of the
196      * <code>{@link #createTask(int, String, String, String, String, int, long, int)}</code>
197      * method, where: <br>
198      * <ul>
199      * <il>the project id is the current project id.</il>
200      * <il>the task type is the standard task type <b>1</b>.</il>
201      * <il>with no comments</il>
202      * </ul><p>
203      *
204      * @param agentName the user who will edit the task
205      * @param roleName a usergroup for the task
206      * @param taskname the name of the task
207      * @param timeout the time when the task must finished
208      * @param priority the id for the priority of the task
209      *
210      * @return the created task
211      *
212      * @throws CmsException if something goes wrong
213      */

214     public CmsTask createTask(String JavaDoc agentName, String JavaDoc roleName, String JavaDoc taskname, long timeout, int priority)
215     throws CmsException {
216
217         return (m_securityManager.createTask(m_context, agentName, roleName, taskname, timeout, priority));
218     }
219
220     /**
221      * Ends a task.<p>
222      *
223      * @param taskid the id of the task to end
224      *
225      * @throws CmsException if operation was not successful
226      */

227     public void endTask(int taskid) throws CmsException {
228
229         m_securityManager.endTask(m_context, taskid);
230     }
231
232     /**
233      * Forwards a task to a new user.<p>
234      *
235      * @param taskid the id of the task which will be forwarded
236      * @param newRoleName the new group for the task
237      * @param newUserName the new user who gets the task. if it is empty, a new agent will automatic selected
238      *
239      * @throws CmsException if operation was not successful
240      */

241     public void forwardTask(int taskid, String JavaDoc newRoleName, String JavaDoc newUserName) throws CmsException {
242
243         m_securityManager.forwardTask(m_context, taskid, newRoleName, newUserName);
244     }
245
246     /**
247      * Returns the value of the given parameter for the given task.<p>
248      *
249      * @param taskid the id of the task
250      * @param parname the name of the parameter
251      *
252      * @return the parameter value
253      *
254      * @throws CmsException if operation was not successful
255      */

256     public String JavaDoc getTaskPar(int taskid, String JavaDoc parname) throws CmsException {
257
258         return m_securityManager.getTaskPar(m_context, taskid, parname);
259     }
260
261     /**
262      * Returns the template task id for a given taskname.<p>
263      *
264      * @param taskname the name of the task
265      *
266      * @return the id of the task template
267      *
268      * @throws CmsException if operation was not successful
269      */

270     public int getTaskType(String JavaDoc taskname) throws CmsException {
271
272         return m_securityManager.getTaskType(m_context, taskname);
273     }
274
275     /**
276      * Reactivates a task.<p>
277      *
278      * Setting its state to <code>{@link org.opencms.workflow.CmsTaskService#TASK_STATE_STARTED}</code> and
279      * the percentage to <b>zero</b>.<p>
280      *
281      * @param taskId the id of the task to reactivate
282      *
283      * @throws CmsException if something goes wrong
284      */

285     public void reactivateTask(int taskId) throws CmsException {
286
287         m_securityManager.reactivateTask(m_context, taskId);
288     }
289
290     /**
291      * Reads the agent of a task.<p>
292      *
293      * @param task the task to read the agent from
294      *
295      * @return the agent of a task
296      *
297      * @throws CmsException if something goes wrong
298      */

299     public CmsUser readAgent(CmsTask task) throws CmsException {
300
301         return m_securityManager.readAgent(m_context, task);
302     }
303
304     /**
305      * Reads all given tasks from a user for a project.<p>
306      *
307      * The <code>tasktype</code> parameter will filter the tasks.
308      * The possible values for this parameter are:<br>
309      * <ul>
310      * <il><code>{@link org.opencms.workflow.CmsTaskService#TASKS_ALL}</code>: Reads all tasks</il>
311      * <il><code>{@link org.opencms.workflow.CmsTaskService#TASKS_OPEN}</code>: Reads all open tasks</il>
312      * <il><code>{@link org.opencms.workflow.CmsTaskService#TASKS_DONE}</code>: Reads all finished tasks</il>
313      * <il><code>{@link org.opencms.workflow.CmsTaskService#TASKS_NEW}</code>: Reads all new tasks</il>
314      * </ul>
315      *
316      * @param projectId the id of the project in which the tasks are defined
317      * @param ownerName the owner of the task
318      * @param taskType the type of task you want to read
319      * @param orderBy specifies how to order the tasks
320      * @param sort sorting of the tasks
321      *
322      * @return a list of given <code>{@link CmsTask}</code> objects for a user for a project
323      *
324      * @throws CmsException if operation was not successful
325      */

326     public List JavaDoc readGivenTasks(int projectId, String JavaDoc ownerName, int taskType, String JavaDoc orderBy, String JavaDoc sort)
327     throws CmsException {
328
329         return m_securityManager.readGivenTasks(m_context, projectId, ownerName, taskType, orderBy, sort);
330     }
331
332     /**
333      * Reads the group (role) of a task.<p>
334      *
335      * @param task the task to read the group (role) from
336      *
337      * @return the group (role) of the task
338      *
339      * @throws CmsException if something goes wrong
340      */

341     public CmsGroup readGroup(CmsTask task) throws CmsException {
342
343         return m_securityManager.readGroup(m_context, task);
344     }
345
346     /**
347      * Reads the original agent of a task.<p>
348      *
349      * @param task the task to read the original agent from
350      *
351      * @return the original agent of the task
352      *
353      * @throws CmsException if something goes wrong
354      */

355     public CmsUser readOriginalAgent(CmsTask task) throws CmsException {
356
357         return m_securityManager.readOriginalAgent(m_context, task);
358     }
359
360     /**
361      * Reads the owner (initiator) of a task.<p>
362      *
363      * @param task the task to read the owner from
364      *
365      * @return the owner of the task
366      *
367      * @throws CmsException if something goes wrong
368      */

369     public CmsUser readOwner(CmsTask task) throws CmsException {
370
371         return m_securityManager.readOwner(m_context, task);
372     }
373
374     /**
375      * Reads the owner of a task log.<p>
376      *
377      * @param log the task log
378      *
379      * @return the owner of the task log
380      *
381      * @throws CmsException if something goes wrong
382      */

383     public CmsUser readOwner(CmsTaskLog log) throws CmsException {
384
385         return m_securityManager.readOwner(m_context, log);
386     }
387
388     /**
389      * Reads a project of a given task.<p>
390      *
391      * @param task the task for which the project will be read
392      *
393      * @return the project of the task
394      *
395      * @throws CmsException if operation was not successful
396      */

397     public CmsProject readProject(CmsTask task) throws CmsException {
398
399         return m_securityManager.readProject(m_context, task);
400     }
401
402     /**
403      * Reads all task log entries for a project.
404      *
405      * @param projectId the id of the project for which the tasklog will be read
406      *
407      * @return a list of <code>{@link CmsTaskLog}</code> objects
408      *
409      * @throws CmsException if operation was not successful
410      */

411     public List JavaDoc readProjectLogs(int projectId) throws CmsException {
412
413         return m_securityManager.readProjectLogs(m_context, projectId);
414     }
415
416     /**
417      * Reads the task with the given id.<p>
418      *
419      * @param id the id of the task to be read
420      *
421      * @return the task with the given id
422      *
423      * @throws CmsException if operation was not successful
424      */

425     public CmsTask readTask(int id) throws CmsException {
426
427         return m_securityManager.readTask(m_context, id);
428     }
429
430     /**
431      * Reads log entries for a task.<p>
432      *
433      * @param taskid the task for which the tasklog will be read
434      *
435      * @return a list of <code>{@link CmsTaskLog}</code> objects
436      *
437      * @throws CmsException if operation was not successful
438      */

439     public List JavaDoc readTaskLogs(int taskid) throws CmsException {
440
441         return m_securityManager.readTaskLogs(m_context, taskid);
442     }
443
444     /**
445      * Reads all tasks for a project.<p>
446      *
447      * The <code>tasktype</code> parameter will filter the tasks.
448      * The possible values are:<br>
449      * <ul>
450      * <il><code>{@link org.opencms.workflow.CmsTaskService#TASKS_ALL}</code>: Reads all tasks</il>
451      * <il><code>{@link org.opencms.workflow.CmsTaskService#TASKS_OPEN}</code>: Reads all open tasks</il>
452      * <il><code>{@link org.opencms.workflow.CmsTaskService#TASKS_DONE}</code>: Reads all finished tasks</il>
453      * <il><code>{@link org.opencms.workflow.CmsTaskService#TASKS_NEW}</code>: Reads all new tasks</il>
454      * </ul><p>
455      *
456      * @param projectId the id of the project in which the tasks are defined. Can be null to select all tasks
457      * @param tasktype the type of task you want to read
458      * @param orderBy specifies how to order the tasks
459      * @param sort sort order: C_SORT_ASC, C_SORT_DESC, or null
460      *
461      * @return a list of <code>{@link CmsTask}</code> objects for the project
462      *
463      * @throws CmsException if operation was not successful
464      */

465     public List JavaDoc readTasksForProject(int projectId, int tasktype, String JavaDoc orderBy, String JavaDoc sort) throws CmsException {
466
467         return (m_securityManager.readTasksForProject(m_context, projectId, tasktype, orderBy, sort));
468     }
469
470     /**
471      * Reads all tasks for a role in a project.<p>
472      *
473      * The <code>tasktype</code> parameter will filter the tasks.
474      * The possible values for this parameter are:<br>
475      * <ul>
476      * <il><code>{@link org.opencms.workflow.CmsTaskService#TASKS_ALL}</code>: Reads all tasks</il>
477      * <il><code>{@link org.opencms.workflow.CmsTaskService#TASKS_OPEN}</code>: Reads all open tasks</il>
478      * <il><code>{@link org.opencms.workflow.CmsTaskService#TASKS_DONE}</code>: Reads all finished tasks</il>
479      * <il><code>{@link org.opencms.workflow.CmsTaskService#TASKS_NEW}</code>: Reads all new tasks</il>
480      * </ul><p>
481      *
482      * @param projectId the id of the Project in which the tasks are defined
483      * @param roleName the role who has to process the task
484      * @param tasktype the type of task you want to read
485      * @param orderBy specifies how to order the tasks
486      * @param sort sort order C_SORT_ASC, C_SORT_DESC, or null
487      *
488      * @return list of <code>{@link CmsTask}</code> objects for the role
489      *
490      * @throws CmsException if operation was not successful
491      */

492     public List JavaDoc readTasksForRole(int projectId, String JavaDoc roleName, int tasktype, String JavaDoc orderBy, String JavaDoc sort)
493     throws CmsException {
494
495         return m_securityManager.readTasksForRole(m_context, projectId, roleName, tasktype, orderBy, sort);
496     }
497
498     /**
499      * Reads all tasks for a user in a project.<p>
500      *
501      * The <code>tasktype</code> parameter will filter the tasks.
502      * The possible values for this parameter are:<br>
503      * <ul>
504      * <il><code>{@link org.opencms.workflow.CmsTaskService#TASKS_ALL}</code>: Reads all tasks</il>
505      * <il><code>{@link org.opencms.workflow.CmsTaskService#TASKS_OPEN}</code>: Reads all open tasks</il>
506      * <il><code>{@link org.opencms.workflow.CmsTaskService#TASKS_DONE}</code>: Reads all finished tasks</il>
507      * <il><code>{@link org.opencms.workflow.CmsTaskService#TASKS_NEW}</code>: Reads all new tasks</il>
508      * </ul>
509      *
510      * @param projectId the id of the Project in which the tasks are defined
511      * @param userName the user who has to process the task
512      * @param tasktype the type of task you want to read
513      * @param orderBy specifies how to order the tasks
514      * @param sort sort order C_SORT_ASC, C_SORT_DESC, or null
515      *
516      * @return a list of <code>{@link CmsTask}</code> objects for the user
517      *
518      * @throws CmsException if operation was not successful
519      */

520     public List JavaDoc readTasksForUser(int projectId, String JavaDoc userName, int tasktype, String JavaDoc orderBy, String JavaDoc sort)
521     throws CmsException {
522
523         return m_securityManager.readTasksForUser(m_context, projectId, userName, tasktype, orderBy, sort);
524     }
525
526     /**
527      * Sets a new name for a task.<p>
528      *
529      * @param taskId the id of the task
530      * @param name the new name of the task
531      *
532      * @throws CmsException if something goes wrong
533      */

534     public void setName(int taskId, String JavaDoc name) throws CmsException {
535
536         m_securityManager.setName(m_context, taskId, name);
537     }
538
539     /**
540      * Sets the priority of a task.<p>
541      *
542      * @param taskId the id of the task
543      * @param priority the new priority value
544      *
545      * @throws CmsException if something goes wrong
546      */

547     public void setPriority(int taskId, int priority) throws CmsException {
548
549         m_securityManager.setPriority(m_context, taskId, priority);
550     }
551
552     /**
553      * Sets a parameter for a task.<p>
554      *
555      * @param taskid the id of the task
556      * @param parname the name of the parameter
557      * @param parvalue the value of the parameter
558      *
559      * @throws CmsException if something goes wrong
560      */

561     public void setTaskPar(int taskid, String JavaDoc parname, String JavaDoc parvalue) throws CmsException {
562
563         m_securityManager.setTaskPar(m_context, taskid, parname, parvalue);
564     }
565
566     /**
567      * Sets the timeout of a task.<p>
568      *
569      * @param taskId the id of the task
570      * @param timeout the new timeout value
571      *
572      * @throws CmsException if something goes wrong
573      */

574     public void setTimeout(int taskId, long timeout) throws CmsException {
575
576         m_securityManager.setTimeout(m_context, taskId, timeout);
577     }
578
579     /**
580      * Writes a new user tasklog for a task.<p>
581      *
582      * @param taskid the Id of the task
583      * @param comment the description for the log
584      *
585      * @throws CmsException if operation was not successful
586      */

587     public void writeTaskLog(int taskid, String JavaDoc comment) throws CmsException {
588
589         m_securityManager.writeTaskLog(m_context, taskid, comment);
590     }
591
592     /**
593      * Writes a new user tasklog for a task.<p>
594      *
595      * @param taskId the id of the task
596      * @param comment the description for the log
597      * @param taskType the type of the tasklog, user task types must be greater than 100
598      *
599      * @throws CmsException if something goes wrong
600      */

601     public void writeTaskLog(int taskId, String JavaDoc comment, int taskType) throws CmsException {
602
603         m_securityManager.writeTaskLog(m_context, taskId, comment, taskType);
604     }
605 }
Popular Tags