/**
  * 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);
 }
 /**
  * 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();
 }
 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";
 }
 static List<TMailTemplateDefBean> getMailTemplateDefs(Integer templateID) {
   return mailTemplateDefDAO.loadByTemplate(templateID);
 }
 /**
  * Deletes a mail template
  *
  * @param objectID
  * @return
  */
 static void deleteTemplateDef(Integer objectID) {
   mailTemplateDefDAO.delete(objectID);
 }