public void saveTemplate(EmailTemplate template) { // check that fields are set if (template == null) { throw new IllegalArgumentException("Template can't be null"); } if (template.getKey() == null) { throw new IllegalArgumentException("Template key can't be null"); } if (template.getOwner() == null) { throw new IllegalArgumentException("Template owner can't be null"); } if (template.getSubject() == null) { throw new IllegalArgumentException("Template subject can't be null"); } if (template.getMessage() == null) { throw new IllegalArgumentException("Template message can't be null"); } String locale = template.getLocale(); if (locale == null || locale.trim().length() == 0) { // For backward compatibility set it to default template.setLocale(EmailTemplate.DEFAULT_LOCALE); } // update the modified date template.setLastModified(new Date()); try { dao.save(template); } catch (DataIntegrityViolationException die) { throw new IllegalArgumentException( "Key: " + template.getKey() + " and locale: " + template.getLocale() + " in use already", die); } log.info("saved template: " + template.getId()); }