001 /** 002 * Copyright 2005-2013 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.impl.action; 017 018 import java.util.HashSet; 019 import java.util.Set; 020 021 import org.apache.commons.lang.StringUtils; 022 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException; 023 import org.kuali.rice.kew.actions.BlanketApproveAction; 024 import org.kuali.rice.kew.actions.MoveDocumentAction; 025 import org.kuali.rice.kew.actiontaken.ActionTakenValue; 026 import org.kuali.rice.kew.api.KewApiServiceLocator; 027 import org.kuali.rice.kew.api.WorkflowRuntimeException; 028 import org.kuali.rice.kew.api.document.DocumentOrchestrationQueue; 029 import org.kuali.rice.kew.api.document.DocumentProcessingOptions; 030 import org.kuali.rice.kew.api.document.OrchestrationConfig; 031 import org.kuali.rice.kew.api.document.attribute.DocumentAttributeIndexingQueue; 032 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; 033 import org.kuali.rice.kew.service.KEWServiceLocator; 034 import org.kuali.rice.kim.api.identity.principal.Principal; 035 036 import javax.jws.WebParam; 037 038 /** 039 * References implementation of the {@code DocumentOrchestrationQueue}. 040 * 041 * @author Kuali Rice Team (rice.collab@kuali.org) 042 */ 043 public class DocumentOrchestrationQueueImpl implements DocumentOrchestrationQueue { 044 045 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DocumentOrchestrationQueueImpl.class); 046 047 @Override 048 public void orchestrateDocument(String documentId, String principalId, OrchestrationConfig orchestrationConfig, 049 DocumentProcessingOptions documentProcessingOptions) { 050 if (StringUtils.isBlank(principalId)) { 051 throw new RiceIllegalArgumentException("principalId is null or blank"); 052 } 053 054 if (StringUtils.isBlank(documentId)) { 055 throw new RiceIllegalArgumentException("documentId is null"); 056 } 057 058 if (orchestrationConfig == null) { 059 throw new RiceIllegalArgumentException("orchestrationConfig is null"); 060 } 061 if (documentProcessingOptions == null) { 062 documentProcessingOptions = DocumentProcessingOptions.createDefault(); 063 } 064 065 LOG.info("Performing document orchestration on documentId=" + documentId); 066 KEWServiceLocator.getRouteHeaderService().lockRouteHeader(documentId, true); 067 DocumentRouteHeaderValue document = KEWServiceLocator.getRouteHeaderService().getRouteHeader(documentId); 068 ActionTakenValue actionTaken = KEWServiceLocator.getActionTakenService().findByActionTakenId(orchestrationConfig.getActionTakenId()); 069 Principal principal = KEWServiceLocator.getIdentityHelperService().getPrincipal(principalId); 070 BlanketApproveAction blanketApprove = new BlanketApproveAction(document, principal, "", orchestrationConfig.getNodeNames()); 071 try { 072 blanketApprove.performDeferredBlanketApproveWork(actionTaken, documentProcessingOptions); 073 } catch (Exception e) { 074 if (e instanceof RuntimeException) { 075 throw (RuntimeException)e; 076 } 077 throw new WorkflowRuntimeException(e); 078 } 079 if (documentProcessingOptions.isIndexSearchAttributes()) { 080 DocumentAttributeIndexingQueue queue = KewApiServiceLocator.getDocumentAttributeIndexingQueue(document.getDocumentType().getApplicationId()); 081 queue.indexDocument(documentId); 082 } 083 LOG.info("Document orchestration complete against documentId=" + documentId); 084 } 085 086 }