@Test public void testGetMatchingTemplates_MatchesAll() throws Exception { String fileName = getClass().getClassLoader().getResource("mailTemplatesConfigurationMultipleMatchings.json").getFile(); when(templateConfigurations.getInputStream()).thenReturn(new FileInputStream(fileName)); List<EmailTemplateConfiguration> candidates = service.getMatchingTemplates("test@armedia.com", CASE_FILE, EmailSource.MANUAL, Arrays.asList(SEND_AS_ATTACHMENTS, SEND_AS_LINKS)); assertThat(candidates.size(), is(1)); assertThat(candidates, containsInAnyOrder(allOf(hasProperty("emailPattern", is(EMAIL_PATTERN + "@" + EMAIL_PATTERN + "\\.com")), hasProperty("source", is(EmailSource.MANUAL)), hasProperty("templateName", is(TEMPLATE_NAME + "_2")), hasProperty("objectTypes", containsInAnyOrder(CASE_FILE, COMPLAINT)), hasProperty("actions", containsInAnyOrder(SEND_AS_LINKS, SEND_AS_ATTACHMENTS))))); }
@Override public List<EmailTemplateConfiguration> getMatchingTemplates(String email, String objectType, EmailSource source, List<String> actions) throws AcmEmailConfigurationException { List<EmailTemplateConfiguration> configurations = getTemplateConfigurations(); Stream<EmailTemplateConfiguration> filteredConfigurations = configurations.stream() .filter(c -> c.getObjectTypes().contains(objectType)).filter(c -> c.getActions().containsAll(actions)) .filter(c -> c.getSource().equals(source)).filter(c -> matches(c.getEmailPattern(), email)); return filteredConfigurations.collect(Collectors.toList()); }
AcmFilesystemMailTemplateConfigurationService implements AcmMailTemplateConfigurationService { @Override public List<EmailTemplateConfiguration> getMatchingTemplates(String email, String objectType, EmailSource source, List<String> actions) throws AcmEmailConfigurationException { List<EmailTemplateConfiguration> configurations = getTemplateConfigurations(); Stream<EmailTemplateConfiguration> filteredConfigurations = configurations.stream() .filter(c -> c.getObjectTypes().contains(objectType)).filter(c -> c.getActions().containsAll(actions)) .filter(c -> c.getSource().equals(source)).filter(c -> matches(c.getEmailPattern(), email)); return filteredConfigurations.collect(Collectors.toList()); } }
AcmFilesystemMailTemplateConfigurationService implements AcmMailTemplateConfigurationService { @Override public List<EmailTemplateConfiguration> getMatchingTemplates(String email, String objectType, EmailSource source, List<String> actions) throws AcmEmailConfigurationException { List<EmailTemplateConfiguration> configurations = getTemplateConfigurations(); Stream<EmailTemplateConfiguration> filteredConfigurations = configurations.stream() .filter(c -> c.getObjectTypes().contains(objectType)).filter(c -> c.getActions().containsAll(actions)) .filter(c -> c.getSource().equals(source)).filter(c -> matches(c.getEmailPattern(), email)); return filteredConfigurations.collect(Collectors.toList()); }  }
AcmFilesystemMailTemplateConfigurationService implements AcmMailTemplateConfigurationService { @Override public List<EmailTemplateConfiguration> getMatchingTemplates(String email, String objectType, EmailSource source, List<String> actions) throws AcmEmailConfigurationException { List<EmailTemplateConfiguration> configurations = getTemplateConfigurations(); Stream<EmailTemplateConfiguration> filteredConfigurations = configurations.stream() .filter(c -> c.getObjectTypes().contains(objectType)).filter(c -> c.getActions().containsAll(actions)) .filter(c -> c.getSource().equals(source)).filter(c -> matches(c.getEmailPattern(), email)); return filteredConfigurations.collect(Collectors.toList()); }  @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 List<EmailTemplateConfiguration> getMatchingTemplates(String email, String objectType, EmailSource source, List<String> actions) throws AcmEmailConfigurationException { List<EmailTemplateConfiguration> configurations = getTemplateConfigurations(); Stream<EmailTemplateConfiguration> filteredConfigurations = configurations.stream() .filter(c -> c.getObjectTypes().contains(objectType)).filter(c -> c.getActions().containsAll(actions)) .filter(c -> c.getSource().equals(source)).filter(c -> matches(c.getEmailPattern(), email)); return filteredConfigurations.collect(Collectors.toList()); }  @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);  }