View Javadoc

1   /**
2    * Copyright 2005-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * EDL pipeline component that exposes annotations from the previous array of taken actions in the
36   * EDL to render.
37   * @author Kuali Rice Team (rice.collab@kuali.org)
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          // insert current annotation into docContent
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              // get the current version of data
57              // Element currentVersion = VersioningPreprocessor.findCurrentVersion(dom);
58              // for every ActionTaken, append every annotation as a child element of EDL data element
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  }