TaskNotificationImpl.java
9.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.security.user.UserProperties
* com.adobe.granite.security.user.UserPropertiesManager
* com.adobe.granite.taskmanagement.Task
* com.adobe.granite.taskmanagement.TaskEvent
* com.adobe.granite.taskmanagement.TaskEventType
* com.adobe.granite.workflow.exec.InboxItem
* com.adobe.granite.workflow.payload.PayloadInfo
* com.adobe.granite.workflow.payload.PayloadInfoBuilderContext
* com.adobe.granite.workflow.payload.PayloadInfoBuilderContext$INITIATOR_HINT
* com.adobe.granite.workflow.payload.PayloadInfoBuilderManager
* com.day.cq.workflow.event.WorkflowEvent
* com.day.cq.workflow.exec.WorkItem
* com.day.cq.workflow.exec.Workflow
* javax.jcr.RepositoryException
* javax.jcr.Value
* org.apache.jackrabbit.api.security.user.Authorizable
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.api.wrappers.ValueMapDecorator
* org.osgi.service.event.Event
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.workflow.impl.email;
import com.adobe.granite.security.user.UserProperties;
import com.adobe.granite.security.user.UserPropertiesManager;
import com.adobe.granite.taskmanagement.Task;
import com.adobe.granite.taskmanagement.TaskEvent;
import com.adobe.granite.taskmanagement.TaskEventType;
import com.adobe.granite.workflow.exec.InboxItem;
import com.adobe.granite.workflow.payload.PayloadInfo;
import com.adobe.granite.workflow.payload.PayloadInfoBuilderContext;
import com.adobe.granite.workflow.payload.PayloadInfoBuilderManager;
import com.day.cq.workflow.event.WorkflowEvent;
import com.day.cq.workflow.exec.WorkItem;
import com.day.cq.workflow.exec.Workflow;
import com.day.cq.workflow.impl.email.Notification;
import com.day.cq.workflow.impl.email.TaskEMailNotificationService;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.TreeSet;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
import org.apache.jackrabbit.api.security.user.Authorizable;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.wrappers.ValueMapDecorator;
import org.osgi.service.event.Event;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TaskNotificationImpl
implements Notification {
private static final Logger log = LoggerFactory.getLogger(TaskNotificationImpl.class);
private Task task;
private final TaskEvent event;
private final ValueMap properties = new ValueMapDecorator(new HashMap());
private String emailFromAddress;
private String hostPrefix;
private Authorizable participant;
private ResourceResolver resolver;
public TaskNotificationImpl(Task task, TaskEvent event, ResourceResolver resolver) {
this.task = task;
this.event = event;
this.resolver = resolver;
}
public void load(TaskEMailNotificationService svc, Authorizable participant) {
this.putAll((Event)this.event, "event.");
this.participant = participant;
ResourceBundle bundle = null;
if (participant != null) {
this.putAll(participant, "participant.");
String language = null;
try {
language = svc.getUserLanguage(participant.getID());
}
catch (RepositoryException e) {
log.warn("Unable to query for user's preferred language.", (Throwable)e);
}
if (language != null) {
bundle = svc.getUserResourceBundle(language);
}
if (bundle != null) {
this.put("participant.language", bundle.getLocale().getLanguage());
} else if (language != null) {
this.put("participant.language", language);
}
}
switch (this.event.getEventType()) {
case TASK_CREATED: {
this.put("event.type.title", bundle != null ? bundle.getString("Task Created") : "Task Created");
break;
}
case TASK_COMPLETED: {
this.put("event.type.title", bundle != null ? bundle.getString("Task Completed") : "Task Completed");
break;
}
case TASK_SAVED: {
this.put("event.type.title", bundle != null ? bundle.getString("Task Updated") : "Task Updated");
break;
}
default: {
this.put("event.type.title", bundle != null ? bundle.getString("Task Event") : "Task Event");
}
}
if (this.task != null) {
this.put("item.id", this.task.getId());
this.put("item.name", this.task.getName());
this.put("item.description", this.task.getDescription());
String taskComment = "";
Object taskCommentObject = this.task.getProperty("comment");
if (taskCommentObject instanceof String) {
taskComment = (String)taskCommentObject;
}
this.put("item.comment", taskComment);
this.put("payload.path", this.task.getContentPath());
PayloadInfoBuilderManager payloadBuilder = (PayloadInfoBuilderManager)this.resolver.adaptTo(PayloadInfoBuilderManager.class);
String payloadOpenPath = payloadBuilder.getPayloadInfo((InboxItem)this.task, PayloadInfoBuilderContext.INITIATOR_HINT.NOTIFICATION.name()).getBrowserPath();
if (payloadOpenPath == null) {
payloadOpenPath = this.task.getContentPath();
}
this.put("payload.path.open", payloadOpenPath);
Iterator propertyNames = this.task.getPropertyNames();
if (propertyNames != null) {
while (propertyNames.hasNext()) {
String key = (String)propertyNames.next();
Object property = this.task.getProperty(key);
if (property == null) continue;
this.put("task.property." + key, property.toString());
}
}
} else {
this.put("item.id", bundle != null ? bundle.getString("[Information not available]") : "[Information not available]");
}
this.hostPrefix = svc.getHostPrefix();
this.put("host.prefix", this.hostPrefix);
if (log.isDebugEnabled()) {
StringBuilder props = new StringBuilder();
TreeSet names = new TreeSet(this.properties.keySet());
for (String name : names) {
Object value = this.properties.get((Object)name);
log.debug("- {}:{}", (Object)name, value);
props.append(name).append(":").append(value).append("\n");
}
this.put("properties", props.toString());
}
}
public void put(String name, Object value) {
if (value != null) {
this.properties.put((Object)name, value);
}
}
public void putAll(Authorizable auth, String prefix) {
try {
Iterator iter = auth.getPropertyNames();
while (iter.hasNext()) {
String name = (String)iter.next();
this.properties.put((Object)(prefix + name), (Object)auth.getProperty(name));
}
this.properties.put((Object)(prefix + "id"), (Object)auth.getID());
this.properties.put((Object)(prefix + "home"), (Object)auth.getPath());
}
catch (RepositoryException e) {
log.error("Unable to load the properties from the Authorizable.", (Throwable)e);
}
try {
UserProperties profile;
UserPropertiesManager upm = (UserPropertiesManager)this.resolver.adaptTo(UserPropertiesManager.class);
if (upm != null && (profile = upm.getUserProperties(auth, "profile")) != null) {
for (String name : profile.getPropertyNames()) {
this.properties.put((Object)(prefix + name), profile.getProperty(name, (Object)"", String.class));
}
this.properties.put((Object)(prefix + "name"), (Object)profile.getDisplayName());
}
}
catch (RepositoryException e) {
log.error("Unable to load teh properties from the Authorizable's profile.", (Throwable)e);
}
}
public void putAll(Event evt, String prefix) {
for (String name : evt.getPropertyNames()) {
this.properties.put((Object)(prefix + name), evt.getProperty(name));
}
}
@Override
public ValueMap getProperties() {
return this.properties;
}
@Override
public String getEmailFromAddress() {
return this.emailFromAddress;
}
public void setEmailFromAddress(String emailFromAddress) {
this.emailFromAddress = emailFromAddress;
}
@Override
public String getHostPrefix() {
return this.hostPrefix;
}
@Override
public Authorizable getParticipant() {
return this.participant;
}
@Override
public WorkflowEvent getEvent() {
return null;
}
@Override
public Workflow getWorkflow() {
return null;
}
@Override
public WorkItem getWorkItem() {
return null;
}
@Override
public Authorizable getInitiator() {
return null;
}
}