1 package org.exoplatform.commons.search.indexing.listeners;
2
3 import org.exoplatform.commons.api.indexing.IndexingService;
4 import org.exoplatform.commons.api.indexing.data.SearchEntry;
5 import org.exoplatform.commons.api.indexing.data.SearchEntryId;
6 import org.exoplatform.forum.service.*;
7 import org.exoplatform.services.log.ExoLogger;
8 import org.exoplatform.services.log.Log;
9
10 import java.util.HashMap;
11 import java.util.List;
12 import java.util.Map;
13
14
15
16
17
18
19
20
21
22 public class UnifiedSearchForumListener extends ForumEventListener {
23
24 private static Log log = ExoLogger.getLogger(UnifiedSearchForumListener.class);
25
26 private final IndexingService indexingService;
27
28 public UnifiedSearchForumListener(IndexingService indexingService) {
29 this.indexingService = indexingService;
30 }
31
32 @Override
33 public void saveCategory(Category category) {
34
35
36 if(indexingService != null) {
37 Map<String, Object> content = new HashMap<String, Object>();
38 content.put("category", category);
39 SearchEntry searchEntry = new SearchEntry("forum", "category", category.getId(), content);
40 indexingService.add(searchEntry);
41 }
42 }
43
44 @Override
45 public void saveForum(Forum forum) {
46
47
48 if(indexingService != null) {
49 Map<String, Object> content = new HashMap<String, Object>();
50 content.put("forum", forum);
51 SearchEntry searchEntry = new SearchEntry("forum", "forum", forum.getId(), content);
52 indexingService.add(searchEntry);
53 }
54 }
55
56 @Override
57 public void addTopic(Topic topic) {
58 if(indexingService != null) {
59 Map<String, Object> content = new HashMap<String, Object>();
60 content.put("topic", topic);
61 SearchEntry searchEntry = new SearchEntry("forum", "topic", topic.getId(), content);
62 indexingService.add(searchEntry);
63 }
64 }
65
66 @Override
67 public void updateTopic(Topic topic) {
68 if(indexingService != null) {
69 Map<String, Object> content = new HashMap<String, Object>();
70 content.put("topic", topic);
71 SearchEntryId searchEntryId = new SearchEntryId("forum", "topic", topic.getId());
72 indexingService.update(searchEntryId, content);
73 }
74 }
75
76 @Override
77 public void updateTopics(List<Topic> topics, boolean isLock) {
78 for(Topic topic: topics) {
79 updateTopic(topic);
80 }
81 }
82
83 @Override
84 public void moveTopic(Topic topic, String toCategoryName, String toForumName) {
85
86 }
87
88 public void movePost(List <Post> posts, List<String> srcPostActivityIds, String desTopicPath) {
89 }
90
91 @Override
92 public void mergeTopic(Topic topic, String removeActivityId1, String removeActivityId2) {
93
94 }
95
96 @Override
97 public void splitTopic(Topic newTopic, Topic splitedTopic, String removeActivityId) {
98 if(indexingService != null) {
99 Map<String, Object> content = new HashMap<String, Object>();
100 content.put("topic", splitedTopic);
101 SearchEntryId searchEntryId = new SearchEntryId("forum", "topic", splitedTopic.getId());
102 indexingService.update(searchEntryId, content);
103
104 Map<String, Object> contentNewTopic = new HashMap<String, Object>();
105 contentNewTopic.put("topic", newTopic);
106 SearchEntry searchEntry = new SearchEntry("forum", "topic", newTopic.getId(), contentNewTopic);
107 indexingService.add(searchEntry);
108 }
109 }
110
111 @Override
112 public void addPost(Post post) {
113 if(indexingService != null) {
114 Map<String, Object> content = new HashMap<String, Object>();
115 content.put("post", post);
116 SearchEntry searchEntry = new SearchEntry("forum", "post", post.getId(), content);
117 indexingService.add(searchEntry);
118 }
119 }
120
121 @Override
122 public void updatePost(Post post) {
123 if(indexingService != null) {
124 Map<String, Object> content = new HashMap<String, Object>();
125 content.put("post", post);
126 SearchEntryId searchEntryId = new SearchEntryId("forum", "post", post.getId());
127 indexingService.update(searchEntryId, content);
128 }
129 }
130
131 @Override
132 public void updatePost(Post post, int type) {
133 updatePost(post);
134 }
135
136 @Override
137 public void removeActivity(String activityId) {
138
139 }
140
141 @Override
142 public void removeComment(String activityId, String commentId) {
143
144 }
145 }