📄 cmstaskaction.java
字号:
/**
* Sends a message to the initiator (owner) of the task.
* @param cms The cms-object.
* @param int taskid The id of the task.
* @param message The text of the message.
* @throws CmsException Throws CmsExceptions, that are be
* thrown in calling methods.
*/
public static void query(CmsObject cms, int taskid, String message) throws CmsException {
CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);
CmsTaskService taskService = cms.getTaskService();
CmsTask task = taskService.readTask(taskid);
String comment = lang.getLanguageValue("task.dialog.query.head") + " ";
if ((message != null) && (message.length() != 0)) {
comment += CmsUser.getFullName(taskService.readOwner(task)) + "\n";
comment += message;
taskService.writeTaskLog(taskid, comment, CmsWorkplaceDefault.C_TASKLOGTYPE_CALL);
}
// send an email.
StringBuffer contentBuf = new StringBuffer(lang.getLanguageValue("task.email.query.content"));
contentBuf.append("\n");
contentBuf.append(lang.getLanguageValue("task.label.project"));
contentBuf.append(": ");
String projectname = "?";
try {
projectname = taskService.readTask(task.getRoot()).getName();
} catch (Exception exc) {
// no root?!
}
contentBuf.append(projectname);
contentBuf.append("\n");
contentBuf.append(lang.getLanguageValue("task.label.task"));
contentBuf.append(": ");
contentBuf.append(task.getName());
contentBuf.append("\n");
contentBuf.append(lang.getLanguageValue("task.label.editor"));
contentBuf.append(": ");
contentBuf.append(CmsUser.getFullName(taskService.readAgent(task)));
int projectid = taskService.readProject(task).getId();
contentBuf.append("\n\n\n" + getTaskUrl(cms, task.getId(), projectid));
contentBuf.append(addTaskText(task, taskService));
String subject = lang.getLanguageValue("task.email.query.subject")
+ " "
+ CmsUser.getFullName(taskService.readAgent(task));
CmsUser[] users = {taskService.readOwner(task)};
try {
CmsSimpleMail mail = createMail(taskService.readAgent(task), users, subject, contentBuf.toString());
new CmsMailTransport(mail).send();
} catch (Exception exc) {
if (CmsLog.getLog(CmsTaskAction.class).isWarnEnabled()) {
CmsLog.getLog(CmsTaskAction.class).warn("Error while sending task mail", exc);
}
}
}
/**
* Reaktivates a task.
* @param cms The cms-object.
* @param int taskid The id of the task.
* @param agentName The name of the new editor for this task.
* @param roleName The name of the new role for the user.
* @param taskName The new name of the task.
* @param taskcomment The new comment for this task.
* @param timeoutString The new timeout-date as a string in the following format:
* "dd.mm.yyyy"
* @param priorityString the new priority as String ("1" = high,
* "2" = normal or "3" = low)
* @param paraAcceptation controls if a message should be send by acceptation. ("checked" | "")
* @param paraAll controls if a message should be send to all users in a role. ("checked" | "")
* @param paraCompletion controls if a message should be send by completing this task. ("checked" | "")
* @param paraDelivery controls if a message should be send by delivering a task. ("checked" | "")
* @throws CmsException Throws CmsExceptions, that are be
* thrown in calling methods.
*/
public static void reakt(
CmsObject cms,
int taskid,
String agentName,
String roleName,
String taskName,
String taskcomment,
String timeoutString,
String priorityString,
String paraAcceptation,
String paraAll,
String paraCompletion,
String paraDelivery) throws CmsException {
CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);
CmsTaskService taskService = cms.getTaskService();
CmsTask task = taskService.readTask(taskid);
// TODO: CW: check effects of this
//if(roleName.equals(C_ALL_ROLES)) {
// roleName = cms.readUser(agentName).getDefaultGroup().getName();
//}
taskService.setName(taskid, taskName);
// try to reaktivate the task
taskService.reactivateTask(taskid);
int priority = Integer.parseInt(priorityString);
taskService.setPriority(taskid, priority);
// create a long from the overgiven date.
String splittetDate[] = CmsStringUtil.splitAsArray(timeoutString, '.');
GregorianCalendar cal = new GregorianCalendar(
Integer.parseInt(splittetDate[2]),
Integer.parseInt(splittetDate[1]) - 1,
Integer.parseInt(splittetDate[0]),
0,
0,
0);
long timeout = cal.getTime().getTime();
taskService.setTimeout(taskid, timeout);
taskService.setTaskPar(taskid, CmsWorkplaceDefault.C_TASKPARA_ACCEPTATION, paraAcceptation);
taskService.setTaskPar(taskid, CmsWorkplaceDefault.C_TASKPARA_ALL, paraAll);
taskService.setTaskPar(taskid, CmsWorkplaceDefault.C_TASKPARA_COMPLETION, paraCompletion);
taskService.setTaskPar(taskid, CmsWorkplaceDefault.C_TASKPARA_DELIVERY, paraDelivery);
taskService.forwardTask(taskid, roleName, agentName);
String comment = lang.getLanguageValue("task.label.forrole") + ": " + roleName + "\n";
comment += lang.getLanguageValue("task.label.editor")
+ ": "
+ CmsUser.getFullName(cms.readUser(agentName))
+ "\n";
comment += taskcomment;
taskService.writeTaskLog(task.getId(), comment, CmsWorkplaceDefault.C_TASKLOGTYPE_REACTIVATED);
// send an email
StringBuffer contentBuf = new StringBuffer(lang.getLanguageValue("task.email.reakt.content"));
contentBuf.append("\n");
contentBuf.append(lang.getLanguageValue("task.label.project"));
contentBuf.append(": ");
String projectname = "?";
try {
projectname = taskService.readTask(task.getRoot()).getName();
} catch (Exception exc) {
// no root?!
}
contentBuf.append(projectname);
contentBuf.append("\n");
contentBuf.append(lang.getLanguageValue("task.label.task"));
contentBuf.append(": ");
contentBuf.append(task.getName());
int projectid = taskService.readProject(task).getId();
contentBuf.append("\n\n\n" + getTaskUrl(cms, task.getId(), projectid));
String subject = lang.getLanguageValue("task.email.reakt.subject")
+ " "
+ CmsUser.getFullName(cms.readUser(task.getAgentUser()))
+ " / "
+ roleName;
CmsUser[] users = {taskService.readAgent(task)};
CmsSimpleMail mail;
mail = createMail(taskService.readOwner(task), users, subject, contentBuf.toString());
String sendToAll = taskService.getTaskPar(task.getId(), CmsWorkplaceDefault.C_TASKPARA_ALL);
if (!CmsStringUtil.isEmpty(sendToAll)) {
CmsGroup group = taskService.readGroup(task);
List groupUsers = cms.getUsersOfGroup(group.getName());
mail = createMail(taskService.readOwner(task), groupUsers, subject, contentBuf.toString(), true);
}
try {
new CmsMailTransport(mail).send();
} catch (Exception exc) {
if (CmsLog.getLog(CmsTaskAction.class).isWarnEnabled()) {
CmsLog.getLog(CmsTaskAction.class).warn("Error while sending task mail", exc);
}
}
}
/**
* Takes a task. The calling user is now the agent for this task.
* @param cms The cms-object.
* @param int taskid The id of the task.
* @throws CmsException Throws CmsExceptions, that are be
* thrown in calling methods.
*/
public static void take(CmsObject cms, int taskid) throws CmsException {
CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);
CmsRequestContext context = cms.getRequestContext();
CmsTaskService taskService = cms.getTaskService();
CmsTask task = taskService.readTask(taskid);
CmsUser newEditor = context.currentUser();
CmsGroup oldRole = taskService.readGroup(task);
// has the user the correct role?
if (cms.userInGroup(newEditor.getName(), oldRole.getName())) {
taskService.forwardTask(taskid, oldRole.getName(), newEditor.getName());
taskService.acceptTask(taskid);
String comment = lang.getLanguageValue("task.dialog.take.logmessage");
comment += " " + CmsUser.getFullName(newEditor);
taskService.writeTaskLog(taskid, comment, CmsWorkplaceDefault.C_TASKLOGTYPE_TAKE);
}
// send an email
StringBuffer contentBuf = new StringBuffer(lang.getLanguageValue("task.email.take.content"));
contentBuf.append("\n");
contentBuf.append(lang.getLanguageValue("task.label.project"));
contentBuf.append(": ");
String projectname = "?";
try {
projectname = taskService.readTask(task.getRoot()).getName();
} catch (Exception exc) {
// no root?!
}
contentBuf.append(projectname);
contentBuf.append("\n");
contentBuf.append(lang.getLanguageValue("task.label.task"));
contentBuf.append(": ");
contentBuf.append(task.getName());
contentBuf.append("\n");
contentBuf.append(lang.getLanguageValue("task.label.taskfor"));
contentBuf.append(": ");
contentBuf.append(CmsUser.getFullName(taskService.readAgent(task)));
int projectid = taskService.readProject(task).getId();
contentBuf.append("\n\n\n" + getTaskUrl(cms, task.getId(), projectid));
String subject = lang.getLanguageValue("task.email.take.subject") + " " + CmsUser.getFullName(newEditor);
CmsUser[] users = {taskService.readAgent(task)};
try {
CmsSimpleMail mail = createMail(taskService.readOwner(task), users, subject, contentBuf.toString());
new CmsMailTransport(mail).send();
} catch (Exception exc) {
if (CmsLog.getLog(CmsTaskAction.class).isWarnEnabled()) {
CmsLog.getLog(CmsTaskAction.class).warn("Error while sending task mail", exc);
}
}
}
/**
* Adds the message text to the generated mail text.<p>
* @param task the current task
* @param taskService the task log containing the task message
* @return StringBuffer containing the message texgt
* @throws CmsException if something goes wrong
*/
private static StringBuffer addTaskText(CmsTask task, CmsTaskService taskService) throws CmsException {
StringBuffer text = new StringBuffer();
if (OpenCms.getWorkplaceManager().isEnableWorkflowMessages()) {
text.append("\n\n\n");
List taskLog = taskService.readTaskLogs(task.getId());
if (taskLog != null && taskLog.size() > 0) {
CmsTaskLog log = (CmsTaskLog)taskLog.get(taskLog.size() - 1);
if (log != null) {
text.append(log.getComment());
}
}
}
return text;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -