@Test public void test_should_return_messages_filtered_by_module_name() { String tenantId = "a.b.c"; final Tenant defaultTenant = new Tenant(Tenant.DEFAULT_TENANT); final MessageIdentity messageIdentity1 = MessageIdentity.builder() .code("code1") .locale(ENGLISH_INDIA) .module("module1") .tenant(defaultTenant) .build(); Message defaultMessage1 = Message.builder() .messageIdentity(messageIdentity1) .message("default message1") .build(); final MessageIdentity messageIdentity2 = MessageIdentity.builder() .code("code2") .locale(ENGLISH_INDIA) .module("module2") .tenant(defaultTenant) .build(); Message defaultMessage2 = Message.builder() .messageIdentity(messageIdentity2) .message("default message2") .build(); List<Message> expectedMessages = Arrays.asList(defaultMessage1, defaultMessage2); when(messageCacheRepository.getComputedMessages(MR_IN, new Tenant(tenantId))) .thenReturn(expectedMessages); final MessageSearchCriteria searchCriteria = MessageSearchCriteria.builder() .locale(MR_IN) .tenantId(new Tenant(tenantId)) .module("module1") .build(); List<Message> actualMessages = messageService.getFilteredMessages(searchCriteria); assertEquals(0, actualMessages.size()); }
public List<Message> getFilteredMessages(MessageSearchCriteria searchCriteria) { List<Message> messages = getMessages(searchCriteria); if (searchCriteria.isModuleAbsent()) { return messages.parallelStream() .filter(e -> e.getLocale().equals(searchCriteria.getLocale()) && e.getTenant().equals(searchCriteria.getTenantId().getTenantId())) .collect(Collectors.toList()); } else { List<String> modules = Arrays.asList(searchCriteria.getModule().split("[,]")); messages = messages.stream() .filter(message -> modules.contains(message.getModule()) && message.getLocale().equals(searchCriteria.getLocale()) && message.getTenant().equals(searchCriteria.getTenantId().getTenantId())) .collect(Collectors.toList()); } return messages; }
MessageService { public List<Message> getFilteredMessages(MessageSearchCriteria searchCriteria) { List<Message> messages = getMessages(searchCriteria); if (searchCriteria.isModuleAbsent()) { return messages.parallelStream() .filter(e -> e.getLocale().equals(searchCriteria.getLocale()) && e.getTenant().equals(searchCriteria.getTenantId().getTenantId())) .collect(Collectors.toList()); } else { List<String> modules = Arrays.asList(searchCriteria.getModule().split("[,]")); messages = messages.stream() .filter(message -> modules.contains(message.getModule()) && message.getLocale().equals(searchCriteria.getLocale()) && message.getTenant().equals(searchCriteria.getTenantId().getTenantId())) .collect(Collectors.toList()); } return messages; } }
MessageService { public List<Message> getFilteredMessages(MessageSearchCriteria searchCriteria) { List<Message> messages = getMessages(searchCriteria); if (searchCriteria.isModuleAbsent()) { return messages.parallelStream() .filter(e -> e.getLocale().equals(searchCriteria.getLocale()) && e.getTenant().equals(searchCriteria.getTenantId().getTenantId())) .collect(Collectors.toList()); } else { List<String> modules = Arrays.asList(searchCriteria.getModule().split("[,]")); messages = messages.stream() .filter(message -> modules.contains(message.getModule()) && message.getLocale().equals(searchCriteria.getLocale()) && message.getTenant().equals(searchCriteria.getTenantId().getTenantId())) .collect(Collectors.toList()); } return messages; } MessageService(MessageRepository messageRepository, MessageCacheRepository messageCacheRepository); }
MessageService { public List<Message> getFilteredMessages(MessageSearchCriteria searchCriteria) { List<Message> messages = getMessages(searchCriteria); if (searchCriteria.isModuleAbsent()) { return messages.parallelStream() .filter(e -> e.getLocale().equals(searchCriteria.getLocale()) && e.getTenant().equals(searchCriteria.getTenantId().getTenantId())) .collect(Collectors.toList()); } else { List<String> modules = Arrays.asList(searchCriteria.getModule().split("[,]")); messages = messages.stream() .filter(message -> modules.contains(message.getModule()) && message.getLocale().equals(searchCriteria.getLocale()) && message.getTenant().equals(searchCriteria.getTenantId().getTenantId())) .collect(Collectors.toList()); } return messages; } MessageService(MessageRepository messageRepository, MessageCacheRepository messageCacheRepository); void upsert(Tenant tenant, List<Message> messages, AuthenticatedUser user); void create(Tenant tenant, List<Message> messages, AuthenticatedUser user); void updateMessagesForModule(Tenant tenant, List<Message> messages, AuthenticatedUser user); void bustCache(); List<Message> getFilteredMessages(MessageSearchCriteria searchCriteria); void delete(List<MessageIdentity> messageIdentities); }
MessageService { public List<Message> getFilteredMessages(MessageSearchCriteria searchCriteria) { List<Message> messages = getMessages(searchCriteria); if (searchCriteria.isModuleAbsent()) { return messages.parallelStream() .filter(e -> e.getLocale().equals(searchCriteria.getLocale()) && e.getTenant().equals(searchCriteria.getTenantId().getTenantId())) .collect(Collectors.toList()); } else { List<String> modules = Arrays.asList(searchCriteria.getModule().split("[,]")); messages = messages.stream() .filter(message -> modules.contains(message.getModule()) && message.getLocale().equals(searchCriteria.getLocale()) && message.getTenant().equals(searchCriteria.getTenantId().getTenantId())) .collect(Collectors.toList()); } return messages; } MessageService(MessageRepository messageRepository, MessageCacheRepository messageCacheRepository); void upsert(Tenant tenant, List<Message> messages, AuthenticatedUser user); void create(Tenant tenant, List<Message> messages, AuthenticatedUser user); void updateMessagesForModule(Tenant tenant, List<Message> messages, AuthenticatedUser user); void bustCache(); List<Message> getFilteredMessages(MessageSearchCriteria searchCriteria); void delete(List<MessageIdentity> messageIdentities);  }