@Test void testAddMissingMessageIds() { Set<String> messageIds = ImmutableSet.of("EN_PLUS_NL", "NEW"); @SuppressWarnings("unchecked") Query<L10nString> query = mock(Query.class, RETURNS_SELF); when(dataService.query(L10N_STRING, L10nString.class)).thenReturn(query); when(query.in(MSGID, messageIds).and().eq(NAMESPACE, "test").findAll()) .thenReturn(Stream.of(enPlusNl)); when(enPlusNl.getMessageID()).thenReturn("EN_PLUS_NL"); when(l10nStringFactory.create("NEW")).thenReturn(newString1); when(newString1.setMessageID("NEW")).thenReturn(newString1); when(newString1.setNamespace("test")).thenReturn(newString1); localizationService.addMissingMessageIds("test", messageIds); verify(dataService).add(eq(L10N_STRING), addCaptor.capture()); assertEquals(singleton(newString1), addCaptor.getValue().collect(toSet())); }
@Transactional public void addMissingMessageIds(String namespace, Set<String> messageIDs) { Set<String> alreadyPresent = getExistingMessages(namespace, messageIDs) .map(L10nString::getMessageID) .collect(toCollection(TreeSet::new)); Set<String> toAdd = Sets.difference(messageIDs, alreadyPresent); if (!toAdd.isEmpty()) { Stream<L10nString> entities = toAdd.stream() .map(key -> l10nStringFactory.create(key).setMessageID(key)) .map(l -> l.setNamespace(namespace)); dataService.add(L10N_STRING, entities); LOG.debug("Added message IDs to namespace '{}' : {}.", namespace, messageIDs); } }
LocalizationService implements MessageResolution { @Transactional public void addMissingMessageIds(String namespace, Set<String> messageIDs) { Set<String> alreadyPresent = getExistingMessages(namespace, messageIDs) .map(L10nString::getMessageID) .collect(toCollection(TreeSet::new)); Set<String> toAdd = Sets.difference(messageIDs, alreadyPresent); if (!toAdd.isEmpty()) { Stream<L10nString> entities = toAdd.stream() .map(key -> l10nStringFactory.create(key).setMessageID(key)) .map(l -> l.setNamespace(namespace)); dataService.add(L10N_STRING, entities); LOG.debug("Added message IDs to namespace '{}' : {}.", namespace, messageIDs); } } }
LocalizationService implements MessageResolution { @Transactional public void addMissingMessageIds(String namespace, Set<String> messageIDs) { Set<String> alreadyPresent = getExistingMessages(namespace, messageIDs) .map(L10nString::getMessageID) .collect(toCollection(TreeSet::new)); Set<String> toAdd = Sets.difference(messageIDs, alreadyPresent); if (!toAdd.isEmpty()) { Stream<L10nString> entities = toAdd.stream() .map(key -> l10nStringFactory.create(key).setMessageID(key)) .map(l -> l.setNamespace(namespace)); dataService.add(L10N_STRING, entities); LOG.debug("Added message IDs to namespace '{}' : {}.", namespace, messageIDs); } } LocalizationService(DataService dataService, L10nStringFactory l10nStringFactory); }
LocalizationService implements MessageResolution { @Transactional public void addMissingMessageIds(String namespace, Set<String> messageIDs) { Set<String> alreadyPresent = getExistingMessages(namespace, messageIDs) .map(L10nString::getMessageID) .collect(toCollection(TreeSet::new)); Set<String> toAdd = Sets.difference(messageIDs, alreadyPresent); if (!toAdd.isEmpty()) { Stream<L10nString> entities = toAdd.stream() .map(key -> l10nStringFactory.create(key).setMessageID(key)) .map(l -> l.setNamespace(namespace)); dataService.add(L10N_STRING, entities); LOG.debug("Added message IDs to namespace '{}' : {}.", namespace, messageIDs); } } LocalizationService(DataService dataService, L10nStringFactory l10nStringFactory); @Override @RunAsSystem String resolveCodeWithoutArguments(String code, Locale locale); @RunAsSystem Map<String, String> getMessages(String namespace, Locale locale); List<String> getAllMessageIds(); Stream<L10nString> getExistingMessages(String namespace, Set<String> messageIds); @Transactional void addMissingMessageIds(String namespace, Set<String> messageIDs); @Transactional void deleteNamespace(String namespace); void store(Collection<L10nString> toUpdate, Collection<L10nString> toAdd); }
LocalizationService implements MessageResolution { @Transactional public void addMissingMessageIds(String namespace, Set<String> messageIDs) { Set<String> alreadyPresent = getExistingMessages(namespace, messageIDs) .map(L10nString::getMessageID) .collect(toCollection(TreeSet::new)); Set<String> toAdd = Sets.difference(messageIDs, alreadyPresent); if (!toAdd.isEmpty()) { Stream<L10nString> entities = toAdd.stream() .map(key -> l10nStringFactory.create(key).setMessageID(key)) .map(l -> l.setNamespace(namespace)); dataService.add(L10N_STRING, entities); LOG.debug("Added message IDs to namespace '{}' : {}.", namespace, messageIDs); } } LocalizationService(DataService dataService, L10nStringFactory l10nStringFactory); @Override @RunAsSystem String resolveCodeWithoutArguments(String code, Locale locale); @RunAsSystem Map<String, String> getMessages(String namespace, Locale locale); List<String> getAllMessageIds(); Stream<L10nString> getExistingMessages(String namespace, Set<String> messageIds); @Transactional void addMissingMessageIds(String namespace, Set<String> messageIDs); @Transactional void deleteNamespace(String namespace); void store(Collection<L10nString> toUpdate, Collection<L10nString> toAdd);  }