View Javadoc

1   /*
2    * Copyright 2005-2008 The Kuali Foundation
3    *
4    *
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.opensource.org/licenses/ecl2.php
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.kuali.rice.kew.edl.components;
19  
20  import org.apache.commons.lang.StringUtils;
21  import org.apache.log4j.Logger;
22  import org.kuali.rice.kew.dto.ActionTakenDTO;
23  import org.kuali.rice.kew.edl.EDLContext;
24  import org.kuali.rice.kew.edl.EDLModelComponent;
25  import org.kuali.rice.kew.edl.EDLXmlUtils;
26  import org.kuali.rice.kew.edl.RequestParser;
27  import org.kuali.rice.kew.exception.WorkflowException;
28  import org.kuali.rice.kew.service.WorkflowDocument;
29  import org.kuali.rice.kew.util.XmlHelper;
30  import org.kuali.rice.kim.bo.Person;
31  import org.kuali.rice.kim.service.KIMServiceLocator;
32  import org.w3c.dom.Document;
33  import org.w3c.dom.Element;
34  
35  
36  /**
37   * EDL pipeline component that exposes annotations from the previous array of taken actions
38   * in the EDL to render.
39   * @author Kuali Rice Team (rice.collab@kuali.org)
40   */
41  public class AnnotationComponent implements EDLModelComponent {
42      private static final Logger LOG = Logger.getLogger(AnnotationComponent.class);
43  
44      public void updateDOM(Document dom, Element configElement, EDLContext edlContext) {
45          WorkflowDocument document = (WorkflowDocument)edlContext.getRequestParser().getAttribute(RequestParser.WORKFLOW_DOCUMENT_SESSION_KEY);
46  
47          // insert current annotation into docContent
48      	Element currentVersion = VersioningPreprocessor.findCurrentVersion(dom);
49          String annotation = edlContext.getRequestParser().getParameterValue("annotation");
50          if (!StringUtils.isEmpty(annotation)) {
51          	EDLXmlUtils.createTextElementOnParent(currentVersion, "currentAnnotation", annotation);
52          }
53      	LOG.debug("Inserting annotation: " + annotation);
54  
55          // get the array of actions taken
56          ActionTakenDTO[] actionsTaken;
57          try {
58              actionsTaken = document.getActionsTaken();
59          } catch (WorkflowException we) {
60              try {
61                  LOG.error("Error retrieving actions taken on document " + document.getRouteHeaderId() + " (" + document.getDocumentType() + ")", we);
62              } catch (WorkflowException we2) {
63                  // give me a break :/
64                  LOG.error("Error retrieving route header id from document");
65              }
66              return;
67          }
68          if (actionsTaken != null) {
69              // get the current version of data
70              //Element currentVersion = VersioningPreprocessor.findCurrentVersion(dom);
71              // for every ActionTaken, append every annotation as a child element of EDL data element
72              for (ActionTakenDTO actionTaken: actionsTaken) {
73                  if (actionTaken != null) {
74                      annotation = actionTaken.getAnnotation();
75                      if (annotation != null) {
76                          LOG.debug("Adding annotation: " + annotation);
77                          Person person = KIMServiceLocator.getPersonService().getPerson(actionTaken.getPrincipalId());
78                          EDLXmlUtils.createTextElementOnParent(currentVersion, "annotation", person.getName() + ": " + annotation);
79                          if (LOG.isDebugEnabled()) {
80                              LOG.debug("dom: " + XmlHelper.jotNode(dom));
81                          }
82                      }
83                  }
84              }
85          }
86      }
87  }