⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmstaskaction.java

📁 OpenCms 是一个J2EE的产品
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            } catch (Exception exc) {
                if (CmsLog.getLog(CmsTaskAction.class).isWarnEnabled()) {
                    CmsLog.getLog(CmsTaskAction.class).warn("Error while sending task mail", exc);
                }
            }
        }
    }

    /**
     * Forwards a task. The task is forwarded to a new editor in a new role.
     * @param cms The cms-object.
     * @param taskid The id of the task.
     * @param newEditorName The name of the new editor for this task.
     * @param newRoleName The name of the new role for the user.
     * @throws CmsException Throws CmsExceptions, that are be
     * thrown in calling methods.
     */

    public static void forward(CmsObject cms, int taskid, String newEditorName, String newRoleName) throws CmsException {

        CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);
        CmsUser newEditor = cms.readUser(newEditorName);
        // TODO: CW: check effects of this
        // if(newRoleName.equals(C_ALL_ROLES)) {
        //    newRoleName = cms.readUser(newEditorName).getDefaultGroup().getName();
        // }
        CmsGroup oldRole = cms.readGroup(newRoleName);
        CmsTaskService taskService = cms.getTaskService();
        taskService.forwardTask(taskid, oldRole.getName(), newEditor.getName());
        String comment = lang.getLanguageValue("task.dialog.forward.logmessage");
        comment += " " + CmsUser.getFullName(newEditor);
        taskService.writeTaskLog(taskid, comment, CmsWorkplaceDefault.C_TASKLOGTYPE_FORWARDED);

        // send an email if "Benachrichtigung bei Weiterleitung" was selected.
        CmsTask task = taskService.readTask(taskid);
        if (taskService.getTaskPar(task.getId(), CmsWorkplaceDefault.C_TASKPARA_DELIVERY) != null) {
            StringBuffer contentBuf = new StringBuffer(lang.getLanguageValue("task.email.forward.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.actuator"));
            contentBuf.append(": ");
            contentBuf.append(CmsUser.getFullName(taskService.readOwner(task)));
            contentBuf.append("\n");
            contentBuf.append(lang.getLanguageValue("task.label.taskfor"));
            contentBuf.append(": ");
            contentBuf.append(CmsUser.getFullName(taskService.readOriginalAgent(task)));
            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));
            String subject = lang.getLanguageValue("task.email.forward.subject")
                + " "
                + CmsUser.getFullName(cms.readUser(task.getAgentUser()))
                + " / "
                + newRoleName;

            // if "Alle Rollenmitglieder von Aufgabe Benachrichtigen" checkbox is selected.
            String sendToAll = taskService.getTaskPar(task.getId(), CmsWorkplaceDefault.C_TASKPARA_ALL);
            if (!CmsStringUtil.isEmpty(sendToAll)) {
                try {
                    CmsGroup group = taskService.readGroup(task);
                    List users = cms.getUsersOfGroup(group.getName());
                    CmsSimpleMail mail = createMail(
                        cms.getRequestContext().currentUser(),
                        users,
                        subject,
                        contentBuf.toString(),
                        true);
                    new CmsMailTransport(mail).send();
                } catch (Exception exc) {
                    if (CmsLog.getLog(CmsTaskAction.class).isWarnEnabled()) {
                        CmsLog.getLog(CmsTaskAction.class).warn("Error while sending task mail", exc);
                    }
                }
            } else {

                // send a mail to user
                CmsUser[] user = {taskService.readAgent(task)};
                try {
                    CmsSimpleMail mail1 = createMail(
                        cms.getRequestContext().currentUser(),
                        user,
                        subject,
                        contentBuf.toString());
                    new CmsMailTransport(mail1).send();
                } catch (Exception exc) {
                    if (CmsLog.getLog(CmsTaskAction.class).isWarnEnabled()) {
                        CmsLog.getLog(CmsTaskAction.class).warn("Error while sending task mail", exc);
                    }
                }

                // send a mail to owner
                CmsUser[] owner = {taskService.readOwner(task)};
                try {
                    CmsSimpleMail mail2 = createMail(
                        cms.getRequestContext().currentUser(),
                        owner,
                        subject,
                        contentBuf.toString());
                    new CmsMailTransport(mail2).send();
                } catch (Exception exc) {
                    if (CmsLog.getLog(CmsTaskAction.class).isWarnEnabled()) {
                        CmsLog.getLog(CmsTaskAction.class).warn("Error while sending task mail", exc);
                    }
                }
            }
        }
    }

    /**
     * Gets the description of a task.
     * The description is stored in the task-log.
     * @param cms The cms-object.
     * @param int taskid The id of the task.
     * @return String the comment-string.
     * @throws CmsException Throws CmsExceptions, that are be
     * thrown in calling methods.
     */

    public static String getDescription(CmsObject cms, int taskid) throws CmsException {

        StringBuffer retValue = new StringBuffer("");
        CmsTaskLog tasklog;
        List taskdocs = cms.getTaskService().readTaskLogs(taskid);

        // go through all tasklogs to find the comment
        for (int i = 1; i <= taskdocs.size(); i++) {
            tasklog = (CmsTaskLog)taskdocs.get(taskdocs.size() - i);
            int type = tasklog.getType();

            // check if this is a type "created" or "new"
            if ((type == CmsWorkplaceDefault.C_TASKLOGTYPE_CREATED)
                || (type == CmsWorkplaceDefault.C_TASKLOGTYPE_REACTIVATED)) {
                String comment[] = CmsStringUtil.splitAsArray(tasklog.getComment(), '\n');
                for (int j = 2; j < comment.length; j++) {
                    retValue.append(comment[j] + "\n");
                }
                break;
            }
        }
        return retValue.toString();
    }

    public static String getTaskUrl(CmsObject cms, int taskid, int projectid) {

        String frameLink = OpenCms.getLinkManager().substituteLink(cms, CmsFrameset.JSP_WORKPLACE_URI);
        String taskViewLink = OpenCms.getLinkManager().substituteLink(
            cms,
            CmsWorkplaceAction.PATH_XML_WORKPLACE + "tasks.html")
            + "%3Ftaskid%3D"
            + taskid;

        return OpenCms.getSiteManager().getWorkplaceSiteMatcher().toString()
            + frameLink
            + "?"
            + CmsFrameset.PARAM_WP_VIEW
            + "="
            + taskViewLink;
    }

    /**
     * Sends a message to the editor 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 message(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.message.head") + " ";
        if ((message != null) && (message.length() != 0)) {
            comment += CmsUser.getFullName(taskService.readAgent(task)) + "\n";
            comment += message;
            taskService.writeTaskLog(taskid, comment, CmsWorkplaceDefault.C_TASKLOGTYPE_CALL);
        }

        // send an email
        StringBuffer contentBuf = new StringBuffer(lang.getLanguageValue("task.email.message.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.actuator"));
        contentBuf.append(": ");
        contentBuf.append(CmsUser.getFullName(taskService.readOwner(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.message.subject")
            + " "
            + CmsUser.getFullName(taskService.readOwner(task));
        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);
            }
        }
    }

    /**
     * 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)
     * @throws 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);
        CmsTaskService taskService = cms.getTaskService();
        CmsTask task = taskService.readTask(taskid);
        int priority = Integer.parseInt(priorityString);
        taskService.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) + " ";
        taskService.writeTaskLog(taskid, comment, CmsWorkplaceDefault.C_TASKLOGTYPE_PRIORITYCHANGED);
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -