cmstaskaction.java
来自「java 编写的程序」· Java 代码 · 共 771 行 · 第 1/3 页
JAVA
771 行
* Changes the priority of a task.
* @param cms The cms-object.
* @param int taskid The id of the task.
* @param priorityString the new priority as String ("1" = high,
* "2" = normal or "3" = low)
* @exception CmsException Throws CmsExceptions, that are be
* thrown in calling methods.
*/
public static void priority(CmsObject cms, int taskid, String priorityString) throws CmsException {
CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);
CmsTask task = cms.readTask(taskid);
int priority = Integer.parseInt(priorityString);
cms.setPriority(taskid, priority);
// add comment
String comment = "";
comment += lang.getLanguageValue("task.dialog.priority.logmessage1") + " ";
comment += lang.getLanguageValue("task.dialog.priority.logmessageprio" + task.getPriority()) + " ";
comment += lang.getLanguageValue("task.dialog.priority.logmessage2") + " ";
comment += lang.getLanguageValue("task.dialog.priority.logmessageprio" + priority) + " ";
cms.writeTaskLog(taskid, comment, C_TASKLOGTYPE_PRIORITYCHANGED);
}
/**
* 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.
* @exception 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);
CmsTask task = cms.readTask(taskid);
String comment = lang.getLanguageValue("task.dialog.query.head") + " ";
if((message != null) && (message.length() != 0)) {
comment += Utils.getFullName(cms.readOwner(task)) + "\n";
comment += message;
cms.writeTaskLog(taskid, comment, 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 = cms.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(Utils.getFullName(cms.readAgent(task)));
int projectid = cms.readProject(task).getId();
contentBuf.append("\n\n\n" + getTaskUrl(cms, task.getId(), projectid));
String subject = lang.getLanguageValue("task.email.query.subject") + " " + Utils.getFullName(cms.readAgent(task));
CmsUser[] users = {
cms.readOwner(task)
};
try {
com.opencms.defaults.CmsMail mail = new com.opencms.defaults.CmsMail(cms, cms.readAgent(task),
users, subject, contentBuf.toString(), "text/plain");
mail.start();
}
catch(Exception exc) {
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(I_CmsLogChannels.C_OPENCMS_INFO, "[CmsTaskAction] error while sending mail " + exc.getMessage());
}
}
}
/**
* 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" | "")
* @exception 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);
CmsTask task = cms.readTask(taskid);
if(roleName.equals(C_ALL_ROLES)) {
roleName = cms.readUser(agentName).getDefaultGroup().getName();
}
cms.setName(taskid, taskName);
// try to reaktivate the task
cms.reaktivateTask(taskid);
int priority = Integer.parseInt(priorityString);
cms.setPriority(taskid, priority);
// create a long from the overgiven date.
String splittetDate[] = Utils.split(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();
cms.setTimeout(taskid, timeout);
cms.setTaskPar(taskid, C_TASKPARA_ACCEPTATION, paraAcceptation);
cms.setTaskPar(taskid, C_TASKPARA_ALL, paraAll);
cms.setTaskPar(taskid, C_TASKPARA_COMPLETION, paraCompletion);
cms.setTaskPar(taskid, C_TASKPARA_DELIVERY, paraDelivery);
cms.forwardTask(taskid, roleName, agentName);
String comment = lang.getLanguageValue("task.label.forrole") + ": " + roleName + "\n";
comment += lang.getLanguageValue("task.label.editor") + ": " + Utils.getFullName(cms.readUser(agentName)) + "\n";
comment += taskcomment;
cms.writeTaskLog(task.getId(), comment, 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 = cms.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 = cms.readProject(task).getId();
contentBuf.append("\n\n\n" + getTaskUrl(cms, task.getId(), projectid));
String subject = lang.getLanguageValue("task.email.reakt.subject") + " " + Utils.getFullName(cms.readUser(task.getAgentUser())) + " / " + roleName;
CmsUser[] users = {
cms.readAgent(task)
};
com.opencms.defaults.CmsMail mail;
mail = new com.opencms.defaults.CmsMail(cms, cms.readOwner(task), users, subject, contentBuf.toString(), "text/plain");
// if "Alle Rollenmitglieder von Aufgabe Benachrichtigen" checkbox is selected.
if(cms.getTaskPar(task.getId(), C_TASKPARA_ALL) != null) {
mail = new com.opencms.defaults.CmsMail(cms, cms.readOwner(task), cms.readGroup(task),
subject, contentBuf.toString(), "text/plain");
}
try {
mail.start();
}
catch(Exception exc) {
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(I_CmsLogChannels.C_OPENCMS_INFO, "[CmsTaskAction] error while sending mail " + exc.getMessage());
}
}
}
/**
* 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.
* @exception 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();
CmsTask task = cms.readTask(taskid);
CmsUser newEditor = context.currentUser();
CmsGroup oldRole = cms.readGroup(task);
// has the user the correct role?
if(cms.userInGroup(newEditor.getName(), oldRole.getName())) {
cms.forwardTask(taskid, oldRole.getName(), newEditor.getName());
cms.acceptTask(taskid);
String comment = lang.getLanguageValue("task.dialog.take.logmessage");
comment += " " + Utils.getFullName(newEditor);
cms.writeTaskLog(taskid, comment, 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 = cms.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(Utils.getFullName(cms.readAgent(task)));
int projectid = cms.readProject(task).getId();
contentBuf.append("\n\n\n" + getTaskUrl(cms, task.getId(), projectid));
String subject = lang.getLanguageValue("task.email.take.subject") + " " + Utils.getFullName(newEditor);
CmsUser[] users = {
cms.readAgent(task)
};
try {
com.opencms.defaults.CmsMail mail = new com.opencms.defaults.CmsMail(cms, cms.readOwner(task),
users, subject, contentBuf.toString(), "text/plain");
mail.start();
}
catch(Exception exc) {
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(I_CmsLogChannels.C_OPENCMS_INFO, "[CmsTaskAction] error while sending mail " + exc.getMessage());
}
}
}
private static String getTaskUrl(CmsObject cms, int taskid, int projectid) throws CmsException {
String servletPath = cms.getRequestContext().getRequest().getServletUrl();
String serverName = ((HttpServletRequest)cms.getRequestContext().getRequest().getOriginalRequest()).getServerName();
int serverPort = ((HttpServletRequest)cms.getRequestContext().getRequest().getOriginalRequest()).getServerPort();
if(serverPort != 80) {
serverName += ":" + serverPort;
}
CmsXmlWpConfigFile conf = new CmsXmlWpConfigFile(cms);
String actionPath = conf.getWorkplaceActionPath();
return "http://" + serverName + servletPath + actionPath + "login.html?startTaskId="
+ taskid + "&startProjectId=" + projectid;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?