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