1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kcb.service.impl; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.Collection; |
20 | |
import java.util.HashMap; |
21 | |
import java.util.HashSet; |
22 | |
import java.util.Set; |
23 | |
import java.util.Map.Entry; |
24 | |
|
25 | |
import org.apache.log4j.Logger; |
26 | |
import org.kuali.rice.kcb.bo.MessageDelivery; |
27 | |
import org.kuali.rice.kcb.deliverer.MessageDeliverer; |
28 | |
import org.kuali.rice.kcb.deliverer.impl.AOLInstantMessageDeliverer; |
29 | |
import org.kuali.rice.kcb.deliverer.impl.EmailMessageDeliverer; |
30 | |
import org.kuali.rice.kcb.deliverer.impl.MockMessageDeliverer; |
31 | |
import org.kuali.rice.kcb.deliverer.impl.SMSMessageDeliverer; |
32 | |
import org.kuali.rice.kcb.service.MessageDelivererRegistryService; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
public class MessageDelivererRegistryServiceImpl implements MessageDelivererRegistryService { |
39 | 0 | private static Logger LOG = Logger.getLogger(MessageDelivererRegistryServiceImpl.class); |
40 | |
|
41 | |
|
42 | |
private HashMap<String, Class<? extends MessageDeliverer>> messageDelivererTypes; |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | 0 | public MessageDelivererRegistryServiceImpl() { |
52 | |
|
53 | 0 | EmailMessageDeliverer email = new EmailMessageDeliverer(); |
54 | 0 | SMSMessageDeliverer sms = new SMSMessageDeliverer(); |
55 | 0 | AOLInstantMessageDeliverer aim = new AOLInstantMessageDeliverer(); |
56 | 0 | MockMessageDeliverer mock = new MockMessageDeliverer(); |
57 | |
|
58 | 0 | messageDelivererTypes = new HashMap<String, Class<? extends MessageDeliverer>>(4); |
59 | |
|
60 | 0 | messageDelivererTypes.put(email.getName().toLowerCase(), email.getClass()); |
61 | 0 | messageDelivererTypes.put(sms.getName().toLowerCase(), sms.getClass()); |
62 | 0 | messageDelivererTypes.put(aim.getName().toLowerCase(), aim.getClass()); |
63 | 0 | messageDelivererTypes.put(mock.getName().toLowerCase(), mock.getClass()); |
64 | 0 | } |
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
public Collection<String> getAllDelivererTypes() { |
70 | 0 | Collection<MessageDeliverer> deliverers = getAllDeliverers(); |
71 | 0 | Set<String> types = new HashSet<String>(deliverers.size()); |
72 | 0 | for (MessageDeliverer deliverer: deliverers) { |
73 | 0 | types.add(deliverer.getName().toLowerCase()); |
74 | |
} |
75 | 0 | return types; |
76 | |
} |
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
public Collection<MessageDeliverer> getAllDeliverers() { |
84 | 0 | ArrayList<MessageDeliverer> delivererTypes = new ArrayList<MessageDeliverer>(); |
85 | |
|
86 | 0 | Set<Entry<String, Class<? extends MessageDeliverer>>> registeredTypes = messageDelivererTypes.entrySet(); |
87 | |
|
88 | |
|
89 | 0 | for(Entry<String, Class<? extends MessageDeliverer>> entry: registeredTypes ) { |
90 | |
try { |
91 | 0 | delivererTypes.add(entry.getValue().newInstance()); |
92 | 0 | } catch (InstantiationException e) { |
93 | 0 | LOG.error(e.getStackTrace()); |
94 | 0 | } catch (IllegalAccessException e) { |
95 | 0 | LOG.error(e.getStackTrace()); |
96 | 0 | } |
97 | |
} |
98 | |
|
99 | 0 | return delivererTypes; |
100 | |
} |
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
public MessageDeliverer getDeliverer(MessageDelivery messageDelivery) { |
107 | 0 | MessageDeliverer nmd = getDelivererByName(messageDelivery.getDelivererTypeName()); |
108 | 0 | if (nmd == null) { |
109 | 0 | LOG.error("The message deliverer type ('" + messageDelivery.getDelivererTypeName() + "') " + |
110 | |
"associated with message delivery id='" + messageDelivery.getId() + "' was not found in the message deliverer registry. This deliverer " + |
111 | |
"plugin is not in the system."); |
112 | |
} |
113 | 0 | return nmd; |
114 | |
} |
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
public MessageDeliverer getDelivererByName(String messageDelivererName) { |
122 | 0 | Class<? extends MessageDeliverer> clazz = messageDelivererTypes.get(messageDelivererName.toLowerCase()); |
123 | |
|
124 | 0 | if(clazz == null) { |
125 | 0 | LOG.error("The message deliverer type ('" + messageDelivererName + "') " + |
126 | |
" was not found in the message deliverer registry. This deliverer " + |
127 | |
"plugin is not in the system."); |
128 | 0 | return null; |
129 | |
} |
130 | |
|
131 | 0 | MessageDeliverer messageDeliverer = null; |
132 | |
try { |
133 | 0 | messageDeliverer = clazz.newInstance(); |
134 | 0 | } catch (InstantiationException e) { |
135 | 0 | LOG.error(e.getStackTrace()); |
136 | 0 | } catch (IllegalAccessException e) { |
137 | 0 | LOG.error(e.getStackTrace()); |
138 | 0 | } |
139 | |
|
140 | 0 | return messageDeliverer; |
141 | |
} |
142 | |
} |