1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.opencastproject.event.comment.list;
23
24 import org.opencastproject.event.comment.EventCommentException;
25 import org.opencastproject.event.comment.EventCommentService;
26 import org.opencastproject.list.api.ListProviderException;
27 import org.opencastproject.list.api.ResourceListProvider;
28 import org.opencastproject.list.api.ResourceListQuery;
29
30 import org.osgi.framework.BundleContext;
31 import org.osgi.service.component.annotations.Activate;
32 import org.osgi.service.component.annotations.Component;
33 import org.osgi.service.component.annotations.Reference;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36
37 import java.util.ArrayList;
38 import java.util.HashMap;
39 import java.util.List;
40 import java.util.Map;
41
42 @Component(
43 service = ResourceListProvider.class,
44 property = {
45 "service.description=Comments list provider",
46 "opencast.service.type=org.opencastproject.list.provider.EventCommentsListProvider"
47 }
48 )
49 public class EventCommentsListProvider implements ResourceListProvider {
50
51 private static final Logger logger = LoggerFactory.getLogger(EventCommentsListProvider.class);
52
53 public static final String PROVIDER_PREFIX = "comments";
54
55
56 public enum CommentsFilterList {
57 REASON, RESOLUTION;
58 };
59
60
61 public enum RESOLUTION {
62 ALL, UNRESOLVED, RESOLVED;
63 };
64
65
66 private final List<String> listNames = new ArrayList<String>();
67
68 private EventCommentService eventCommentService;
69
70 @Activate
71 protected void activate(BundleContext bundleContext) {
72
73 for (CommentsFilterList value : CommentsFilterList.values()) {
74 listNames.add(getListNameFromFilter(value));
75 }
76
77 logger.info("Comments list provider activated!");
78 }
79
80
81 @Reference
82 public void setEventCommentService(EventCommentService eventCommentService) {
83 this.eventCommentService = eventCommentService;
84 }
85
86 @Override
87 public String[] getListNames() {
88 return listNames.toArray(new String[listNames.size()]);
89 }
90
91 @Override
92 public Map<String, String> getList(String listName, ResourceListQuery query)
93 throws ListProviderException {
94 Map<String, String> result = new HashMap<String, String>();
95
96 if (CommentsFilterList.REASON.equals(listName)) {
97 List<String> reasons;
98 try {
99 reasons = eventCommentService.getReasons();
100 } catch (EventCommentException e) {
101 logger.error("Error retreiving reasons from event comment service", e);
102 throw new ListProviderException("Error retreiving reasons from event comment service", e);
103 }
104
105 for (String reason : reasons) {
106 result.put(reason, reason);
107 }
108 } else if (CommentsFilterList.RESOLUTION.equals(listName)) {
109 for (RESOLUTION value : RESOLUTION.values()) {
110 result.put(value.toString(), value.toString());
111 }
112 } else {
113 logger.warn("No comments list for list name {} found", listName);
114 throw new ListProviderException("No comments list for list name " + listName + " found!");
115 }
116
117 return result;
118 }
119
120
121
122
123
124
125
126
127 public static String getListNameFromFilter(CommentsFilterList filter) {
128 return PROVIDER_PREFIX.toLowerCase() + "_" + filter.toString().toLowerCase();
129 }
130
131 @Override
132 public boolean isTranslatable(String listName) {
133 return true;
134 }
135
136 @Override
137 public String getDefault() {
138 return null;
139 }
140 }