class 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();
            }
        }
    }

}