View Javadoc
1   /*
2    * Copyright 2008-2009 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.ole.module.purap.document.authorization;
17  
18  import org.kuali.ole.module.purap.PurapAuthorizationConstants.PurchaseOrderEditMode;
19  import org.kuali.ole.module.purap.PurapConstants.PurchaseOrderStatuses;
20  import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
21  import org.kuali.ole.module.purap.document.PurchasingAccountsPayableDocument;
22  import org.kuali.ole.module.purap.document.service.PurapService;
23  import org.kuali.ole.sys.context.SpringContext;
24  import org.kuali.rice.kew.api.WorkflowDocument;
25  import org.kuali.rice.krad.document.Document;
26  
27  import java.util.Set;
28  
29  public class PurchaseOrderAmendmentDocumentPresentationController extends PurchaseOrderDocumentPresentationController {
30  
31      @Override
32      public boolean canEdit(Document document) {
33          PurchaseOrderDocument poDocument = (PurchaseOrderDocument) document;
34          // po amend docs in CGIP status are only editable when in Initiated or Saved status
35          if (PurchaseOrderStatuses.APPDOC_CHANGE_IN_PROCESS.equals(poDocument.getApplicationDocumentStatus())) {
36              WorkflowDocument workflowDocument = poDocument.getFinancialSystemDocumentHeader().getWorkflowDocument();
37  
38              if (!workflowDocument.isInitiated() && !workflowDocument.isSaved()) {
39                  return false;
40              }
41          }
42          return super.canEdit(document);
43      }
44  
45      @Override
46      public Set<String> getEditModes(Document document) {
47          Set<String> editModes = super.getEditModes(document);
48          PurchaseOrderDocument poDocument = (PurchaseOrderDocument) document;
49  
50          if (PurchaseOrderStatuses.APPDOC_CHANGE_IN_PROCESS.equals(poDocument.getApplicationDocumentStatus())) {
51              WorkflowDocument workflowDocument = poDocument.getFinancialSystemDocumentHeader().getWorkflowDocument();
52              //  amendment doc needs to lock its field for initiator while enroute
53              if (workflowDocument.isInitiated() || workflowDocument.isSaved()) {
54                  editModes.add(PurchaseOrderEditMode.AMENDMENT_ENTRY);
55              }
56          }
57          if (PurchaseOrderStatuses.APPDOC_AWAIT_NEW_UNORDERED_ITEM_REVIEW.equals(poDocument.getApplicationDocumentStatus())) {
58              editModes.add(PurchaseOrderEditMode.AMENDMENT_ENTRY);
59          }
60  
61          if (SpringContext.getBean(PurapService.class).isDocumentStoppedInRouteNode((PurchasingAccountsPayableDocument) document, "New Unordered Items")) {
62              editModes.add(PurchaseOrderEditMode.UNORDERED_ITEM_ACCOUNT_ENTRY);
63          }
64  
65          return editModes;
66      }
67  
68      @Override
69      public boolean canReload(Document document) {
70          //  show the reload button if the doc is anything but processed or final
71          PurchaseOrderDocument poDocument = (PurchaseOrderDocument) document;
72          WorkflowDocument workflowDocument = poDocument.getFinancialSystemDocumentHeader().getWorkflowDocument();
73          return (workflowDocument.isSaved() || workflowDocument.isEnroute());
74      }
75  }