View Javadoc

1   /*
2    * Copyright 2007-2008 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.exception.WorkflowException;
22  import org.kuali.rice.kew.postprocessor.ActionTakenEvent;
23  import org.kuali.rice.kew.postprocessor.AfterProcessEvent;
24  import org.kuali.rice.kew.postprocessor.BeforeProcessEvent;
25  import org.kuali.rice.kew.postprocessor.DeleteEvent;
26  import org.kuali.rice.kew.postprocessor.DocumentLockingEvent;
27  import org.kuali.rice.kew.postprocessor.DocumentRouteLevelChange;
28  import org.kuali.rice.kew.postprocessor.DocumentRouteStatusChange;
29  import org.kuali.rice.kew.postprocessor.PostProcessor;
30  import org.kuali.rice.kew.postprocessor.ProcessDocReport;
31  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
32  
33  import java.util.ArrayList;
34  import java.util.Arrays;
35  import java.util.List;
36  import java.util.Set;
37  
38  
39  /**
40   * This is a post processor class used for a Super User Test 
41   * 
42   * @author Kuali Rice Team (rice.collab@kuali.org)
43   *
44   */
45  public class SuperUserActionInvalidPostProcessor implements PostProcessor {
46  
47      private static final String USER_AUTH_ID = "rkirkend";
48      
49      /**
50       * THIS METHOD WILL THROW AN EXCEPTION IF OLD ROUTE NODE IS 'WorkflowTemplate'
51       */
52      public ProcessDocReport doActionTaken(ActionTakenEvent event) throws Exception {
53          if (isDocumentPostProcessable(WorkflowDocumentFactory.loadDocument(getPrincipalId(USER_AUTH_ID), event.getDocumentId()))) {
54              return new ProcessDocReport(true, "");
55          }
56          throw new WorkflowRuntimeException("Post Processor should never be called in this instance");
57      }
58  
59      /**
60       * THIS METHOD WILL THROW AN EXCEPTION IF OLD ROUTE NODE IS 'WorkflowTemplate'
61       */
62      public ProcessDocReport doDeleteRouteHeader(DeleteEvent event) throws Exception {
63          if (isDocumentPostProcessable(WorkflowDocumentFactory.loadDocument(getPrincipalId(USER_AUTH_ID), event.getDocumentId()))) {
64              return new ProcessDocReport(true, "");
65          }
66          throw new WorkflowRuntimeException("Post Processor should never be called in this instance");
67      }
68  
69      /**
70       * THIS METHOD WILL THROW AN EXCEPTION IF OLD ROUTE NODE IS 'WorkflowTemplate'
71       */
72      public ProcessDocReport doRouteLevelChange(DocumentRouteLevelChange levelChangeEvent) throws Exception {
73          if (isDocumentPostProcessable(WorkflowDocumentFactory.loadDocument(getPrincipalId(USER_AUTH_ID), levelChangeEvent.getDocumentId()))) {
74              return new ProcessDocReport(true, "");
75          }
76          if ("WorkflowDocument2".equals(levelChangeEvent.getNewNodeName())) {
77              return new ProcessDocReport(true, "");
78          }
79          throw new WorkflowRuntimeException("Post Processor should never be called in this instance");
80      }
81  
82      /**
83       * THIS METHOD WILL THROW AN EXCEPTION IF OLD ROUTE NODE IS 'WorkflowTemplate'
84       */
85      public ProcessDocReport doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) throws Exception {
86          if (isDocumentPostProcessable(WorkflowDocumentFactory.loadDocument(getPrincipalId(USER_AUTH_ID), statusChangeEvent.getDocumentId()))) {
87              return new ProcessDocReport(true, "");
88          }
89          throw new WorkflowRuntimeException("Post Processor should never be called in this instance");
90      }
91      
92      /**
93       * THIS METHOD WILL THROW AN EXCEPTION IF OLD ROUTE NODE IS 'WorkflowTemplate'
94       */
95      public ProcessDocReport beforeProcess(BeforeProcessEvent beforeProcessEvent) throws Exception {
96          if (isDocumentPostProcessable(WorkflowDocumentFactory.loadDocument(getPrincipalId(USER_AUTH_ID), beforeProcessEvent.getDocumentId()))) {
97              return new ProcessDocReport(true, "");
98          }
99          throw new WorkflowRuntimeException("Post Processor should never be called in this instance");
100     }
101     
102     /**
103      * THIS METHOD WILL THROW AN EXCEPTION IF OLD ROUTE NODE IS 'WorkflowTemplate'
104      */
105     public ProcessDocReport afterProcess(AfterProcessEvent afterProcessEvent) throws Exception {
106         if (isDocumentPostProcessable(WorkflowDocumentFactory.loadDocument(getPrincipalId(USER_AUTH_ID), afterProcessEvent.getDocumentId()), Arrays.asList(new String[]{"WorkflowDocument2"}))) {
107             return new ProcessDocReport(true, "");
108         }
109         throw new WorkflowRuntimeException("Post Processor should never be called in this instance");
110     }
111     
112     /**
113      * @see org.kuali.rice.kew.postprocessor.PostProcessor#getDocumentIdsToLock(org.kuali.rice.kew.postprocessor.DocumentLockingEvent)
114      */
115     public List<String> getDocumentIdsToLock(DocumentLockingEvent lockingEvent) throws Exception {
116 		return null;
117 	}
118 
119 	private boolean isDocumentPostProcessable(WorkflowDocument doc) throws WorkflowException {
120     	return isDocumentPostProcessable(doc, new ArrayList<String>());
121     }
122     
123     private boolean isDocumentPostProcessable(WorkflowDocument doc, List<String> validNodeNames) throws WorkflowException {
124         Set<String> nodeNames = doc.getNodeNames();
125         if (nodeNames != null && nodeNames.size() > 0) {
126         	String nodeName = nodeNames.iterator().next();
127         	return validNodeNames.contains(nodeName) || (nodeName.equals("AdHoc")) || (nodeName.equals("WorkflowDocument"));
128         }
129         return false;
130     }
131 
132     private String getPrincipalId(String principalName) {
133         return KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(principalName).getPrincipalId();
134     }
135 }