Пример #1
0
 /**
  * Loads the details for a template
  *
  * @param objectID
  * @return
  */
 static String loadTemplateDef(Integer objectID) {
   List<LabelValueBean> localeList = LocaleHandler.getAvailableLocales();
   TMailTemplateDefBean mailTemplateDefBean = null;
   if (objectID != null) {
     mailTemplateDefBean = mailTemplateDefDAO.loadByPrimaryKey(objectID);
   }
   if (mailTemplateDefBean == null) {
     mailTemplateDefBean = new TMailTemplateDefBean();
     // set template to the first (template type is required, locale is not required)
     mailTemplateDefBean.setIsPlainEmailBool(false);
   }
   return MailTemplatesJSON.encodeMailTemplateDefJSON(mailTemplateDefBean, localeList);
 }
Пример #2
0
 /**
  * Saves a mail template
  *
  * @param copy
  * @param objectID
  * @param templateID
  * @param plain
  * @param theLocale
  * @param mailSubject
  * @param mailBody
  * @param locale
  * @return
  */
 static String saveTemplateDef(
     boolean copy,
     Integer templateID,
     Integer objectID,
     boolean plain,
     String theLocale,
     String mailSubject,
     String mailBody,
     Locale locale) {
   TMailTemplateDefBean mailTemplateDefBean = null;
   if (objectID != null && !copy) {
     LOGGER.info("Load by primary key=" + objectID.toString());
     mailTemplateDefBean = mailTemplateDefDAO.loadByPrimaryKey(objectID);
   }
   List<TMailTemplateDefBean> mailTemplates =
       mailTemplateDefDAO.loadByTemplateTypeAndLocale(templateID, plain, theLocale);
   if (mailTemplates != null && !mailTemplates.isEmpty()) {
     TMailTemplateDefBean existingMailTemplateBean = mailTemplates.get(0);
     LOGGER.info("Existing TemplateBean ID=" + existingMailTemplateBean.getObjectID().toString());
     if (objectID == null || copy || !existingMailTemplateBean.getObjectID().equals(objectID)) {
       return JSONUtility.encodeJSONFailure(
           LocalizeUtil.getLocalizedTextFromApplicationResources(
               "admin.customize.mailTemplate.err.existingTemplate", locale));
     }
   }
   if (mailTemplateDefBean == null) {
     mailTemplateDefBean = new TMailTemplateDefBean();
   }
   LOGGER.debug("setting data");
   mailTemplateDefBean.setMailTemplate(templateID);
   mailTemplateDefBean.setTheLocale(theLocale);
   mailTemplateDefBean.setIsPlainEmailBool(plain);
   mailTemplateDefBean.setMailSubject(mailSubject);
   mailTemplateDefBean.setMailBody(mailBody);
   mailTemplateDefBean.setTemplateChanged(BooleanFields.TRUE_VALUE); // mark it private
   mailTemplateDefDAO.save(mailTemplateDefBean);
   LOGGER.debug("saving data");
   return JSONUtility.encodeJSONSuccess();
 }
Пример #3
0
 public static String getExportFileName(List<Integer> mailTemplateDefIDList) {
   if (mailTemplateDefIDList.size() == 1) {
     TMailTemplateDefBean mailTemplateDefBean =
         mailTemplateDefDAO.loadByPrimaryKey(mailTemplateDefIDList.get(0));
     if (mailTemplateDefBean != null) {
       Integer mailTemplateID = mailTemplateDefBean.getMailTemplate();
       TMailTemplateBean mailTemplateBean = mailTemplateDAO.loadByPrimaryKey(mailTemplateID);
       String type = mailTemplateDefBean.isPlainEmail() ? "plain" : "HTML";
       return "MAIL_TMPL_DEF-"
           + mailTemplateBean.getName()
           + "_"
           + mailTemplateDefBean.getTheLocale()
           + "_"
           + type
           + ".xml";
     }
   }
   return "MailTemplateDefs.xml";
 }
Пример #4
0
 static List<TMailTemplateDefBean> getMailTemplateDefs(Integer templateID) {
   return mailTemplateDefDAO.loadByTemplate(templateID);
 }
Пример #5
0
 /**
  * Deletes a mail template
  *
  * @param objectID
  * @return
  */
 static void deleteTemplateDef(Integer objectID) {
   mailTemplateDefDAO.delete(objectID);
 }