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.krad.uif.view.RequestAuthorizationCache;
19  import org.kuali.rice.krad.uif.view.View;
20  import org.kuali.rice.krad.uif.view.ViewModel;
21  import org.kuali.rice.krad.uif.view.ViewPresentationControllerBase;
22  import org.kuali.rice.krad.util.KRADConstants;
23  import org.kuali.rice.krad.util.KRADUtils;
24  import org.kuali.rice.krad.web.form.DocumentFormBase;
25  import org.kuali.rice.krad.web.form.UifFormBase;
26  
27  import java.util.HashSet;
28  import java.util.Set;
29  
30  /**
31   * Implementation of {@link org.kuali.rice.krad.uif.view.ViewPresentationController} for
32   * {@link org.kuali.rice.krad.uif.view.DocumentView} instances
33   *
34   * <p>
35   * Adds flags for various document actions like save, route, cancel
36   * </p>
37   *
38   * <p>
39   * By default delegates to the {@link DocumentPresentationController} configured for the document in the data dictionary
40   * </p>
41   *
42   * @author Kuali Rice Team (rice.collab@kuali.org)
43   */
44  public class DocumentViewPresentationControllerBase extends ViewPresentationControllerBase implements DocumentPresentationController {
45      private static final long serialVersionUID = 1461173145806477758L;
46  
47      private DocumentPresentationController documentPresentationController;
48  
49      @Override
50      public Set<String> getActionFlags(View view, UifFormBase model) {
51          Set<String> documentActions = new HashSet<String>();
52  
53          Document document = ((DocumentFormBase) model).getDocument();
54  
55          DocumentRequestAuthorizationCache requestAuthorizationCache =
56                  (DocumentRequestAuthorizationCache) getRequestAuthorizationCache();
57  
58          if (canEdit(document)) {
59              documentActions.add(KRADConstants.KUALI_ACTION_CAN_EDIT);
60          }
61  
62          if (canAnnotate(document)) {
63              documentActions.add(KRADConstants.KUALI_ACTION_CAN_ANNOTATE);
64          }
65  
66          if (canClose(document)) {
67              documentActions.add(KRADConstants.KUALI_ACTION_CAN_CLOSE);
68          }
69  
70          if (canSave(document)) {
71              documentActions.add(KRADConstants.KUALI_ACTION_CAN_SAVE);
72          }
73  
74          if (canRoute(document)) {
75              documentActions.add(KRADConstants.KUALI_ACTION_CAN_ROUTE);
76          }
77  
78          if (canCancel(document)) {
79              documentActions.add(KRADConstants.KUALI_ACTION_CAN_CANCEL);
80          }
81  
82          if (canReload(document)) {
83              documentActions.add(KRADConstants.KUALI_ACTION_CAN_RELOAD);
84          }
85  
86          if (canCopy(document)) {
87              documentActions.add(KRADConstants.KUALI_ACTION_CAN_COPY);
88          }
89  
90          if (canPerformRouteReport(document)) {
91              documentActions.add(KRADConstants.KUALI_ACTION_PERFORM_ROUTE_REPORT);
92          }
93  
94          if (canAddAdhocRequests(document)) {
95              documentActions.add(KRADConstants.KUALI_ACTION_CAN_ADD_ADHOC_REQUESTS);
96          }
97  
98          if (canBlanketApprove(document)) {
99              documentActions.add(KRADConstants.KUALI_ACTION_CAN_BLANKET_APPROVE);
100         }
101 
102         if (canApprove(document)) {
103             documentActions.add(KRADConstants.KUALI_ACTION_CAN_APPROVE);
104         }
105 
106         if (canDisapprove(document)) {
107             documentActions.add(KRADConstants.KUALI_ACTION_CAN_DISAPPROVE);
108         }
109 
110         if (canSendAdhocRequests(document)) {
111             documentActions.add(KRADConstants.KUALI_ACTION_CAN_SEND_ADHOC_REQUESTS);
112         }
113 
114         if (canSendNoteFyi(document)) {
115             documentActions.add(KRADConstants.KUALI_ACTION_CAN_SEND_NOTE_FYI);
116         }
117 
118         if (this.canEditDocumentOverview(document)) {
119             documentActions.add(KRADConstants.KUALI_ACTION_CAN_EDIT_DOCUMENT_OVERVIEW);
120         }
121 
122         if (canFyi(document)) {
123             documentActions.add(KRADConstants.KUALI_ACTION_CAN_FYI);
124         }
125 
126         if (canAcknowledge(document)) {
127             documentActions.add(KRADConstants.KUALI_ACTION_CAN_ACKNOWLEDGE);
128         }
129 
130         if (canComplete(document)) {
131             documentActions.add(KRADConstants.KUALI_ACTION_CAN_COMPLETE);
132         }
133 
134         if (canRecall(document)) {
135             documentActions.add(KRADConstants.KUALI_ACTION_CAN_RECALL);
136         }
137 
138         if (canSuperUserTakeAction(document)) {
139             documentActions.add(KRADConstants.KUALI_ACTION_CAN_SUPER_USER_TAKE_ACTION);
140         }
141 
142         if (canSuperUserApprove(document)) {
143             documentActions.add(KRADConstants.KUALI_ACTION_CAN_SUPER_USER_APPROVE);
144         }
145 
146         if (canSuperUserDisapprove(document)) {
147             documentActions.add(KRADConstants.KUALI_ACTION_CAN_SUPER_USER_DISAPPROVE);
148         }
149 
150         return documentActions;
151     }
152 
153     public boolean canInitiate(String documentTypeName) {
154         return getDocumentPresentationController().canInitiate(documentTypeName);
155     }
156 
157     public boolean canEdit(Document document) {
158         return getDocumentPresentationController().canEdit(document);
159     }
160 
161     /**
162      * Verify the document can be edited in addition to the view
163      */
164     @Override
165     public boolean canEditView(View view, ViewModel model) {
166         DocumentFormBase documentForm = (DocumentFormBase) model;
167 
168         return super.canEditView(view, model) && canEdit(documentForm.getDocument());
169     }
170 
171     public boolean canAnnotate(Document document) {
172         return getDocumentPresentationController().canAnnotate(document);
173     }
174 
175     public boolean canReload(Document document) {
176         return getDocumentPresentationController().canReload(document);
177     }
178 
179     public boolean canClose(Document document) {
180         return getDocumentPresentationController().canClose(document);
181     }
182 
183     public boolean canSave(Document document) {
184         return getDocumentPresentationController().canSave(document);
185     }
186 
187     public boolean canRoute(Document document) {
188         return getDocumentPresentationController().canRoute(document);
189     }
190 
191     public boolean canCancel(Document document) {
192         return getDocumentPresentationController().canCancel(document);
193     }
194 
195     public boolean canRecall(Document document) {
196         return getDocumentPresentationController().canRecall(document);
197     }
198 
199     public boolean canCopy(Document document) {
200         return getDocumentPresentationController().canCopy(document);
201     }
202 
203     public boolean canPerformRouteReport(Document document) {
204         return getDocumentPresentationController().canPerformRouteReport(document);
205     }
206 
207     public boolean canAddAdhocRequests(Document document) {
208         return getDocumentPresentationController().canAddAdhocRequests(document);
209     }
210 
211     public boolean canBlanketApprove(Document document) {
212         return getDocumentPresentationController().canBlanketApprove(document);
213     }
214 
215     public boolean canApprove(Document document) {
216         return getDocumentPresentationController().canApprove(document);
217     }
218 
219     public boolean canDisapprove(Document document) {
220         return getDocumentPresentationController().canDisapprove(document);
221     }
222 
223     public boolean canSendAdhocRequests(Document document) {
224         return getDocumentPresentationController().canSendAdhocRequests(document);
225     }
226 
227     public boolean canSendNoteFyi(Document document) {
228         return getDocumentPresentationController().canSendNoteFyi(document);
229     }
230 
231     public boolean canEditDocumentOverview(Document document) {
232         return getDocumentPresentationController().canEditDocumentOverview(document);
233     }
234 
235     public boolean canFyi(Document document) {
236         return getDocumentPresentationController().canFyi(document);
237     }
238 
239     public boolean canAcknowledge(Document document) {
240         return getDocumentPresentationController().canAcknowledge(document);
241     }
242 
243     public boolean canComplete(Document document) {
244         return getDocumentPresentationController().canComplete(document);
245     }
246 
247     /**
248      * {@inheritDoc}
249      */
250     @Override
251     public boolean canSuperUserTakeAction(Document document) {
252         return getDocumentPresentationController().canSuperUserTakeAction(document);
253     }
254 
255     /**
256      * {@inheritDoc}
257      */
258     @Override
259     public boolean canSuperUserApprove(Document document) {
260         return getDocumentPresentationController().canSuperUserApprove(document);
261     }
262 
263     /**
264      * {@inheritDoc}
265      */
266     @Override
267     public boolean canSuperUserDisapprove(Document document) {
268         return getDocumentPresentationController().canSuperUserDisapprove(document);
269     }
270 
271     public DocumentPresentationController getDocumentPresentationController() {
272         return documentPresentationController;
273     }
274 
275     public void setDocumentPresentationController(DocumentPresentationController documentPresentationController) {
276         this.documentPresentationController = documentPresentationController;
277     }
278 
279     public void setDocumentPresentationControllerClass(
280             Class<? extends DocumentPresentationController> documentPresentationControllerClass) {
281         this.documentPresentationController = KRADUtils.createNewObjectFromClass(documentPresentationControllerClass);
282     }
283 
284     protected DocumentRequestAuthorizationCache getDocumentRequestAuthorizationCache(Document document) {
285         if (getRequestAuthorizationCache() == null) {
286             setRequestAuthorizationCache(new DocumentRequestAuthorizationCache());
287         }
288 
289         DocumentRequestAuthorizationCache documentRequestAuthorizationCache =
290                 (DocumentRequestAuthorizationCache) getRequestAuthorizationCache();
291         if (documentRequestAuthorizationCache.getWorkflowDocumentInfo() == null) {
292             documentRequestAuthorizationCache.createWorkflowDocumentInfo(
293                     document.getDocumentHeader().getWorkflowDocument());
294         }
295 
296         return documentRequestAuthorizationCache;
297     }
298 
299     /**
300      * {@inheritDoc}
301      */
302     @Override
303     public void setDocumentRequestAuthorizationCache(
304             DocumentRequestAuthorizationCache documentRequestAuthorizationCache) {
305           this.setRequestAuthorizationCache(documentRequestAuthorizationCache);
306     }
307 
308     /**
309      * {@inheritDoc}
310      */
311     @Override
312     public void setRequestAuthorizationCache(RequestAuthorizationCache requestAuthorizationCache) {
313         super.setRequestAuthorizationCache(requestAuthorizationCache);
314 
315         if (!(requestAuthorizationCache instanceof DocumentRequestAuthorizationCache)) {
316             throw new RuntimeException(
317                     "Request authorization cache should be instance of " + DocumentRequestAuthorizationCache.class
318                             .getName());
319         }
320 
321         getDocumentPresentationController().setDocumentRequestAuthorizationCache(
322                 (DocumentRequestAuthorizationCache) requestAuthorizationCache);
323     }
324 }