public TagUI create(TagUI uiBean, Principal principal) { Tag newTag = tMapper.toPersistenceBean(uiBean); User user = userRepo.findByUserName(principal.getName()); if (user != null) { newTag.setCreatedBy(user); } newTag.setCreatedDate(Calendar.getInstance().getTime()); newTag = tagRepo.save(newTag); logger.debug(newTag); return tMapper.toUIBean(newTag); }
private void addTags(Question question) { for (String tagName : question.getTags()) { Tag existingTag = tagRepo.findByName(tagName); if (existingTag != null) { Query q = new Query(Criteria.where("id").is(existingTag.getId())); template.updateFirst( q, new Update().push("questions", question.getId()).inc("questionCount", 1), Tag.class); } else { Tag newTag = new Tag(); newTag.setName(tagName); newTag.setCreatedBy(question.getCreatedBy()); newTag.setCreatedDate(Calendar.getInstance().getTime()); newTag.setQuestionCount(1); List<String> questions = new ArrayList<String>(); questions.add(question.getId()); newTag.setQuestions(questions); template.insert(newTag); } } }
public TagUI findById(String id) { return tMapper.toUIBean(tagRepo.findById(id)); }
public TagUI findByName(String name) { return tMapper.toUIBean(tagRepo.findByName(name)); }
public Page<TagUI> findAll(Pageable pageable) { return tMapper.toUIBean(tagRepo.findAll(pageable), pageable); }
public List<TagUI> findAll() { return tMapper.toUIBean(tagRepo.findAll()); }