private void associateLinkedEntity(Page<Link> page) {
for(Link link : page.getResult()) {
Object entity = null;
if(StringUtils.equals(link.getEntity(), Question.NAME)) {
entity = questionService.getQuestion(link.getToId());
Statistic statistic = statisticService.getStatistic(Statistic.TYPE_VIEW, link.getToId(), Question.NAME);
Long views = statistic!=null ? statistic.getCount() : 0L;
((Question)entity).setViews(views);
} else if (StringUtils.equals(link.getEntity(), Post.NAME)) {
entity = postService.getPost(link.getToId());
Statistic statistic = statisticService.getStatistic(Statistic.TYPE_VIEW, link.getToId(), Post.NAME);
Long views = statistic!=null ? statistic.getCount() : 0L;
((Post)entity).setViews(views);
} else if (StringUtils.equals(link.getEntity(), Topic.NAME)) {
entity = topicService.getTopic(link.getToId());
Statistic statistic = statisticService.getStatistic(Statistic.TYPE_VIEW, link.getToId(), Topic.NAME);
Long views = statistic!=null ? statistic.getCount() : 0L;
((Topic)entity).setViews(views);
} else if (StringUtils.equals(link.getEntity(), Photo.NAME)) {
entity = photoService.getPhoto(link.getToId());
} else if (StringUtils.equals(link.getEntity(), File.NAME)) {
entity = fileService.getFile(link.getToId());