1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kns.service.impl; |
17 | |
|
18 | |
import java.text.MessageFormat; |
19 | |
import java.util.ArrayList; |
20 | |
import java.util.Iterator; |
21 | |
import java.util.List; |
22 | |
|
23 | |
import org.apache.commons.lang.StringUtils; |
24 | |
import org.kuali.rice.kew.exception.WorkflowException; |
25 | |
import org.kuali.rice.kim.bo.Person; |
26 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
27 | |
import org.kuali.rice.kim.service.PersonService; |
28 | |
import org.kuali.rice.kns.bo.AdHocRoutePerson; |
29 | |
import org.kuali.rice.kns.bo.AdHocRouteRecipient; |
30 | |
import org.kuali.rice.kns.bo.Note; |
31 | |
import org.kuali.rice.kns.bo.PersistableBusinessObject; |
32 | |
import org.kuali.rice.kns.dao.NoteDao; |
33 | |
import org.kuali.rice.kns.document.Document; |
34 | |
import org.kuali.rice.kns.service.KualiConfigurationService; |
35 | |
import org.kuali.rice.kns.service.NoteService; |
36 | |
import org.kuali.rice.kns.util.GlobalVariables; |
37 | |
import org.kuali.rice.kns.util.KNSConstants; |
38 | |
import org.kuali.rice.kns.util.ObjectUtils; |
39 | |
import org.kuali.rice.kns.util.RiceKeyConstants; |
40 | |
import org.kuali.rice.kns.util.KNSConstants.NoteTypeEnum; |
41 | |
import org.kuali.rice.kns.workflow.service.WorkflowDocumentService; |
42 | |
import org.springframework.transaction.annotation.Transactional; |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
@Transactional |
50 | |
public class NoteServiceImpl implements NoteService { |
51 | |
|
52 | 0 | private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(NoteServiceImpl.class); |
53 | |
|
54 | |
private NoteDao noteDao; |
55 | |
private PersonService personService; |
56 | |
private WorkflowDocumentService workflowDocumentService; |
57 | |
private KualiConfigurationService kualiConfigurationService; |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
public NoteServiceImpl() { |
63 | 0 | super(); |
64 | 0 | } |
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
public void saveNoteList(List notes) { |
70 | 0 | if (notes != null) { |
71 | 0 | for (Iterator iter = notes.iterator(); iter.hasNext();) { |
72 | 0 | noteDao.save((Note) iter.next()); |
73 | |
} |
74 | |
} |
75 | 0 | } |
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
public Note save(Note note) throws Exception { |
83 | 0 | noteDao.save(note); |
84 | 0 | return note; |
85 | |
} |
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
public ArrayList getByRemoteObjectId(String remoteObjectId) { |
93 | |
|
94 | 0 | return noteDao.findByremoteObjectId(remoteObjectId); |
95 | |
} |
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
public Note getNoteByNoteId(Long noteId) { |
103 | 0 | return noteDao.getNoteByNoteId(noteId); |
104 | |
} |
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
public void deleteNote(Note note) throws Exception { |
112 | 0 | noteDao.deleteNote(note); |
113 | 0 | } |
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
public void setNoteDao(NoteDao d) { |
122 | 0 | this.noteDao = d; |
123 | 0 | } |
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
public NoteDao getNoteDao() { |
129 | 0 | return noteDao; |
130 | |
} |
131 | |
|
132 | |
public Note createNote(Note note, PersistableBusinessObject bo) throws Exception { |
133 | |
|
134 | |
|
135 | 0 | Note tmpNote = (Note) ObjectUtils.deepCopy(note); |
136 | 0 | Person kualiUser = GlobalVariables.getUserSession().getPerson(); |
137 | 0 | tmpNote.setRemoteObjectIdentifier(bo.getObjectId()); |
138 | 0 | tmpNote.setAuthorUniversalIdentifier(kualiUser.getPrincipalId()); |
139 | 0 | return tmpNote; |
140 | |
} |
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
public String extractNoteProperty(Note note) { |
149 | 0 | String propertyName = null; |
150 | 0 | for (NoteTypeEnum nte : NoteTypeEnum.values()) { |
151 | 0 | if (StringUtils.equals(nte.getCode(), note.getNoteTypeCode())) { |
152 | 0 | propertyName = nte.getPath(); |
153 | |
} |
154 | |
} |
155 | 0 | return propertyName; |
156 | |
} |
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
public void sendNoteRouteNotification(Document document, Note note, Person sender) throws WorkflowException { |
163 | 0 | AdHocRouteRecipient routeRecipient = note.getAdHocRouteRecipient(); |
164 | |
|
165 | |
|
166 | 0 | Person requestedUser = this.getPersonService().getPersonByPrincipalName(routeRecipient.getId()); |
167 | 0 | String senderName = sender.getFirstName() + " " + sender.getLastName(); |
168 | 0 | String requestedName = requestedUser.getFirstName() + " " + requestedUser.getLastName(); |
169 | |
|
170 | 0 | String notificationText = kualiConfigurationService.getPropertyString(RiceKeyConstants.MESSAGE_NOTE_NOTIFICATION_ANNOTATION); |
171 | 0 | if (StringUtils.isBlank(notificationText)) { |
172 | 0 | throw new RuntimeException("No annotation message found for note notification. Message needs added to application resources with key:" + RiceKeyConstants.MESSAGE_NOTE_NOTIFICATION_ANNOTATION); |
173 | |
} |
174 | 0 | notificationText = MessageFormat.format(notificationText, new Object[] { senderName, requestedName, note.getNoteText() }); |
175 | |
|
176 | 0 | List<AdHocRouteRecipient> routeRecipients = new ArrayList<AdHocRouteRecipient>(); |
177 | 0 | routeRecipients.add(routeRecipient); |
178 | |
|
179 | 0 | workflowDocumentService.sendWorkflowNotification(document.getDocumentHeader().getWorkflowDocument(), notificationText, routeRecipients, KNSConstants.NOTE_WORKFLOW_NOTIFICATION_REQUEST_LABEL); |
180 | |
|
181 | |
|
182 | 0 | note.setAdHocRouteRecipient(new AdHocRoutePerson()); |
183 | 0 | } |
184 | |
|
185 | |
|
186 | |
|
187 | |
|
188 | |
public void setPersonService(PersonService personService) { |
189 | 0 | this.personService = personService; |
190 | 0 | } |
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | |
public void setWorkflowDocumentService(WorkflowDocumentService workflowDocumentService) { |
196 | 0 | this.workflowDocumentService = workflowDocumentService; |
197 | 0 | } |
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
public void setKualiConfigurationService(KualiConfigurationService kualiConfigurationService) { |
203 | 0 | this.kualiConfigurationService = kualiConfigurationService; |
204 | 0 | } |
205 | |
|
206 | |
protected PersonService getPersonService() { |
207 | 0 | if ( personService == null ) { |
208 | 0 | personService = KIMServiceLocator.getPersonService(); |
209 | |
} |
210 | 0 | return personService; |
211 | |
} |
212 | |
} |