001/** 002 * Copyright 2005-2015 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krad.document; 017 018import org.kuali.rice.krad.uif.view.RequestAuthorizationCache; 019import org.kuali.rice.krad.uif.view.View; 020import org.kuali.rice.krad.uif.view.ViewModel; 021import org.kuali.rice.krad.uif.view.ViewPresentationControllerBase; 022import org.kuali.rice.krad.util.KRADConstants; 023import org.kuali.rice.krad.util.KRADUtils; 024import org.kuali.rice.krad.web.form.DocumentFormBase; 025import org.kuali.rice.krad.web.form.UifFormBase; 026 027import java.util.HashSet; 028import java.util.Set; 029 030/** 031 * Implementation of {@link org.kuali.rice.krad.uif.view.ViewPresentationController} for 032 * {@link org.kuali.rice.krad.uif.view.DocumentView} instances 033 * 034 * <p> 035 * Adds flags for various document actions like save, route, cancel 036 * </p> 037 * 038 * <p> 039 * By default delegates to the {@link DocumentPresentationController} configured for the document in the data dictionary 040 * </p> 041 * 042 * @author Kuali Rice Team (rice.collab@kuali.org) 043 */ 044public class DocumentViewPresentationControllerBase extends ViewPresentationControllerBase implements DocumentPresentationController { 045 private static final long serialVersionUID = 1461173145806477758L; 046 047 private DocumentPresentationController documentPresentationController; 048 049 @Override 050 public Set<String> getActionFlags(View view, UifFormBase model) { 051 Set<String> documentActions = new HashSet<String>(); 052 053 Document document = ((DocumentFormBase) model).getDocument(); 054 055 DocumentRequestAuthorizationCache requestAuthorizationCache = 056 (DocumentRequestAuthorizationCache) getRequestAuthorizationCache(); 057 058 if (canEdit(document)) { 059 documentActions.add(KRADConstants.KUALI_ACTION_CAN_EDIT); 060 } 061 062 if (canAnnotate(document)) { 063 documentActions.add(KRADConstants.KUALI_ACTION_CAN_ANNOTATE); 064 } 065 066 if (canClose(document)) { 067 documentActions.add(KRADConstants.KUALI_ACTION_CAN_CLOSE); 068 } 069 070 if (canSave(document)) { 071 documentActions.add(KRADConstants.KUALI_ACTION_CAN_SAVE); 072 } 073 074 if (canRoute(document)) { 075 documentActions.add(KRADConstants.KUALI_ACTION_CAN_ROUTE); 076 } 077 078 if (canCancel(document)) { 079 documentActions.add(KRADConstants.KUALI_ACTION_CAN_CANCEL); 080 } 081 082 if (canReload(document)) { 083 documentActions.add(KRADConstants.KUALI_ACTION_CAN_RELOAD); 084 } 085 086 if (canCopy(document)) { 087 documentActions.add(KRADConstants.KUALI_ACTION_CAN_COPY); 088 } 089 090 if (canPerformRouteReport(document)) { 091 documentActions.add(KRADConstants.KUALI_ACTION_PERFORM_ROUTE_REPORT); 092 } 093 094 if (canAddAdhocRequests(document)) { 095 documentActions.add(KRADConstants.KUALI_ACTION_CAN_ADD_ADHOC_REQUESTS); 096 } 097 098 if (canBlanketApprove(document)) { 099 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}