KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opencms > workplace > CmsTaskContentDetail


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsTaskContentDetail.java,v $
3  * Date : $Date: 2005/08/31 07:29:39 $
4  * Version: $Revision: 1.7 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (C) 2001 The OpenCms Group
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 OpenCms, please see the
22  * OpenCms Website: http://www.opencms.org
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with this library; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27  */

28
29 package com.opencms.workplace;
30
31 import org.opencms.file.CmsGroup;
32 import org.opencms.file.CmsObject;
33 import org.opencms.file.CmsRequestContext;
34 import org.opencms.file.CmsUser;
35 import org.opencms.main.CmsException;
36 import org.opencms.main.CmsLog;
37 import org.opencms.util.CmsDateUtil;
38 import org.opencms.workflow.CmsTask;
39 import org.opencms.workflow.CmsTaskService;
40
41 import com.opencms.core.I_CmsSession;
42 import com.opencms.legacy.CmsLegacyException;
43 import com.opencms.legacy.CmsXmlTemplateLoader;
44
45 import java.io.IOException JavaDoc;
46 import java.util.Calendar JavaDoc;
47 import java.util.Date JavaDoc;
48 import java.util.GregorianCalendar JavaDoc;
49 import java.util.Hashtable JavaDoc;
50
51 /**
52  * Template class for displaying OpenCms workplace task content detail screens.
53  * <P>
54  *
55  * @author Andreas Schouten
56  * @author Mario Stanke
57  * @version $Revision: 1.7 $ $Date: 2005/08/31 07:29:39 $
58  * @see com.opencms.workplace.CmsXmlWpTemplateFile
59  *
60  * @deprecated Will not be supported past the OpenCms 6 release.
61  */

62
63 public class CmsTaskContentDetail extends CmsWorkplaceDefault {
64
65     /**
66      * Gets the content of a defined section in a given template file and its subtemplates
67      * with the given parameters.
68      *
69      * @see #getContent(CmsObject, String, String, Hashtable, String)
70      * @param cms CmsObject Object for accessing system resources.
71      * @param templateFile Filename of the template file.
72      * @param elementName Element name of this template in our parent template.
73      * @param parameters Hashtable with all template class parameters.
74      * @param templateSelector template section that should be processed.
75      */

76
77     public byte[] getContent(
78         CmsObject cms,
79         String JavaDoc templateFile,
80         String JavaDoc elementName,
81         Hashtable JavaDoc parameters,
82         String JavaDoc templateSelector) throws CmsException {
83
84         if (CmsLog.getLog(this).isDebugEnabled() && C_DEBUG) {
85             CmsLog.getLog(this).debug("Getting content of element " + ((elementName == null) ? "<root>" : elementName));
86             CmsLog.getLog(this).debug("Template file is: " + templateFile);
87             CmsLog.getLog(this).debug(
88                 "Selected template section is: " + ((templateSelector == null) ? "<default>" : templateSelector));
89         }
90         CmsRequestContext context = cms.getRequestContext();
91         CmsXmlWpTemplateFile xmlTemplateDocument = (CmsXmlWpTemplateFile)getOwnTemplateFile(
92             cms,
93             templateFile,
94             elementName,
95             parameters,
96             templateSelector);
97         CmsTask task;
98         int taskid = -1;
99         I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
100
101         CmsTaskService taskService = cms.getTaskService();
102         // getting the URL to which we need to return when we're done
103
String JavaDoc lastUrl;
104         String JavaDoc lastRelUrl = (String JavaDoc)parameters.get("lastrelurl");
105         if (lastRelUrl != null) {
106
107             // have a URL relative to the workplace action path (when clicking on the task name)
108
lastUrl = getConfigFile(cms).getWorkplaceActionPath() + lastRelUrl;
109             session.putValue("lasturl", lastUrl);
110         } else {
111
112             // have the complete path (when using the context menu)
113
lastUrl = this.getLastUrl(cms, parameters);
114         }
115         try {
116             Integer JavaDoc sessionTaskid = (Integer JavaDoc)session.getValue("taskid");
117             if (sessionTaskid != null) {
118                 taskid = sessionTaskid.intValue();
119             }
120             try {
121                 taskid = Integer.parseInt((String JavaDoc)parameters.get("taskid"));
122             } catch (Exception JavaDoc exc) {
123
124                 // no new taskid use the one from session
125
}
126             session.putValue("taskid", new Integer JavaDoc(taskid));
127             parameters.put("taskid", taskid + "");
128             task = taskService.readTask(taskid);
129             if ("acceptok".equals(parameters.get("action"))) {
130
131                 // accept the task
132
CmsTaskAction.accept(cms, taskid);
133             } else {
134                 if ("accept".equals(parameters.get("action"))) {
135
136                     // show dialog
137
templateSelector = "accept";
138                 } else {
139                     if ("take".equals(parameters.get("action"))) {
140
141                         // show dialog
142
templateSelector = "take";
143                     } else {
144                         if ("takeok".equals(parameters.get("action"))) {
145
146                             // take the task
147
CmsTaskAction.take(cms, taskid);
148                         } else {
149                             if ("forwardok".equals(parameters.get("action"))) {
150
151                                 // forward the task
152
CmsTaskAction.forward(
153                                     cms,
154                                     taskid,
155                                     (String JavaDoc)parameters.get("USER"),
156                                     (String JavaDoc)parameters.get("TEAM"));
157                             } else {
158                                 if ("due".equals(parameters.get("action"))) {
159
160                                     // show dialog
161
templateSelector = "due";
162                                 } else {
163                                     if ("dueok".equals(parameters.get("action"))) {
164
165                                         // change the due-date of the task
166
CmsTaskAction.due(cms, taskid, (String JavaDoc)parameters.get("DATE"));
167                                     } else {
168                                         if ("priorityok".equals(parameters.get("action"))) {
169
170                                             // change the priority of the task
171
CmsTaskAction.priority(cms, taskid, (String JavaDoc)parameters.get("PRIORITY"));
172                                         } else {
173                                             if ("reaktok".equals(parameters.get("action"))) {
174
175                                                 // reaktivate the task
176
CmsTaskAction.reakt(
177                                                     cms,
178                                                     taskid,
179                                                     (String JavaDoc)parameters.get("USER"),
180                                                     (String JavaDoc)parameters.get("TEAM"),
181                                                     (String JavaDoc)parameters.get("TASK"),
182                                                     (String JavaDoc)parameters.get("DESCRIPTION"),
183                                                     (String JavaDoc)parameters.get("DATE"),
184                                                     (String JavaDoc)parameters.get("PRIORITY"),
185                                                     (String JavaDoc)parameters.get("MSG_ACCEPTATION"),
186                                                     (String JavaDoc)parameters.get("MSG_ALL"),
187                                                     (String JavaDoc)parameters.get("MSG_COMPLETION"),
188                                                     (String JavaDoc)parameters.get("MSG_DELIVERY"));
189                                             } else {
190                                                 if ("okok".equals(parameters.get("action"))) {
191
192                                                     // ok the task
193
CmsTaskAction.end(cms, taskid);
194                                                 } else {
195                                                     if ("ok".equals(parameters.get("action"))) {
196
197                                                         // show dialog
198
templateSelector = "ok";
199                                                     } else {
200                                                         if ("comment".equals(parameters.get("action"))) {
201
202                                                             // add comment
203
// String comment = (String)parameters.get("DESCRIPTION");
204
// if((comment != null) && (comment.length() != 0)) {
205
// taskService.writeTaskLog(taskid, comment, CmsWorkplaceDefault.C_TASKLOGTYPE_COMMENT);
206
// }
207
// add message
208
CmsTaskAction.comment(
209                                                                 cms,
210                                                                 taskid,
211                                                                 (String JavaDoc)parameters.get("DESCRIPTION"));
212
213                                                         } else {
214                                                             if ("messageok".equals(parameters.get("action"))) {
215
216                                                                 // add message
217
CmsTaskAction.message(
218                                                                     cms,
219                                                                     taskid,
220                                                                     (String JavaDoc)parameters.get("DESCRIPTION"));
221                                                             } else {
222                                                                 if ("queryok".equals(parameters.get("action"))) {
223
224                                                                     // add message
225
CmsTaskAction.query(
226                                                                         cms,
227                                                                         taskid,
228                                                                         (String JavaDoc)parameters.get("DESCRIPTION"));
229                                                                 }
230                                                             }
231                                                         }
232                                                     }
233                                                 }
234                                             }
235                                         }
236                                     }
237                                 }
238                             }
239                         }
240                     }
241                 }
242             }
243
244             // update the task-data
245
// it maybe had been changed
246
task = taskService.readTask(taskid);
247         } catch (Exception JavaDoc exc) {
248             throw new CmsLegacyException(CmsLegacyException.C_UNKNOWN_EXCEPTION, exc);
249         }
250         CmsUser owner = null;
251         try {
252             owner = taskService.readOwner(task);
253         } catch (Exception JavaDoc exc) {
254
255             // ignore the exception
256
}
257         CmsUser editor = null;
258         try {
259             editor = taskService.readAgent(task);
260         } catch (Exception JavaDoc exc) {
261
262             // ignore the exception
263
}
264         CmsGroup role = null;
265         String JavaDoc roleName = "";
266         try {
267             role = taskService.readGroup(task);
268             roleName = role.getName();
269         } catch (Exception JavaDoc exc) {
270
271             // ignore the exception
272
}
273         String JavaDoc priority;
274         String JavaDoc projectname = "?";
275         String JavaDoc style;
276         String JavaDoc button1;
277         String JavaDoc button2;
278         String JavaDoc button3;
279         String JavaDoc button4;
280         String JavaDoc button5;
281         String JavaDoc button6;
282         long startTime;
283         long timeout;
284         GregorianCalendar JavaDoc cal = new GregorianCalendar JavaDoc();
285         cal.setTime(new Date JavaDoc(System.currentTimeMillis()));
286         cal.set(Calendar.HOUR, 0);
287         cal.set(Calendar.MINUTE, 0);
288         cal.set(Calendar.SECOND, 0);
289         cal.set(Calendar.MILLISECOND, 0);
290         GregorianCalendar JavaDoc newcal = new GregorianCalendar JavaDoc(
291             cal.get(Calendar.YEAR),
292             cal.get(Calendar.MONTH),
293             cal.get(Calendar.DAY_OF_MONTH),
294             0,
295             0,
296             0);
297         long now = newcal.getTime().getTime();
298         try {
299             projectname = taskService.readTask(task.getRoot()).getName();
300         } catch (Exception JavaDoc exc) {
301
302             // no root?!
303
}
304         priority = xmlTemplateDocument.getProcessedDataValue("priority" + task.getPriority(), this);
305         startTime = task.getStartTime().getTime();
306         timeout = task.getTimeOut().getTime();
307         String JavaDoc due = "";
308         try {
309             due = CmsDateUtil.getDateShort(timeout);
310         } catch (Exception JavaDoc exc) {
311
312             // ignore the exception
313
}
314         String JavaDoc from = "";
315         try {
316             from = CmsDateUtil.getDateShort(startTime);
317         } catch (Exception JavaDoc exc) {
318
319             // ignore the exception
320
}
321         xmlTemplateDocument.setData("taskid", task.getId() + "");
322         boolean isOwner = context.currentUser().equals(owner);
323         boolean isEditor = context.currentUser().equals(editor);
324         boolean isInRole = false;
325         try {
326             isInRole = cms.userInGroup(context.currentUser().getName(), roleName);
327         } catch (Exception JavaDoc exc) {
328
329             // ignore the exception
330
}
331
332         // choose the right style and buttons
333
if (task.getState() == CmsTaskService.TASK_STATE_ENDED) {
334             if (isOwner) {
335
336                 // this is the owner of the task
337
button1 = getButton(xmlTemplateDocument, "button_message", false);
338                 button2 = getButton(xmlTemplateDocument, "button_accept", false);
339                 button3 = getButton(xmlTemplateDocument, "button_due", false);
340                 button4 = getButton(xmlTemplateDocument, "button_priority", false);
341                 button5 = getButton(xmlTemplateDocument, "button_comment", false);
342                 button6 = getButton(xmlTemplateDocument, "button_reakt", true);
343             } else {
344                 if (isEditor) {
345
346                     // this user is the editor for this task
347
button1 = getButton(xmlTemplateDocument, "button_query", false);
348                     button2 = getButton(xmlTemplateDocument, "button_forward", false);
349                     button3 = getButton(xmlTemplateDocument, "button_due", false);
350                     button4 = getButton(xmlTemplateDocument, "button_priority", false);
351                     button5 = getButton(xmlTemplateDocument, "button_comment", false);
352                     button6 = getButton(xmlTemplateDocument, "button_reakt", false);
353                 } else {
354                     if (isInRole) {
355
356                         // this user is in the role for this task
357
button1 = getButton(xmlTemplateDocument, "button_query", false);
358                         button2 = getButton(xmlTemplateDocument, "button_take", false);
359                         button3 = getButton(xmlTemplateDocument, "button_due", false);
360                         button4 = getButton(xmlTemplateDocument, "button_priority", false);
361                         button5 = getButton(xmlTemplateDocument, "button_comment", false);
362                         button6 = getButton(xmlTemplateDocument, "button_reakt", false);
363                     } else {
364
365                         // all other users
366
button1 = getButton(xmlTemplateDocument, "button_query", false);
367                         button2 = getButton(xmlTemplateDocument, "button_take", false);
368                         button3 = getButton(xmlTemplateDocument, "button_due", false);
369                         button4 = getButton(xmlTemplateDocument, "button_priority", false);
370                         button5 = getButton(xmlTemplateDocument, "button_comment", false);
371                         button6 = getButton(xmlTemplateDocument, "button_reakt", false);
372                     }
373                 }
374             }
375             if (timeout < now) {
376                 style = xmlTemplateDocument.getProcessedDataValue("style_ok", this);
377             } else {
378                 style = xmlTemplateDocument.getProcessedDataValue("style_ok", this);
379             }
380         } else {
381             if (task.getPercentage() == 0) {
382                 if (isOwner && isEditor) {
383
384                     // this is a task from me and for me
385
button1 = getButton(xmlTemplateDocument, "button_query", true);
386                     button2 = getButton(xmlTemplateDocument, "button_accept", true);
387                     button3 = getButton(xmlTemplateDocument, "button_due", true);
388                     button4 = getButton(xmlTemplateDocument, "button_priority", true);
389                     button5 = getButton(xmlTemplateDocument, "button_comment", true);
390                     button6 = getButton(xmlTemplateDocument, "button_ok", false);
391                 } else {
392                     if (isOwner) {
393
394                         // this is the owner of the task
395
button1 = getButton(xmlTemplateDocument, "button_message", true);
396                         button2 = getButton(xmlTemplateDocument, "button_forward", true);
397                         button3 = getButton(xmlTemplateDocument, "button_due", true);
398                         button4 = getButton(xmlTemplateDocument, "button_priority", true);
399                         button5 = getButton(xmlTemplateDocument, "button_comment", true);
400                         button6 = getButton(xmlTemplateDocument, "button_ok", false);
401                     } else {
402                         if (isEditor) {
403
404                             // this user is the editor for this task
405
button1 = getButton(xmlTemplateDocument, "button_query", true);
406                             button2 = getButton(xmlTemplateDocument, "button_accept", true);
407                             button3 = getButton(xmlTemplateDocument, "button_due", false);
408                             button4 = getButton(xmlTemplateDocument, "button_priority", false);
409                             button5 = getButton(xmlTemplateDocument, "button_comment", true);
410                             button6 = getButton(xmlTemplateDocument, "button_ok", false);
411                         } else {
412                             if (isInRole) {
413
414                                 // this user is in the role for this task
415
button1 = getButton(xmlTemplateDocument, "button_query", false);
416                                 button2 = getButton(xmlTemplateDocument, "button_take", true);
417                                 button3 = getButton(xmlTemplateDocument, "button_due", false);
418                                 button4 = getButton(xmlTemplateDocument, "button_priority", false);
419                                 button5 = getButton(xmlTemplateDocument, "button_comment", false);
420                                 button6 = getButton(xmlTemplateDocument, "button_ok", false);
421                             } else {
422
423                                 // all other users
424
button1 = getButton(xmlTemplateDocument, "button_query", false);
425                                 button2 = getButton(xmlTemplateDocument, "button_take", false);
426                                 button3 = getButton(xmlTemplateDocument, "button_due", false);
427                                 button4 = getButton(xmlTemplateDocument, "button_priority", false);
428                                 button5 = getButton(xmlTemplateDocument, "button_comment", false);
429                                 button6 = getButton(xmlTemplateDocument, "button_ok", false);
430                             }
431                         }
432                     }
433                 }
434                 if (timeout < now) {
435                     style = xmlTemplateDocument.getProcessedDataValue("style_alert", this);
436                 } else {
437                     style = xmlTemplateDocument.getProcessedDataValue("style_new", this);
438                 }
439             } else {
440                 if (isOwner && isEditor) {
441
442                     // this is a task from me and for me
443
button1 = getButton(xmlTemplateDocument, "button_query", true);
444                     button2 = getButton(xmlTemplateDocument, "button_forward", true);
445                     button3 = getButton(xmlTemplateDocument, "button_due", true);
446                     button4 = getButton(xmlTemplateDocument, "button_priority", true);
447                     button5 = getButton(xmlTemplateDocument, "button_comment", true);
448                     button6 = getButton(xmlTemplateDocument, "button_ok", true);
449                 } else {
450                     if (isOwner) {
451
452                         // this is the owner of the task
453
button1 = getButton(xmlTemplateDocument, "button_message", true);
454                         button2 = getButton(xmlTemplateDocument, "button_forward", true);
455                         button3 = getButton(xmlTemplateDocument, "button_due", true);
456                         button4 = getButton(xmlTemplateDocument, "button_priority", true);
457                         button5 = getButton(xmlTemplateDocument, "button_comment", true);
458                         button6 = getButton(xmlTemplateDocument, "button_ok", false);
459                     } else {
460                         if (isEditor) {
461
462                             // this user is the editor for this task
463
button1 = getButton(xmlTemplateDocument, "button_query", true);
464                             button2 = getButton(xmlTemplateDocument, "button_forward", true);
465                             button3 = getButton(xmlTemplateDocument, "button_due", false);
466                             button4 = getButton(xmlTemplateDocument, "button_priority", false);
467                             button5 = getButton(xmlTemplateDocument, "button_comment", true);
468                             button6 = getButton(xmlTemplateDocument, "button_ok", true);
469                         } else {
470                             if (isInRole) {
471
472                                 // this user is in the role for this task
473
button1 = getButton(xmlTemplateDocument, "button_query", false);
474                                 button2 = getButton(xmlTemplateDocument, "button_take", true);
475                                 button3 = getButton(xmlTemplateDocument, "button_due", false);
476                                 button4 = getButton(xmlTemplateDocument, "button_priority", false);
477                                 button5 = getButton(xmlTemplateDocument, "button_comment", false);
478                                 button6 = getButton(xmlTemplateDocument, "button_ok", false);
479                             } else {
480
481                                 // all other users
482
button1 = getButton(xmlTemplateDocument, "button_query", false);
483                                 button2 = getButton(xmlTemplateDocument, "button_take", false);
484                                 button3 = getButton(xmlTemplateDocument, "button_due", false);
485                                 button4 = getButton(xmlTemplateDocument, "button_priority", false);
486                                 button5 = getButton(xmlTemplateDocument, "button_comment", false);
487                                 button6 = getButton(xmlTemplateDocument, "button_ok", false);
488                             }
489                         }
490                     }
491                 }
492                 if (timeout < now) {
493                     style = xmlTemplateDocument.getProcessedDataValue("style_alert", this);
494                 } else {
495                     style = xmlTemplateDocument.getProcessedDataValue("style_activ", this);
496                 }
497             }
498         }
499
500         // get the processed list.
501
xmlTemplateDocument.setData("style", style);
502         xmlTemplateDocument.setData("priority", priority);
503         xmlTemplateDocument.setData("task", task.getName());
504         xmlTemplateDocument.setData("foruser", CmsUser.getFullName(editor));
505         xmlTemplateDocument.setData("forrole", roleName);
506         xmlTemplateDocument.setData("actuator", CmsUser.getFullName(owner));
507         xmlTemplateDocument.setData("due", due);
508         xmlTemplateDocument.setData("from", from);
509         xmlTemplateDocument.setData("project", projectname);
510
511         // now setting the buttons
512
xmlTemplateDocument.setData("button1", button1);
513         xmlTemplateDocument.setData("button2", button2);
514         xmlTemplateDocument.setData("button3", button3);
515         xmlTemplateDocument.setData("button4", button4);
516         xmlTemplateDocument.setData("button5", button5);
517         xmlTemplateDocument.setData("button6", button6);
518
519         // now check where to go back
520
if ((templateSelector == null || templateSelector == "") && lastUrl != null) {
521
522             // tasks either completed or aborted, go back
523
try {
524                 if (lastUrl.startsWith("http:")) {
525
526                     // complete path
527
CmsXmlTemplateLoader.getResponse(context).sendRedirect(lastUrl);
528                 } else {
529
530                     // relative to the opencms path
531
CmsXmlTemplateLoader.getResponse(context).sendCmsRedirect(lastUrl);
532                 }
533                 session.removeValue("lasturl");
534             } catch (IOException JavaDoc exc) {
535                 throw new CmsLegacyException("Could not redirect to " + lastUrl, exc);
536             }
537             return null;
538         }
539
540         // Now load the template file and start the processing
541
return startProcessing(cms, xmlTemplateDocument, elementName, parameters, templateSelector);
542     }
543
544     /**
545      * Indicates if the results of this class are cacheable.
546      *
547      * @param cms CmsObject Object for accessing system resources
548      * @param templateFile Filename of the template file
549      * @param elementName Element name of this template in our parent template.
550      * @param parameters Hashtable with all template class parameters.
551      * @param templateSelector template section that should be processed.
552      * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
553      */

554
555     public boolean isCacheable(
556         CmsObject cms,
557         String JavaDoc templateFile,
558         String JavaDoc elementName,
559         Hashtable JavaDoc parameters,
560         String JavaDoc templateSelector) {
561
562         return false;
563     }
564
565     /**
566      * This private helper method generates a string-representation of a button.
567      * @param xmlTemplateDocument The xml-document in which the buttons are defined.
568      * @param name The name of the button to generate.
569      * @param enabled True, if the button is enabled, else false.
570      * @return the string-representation of the button.
571      * @throws Throws CmsException, if something goes wrong.
572      */

573
574     private String JavaDoc getButton(CmsXmlWpTemplateFile xmlTemplateDocument, String JavaDoc name, boolean enabled)
575     throws CmsException {
576
577         if (enabled) {
578
579             // the button is enabled
580
xmlTemplateDocument.setData("disabled", "");
581         } else {
582
583             // the button is disabled
584
xmlTemplateDocument.setData("disabled", "disabled");
585         }
586
587         // return the generated button
588
return xmlTemplateDocument.getProcessedDataValue(name, this);
589     }
590 }
591
Popular Tags