1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
package org.kuali.rice.edl.impl.components; |
19 | |
|
20 | |
import org.apache.commons.lang.StringUtils; |
21 | |
import org.apache.log4j.Logger; |
22 | |
import org.kuali.rice.core.util.xml.XmlJotter; |
23 | |
import org.kuali.rice.edl.impl.EDLContext; |
24 | |
import org.kuali.rice.edl.impl.EDLModelComponent; |
25 | |
import org.kuali.rice.edl.impl.EDLXmlUtils; |
26 | |
import org.kuali.rice.edl.impl.RequestParser; |
27 | |
import org.kuali.rice.kew.dto.ActionTakenDTO; |
28 | |
import org.kuali.rice.kew.exception.WorkflowException; |
29 | |
import org.kuali.rice.kew.service.WorkflowDocument; |
30 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
31 | |
import org.kuali.rice.kim.bo.Person; |
32 | |
import org.w3c.dom.Document; |
33 | |
import org.w3c.dom.Element; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | 0 | public class AnnotationComponent implements EDLModelComponent { |
42 | 0 | private static final Logger LOG = Logger.getLogger(AnnotationComponent.class); |
43 | |
|
44 | |
public void updateDOM(Document dom, Element configElement, EDLContext edlContext) { |
45 | 0 | WorkflowDocument document = (WorkflowDocument)edlContext.getRequestParser().getAttribute(RequestParser.WORKFLOW_DOCUMENT_SESSION_KEY); |
46 | |
|
47 | |
|
48 | 0 | Element currentVersion = VersioningPreprocessor.findCurrentVersion(dom); |
49 | 0 | String annotation = edlContext.getRequestParser().getParameterValue("annotation"); |
50 | 0 | if (!StringUtils.isEmpty(annotation)) { |
51 | 0 | EDLXmlUtils.createTextElementOnParent(currentVersion, "currentAnnotation", annotation); |
52 | |
} |
53 | 0 | LOG.debug("Inserting annotation: " + annotation); |
54 | |
|
55 | |
|
56 | |
ActionTakenDTO[] actionsTaken; |
57 | |
try { |
58 | 0 | actionsTaken = document.getActionsTaken(); |
59 | 0 | } catch (WorkflowException we) { |
60 | |
try { |
61 | 0 | LOG.error("Error retrieving actions taken on document " + document.getDocumentId() + " (" + document.getDocumentType() + ")", we); |
62 | 0 | } catch (WorkflowException we2) { |
63 | |
|
64 | 0 | LOG.error("Error retrieving document id from document"); |
65 | 0 | } |
66 | 0 | return; |
67 | 0 | } |
68 | 0 | if (actionsTaken != null) { |
69 | |
|
70 | |
|
71 | |
|
72 | 0 | for (ActionTakenDTO actionTaken: actionsTaken) { |
73 | 0 | if (actionTaken != null) { |
74 | 0 | annotation = actionTaken.getAnnotation(); |
75 | 0 | if (annotation != null) { |
76 | 0 | LOG.debug("Adding annotation: " + annotation); |
77 | 0 | Person person = KimApiServiceLocator.getPersonService().getPerson(actionTaken.getPrincipalId()); |
78 | 0 | EDLXmlUtils.createTextElementOnParent(currentVersion, "annotation", person.getName() + ": " + annotation); |
79 | 0 | if (LOG.isDebugEnabled()) { |
80 | 0 | LOG.debug("dom: " + XmlJotter.jotNode(dom)); |
81 | |
} |
82 | |
} |
83 | |
} |
84 | |
} |
85 | |
} |
86 | 0 | } |
87 | |
} |