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.action.ActionType;
22  import org.kuali.rice.kew.api.exception.WorkflowException;
23  import org.kuali.rice.kew.framework.postprocessor.*;
24  import org.kuali.rice.kew.framework.postprocessor.AfterProcessEvent;
25  import org.kuali.rice.kew.framework.postprocessor.BeforeProcessEvent;
26  import org.kuali.rice.kew.framework.postprocessor.DeleteEvent;
27  import org.kuali.rice.kew.framework.postprocessor.DocumentLockingEvent;
28  import org.kuali.rice.kew.framework.postprocessor.DocumentRouteLevelChange;
29  import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange;
30  import org.kuali.rice.kew.framework.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(org.kuali.rice.kew.framework.postprocessor.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 afterActionTaken(ActionType performed, org.kuali.rice.kew.framework.postprocessor.ActionTakenEvent 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 doDeleteRouteHeader(DeleteEvent event) throws Exception {
73          if (isDocumentPostProcessable(WorkflowDocumentFactory.loadDocument(getPrincipalId(USER_AUTH_ID), event.getDocumentId()))) {
74              return new ProcessDocReport(true, "");
75          }
76          throw new WorkflowRuntimeException("Post Processor should never be called in this instance");
77      }
78  
79      /**
80       * THIS METHOD WILL THROW AN EXCEPTION IF OLD ROUTE NODE IS 'WorkflowTemplate'
81       */
82      public ProcessDocReport doRouteLevelChange(DocumentRouteLevelChange levelChangeEvent) throws Exception {
83          if (isDocumentPostProcessable(WorkflowDocumentFactory.loadDocument(getPrincipalId(USER_AUTH_ID), levelChangeEvent.getDocumentId()))) {
84              return new ProcessDocReport(true, "");
85          }
86          if ("WorkflowDocument2".equals(levelChangeEvent.getNewNodeName())) {
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 doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) throws Exception {
96          if (isDocumentPostProcessable(WorkflowDocumentFactory.loadDocument(getPrincipalId(USER_AUTH_ID), statusChangeEvent.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 beforeProcess(BeforeProcessEvent beforeProcessEvent) throws Exception {
106         if (isDocumentPostProcessable(WorkflowDocumentFactory.loadDocument(getPrincipalId(USER_AUTH_ID), beforeProcessEvent.getDocumentId()))) {
107             return new ProcessDocReport(true, "");
108         }
109         throw new WorkflowRuntimeException("Post Processor should never be called in this instance");
110     }
111     
112     /**
113      * THIS METHOD WILL THROW AN EXCEPTION IF OLD ROUTE NODE IS 'WorkflowTemplate'
114      */
115     public ProcessDocReport afterProcess(AfterProcessEvent afterProcessEvent) throws Exception {
116         if (isDocumentPostProcessable(WorkflowDocumentFactory.loadDocument(getPrincipalId(USER_AUTH_ID), afterProcessEvent.getDocumentId()), Arrays.asList(new String[]{"WorkflowDocument2"}))) {
117             return new ProcessDocReport(true, "");
118         }
119         throw new WorkflowRuntimeException("Post Processor should never be called in this instance");
120     }
121     
122     /**
123      * @see org.kuali.rice.kew.framework.postprocessor.PostProcessor#getDocumentIdsToLock(org.kuali.rice.kew.framework.postprocessor.DocumentLockingEvent)
124      */
125     public List<String> getDocumentIdsToLock(DocumentLockingEvent lockingEvent) throws Exception {
126 		return null;
127 	}
128 
129 	private boolean isDocumentPostProcessable(WorkflowDocument doc) throws WorkflowException {
130     	return isDocumentPostProcessable(doc, new ArrayList<String>());
131     }
132     
133     private boolean isDocumentPostProcessable(WorkflowDocument doc, List<String> validNodeNames) throws WorkflowException {
134         Set<String> nodeNames = doc.getNodeNames();
135         if (nodeNames != null && nodeNames.size() > 0) {
136         	String nodeName = nodeNames.iterator().next();
137         	return validNodeNames.contains(nodeName) || (nodeName.equals("AdHoc")) || (nodeName.equals("WorkflowDocument"));
138         }
139         return false;
140     }
141 
142     private String getPrincipalId(String principalName) {
143         return KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(principalName).getPrincipalId();
144     }
145 }