Coverage Report - org.kuali.rice.kns.uif.authorization.DocumentPresentationControllerBase
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentPresentationControllerBase
0%
0/85
0%
0/72
2.762
 
 1  
 /*
 2  
  * Copyright 2011 The Kuali Foundation
 3  
  * 
 4  
  * Licensed under the Educational Community License, Version 1.0 (the
 5  
  * "License"); 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/ecl1.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, WITHOUT
 12  
  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 13  
  * License for the specific language governing permissions and limitations under
 14  
  * the License.
 15  
  */
 16  
 package org.kuali.rice.kns.uif.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.kns.document.Document;
 25  
 import org.kuali.rice.kns.util.GlobalVariables;
 26  
 import org.kuali.rice.kns.util.KNSConstants;
 27  
 import org.kuali.rice.kns.web.spring.form.DocumentFormBase;
 28  
 import org.kuali.rice.kns.web.spring.form.UifFormBase;
 29  
 import org.kuali.rice.kns.workflow.service.KualiWorkflowDocument;
 30  
 
 31  
 /**
 32  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 33  
  */
 34  0
 public class DocumentPresentationControllerBase extends PresentationControllerBase {
 35  
 
 36  
     private static transient ParameterService parameterService;
 37  
 
 38  
     @Override
 39  
     public Set<String> getActionFlags(UifFormBase model) {
 40  0
         Set<String> documentActions = new HashSet<String>();
 41  
       
 42  0
         Document document = ((DocumentFormBase) model).getDocument();
 43  
 
 44  0
         if (canEdit(document)) {
 45  0
             documentActions.add(KNSConstants.KUALI_ACTION_CAN_EDIT);
 46  
         }
 47  
 
 48  0
         if (canAnnotate(document)) {
 49  0
             documentActions.add(KNSConstants.KUALI_ACTION_CAN_ANNOTATE);
 50  
         }
 51  
 
 52  0
         if (canClose(document)) {
 53  0
             documentActions.add(KNSConstants.KUALI_ACTION_CAN_CLOSE);
 54  
         }
 55  
 
 56  0
         if (canSave(document)) {
 57  0
             documentActions.add(KNSConstants.KUALI_ACTION_CAN_SAVE);
 58  
         }
 59  
 
 60  0
         if (canRoute(document)) {
 61  0
             documentActions.add(KNSConstants.KUALI_ACTION_CAN_ROUTE);
 62  
         }
 63  
 
 64  0
         if (canCancel(document)) {
 65  0
             documentActions.add(KNSConstants.KUALI_ACTION_CAN_CANCEL);
 66  
         }
 67  
 
 68  0
         if (canReload(document)) {
 69  0
             documentActions.add(KNSConstants.KUALI_ACTION_CAN_RELOAD);
 70  
         }
 71  
 
 72  0
         if (canCopy(document)) {
 73  0
             documentActions.add(KNSConstants.KUALI_ACTION_CAN_COPY);
 74  
         }
 75  
 
 76  0
         if (canPerformRouteReport(document)) {
 77  0
             documentActions.add(KNSConstants.KUALI_ACTION_PERFORM_ROUTE_REPORT);
 78  
         }
 79  
 
 80  0
         if (canAddAdhocRequests(document)) {
 81  0
             documentActions.add(KNSConstants.KUALI_ACTION_CAN_ADD_ADHOC_REQUESTS);
 82  
         }
 83  
 
 84  0
         if (canBlanketApprove(document)) {
 85  0
             documentActions.add(KNSConstants.KUALI_ACTION_CAN_BLANKET_APPROVE);
 86  
         }
 87  
 
 88  0
         if (canApprove(document)) {
 89  0
             documentActions.add(KNSConstants.KUALI_ACTION_CAN_APPROVE);
 90  
         }
 91  
 
 92  0
         if (canDisapprove(document)) {
 93  0
             documentActions.add(KNSConstants.KUALI_ACTION_CAN_DISAPPROVE);
 94  
         }
 95  
 
 96  0
         if (canSendAdhocRequests(document)) {
 97  0
             documentActions.add(KNSConstants.KUALI_ACTION_CAN_SEND_ADHOC_REQUESTS);
 98  
         }
 99  
 
 100  0
         if (canSendNoteFyi(document)) {
 101  0
             documentActions.add(KNSConstants.KUALI_ACTION_CAN_SEND_NOTE_FYI);
 102  
         }
 103  
 
 104  0
         if (this.canEditDocumentOverview(document)) {
 105  0
             documentActions.add(KNSConstants.KUALI_ACTION_CAN_EDIT__DOCUMENT_OVERVIEW);
 106  
         }
 107  
 
 108  0
         if (canFyi(document)) {
 109  0
             documentActions.add(KNSConstants.KUALI_ACTION_CAN_FYI);
 110  
         }
 111  
 
 112  0
         if (canAcknowledge(document)) {
 113  0
             documentActions.add(KNSConstants.KUALI_ACTION_CAN_ACKNOWLEDGE);
 114  
         }
 115  
 
 116  0
         return documentActions;
 117  
     }
 118  
 
 119  
     public boolean canInitiate(String documentTypeName) {
 120  0
         return true;
 121  
     }
 122  
 
 123  
     /**
 124  
      * @param document
 125  
      * @return boolean (true if can edit the document)
 126  
      */
 127  
     protected boolean canEdit(Document document) {
 128  0
         boolean canEdit = false;
 129  0
         KualiWorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
 130  0
         if (workflowDocument.stateIsInitiated() || workflowDocument.stateIsSaved() || workflowDocument.stateIsEnroute()
 131  
                 || workflowDocument.stateIsException()) {
 132  0
             canEdit = true;
 133  
         }
 134  
 
 135  0
         return canEdit;
 136  
     }
 137  
 
 138  
     /**
 139  
      * @param document
 140  
      * @return boolean (true if can add notes to the document)
 141  
      */
 142  
     protected boolean canAnnotate(Document document) {
 143  0
         return canEdit(document);
 144  
     }
 145  
 
 146  
     /**
 147  
      * @param document
 148  
      * @return boolean (true if can reload the document)
 149  
      */
 150  
     protected boolean canReload(Document document) {
 151  0
         KualiWorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
 152  0
         return (canEdit(document) && !workflowDocument.stateIsInitiated());
 153  
 
 154  
     }
 155  
 
 156  
     /**
 157  
      * @param document
 158  
      * @return boolean (true if can close the document)
 159  
      */
 160  
     protected boolean canClose(Document document) {
 161  0
         return true;
 162  
     }
 163  
 
 164  
     /**
 165  
      * @param document
 166  
      * @return boolean (true if can save the document)
 167  
      */
 168  
     protected boolean canSave(Document document) {
 169  0
         return canEdit(document);
 170  
     }
 171  
 
 172  
     /**
 173  
      * @param document
 174  
      * @return boolean (true if can route the document)
 175  
      */
 176  
     protected boolean canRoute(Document document) {
 177  0
         boolean canRoute = false;
 178  0
         KualiWorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
 179  0
         if (workflowDocument.stateIsInitiated() || workflowDocument.stateIsSaved()) {
 180  0
             canRoute = true;
 181  
         }
 182  0
         return canRoute;
 183  
     }
 184  
 
 185  
     /**
 186  
      * @param document
 187  
      * @return boolean (true if can cancel the document)
 188  
      */
 189  
     protected boolean canCancel(Document document) {
 190  0
         return canEdit(document);
 191  
     }
 192  
 
 193  
     /**
 194  
      * @param document
 195  
      * @return boolean (true if can copy the document)
 196  
      */
 197  
     protected boolean canCopy(Document document) {
 198  0
         boolean canCopy = false;
 199  0
         if (document.getAllowsCopy()) {
 200  0
             canCopy = true;
 201  
         }
 202  0
         return canCopy;
 203  
     }
 204  
 
 205  
     /**
 206  
      * @param document
 207  
      * @return boolean (true if can perform route report)
 208  
      */
 209  
     protected boolean canPerformRouteReport(Document document) {
 210  0
         return getParameterService().getParameterValueAsBoolean(KNSConstants.KNS_NAMESPACE,
 211  
                 KNSConstants.DetailTypes.DOCUMENT_DETAIL_TYPE,
 212  
                 KNSConstants.SystemGroupParameterNames.DEFAULT_CAN_PERFORM_ROUTE_REPORT_IND);
 213  
     }
 214  
 
 215  
     /**
 216  
      * @param document
 217  
      * @return boolean (true if can do ad hoc route)
 218  
      */
 219  
     protected boolean canAddAdhocRequests(Document document) {
 220  0
         return true;
 221  
     }
 222  
 
 223  
     /**
 224  
      * This method ...
 225  
      * 
 226  
      * @param document
 227  
      * @return boolean (true if can blanket approve the document)
 228  
      */
 229  
     protected boolean canBlanketApprove(Document document) {
 230  
         // check system parameter - if Y, use default workflow behavior: allow a
 231  
         // user with the permission
 232  
         // to perform the blanket approve action at any time
 233  
         try {
 234  0
             if (getParameterService().getParameterValueAsBoolean(KNSConstants.KNS_NAMESPACE,
 235  
                     KNSConstants.DetailTypes.DOCUMENT_DETAIL_TYPE,
 236  
                     KNSConstants.SystemGroupParameterNames.ALLOW_ENROUTE_BLANKET_APPROVE_WITHOUT_APPROVAL_REQUEST_IND)) {
 237  0
                 return canEdit(document);
 238  
             }
 239  
         }
 240  0
         catch (IllegalArgumentException ex) {
 241  
             // do nothing, the parameter does not exist and defaults to "N"
 242  0
         }
 243  
         // otherwise, limit the display of the blanket approve button to only
 244  
         // the initiator of the document
 245  
         // (prior to routing)
 246  0
         KualiWorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
 247  0
         if (canRoute(document)
 248  
                 && StringUtils.equals(workflowDocument.getInitiatorPrincipalId(), GlobalVariables.getUserSession()
 249  
                         .getPrincipalId())) {
 250  0
             return true;
 251  
         }
 252  
         // or to a user with an approval action request
 253  0
         if (workflowDocument.isApprovalRequested()) {
 254  0
             return true;
 255  
         }
 256  
 
 257  0
         return false;
 258  
     }
 259  
 
 260  
     protected boolean canApprove(Document document) {
 261  0
         return true;
 262  
     }
 263  
 
 264  
     protected boolean canDisapprove(Document document) {
 265  
         // most of the time, a person who can approve can disapprove
 266  0
         return canApprove(document);
 267  
     }
 268  
 
 269  
     protected boolean canSendAdhocRequests(Document document) {
 270  0
         KualiWorkflowDocument kualiWorkflowDocument = document.getDocumentHeader().getWorkflowDocument();
 271  0
         return !(kualiWorkflowDocument.stateIsInitiated() || kualiWorkflowDocument.stateIsSaved());
 272  
     }
 273  
 
 274  
     protected boolean canSendNoteFyi(Document document) {
 275  0
         return true;
 276  
     }
 277  
 
 278  
     protected boolean canEditDocumentOverview(Document document) {
 279  0
         KualiWorkflowDocument kualiWorkflowDocument = document.getDocumentHeader().getWorkflowDocument();
 280  0
         return (kualiWorkflowDocument.stateIsInitiated() || kualiWorkflowDocument.stateIsSaved());
 281  
     }
 282  
 
 283  
     protected boolean canFyi(Document document) {
 284  0
         return true;
 285  
     }
 286  
 
 287  
     protected boolean canAcknowledge(Document document) {
 288  0
         return true;
 289  
     }
 290  
 
 291  
     protected ParameterService getParameterService() {
 292  0
         if (parameterService == null) {
 293  0
             parameterService = CoreFrameworkServiceLocator.getParameterService();
 294  
         }
 295  0
         return parameterService;
 296  
     }
 297  
 
 298  
 }