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

📄 cmstaskaction.java

📁 OpenCms 是一个J2EE的产品
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            // 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.create.subject")
            + " "
            + CmsUser.getFullName(cms.readUser(task.getAgentUser()))
            + " / "
            + roleName;
        CmsUser[] users = {taskService.readAgent(task)};
        CmsSimpleMail mail = null;
        try {
            mail = createMail(taskService.readOwner(task), users, subject, contentBuf.toString());
        } catch (CmsException e) {
            if (CmsLog.getLog(CmsTaskAction.class).isWarnEnabled()) {
                CmsLog.getLog(CmsTaskAction.class).warn(
                    "Could not generate mail while creating task for " + taskService.readOwner(task).getName(),
                    e);
            }
        }

        // if "Alle Rollenmitglieder von Aufgabe Benachrichtigen" checkbox is selected.
        if (taskService.getTaskPar(task.getId(), CmsWorkplaceDefault.C_TASKPARA_ALL) != null) {

            // the news deliver always "checked" or ""
            if (taskService.getTaskPar(task.getId(), CmsWorkplaceDefault.C_TASKPARA_ALL).equals("checked")) {
                try {
                    CmsGroup group = taskService.readGroup(task);
                    List groupUser = cms.getUsersOfGroup(group.getName());
                    mail = createMail(taskService.readOwner(task), groupUser, subject, contentBuf.toString(), true);
                } catch (CmsException e) {
                    if (CmsLog.getLog(CmsTaskAction.class).isWarnEnabled()) {
                        CmsLog.getLog(CmsTaskAction.class).warn(
                            "Could not generate mail while creating task for " + taskService.readOwner(task).getName(),
                            e);
                    }
                }
            }
        }
        if (mail != null) {
            new CmsMailTransport(mail).send();
        }
    }

    /**
     * Helper method to create an email object.<p>
     * 
     * @param from the mail sender
     * @param to the mail receivers
     * @param subject the mail subject
     * @param content the mail content
     * @return the mail object to send
     * @throws CmsException if creating the mail object fails
     */
    public static CmsSimpleMail createMail(CmsUser from, CmsUser[] to, String subject, String content)
    throws CmsException {

        Vector v = new Vector(to.length);
        for (int i = 0; i < to.length; i++) {
            if (to[i].getEmail() == null) {
                continue;
            }
            if (to[i].getEmail().equals("")) {
                continue;
            }
            if (to[i].getEmail().indexOf("@") == -1 || to[i].getEmail().indexOf(".") == -1) {
                throw new CmsLegacyException("["
                    + CmsTaskAction.class.getName()
                    + "] "
                    + "Error in sending email, Invalid recipient email address: "
                    + to[i].getEmail(), CmsLegacyException.C_BAD_NAME);
            }
            try {
                v.addElement(new InternetAddress(to[i].getEmail()));
            } catch (AddressException e) {
                throw new CmsLegacyException("["
                    + CmsTaskAction.class.getName()
                    + "] "
                    + "Error in sending email, Invalid recipient email address: "
                    + to[i].getEmail(), CmsLegacyException.C_BAD_NAME);
            }
        }

        if (v.size() == 0) {
            throw new CmsLegacyException("["
                + CmsTaskAction.class.getName()
                + "] "
                + "Error in sending email,Unknown recipient email address.", CmsLegacyException.C_BAD_NAME);
        }
        return createMail(from, v, subject, content, false);
    }

    /**
     * Helper method to create an email object.<p>
     * @param from the mail sender
     * @param to the mail receivers
     * @param subject the mail subject
     * @param content the mail content
     * @param createAddresses if true, the Vector of receivers contains CmsUsers and they are transformed into Internetaddresses
     * 
     * @return the mail object to send
     * @throws CmsException if creating the mail object fails
     */
    public static CmsSimpleMail createMail(
        CmsUser from,
        List to,
        String subject,
        String content,
        boolean createAddresses) throws CmsException {

        CmsSimpleMail mail = new CmsSimpleMail();
        //      check sender email address
        String fromAddress = from.getEmail();
        if (fromAddress == null || fromAddress.equals("")) {
            fromAddress = OpenCms.getSystemInfo().getMailSettings().getMailFromDefault();
        }
        if (fromAddress == null || fromAddress.equals("")) {
            throw new CmsLegacyException("["
                + CmsTaskAction.class.getName()
                + "] "
                + "Error in sending email,Unknown sender email address.", CmsLegacyException.C_BAD_NAME);
        }
        if (fromAddress.indexOf("@") == -1 || fromAddress.indexOf(".") == -1) {
            throw new CmsLegacyException("["
                + CmsTaskAction.class.getName()
                + "] "
                + "Error in sending email,Unknown sender email address: "
                + fromAddress, CmsLegacyException.C_BAD_NAME);
        }

        if (to.size() == 0) {
            throw new CmsLegacyException("["
                + CmsTaskAction.class.getName()
                + "] "
                + "Error in sending email,Unknown recipient email address.", CmsLegacyException.C_BAD_NAME);
        } else if (createAddresses) {
            List receivers = new ArrayList(to.size());
            for (int i = 0; i < to.size(); i++) {
                CmsUser rec = (CmsUser)to.get(i);
                try {
                    receivers.add(new InternetAddress(rec.getEmail()));
                } catch (AddressException e) {
                    throw new CmsLegacyException("["
                        + CmsTaskAction.class.getName()
                        + "] "
                        + "Error in sending email, invalid recipient email address.", CmsLegacyException.C_BAD_NAME);
                }
            }
            mail.setTo(receivers);
        } else {
            mail.setTo(to);
        }
        try {
            mail.setFrom(fromAddress);
        } catch (MessagingException e) {
            throw new CmsLegacyException("["
                + CmsTaskAction.class.getName()
                + "] "
                + "Error in sending email, invalid sender email address.", CmsLegacyException.C_BAD_NAME);
        }
        mail.setSubject(subject == null ? "" : subject);
        mail.setMsg(content == null ? "" : content);
        return mail;
    }

    /**
     * Changes the timeou-date of the task.
     * @param cms The cms-object.
     * @param int taskid The id of the task.
     * @param timeoutString The new timeout-date as a string in the following format:
     * "dd.mm.yyyy"
     * @throws CmsException Throws CmsExceptions, that are be
     * thrown in calling methods.
     */

    public static void due(CmsObject cms, int taskid, String timeoutString) throws CmsException {

        CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);
        CmsTaskService taskService = cms.getTaskService();
        CmsTask task = taskService.readTask(taskid);
        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);

        // add comment
        String comment = "";
        comment += lang.getLanguageValue("task.dialog.due.logmessage1") + " ";
        comment += CmsDateUtil.getDateShort(task.getTimeOut().getTime()) + " ";
        comment += lang.getLanguageValue("task.dialog.due.logmessage2") + " ";
        comment += CmsDateUtil.getDateShort(timeout);
        taskService.writeTaskLog(taskid, comment, CmsWorkplaceDefault.C_TASKLOGTYPE_DUECHANGED);
    }

    /**
     * Ends a 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 end(CmsObject cms, int taskid) throws CmsException {

        CmsTaskService taskService = cms.getTaskService();
        taskService.endTask(taskid);
        String comment = "";
        taskService.writeTaskLog(taskid, comment, CmsWorkplaceDefault.C_TASKLOGTYPE_OK);

        // send an email if "Benachrichtigung bei Abhacken" was selected.
        CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);
        CmsTask task = taskService.readTask(taskid);
        if (taskService.getTaskPar(task.getId(), CmsWorkplaceDefault.C_TASKPARA_COMPLETION) != null) {
            StringBuffer contentBuf = new StringBuffer(lang.getLanguageValue("task.email.end.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.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.end.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();

⌨️ 快捷键说明

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