001    /**
002     * Copyright 2005-2011 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.kew.engine;
017    
018    import org.apache.commons.lang.StringUtils;
019    import org.kuali.rice.kew.api.WorkflowDocument;
020    import org.kuali.rice.kew.api.WorkflowDocumentFactory;
021    import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange;
022    import org.kuali.rice.kew.framework.postprocessor.ProcessDocReport;
023    import org.kuali.rice.kew.postprocessor.DefaultPostProcessor;
024    import org.kuali.rice.kew.api.KewApiConstants;
025    import org.kuali.rice.kim.api.services.KimApiServiceLocator;
026    
027    
028    /**
029     * Tests a new document being spawned from the post processing of an existing document
030     * 
031     * @author Kuali Rice Team (rice.collab@kuali.org)
032     */
033    public class PostProcessorSpawnDocument extends DefaultPostProcessor {
034            private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PostProcessorSpawnDocument.class);
035    
036            @Override
037        public ProcessDocReport doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) throws Exception {
038            LOG.info("Moving document " + statusChangeEvent.getDocumentId() + " from status '" + statusChangeEvent.getOldRouteStatus() + "' to status '" + statusChangeEvent.getNewRouteStatus() + "'");
039            if (StringUtils.equals(KewApiConstants.ROUTE_HEADER_PROCESSED_CD, statusChangeEvent.getNewRouteStatus())) {
040                    // spawn and route a new document
041                    WorkflowDocument document = WorkflowDocumentFactory.createDocument(KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName("ewestfal").getPrincipalId(), "SpawnedDocumentType");
042                    document.route("");
043            }
044            return new ProcessDocReport(true, "");
045        }
046    
047    }