001/** 002 * Copyright 2005-2015 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 */ 016package org.kuali.rice.edl.impl.components; 017 018import org.apache.commons.lang.StringUtils; 019import org.apache.logging.log4j.Logger; 020import org.apache.logging.log4j.LogManager; 021import org.kuali.rice.core.api.util.xml.XmlJotter; 022import org.kuali.rice.edl.impl.EDLContext; 023import org.kuali.rice.edl.impl.EDLModelComponent; 024import org.kuali.rice.edl.impl.EDLXmlUtils; 025import org.kuali.rice.edl.impl.RequestParser; 026import org.kuali.rice.kew.api.WorkflowDocument; 027import org.kuali.rice.kew.api.action.ActionTaken; 028import org.kuali.rice.kim.api.identity.Person; 029import org.kuali.rice.kim.api.services.KimApiServiceLocator; 030import org.w3c.dom.Document; 031import org.w3c.dom.Element; 032 033import java.util.List; 034 035/** 036 * EDL pipeline component that exposes annotations from the previous array of taken actions in the 037 * EDL to render. 038 * @author Kuali Rice Team (rice.collab@kuali.org) 039 */ 040public class AnnotationComponent implements EDLModelComponent { 041 private static final Logger LOG = LogManager.getLogger(AnnotationComponent.class); 042 043 public void updateDOM(Document dom, Element configElement, EDLContext edlContext) { 044 WorkflowDocument document = (WorkflowDocument) edlContext.getRequestParser().getAttribute( 045 RequestParser.WORKFLOW_DOCUMENT_SESSION_KEY); 046 047 // insert current annotation into docContent 048 Element currentVersion = VersioningPreprocessor.findCurrentVersion(dom); 049 String annotation = edlContext.getRequestParser().getParameterValue("annotation"); 050 if (!StringUtils.isEmpty(annotation)) { 051 EDLXmlUtils.createTextElementOnParent(currentVersion, "currentAnnotation", annotation); 052 } 053 LOG.debug("Inserting annotation: " + annotation); 054 055 List<ActionTaken> actionsTaken = document.getActionsTaken(); 056 if (actionsTaken != null) { 057 // get the current version of data 058 // Element currentVersion = VersioningPreprocessor.findCurrentVersion(dom); 059 // for every ActionTaken, append every annotation as a child element of EDL data element 060 for (ActionTaken actionTaken : actionsTaken) { 061 if (actionTaken != null) { 062 annotation = actionTaken.getAnnotation(); 063 if (annotation != null) { 064 LOG.debug("Adding annotation: " + annotation); 065 Person person = KimApiServiceLocator.getPersonService().getPerson(actionTaken.getPrincipalId()); 066 EDLXmlUtils.createTextElementOnParent(currentVersion, "annotation", person.getName() + ": " 067 + annotation); 068 if (LOG.isDebugEnabled()) { 069 LOG.debug("dom: " + XmlJotter.jotNode(dom)); 070 } 071 } 072 } 073 } 074 } 075 } 076}