View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kew.actions;
17  
18  import org.kuali.rice.kew.api.WorkflowDocument;
19  import org.kuali.rice.kew.api.WorkflowDocumentFactory;
20  import org.kuali.rice.kew.api.WorkflowRuntimeException;
21  import org.kuali.rice.kew.api.exception.WorkflowException;
22  import org.kuali.rice.kew.framework.postprocessor.*;
23  import org.kuali.rice.kew.framework.postprocessor.AfterProcessEvent;
24  import org.kuali.rice.kew.framework.postprocessor.BeforeProcessEvent;
25  import org.kuali.rice.kew.framework.postprocessor.DeleteEvent;
26  import org.kuali.rice.kew.framework.postprocessor.DocumentLockingEvent;
27  import org.kuali.rice.kew.framework.postprocessor.DocumentRouteLevelChange;
28  import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange;
29  import org.kuali.rice.kew.framework.postprocessor.ProcessDocReport;
30  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
31  
32  import java.util.ArrayList;
33  import java.util.Arrays;
34  import java.util.List;
35  import java.util.Set;
36  
37  
38  /**
39   * This is a post processor class used for a Super User Test 
40   * 
41   * @author Kuali Rice Team (rice.collab@kuali.org)
42   *
43   */
44  public class SuperUserActionInvalidPostProcessor implements PostProcessor {
45  
46      private static final String USER_AUTH_ID = "rkirkend";
47      
48      /**
49       * THIS METHOD WILL THROW AN EXCEPTION IF OLD ROUTE NODE IS 'WorkflowTemplate'
50       */
51      public ProcessDocReport doActionTaken(org.kuali.rice.kew.framework.postprocessor.ActionTakenEvent event) throws Exception {
52          if (isDocumentPostProcessable(WorkflowDocumentFactory.loadDocument(getPrincipalId(USER_AUTH_ID), event.getDocumentId()))) {
53              return new ProcessDocReport(true, "");
54          }
55          throw new WorkflowRuntimeException("Post Processor should never be called in this instance");
56      }
57  
58      /**
59       * THIS METHOD WILL THROW AN EXCEPTION IF OLD ROUTE NODE IS 'WorkflowTemplate'
60       */
61      public ProcessDocReport doDeleteRouteHeader(DeleteEvent event) throws Exception {
62          if (isDocumentPostProcessable(WorkflowDocumentFactory.loadDocument(getPrincipalId(USER_AUTH_ID), event.getDocumentId()))) {
63              return new ProcessDocReport(true, "");
64          }
65          throw new WorkflowRuntimeException("Post Processor should never be called in this instance");
66      }
67  
68      /**
69       * THIS METHOD WILL THROW AN EXCEPTION IF OLD ROUTE NODE IS 'WorkflowTemplate'
70       */
71      public ProcessDocReport doRouteLevelChange(DocumentRouteLevelChange levelChangeEvent) throws Exception {
72          if (isDocumentPostProcessable(WorkflowDocumentFactory.loadDocument(getPrincipalId(USER_AUTH_ID), levelChangeEvent.getDocumentId()))) {
73              return new ProcessDocReport(true, "");
74          }
75          if ("WorkflowDocument2".equals(levelChangeEvent.getNewNodeName())) {
76              return new ProcessDocReport(true, "");
77          }
78          throw new WorkflowRuntimeException("Post Processor should never be called in this instance");
79      }
80  
81      /**
82       * THIS METHOD WILL THROW AN EXCEPTION IF OLD ROUTE NODE IS 'WorkflowTemplate'
83       */
84      public ProcessDocReport doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) throws Exception {
85          if (isDocumentPostProcessable(WorkflowDocumentFactory.loadDocument(getPrincipalId(USER_AUTH_ID), statusChangeEvent.getDocumentId()))) {
86              return new ProcessDocReport(true, "");
87          }
88          throw new WorkflowRuntimeException("Post Processor should never be called in this instance");
89      }
90      
91      /**
92       * THIS METHOD WILL THROW AN EXCEPTION IF OLD ROUTE NODE IS 'WorkflowTemplate'
93       */
94      public ProcessDocReport beforeProcess(BeforeProcessEvent beforeProcessEvent) throws Exception {
95          if (isDocumentPostProcessable(WorkflowDocumentFactory.loadDocument(getPrincipalId(USER_AUTH_ID), beforeProcessEvent.getDocumentId()))) {
96              return new ProcessDocReport(true, "");
97          }
98          throw new WorkflowRuntimeException("Post Processor should never be called in this instance");
99      }
100     
101     /**
102      * THIS METHOD WILL THROW AN EXCEPTION IF OLD ROUTE NODE IS 'WorkflowTemplate'
103      */
104     public ProcessDocReport afterProcess(AfterProcessEvent afterProcessEvent) throws Exception {
105         if (isDocumentPostProcessable(WorkflowDocumentFactory.loadDocument(getPrincipalId(USER_AUTH_ID), afterProcessEvent.getDocumentId()), Arrays.asList(new String[]{"WorkflowDocument2"}))) {
106             return new ProcessDocReport(true, "");
107         }
108         throw new WorkflowRuntimeException("Post Processor should never be called in this instance");
109     }
110     
111     /**
112      * @see org.kuali.rice.kew.framework.postprocessor.PostProcessor#getDocumentIdsToLock(org.kuali.rice.kew.framework.postprocessor.DocumentLockingEvent)
113      */
114     public List<String> getDocumentIdsToLock(DocumentLockingEvent lockingEvent) throws Exception {
115 		return null;
116 	}
117 
118 	private boolean isDocumentPostProcessable(WorkflowDocument doc) throws WorkflowException {
119     	return isDocumentPostProcessable(doc, new ArrayList<String>());
120     }
121     
122     private boolean isDocumentPostProcessable(WorkflowDocument doc, List<String> validNodeNames) throws WorkflowException {
123         Set<String> nodeNames = doc.getNodeNames();
124         if (nodeNames != null && nodeNames.size() > 0) {
125         	String nodeName = nodeNames.iterator().next();
126         	return validNodeNames.contains(nodeName) || (nodeName.equals("AdHoc")) || (nodeName.equals("WorkflowDocument"));
127         }
128         return false;
129     }
130 
131     private String getPrincipalId(String principalName) {
132         return KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(principalName).getPrincipalId();
133     }
134 }