View Javadoc
1   /*
2    * Copyright 2006 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.web.struts;
17  
18  import org.kuali.ole.integration.purap.CapitalAssetLocation;
19  import org.kuali.ole.module.purap.PurapConstants;
20  import org.kuali.ole.module.purap.PurapConstants.RequisitionStatuses;
21  import org.kuali.ole.module.purap.businessobject.*;
22  import org.kuali.ole.module.purap.document.RequisitionDocument;
23  import org.kuali.rice.kew.api.WorkflowDocument;
24  import org.kuali.rice.kns.web.ui.ExtraButton;
25  import org.kuali.rice.kns.web.ui.HeaderField;
26  import org.kuali.rice.krad.util.KRADConstants;
27  import org.kuali.rice.krad.util.ObjectUtils;
28  
29  import javax.servlet.http.HttpServletRequest;
30  import java.math.BigDecimal;
31  import java.util.List;
32  
33  /**
34   * Struts Action Form for Requisition document.
35   */
36  public class RequisitionForm extends PurchasingFormBase {
37  
38      protected String shopUrl;
39  
40      /**
41       * Constructs a RequisitionForm instance and sets up the appropriately casted document.
42       */
43      public RequisitionForm() {
44          super();
45      }
46  
47      /**
48       * Gets the documentType attribute.
49       *
50       * @return Returns the documentType
51       */
52  
53      @Override
54      protected String getDefaultDocumentTypeName() {
55          return "OLE_REQS";
56      }
57  
58      public RequisitionDocument getRequisitionDocument() {
59          return (RequisitionDocument) getDocument();
60      }
61  
62      public void setRequisitionDocument(RequisitionDocument requisitionDocument) {
63          setDocument(requisitionDocument);
64      }
65  
66      /**
67       * KRAD Conversion: Performs customization of header fields.
68       * <p/>
69       * Use of data dictionary for bo RequisitionDocument.
70       */
71      @Override
72      public void populateHeaderFields(WorkflowDocument workflowDocument) {
73          super.populateHeaderFields(workflowDocument);
74  
75          if (ObjectUtils.isNotNull(this.getRequisitionDocument().getPurapDocumentIdentifier())) {
76              getDocInfo().add(new HeaderField("DataDictionary.RequisitionDocument.attributes.purapDocumentIdentifier", ((RequisitionDocument) this.getDocument()).getPurapDocumentIdentifier().toString()));
77          } else {
78              getDocInfo().add(new HeaderField("DataDictionary.RequisitionDocument.attributes.purapDocumentIdentifier", PurapConstants.PURAP_APPLICATION_DOCUMENT_ID_NOT_AVAILABLE));
79          }
80  
81          String applicationDocumentStatus = PurapConstants.PURAP_APPLICATION_DOCUMENT_STATUS_NOT_AVAILABLE;
82  
83          if (ObjectUtils.isNotNull(this.getRequisitionDocument().getApplicationDocumentStatus())) {
84              applicationDocumentStatus = workflowDocument.getApplicationDocumentStatus();
85          }
86  
87          getDocInfo().add(new HeaderField("DataDictionary.RequisitionDocument.attributes.applicationDocumentStatus", applicationDocumentStatus));
88      }
89  
90      /**
91       * @see org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase#shouldMethodToCallParameterBeUsed(java.lang.String, java.lang.String, javax.servlet.http.HttpServletRequest)
92       */
93      @Override
94      public boolean shouldMethodToCallParameterBeUsed(String methodToCallParameterName, String methodToCallParameterValue, HttpServletRequest request) {
95          if (KRADConstants.DISPATCH_REQUEST_PARAMETER.equals(methodToCallParameterName) &&
96                  ("displayB2BRequisition".equals(methodToCallParameterValue))) {
97              return true;
98          }
99          return super.shouldMethodToCallParameterBeUsed(methodToCallParameterName, methodToCallParameterValue, request);
100     }
101 
102     @Override
103     public Class getCapitalAssetLocationClass() {
104         return RequisitionCapitalAssetLocation.class;
105     }
106 
107     @Override
108     public Class getItemCapitalAssetClass() {
109         return RequisitionItemCapitalAsset.class;
110     }
111 
112     /**
113      * @see org.kuali.ole.module.purap.document.web.struts.PurchasingFormBase#setupNewPurchasingItemLine()
114      */
115     @Override
116     public PurApItem setupNewPurchasingItemLine() {
117         return new RequisitionItem();
118     }
119 
120     /**
121      * @see org.kuali.ole.module.purap.document.web.struts.PurchasingFormBase#setupNewPurchasingAccountingLine()
122      */
123     @Override
124     public RequisitionAccount setupNewPurchasingAccountingLine() {
125         return new RequisitionAccount();
126     }
127 
128     /**
129      * @see org.kuali.ole.module.purap.document.web.struts.PurchasingFormBase#setupNewAccountDistributionAccountingLine()
130      */
131     @Override
132     public RequisitionAccount setupNewAccountDistributionAccountingLine() {
133         RequisitionAccount account = setupNewPurchasingAccountingLine();
134         account.setAccountLinePercent(new BigDecimal(100));
135         return account;
136     }
137 
138     @Override
139     public CapitalAssetLocation setupNewPurchasingCapitalAssetLocationLine() {
140         return new RequisitionCapitalAssetLocation();
141     }
142 
143     public String getShopUrl() {
144         return shopUrl;
145     }
146 
147     public void setShopUrl(String shopUrl) {
148         this.shopUrl = shopUrl;
149     }
150 
151     /**
152      * @see org.kuali.ole.module.purap.document.web.struts.PurchasingFormBase#getExtraButtons()
153      *      <p/>
154      *      KRAD Conversion: Performs customization of extra buttons.
155      *      <p/>
156      *      No data dictionary is involved.
157      */
158     @Override
159     public List<ExtraButton> getExtraButtons() {
160         super.getExtraButtons();
161         for (int i = 0; i < extraButtons.size(); i++) {
162             ExtraButton extraButton = extraButtons.get(i);
163             if ("methodToCall.calculate".equalsIgnoreCase(extraButton.getExtraButtonProperty())) {
164                 if (canUserCalculate() == false) {
165                     extraButtons.remove(i);
166                     return extraButtons;
167                 }
168             }
169         }
170         return extraButtons;
171     }
172 
173     @Override
174     public boolean canUserCalculate() {
175         return documentActions != null && documentActions.containsKey(KRADConstants.KUALI_ACTION_CAN_EDIT) &&
176                 !getRequisitionDocument().isDocumentStoppedInRouteNode(RequisitionStatuses.NODE_ORG_REVIEW);
177     }
178 }