private void createFromTagNames(List<String> tagNames) { Set<String> existingNames = tagRepository.findByNames(tagNames).stream().map(Tag::getName).collect(Collectors.toSet()); Set<String> tagNamesToPersist = new HashSet<>(tagNames); tagNamesToPersist.removeAll(existingNames); if (!tagNamesToPersist.isEmpty()) { tagRepository.save(tagNamesToPersist.stream().map(Tag::new).collect(Collectors.toList())); } }
public List<Tag> searchTags(String queryString) { if (null == queryString || queryString.isEmpty()) { return Collections.emptyList(); } return tagRepository.searchByName(queryString); }
public List<Tag> listTags() { return toStream(tagRepository.findAll()).collect(Collectors.toList()); }
@Transactional public List<Tag> upsertTagDtos(List<TagDto> tags) { List<String> tagNames = tags.stream().map(TagDto::getName).collect(Collectors.toList()); createFromTagNames(tagNames); return tagRepository.findByNames(tagNames); }