View Javadoc
1   /**
2    * Copyright 2005-2016 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.krad.document;
17  
18  import org.kuali.rice.kew.api.WorkflowDocument;
19  import org.kuali.rice.kew.api.action.ActionType;
20  import org.kuali.rice.kew.api.action.ValidActions;
21  import org.kuali.rice.krad.uif.view.RequestAuthorizationCache;
22  
23  /**
24   * Request authorization cache object which adds caching on workflow document calls
25   *
26   * @author Kuali Rice Team (rice.collab@kuali.org)
27   */
28  public class DocumentRequestAuthorizationCache extends RequestAuthorizationCache {
29  
30      private static final long serialVersionUID = -3965168125219051628L;
31  
32      private WorkflowDocumentInfo workflowDocumentInfo;
33  
34      public void createWorkflowDocumentInfo(WorkflowDocument workflowDocument) {
35          if (this.workflowDocumentInfo == null) {
36              this.workflowDocumentInfo = new WorkflowDocumentInfo(workflowDocument);
37          }
38      }
39  
40      public WorkflowDocumentInfo getWorkflowDocumentInfo() {
41          return workflowDocumentInfo;
42      }
43  
44      public static class WorkflowDocumentInfo {
45  
46          private Boolean isCompletionRequested;
47          private Boolean isApprovalRequested;
48          private Boolean isAcknowledgeRequested;
49          private Boolean isFYIRequested;
50          private Boolean isInitiated;
51          private Boolean isSaved;
52          private Boolean isEnroute;
53          private Boolean isException;
54          private Boolean isCanceled;
55          private Boolean isRecalled;
56          private Boolean isDisapproved;
57          private Boolean isApproved;
58          private Boolean isProcessed;
59          private Boolean isFinal;
60  
61          private ValidActions validActions;
62  
63          private WorkflowDocument workflowDocument;
64  
65          public WorkflowDocumentInfo(WorkflowDocument workflowDocument) {
66              this.workflowDocument = workflowDocument;
67          }
68  
69          public boolean isCompletionRequested() {
70              if (isCompletionRequested == null) {
71                  isCompletionRequested = Boolean.valueOf(workflowDocument.isCompletionRequested());
72              }
73  
74              return isCompletionRequested.booleanValue();
75          }
76  
77          public boolean isApprovalRequested() {
78              if (isApprovalRequested == null) {
79                  isApprovalRequested = Boolean.valueOf(workflowDocument.isApprovalRequested());
80              }
81  
82              return isApprovalRequested.booleanValue();
83          }
84  
85          public boolean isAcknowledgeRequested() {
86              if (isAcknowledgeRequested == null) {
87                  isAcknowledgeRequested = Boolean.valueOf(workflowDocument.isAcknowledgeRequested());
88              }
89  
90              return isAcknowledgeRequested.booleanValue();
91          }
92  
93          public boolean isFYIRequested() {
94              if (isFYIRequested == null) {
95                  isFYIRequested = Boolean.valueOf(workflowDocument.isFYIRequested());
96              }
97  
98              return isFYIRequested.booleanValue();
99          }
100 
101         public boolean isInitiated() {
102             if (isInitiated == null) {
103                 isInitiated = Boolean.valueOf(workflowDocument.isInitiated());
104             }
105 
106             return isInitiated.booleanValue();
107         }
108 
109         public boolean isSaved() {
110             if (isSaved == null) {
111                 isSaved = Boolean.valueOf(workflowDocument.isSaved());
112             }
113 
114             return isSaved.booleanValue();
115         }
116 
117         public boolean isEnroute() {
118             if (isEnroute == null) {
119                 isEnroute = Boolean.valueOf(workflowDocument.isEnroute());
120             }
121 
122             return isEnroute.booleanValue();
123         }
124 
125         public boolean isException() {
126             if (isException == null) {
127                 isException = Boolean.valueOf(workflowDocument.isException());
128             }
129 
130             return isException.booleanValue();
131         }
132 
133         public boolean isCanceled() {
134             if (isCanceled == null) {
135                 isCanceled = Boolean.valueOf(workflowDocument.isCanceled());
136             }
137 
138             return isCanceled.booleanValue();
139         }
140 
141         public boolean isRecalled() {
142             if (isRecalled == null) {
143                 isRecalled = Boolean.valueOf(workflowDocument.isRecalled());
144             }
145 
146             return isRecalled.booleanValue();
147         }
148 
149         public boolean isDisapproved() {
150             if (isDisapproved == null) {
151                 isDisapproved = Boolean.valueOf(workflowDocument.isDisapproved());
152             }
153 
154             return isDisapproved.booleanValue();
155         }
156 
157         public boolean isApproved() {
158             if (isApproved == null) {
159                 isApproved = Boolean.valueOf(workflowDocument.isApproved());
160             }
161 
162             return isApproved.booleanValue();
163         }
164 
165         public boolean isProcessed() {
166             if (isProcessed == null) {
167                 isProcessed = Boolean.valueOf(workflowDocument.isProcessed());
168             }
169 
170             return isProcessed.booleanValue();
171         }
172 
173         public boolean isFinal() {
174             if (isFinal == null) {
175                 isFinal = Boolean.valueOf(workflowDocument.isFinal());
176             }
177 
178             return isFinal.booleanValue();
179         }
180 
181         public ValidActions getValidActions() {
182             if (validActions == null) {
183                 validActions = workflowDocument.getValidActions();
184             }
185 
186             return validActions;
187         }
188 
189         public boolean isValidAction(ActionType actionType) {
190             if (actionType == null) {
191                 throw new IllegalArgumentException("actionType was null");
192             }
193 
194             return getValidActions().getValidActions().contains(actionType);
195         }
196 
197         public WorkflowDocument getWorkflowDocument() {
198             return workflowDocument;
199         }
200     }
201 }