Example #1
0
  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()));
    }
  }
Example #2
0
 public List<Tag> searchTags(String queryString) {
   if (null == queryString || queryString.isEmpty()) {
     return Collections.emptyList();
   }
   return tagRepository.searchByName(queryString);
 }
Example #3
0
 public List<Tag> listTags() {
   return toStream(tagRepository.findAll()).collect(Collectors.toList());
 }
Example #4
0
 @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);
 }