@Test @Ignore public void testDeleteTemplate() { fail("Not implemented due to interaction with the filesystem."); }
@Override public void deleteTemplate(String templateName) throws AcmEmailConfigurationException { List<EmailTemplateConfiguration> configurations = getTemplateConfigurations(); if (configurations.removeIf(c -> c.getTemplateName().equals(templateName))) { File templateFolder = getTemplateFolder(); File templateFile = new File(templateFolder, templateName); Lock writeLock = lock.writeLock(); writeLock.lock(); try (OutputStream os = getTemplateResourceOutputStream()) { String configurationsString = getObjectConverter().getJsonMarshaller().marshal(configurations); if (configurationsString == null) { log.warn("Error while deleting email templates configuration from {} file.", templateConfigurations.getDescription(), null); throw new AcmEmailConfigurationJsonException( String.format("Error while deleting email templates configuration from %s file.", templateConfigurations.getDescription()), null); } os.write(configurationsString.getBytes(StandardCharsets.UTF_8)); Files.deleteIfExists(templateFile.toPath()); } catch (IOException e) { log.warn("Error while deleting {} email template from the file system.", templateName, e); throw new AcmEmailConfigurationIOException( String.format("Error while deleting %s email template from the file system.", templateName), e); } finally { writeLock.unlock(); } } }
AcmFilesystemMailTemplateConfigurationService implements AcmMailTemplateConfigurationService { @Override public void deleteTemplate(String templateName) throws AcmEmailConfigurationException { List<EmailTemplateConfiguration> configurations = getTemplateConfigurations(); if (configurations.removeIf(c -> c.getTemplateName().equals(templateName))) { File templateFolder = getTemplateFolder(); File templateFile = new File(templateFolder, templateName); Lock writeLock = lock.writeLock(); writeLock.lock(); try (OutputStream os = getTemplateResourceOutputStream()) { String configurationsString = getObjectConverter().getJsonMarshaller().marshal(configurations); if (configurationsString == null) { log.warn("Error while deleting email templates configuration from {} file.", templateConfigurations.getDescription(), null); throw new AcmEmailConfigurationJsonException( String.format("Error while deleting email templates configuration from %s file.", templateConfigurations.getDescription()), null); } os.write(configurationsString.getBytes(StandardCharsets.UTF_8)); Files.deleteIfExists(templateFile.toPath()); } catch (IOException e) { log.warn("Error while deleting {} email template from the file system.", templateName, e); throw new AcmEmailConfigurationIOException( String.format("Error while deleting %s email template from the file system.", templateName), e); } finally { writeLock.unlock(); } } } }
AcmFilesystemMailTemplateConfigurationService implements AcmMailTemplateConfigurationService { @Override public void deleteTemplate(String templateName) throws AcmEmailConfigurationException { List<EmailTemplateConfiguration> configurations = getTemplateConfigurations(); if (configurations.removeIf(c -> c.getTemplateName().equals(templateName))) { File templateFolder = getTemplateFolder(); File templateFile = new File(templateFolder, templateName); Lock writeLock = lock.writeLock(); writeLock.lock(); try (OutputStream os = getTemplateResourceOutputStream()) { String configurationsString = getObjectConverter().getJsonMarshaller().marshal(configurations); if (configurationsString == null) { log.warn("Error while deleting email templates configuration from {} file.", templateConfigurations.getDescription(), null); throw new AcmEmailConfigurationJsonException( String.format("Error while deleting email templates configuration from %s file.", templateConfigurations.getDescription()), null); } os.write(configurationsString.getBytes(StandardCharsets.UTF_8)); Files.deleteIfExists(templateFile.toPath()); } catch (IOException e) { log.warn("Error while deleting {} email template from the file system.", templateName, e); throw new AcmEmailConfigurationIOException( String.format("Error while deleting %s email template from the file system.", templateName), e); } finally { writeLock.unlock(); } } }  }
AcmFilesystemMailTemplateConfigurationService implements AcmMailTemplateConfigurationService { @Override public void deleteTemplate(String templateName) throws AcmEmailConfigurationException { List<EmailTemplateConfiguration> configurations = getTemplateConfigurations(); if (configurations.removeIf(c -> c.getTemplateName().equals(templateName))) { File templateFolder = getTemplateFolder(); File templateFile = new File(templateFolder, templateName); Lock writeLock = lock.writeLock(); writeLock.lock(); try (OutputStream os = getTemplateResourceOutputStream()) { String configurationsString = getObjectConverter().getJsonMarshaller().marshal(configurations); if (configurationsString == null) { log.warn("Error while deleting email templates configuration from {} file.", templateConfigurations.getDescription(), null); throw new AcmEmailConfigurationJsonException( String.format("Error while deleting email templates configuration from %s file.", templateConfigurations.getDescription()), null); } os.write(configurationsString.getBytes(StandardCharsets.UTF_8)); Files.deleteIfExists(templateFile.toPath()); } catch (IOException e) { log.warn("Error while deleting {} email template from the file system.", templateName, e); throw new AcmEmailConfigurationIOException( String.format("Error while deleting %s email template from the file system.", templateName), e); } finally { writeLock.unlock(); } } }  @Override List<EmailTemplateConfiguration> getTemplateConfigurations(); void setTemplateConfigurations(Resource templateConfigurations); @Override EmailTemplateValidationResponse validateEmailTemplate(EmailTemplateConfiguration templateData); @Override void updateEmailTemplate(EmailTemplateConfiguration templateData, MultipartFile template); @Override List<EmailTemplateConfiguration> getMatchingTemplates(String email, String objectType, EmailSource source, List<String> actions); @Override String getTemplate(String templateName); @Override void deleteTemplate(String templateName); @Override AcmEmailServiceExceptionMapper<ME> getExceptionMapper(AcmEmailServiceException e); void setTemplateFolderPath(String templateFolderPath); ObjectConverter getObjectConverter(); void setObjectConverter(ObjectConverter objectConverter); }
AcmFilesystemMailTemplateConfigurationService implements AcmMailTemplateConfigurationService { @Override public void deleteTemplate(String templateName) throws AcmEmailConfigurationException { List<EmailTemplateConfiguration> configurations = getTemplateConfigurations(); if (configurations.removeIf(c -> c.getTemplateName().equals(templateName))) { File templateFolder = getTemplateFolder(); File templateFile = new File(templateFolder, templateName); Lock writeLock = lock.writeLock(); writeLock.lock(); try (OutputStream os = getTemplateResourceOutputStream()) { String configurationsString = getObjectConverter().getJsonMarshaller().marshal(configurations); if (configurationsString == null) { log.warn("Error while deleting email templates configuration from {} file.", templateConfigurations.getDescription(), null); throw new AcmEmailConfigurationJsonException( String.format("Error while deleting email templates configuration from %s file.", templateConfigurations.getDescription()), null); } os.write(configurationsString.getBytes(StandardCharsets.UTF_8)); Files.deleteIfExists(templateFile.toPath()); } catch (IOException e) { log.warn("Error while deleting {} email template from the file system.", templateName, e); throw new AcmEmailConfigurationIOException( String.format("Error while deleting %s email template from the file system.", templateName), e); } finally { writeLock.unlock(); } } }  @Override List<EmailTemplateConfiguration> getTemplateConfigurations(); void setTemplateConfigurations(Resource templateConfigurations); @Override EmailTemplateValidationResponse validateEmailTemplate(EmailTemplateConfiguration templateData); @Override void updateEmailTemplate(EmailTemplateConfiguration templateData, MultipartFile template); @Override List<EmailTemplateConfiguration> getMatchingTemplates(String email, String objectType, EmailSource source, List<String> actions); @Override String getTemplate(String templateName); @Override void deleteTemplate(String templateName); @Override AcmEmailServiceExceptionMapper<ME> getExceptionMapper(AcmEmailServiceException e); void setTemplateFolderPath(String templateFolderPath); ObjectConverter getObjectConverter(); void setObjectConverter(ObjectConverter objectConverter);  }