View Javadoc
1   package org.exoplatform.commons.search.indexing.listeners;
2   
3   import org.exoplatform.calendar.service.CalendarEvent;
4   import org.exoplatform.calendar.service.impl.CalendarEventListener;
5   import org.exoplatform.commons.api.indexing.IndexingService;
6   import org.exoplatform.commons.api.indexing.data.SearchEntry;
7   import org.exoplatform.commons.api.indexing.data.SearchEntryId;
8   import org.exoplatform.services.log.ExoLogger;
9   import org.exoplatform.services.log.Log;
10  
11  import java.util.HashMap;
12  import java.util.Map;
13  
14  /**
15   * Indexing with :
16   * - collection : "calendar"
17   * - type : (event|task)
18   * - name : object id
19   *
20   * TODO Listeners only for public events. What about others events ?
21   */
22  public class UnifiedSearchCalendarListener extends CalendarEventListener {
23  
24    private static Log log = ExoLogger.getLogger(UnifiedSearchCalendarListener.class);
25  
26    private final IndexingService indexingService;
27  
28    public UnifiedSearchCalendarListener(IndexingService indexingService) {
29      this.indexingService = indexingService;
30    }
31  
32    @Override
33    public void savePublicEvent(CalendarEvent event, String calendarId) {
34      // TODO No need of the calendarId argument as it is already contained in the event object
35  
36      if(indexingService != null) {
37        Map<String, Object> content = new HashMap<String, Object>();
38        content.put("event", event);
39        SearchEntry searchEntry = new SearchEntry("calendar", event.getEventType().toLowerCase(), event.getId(), content);
40        indexingService.add(searchEntry);
41      }
42    }
43  
44    @Override
45    public void updatePublicEvent(CalendarEvent event, String calendarId) {
46      // TODO No need of the calendarId argument as it is already contained in the event object
47  
48      if(indexingService != null) {
49        Map<String, Object> content = new HashMap<String, Object>();
50        content.put("event", event);
51        SearchEntryId searchEntryId = new SearchEntryId("calendar", event.getEventType().toLowerCase(), event.getId());
52        indexingService.update(searchEntryId, content);
53      }
54    }
55  
56    @Override
57    public void deletePublicEvent(CalendarEvent event, String calendarId) {
58      if(indexingService != null) {
59        SearchEntryId searchEntryId = new SearchEntryId("calendar", event.getEventType().toLowerCase(), event.getId());
60        indexingService.delete(searchEntryId);
61      }
62    }
63  
64    @Override
65    public void updatePublicEvent(CalendarEvent oldEvent, CalendarEvent event, String calendarId) {
66      // TODO Why 2 methods for an event update ?
67  
68      if(indexingService != null) {
69        Map<String, Object> content = new HashMap<String, Object>();
70        content.put("event", event);
71        SearchEntryId searchEntryId = new SearchEntryId("calendar", event.getEventType().toLowerCase(), event.getId());
72        indexingService.update(searchEntryId, content);
73      }
74    }
75  }