1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.kuali.rice.edl.impl.components;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.apache.log4j.Logger;
20  import org.kuali.rice.core.api.util.xml.XmlJotter;
21  import org.kuali.rice.edl.impl.EDLContext;
22  import org.kuali.rice.edl.impl.EDLModelComponent;
23  import org.kuali.rice.edl.impl.EDLXmlUtils;
24  import org.kuali.rice.edl.impl.RequestParser;
25  import org.kuali.rice.kew.api.WorkflowDocument;
26  import org.kuali.rice.kew.api.action.ActionTaken;
27  import org.kuali.rice.kim.api.identity.Person;
28  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
29  import org.w3c.dom.Document;
30  import org.w3c.dom.Element;
31  
32  import java.util.List;
33  
34  
35  
36  
37  
38  
39  public class AnnotationComponent implements EDLModelComponent {
40      private static final Logger LOG = Logger.getLogger(AnnotationComponent.class);
41  
42      public void updateDOM(Document dom, Element configElement, EDLContext edlContext) {
43          WorkflowDocument document = (WorkflowDocument) edlContext.getRequestParser().getAttribute(
44                  RequestParser.WORKFLOW_DOCUMENT_SESSION_KEY);
45  
46          
47          Element currentVersion = VersioningPreprocessor.findCurrentVersion(dom);
48          String annotation = edlContext.getRequestParser().getParameterValue("annotation");
49          if (!StringUtils.isEmpty(annotation)) {
50              EDLXmlUtils.createTextElementOnParent(currentVersion, "currentAnnotation", annotation);
51          }
52          LOG.debug("Inserting annotation: " + annotation);
53  
54          List<ActionTaken> actionsTaken = document.getActionsTaken();
55          if (actionsTaken != null) {
56              
57              
58              
59              for (ActionTaken actionTaken : actionsTaken) {
60                  if (actionTaken != null) {
61                      annotation = actionTaken.getAnnotation();
62                      if (annotation != null) {
63                          LOG.debug("Adding annotation: " + annotation);
64                          Person person = KimApiServiceLocator.getPersonService().getPerson(actionTaken.getPrincipalId());
65                          EDLXmlUtils.createTextElementOnParent(currentVersion, "annotation", person.getName() + ": "
66                                  + annotation);
67                          if (LOG.isDebugEnabled()) {
68                              LOG.debug("dom: " + XmlJotter.jotNode(dom));
69                          }
70                      }
71                  }
72              }
73          }
74      }
75  }