001 /**
002 * Copyright 2005-2014 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.edl.impl.components;
017
018 import org.apache.commons.lang.StringUtils;
019 import org.apache.log4j.Logger;
020 import org.kuali.rice.core.api.util.xml.XmlJotter;
021 import org.kuali.rice.edl.impl.EDLContext;
022 import org.kuali.rice.edl.impl.EDLModelComponent;
023 import org.kuali.rice.edl.impl.EDLXmlUtils;
024 import org.kuali.rice.edl.impl.RequestParser;
025 import org.kuali.rice.kew.api.WorkflowDocument;
026 import org.kuali.rice.kew.api.action.ActionTaken;
027 import org.kuali.rice.kim.api.identity.Person;
028 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
029 import org.w3c.dom.Document;
030 import org.w3c.dom.Element;
031
032 import java.util.List;
033
034 /**
035 * EDL pipeline component that exposes annotations from the previous array of taken actions in the
036 * EDL to render.
037 * @author Kuali Rice Team (rice.collab@kuali.org)
038 */
039 public class AnnotationComponent implements EDLModelComponent {
040 private static final Logger LOG = Logger.getLogger(AnnotationComponent.class);
041
042 public void updateDOM(Document dom, Element configElement, EDLContext edlContext) {
043 WorkflowDocument document = (WorkflowDocument) edlContext.getRequestParser().getAttribute(
044 RequestParser.WORKFLOW_DOCUMENT_SESSION_KEY);
045
046 // insert current annotation into docContent
047 Element currentVersion = VersioningPreprocessor.findCurrentVersion(dom);
048 String annotation = edlContext.getRequestParser().getParameterValue("annotation");
049 if (!StringUtils.isEmpty(annotation)) {
050 EDLXmlUtils.createTextElementOnParent(currentVersion, "currentAnnotation", annotation);
051 }
052 LOG.debug("Inserting annotation: " + annotation);
053
054 List<ActionTaken> actionsTaken = document.getActionsTaken();
055 if (actionsTaken != null) {
056 // get the current version of data
057 // Element currentVersion = VersioningPreprocessor.findCurrentVersion(dom);
058 // for every ActionTaken, append every annotation as a child element of EDL data element
059 for (ActionTaken actionTaken : actionsTaken) {
060 if (actionTaken != null) {
061 annotation = actionTaken.getAnnotation();
062 if (annotation != null) {
063 LOG.debug("Adding annotation: " + annotation);
064 Person person = KimApiServiceLocator.getPersonService().getPerson(actionTaken.getPrincipalId());
065 EDLXmlUtils.createTextElementOnParent(currentVersion, "annotation", person.getName() + ": "
066 + annotation);
067 if (LOG.isDebugEnabled()) {
068 LOG.debug("dom: " + XmlJotter.jotNode(dom));
069 }
070 }
071 }
072 }
073 }
074 }
075 }