001 /*
002 * Copyright 2005-2007 The Kuali Foundation
003 *
004 *
005 * Licensed under the Educational Community License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.opensource.org/licenses/ecl2.php
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.kuali.rice.kew.engine;
018
019 import org.apache.commons.lang.StringUtils;
020 import org.kuali.rice.kew.api.WorkflowDocument;
021 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
022 import org.kuali.rice.kew.postprocessor.DefaultPostProcessor;
023 import org.kuali.rice.kew.postprocessor.DocumentRouteStatusChange;
024 import org.kuali.rice.kew.postprocessor.ProcessDocReport;
025 import org.kuali.rice.kew.util.KEWConstants;
026 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
027
028
029 /**
030 * Tests a new document being spawned from the post processing of an existing document
031 *
032 * @author Kuali Rice Team (rice.collab@kuali.org)
033 */
034 public class PostProcessorSpawnDocument extends DefaultPostProcessor {
035 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PostProcessorSpawnDocument.class);
036
037 @Override
038 public ProcessDocReport doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) throws Exception {
039 LOG.info("Moving document " + statusChangeEvent.getDocumentId() + " from status '" + statusChangeEvent.getOldRouteStatus() + "' to status '" + statusChangeEvent.getNewRouteStatus() + "'");
040 if (StringUtils.equals(KEWConstants.ROUTE_HEADER_PROCESSED_CD, statusChangeEvent.getNewRouteStatus())) {
041 // spawn and route a new document
042 WorkflowDocument document = WorkflowDocumentFactory.createDocument(KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName("ewestfal").getPrincipalId(), "SpawnedDocumentType");
043 document.route("");
044 }
045 return new ProcessDocReport(true, "");
046 }
047
048 }