Coverage Report - org.kuali.rice.krad.document.authorization.DocumentPresentationControllerBase
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentPresentationControllerBase
0%
0/83
0%
0/74
2.762
 
 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.krad.document.authorization;
 17  
 
 18  
 import java.util.HashSet;
 19  
 import java.util.Set;
 20  
 
 21  
 import org.apache.commons.lang.StringUtils;
 22  
 import org.kuali.rice.core.framework.parameter.ParameterService;
 23  
 import org.kuali.rice.core.framework.services.CoreFrameworkServiceLocator;
 24  
 import org.kuali.rice.kew.api.WorkflowDocument;
 25  
 import org.kuali.rice.krad.document.Document;
 26  
 import org.kuali.rice.krad.util.GlobalVariables;
 27  
 import org.kuali.rice.krad.util.KRADConstants;
 28  
 
 29  
 
 30  0
 public class DocumentPresentationControllerBase implements DocumentPresentationController {
 31  
 //    private static Log LOG = LogFactory.getLog(DocumentPresentationControllerBase.class);
 32  
 
 33  
         private static transient ParameterService parameterService;
 34  
   
 35  
     public boolean canInitiate(String documentTypeName) {
 36  0
             return true;
 37  
     }
 38  
     
 39  
     /**
 40  
      * 
 41  
      * @param document
 42  
      * @return boolean (true if can edit the document)
 43  
      */
 44  
     protected boolean canEdit(Document document){
 45  0
             boolean canEdit = false;
 46  0
             WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
 47  0
         if (workflowDocument.isInitiated() || workflowDocument.isSaved() || workflowDocument.isEnroute() || workflowDocument.isException()) {
 48  0
                 canEdit = true; 
 49  
         }
 50  
         
 51  0
         return canEdit;
 52  
     }
 53  
     
 54  
     
 55  
     /**
 56  
      * 
 57  
      * @param document
 58  
      * @return boolean (true if can add notes to the document)
 59  
      */
 60  
     protected boolean canAnnotate(Document document){
 61  0
             return canEdit(document);
 62  
     }
 63  
     
 64  
    
 65  
     /**
 66  
      * 
 67  
      * @param document
 68  
      * @return boolean (true if can reload the document)
 69  
      */
 70  
     protected boolean canReload(Document document){
 71  0
             WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
 72  0
             return (canEdit(document) && !workflowDocument.isInitiated()) ;
 73  
              
 74  
     }
 75  
     
 76  
     
 77  
     /**
 78  
      * 
 79  
      * @param document
 80  
      * @return boolean (true if can close the document)
 81  
      */
 82  
     protected boolean canClose(Document document){
 83  0
             return true;
 84  
     }
 85  
     
 86  
     
 87  
    
 88  
     /**
 89  
      * 
 90  
      * @param document
 91  
      * @return boolean (true if can save the document)
 92  
      */
 93  
     protected boolean canSave(Document document){
 94  0
             return canEdit(document);
 95  
     }
 96  
     
 97  
   
 98  
     /**
 99  
      * 
 100  
      * @param document
 101  
      * @return boolean (true if can route the document)
 102  
      */
 103  
     protected boolean canRoute(Document document){
 104  0
             boolean canRoute = false;
 105  0
             WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
 106  0
             if (workflowDocument.isInitiated() || workflowDocument.isSaved()){
 107  0
                      canRoute = true;
 108  
             }
 109  0
             return canRoute;
 110  
     }
 111  
         
 112  
    
 113  
     /**
 114  
      * 
 115  
      * @param document
 116  
      * @return boolean (true if can cancel the document)
 117  
      */
 118  
     protected boolean canCancel(Document document){
 119  0
             return canEdit(document);
 120  
     }
 121  
     
 122  
    
 123  
     /**
 124  
      * 
 125  
      * @param document
 126  
      * @return boolean (true if can copy the document)
 127  
      */
 128  
     protected boolean canCopy(Document document){
 129  0
              boolean canCopy = false;
 130  0
              if(document.getAllowsCopy()){
 131  0
                      canCopy = true;
 132  
              }
 133  0
              return canCopy;
 134  
     }
 135  
     
 136  
     
 137  
    
 138  
     /**
 139  
      * 
 140  
      * @param document
 141  
      * @return boolean (true if can perform route report)
 142  
      */
 143  
     protected boolean canPerformRouteReport(Document document){
 144  0
         return getParameterService().getParameterValueAsBoolean(KRADConstants.KRAD_NAMESPACE, KRADConstants.DetailTypes.DOCUMENT_DETAIL_TYPE, KRADConstants.SystemGroupParameterNames.DEFAULT_CAN_PERFORM_ROUTE_REPORT_IND);
 145  
     }
 146  
     
 147  
    
 148  
     /**
 149  
      * 
 150  
      * @param document
 151  
      * @return boolean (true if can do ad hoc route)
 152  
      */
 153  
     protected boolean canAddAdhocRequests(Document document){
 154  0
             return true;
 155  
     }
 156  
     
 157  
    
 158  
     /**
 159  
      * This method ...
 160  
      * 
 161  
      * @param document
 162  
      * @return boolean (true if can blanket approve the document)
 163  
      */
 164  
     protected boolean canBlanketApprove(Document document){
 165  
             // check system parameter - if Y, use default workflow behavior: allow a user with the permission
 166  
             // to perform the blanket approve action at any time
 167  0
             Boolean allowBlanketApproveNoRequest = getParameterService().getParameterValueAsBoolean(KRADConstants.KRAD_NAMESPACE, KRADConstants.DetailTypes.DOCUMENT_DETAIL_TYPE, KRADConstants.SystemGroupParameterNames.ALLOW_ENROUTE_BLANKET_APPROVE_WITHOUT_APPROVAL_REQUEST_IND);
 168  0
             if ( allowBlanketApproveNoRequest != null && allowBlanketApproveNoRequest.booleanValue() ) {
 169  0
                     return canEdit(document);
 170  
             }
 171  
             // otherwise, limit the display of the blanket approve button to only the initiator of the document
 172  
             // (prior to routing)
 173  0
             WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
 174  0
             if ( canRoute(document) && StringUtils.equals( workflowDocument.getInitiatorPrincipalId(), GlobalVariables.getUserSession().getPrincipalId() ) ) {
 175  0
                     return true;
 176  
             }
 177  
             // or to a user with an approval action request
 178  0
             if ( workflowDocument.isApprovalRequested() ) {
 179  0
                     return true;
 180  
             }
 181  
             
 182  0
             return false;
 183  
     }
 184  
     
 185  
     protected boolean canApprove(Document document) {
 186  0
             return true;
 187  
     }
 188  
 
 189  
     protected boolean canDisapprove(Document document) {
 190  
             // most of the time, a person who can approve can disapprove
 191  0
             return canApprove(document);
 192  
     }
 193  
     
 194  
     protected boolean canSendAdhocRequests(Document document) {
 195  0
             WorkflowDocument kualiWorkflowDocument = document.getDocumentHeader().getWorkflowDocument();
 196  0
             return !(kualiWorkflowDocument.isInitiated() || kualiWorkflowDocument.isSaved());
 197  
     }
 198  
     
 199  
     protected boolean canSendNoteFyi(Document document) {
 200  0
             return true;
 201  
     }
 202  
     
 203  
     protected boolean canEditDocumentOverview(Document document){
 204  0
             WorkflowDocument kualiWorkflowDocument = document.getDocumentHeader().getWorkflowDocument();
 205  0
             return (kualiWorkflowDocument.isInitiated() || kualiWorkflowDocument.isSaved());
 206  
     }
 207  
 
 208  
     protected boolean canFyi(Document document) {
 209  0
             return true;
 210  
     }
 211  
     
 212  
     protected boolean canAcknowledge(Document document) {
 213  0
             return true;
 214  
     }
 215  
     
 216  
     /**
 217  
      * @see org.kuali.rice.krad.document.authorization.DocumentPresentationController#getDocumentActions(org.kuali.rice.krad.document.Document)
 218  
      */
 219  
     public Set<String> getDocumentActions(Document document){
 220  0
             Set<String> documentActions = new HashSet<String>();
 221  0
             if (canEdit(document)){
 222  0
                     documentActions.add(KRADConstants.KUALI_ACTION_CAN_EDIT);
 223  
             }
 224  
             
 225  0
             if(canAnnotate(document)){
 226  0
                     documentActions.add(KRADConstants.KUALI_ACTION_CAN_ANNOTATE);
 227  
             }
 228  
              
 229  0
             if(canClose(document)){
 230  0
                     documentActions.add(KRADConstants.KUALI_ACTION_CAN_CLOSE);
 231  
             }
 232  
              
 233  0
             if(canSave(document)){
 234  0
                     documentActions.add(KRADConstants.KUALI_ACTION_CAN_SAVE);
 235  
             }
 236  0
             if(canRoute(document)){
 237  0
                     documentActions.add(KRADConstants.KUALI_ACTION_CAN_ROUTE);
 238  
             }
 239  
              
 240  0
             if(canCancel(document)){
 241  0
                     documentActions.add(KRADConstants.KUALI_ACTION_CAN_CANCEL);
 242  
             }
 243  
              
 244  0
             if(canReload(document)){
 245  0
                     documentActions.add(KRADConstants.KUALI_ACTION_CAN_RELOAD);
 246  
             }
 247  0
             if(canCopy(document)){
 248  0
                     documentActions.add(KRADConstants.KUALI_ACTION_CAN_COPY);
 249  
             }
 250  0
             if(canPerformRouteReport(document)){
 251  0
                     documentActions.add(KRADConstants.KUALI_ACTION_PERFORM_ROUTE_REPORT);
 252  
             }
 253  
             
 254  0
             if(canAddAdhocRequests(document)){
 255  0
                     documentActions.add(KRADConstants.KUALI_ACTION_CAN_ADD_ADHOC_REQUESTS);
 256  
             }
 257  
             
 258  0
             if(canBlanketApprove(document)){
 259  0
                     documentActions.add(KRADConstants.KUALI_ACTION_CAN_BLANKET_APPROVE);
 260  
             }
 261  0
             if (canApprove(document)) {
 262  0
                     documentActions.add(KRADConstants.KUALI_ACTION_CAN_APPROVE);
 263  
             }
 264  0
             if (canDisapprove(document)) {
 265  0
                     documentActions.add(KRADConstants.KUALI_ACTION_CAN_DISAPPROVE);
 266  
             }
 267  0
             if (canSendAdhocRequests(document)) {
 268  0
                     documentActions.add(KRADConstants.KUALI_ACTION_CAN_SEND_ADHOC_REQUESTS);
 269  
             }
 270  0
             if(canSendNoteFyi(document)){
 271  0
                     documentActions.add(KRADConstants.KUALI_ACTION_CAN_SEND_NOTE_FYI);
 272  
             }
 273  0
             if(this.canEditDocumentOverview(document)){
 274  0
                     documentActions.add(KRADConstants.KUALI_ACTION_CAN_EDIT__DOCUMENT_OVERVIEW);
 275  
             }
 276  0
             if (canFyi(document)) {
 277  0
                     documentActions.add(KRADConstants.KUALI_ACTION_CAN_FYI);
 278  
             }
 279  0
             if (canAcknowledge(document)) {
 280  0
                     documentActions.add(KRADConstants.KUALI_ACTION_CAN_ACKNOWLEDGE);
 281  
             }
 282  0
             return documentActions;
 283  
     }
 284  
 
 285  
         protected ParameterService getParameterService() {
 286  0
                 if ( parameterService == null ) {
 287  0
                         parameterService = CoreFrameworkServiceLocator.getParameterService();
 288  
                 }
 289  0
                 return parameterService;
 290  
         }
 291  
 
 292  
 
 293  
 }