View Javadoc
1   /*
2    * Copyright 2007-2008 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.module.purap.document.ElectronicInvoiceRejectDocument;
19  import org.kuali.ole.pdp.PdpPropertyConstants;
20  import org.kuali.ole.pdp.businessobject.PurchasingPaymentDetail;
21  import org.kuali.ole.sys.OLEConstants;
22  import org.kuali.ole.sys.OLEParameterKeyConstants;
23  import org.kuali.ole.sys.context.SpringContext;
24  import org.kuali.ole.sys.document.web.struts.FinancialSystemTransactionalDocumentFormBase;
25  import org.kuali.ole.sys.service.impl.OleParameterConstants;
26  import org.kuali.rice.core.api.config.property.ConfigurationService;
27  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
28  import org.kuali.rice.kns.web.ui.ExtraButton;
29  import org.kuali.rice.krad.util.KRADConstants;
30  import org.kuali.rice.krad.util.UrlFactory;
31  
32  import java.util.List;
33  import java.util.Properties;
34  
35  /**
36   * Struts Action Form for Electronic Invoice Reject document.
37   */
38  public class ElectronicInvoiceRejectForm extends FinancialSystemTransactionalDocumentFormBase {
39  
40      /**
41       * Constructs a PaymentRequestForm instance and sets up the appropriately casted document.
42       */
43      public ElectronicInvoiceRejectForm() {
44          super();
45      }
46  
47      @Override
48      protected String getDefaultDocumentTypeName() {
49          return "OLE_EIRT";
50      }
51  
52      public ElectronicInvoiceRejectDocument getElectronicInvoiceRejectDocument() {
53          return (ElectronicInvoiceRejectDocument) getDocument();
54      }
55  
56      public void setElectronicInvoiceRejectDocument(ElectronicInvoiceRejectDocument eirDocument) {
57          setDocument(eirDocument);
58      }
59  
60      /**
61       * Build additional electronic invoice specific buttons and set extraButtons list.
62       *
63       * @return - list of extra buttons to be displayed to the user
64       *         <p/>
65       *         KRAD Conversion: Performs customization of an extra button.
66       *         <p/>
67       *         No data dictionary is involved.
68       */
69  
70      @Override
71      public List<ExtraButton> getExtraButtons() {
72          // clear out the extra buttons array
73          extraButtons.clear();
74  
75          ElectronicInvoiceRejectDocument eirDoc = this.getElectronicInvoiceRejectDocument();
76  
77          String externalImageURL = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEConstants.RICE_EXTERNALIZABLE_IMAGES_URL_KEY);
78          String appExternalImageURL = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEConstants.EXTERNALIZABLE_IMAGES_URL_KEY);
79  
80          if (eirDoc.getDocumentHeader().getWorkflowDocument().isEnroute()) {
81              if (eirDoc.isInvoiceResearchIndicator()) {
82                  addExtraButton("methodToCall.completeResearch", appExternalImageURL + "buttonsmall_complresearch.gif", "Complete Research");
83              } else {
84                  addExtraButton("methodToCall.startResearch", appExternalImageURL + "buttonsmall_research.gif", "Research");
85              }
86          }
87  
88          return extraButtons;
89      }
90  
91      /**
92       * Adds a new button to the extra buttons collection.
93       *
94       * @param property - property for button
95       * @param source   - location of image
96       * @param altText  - alternate text for button if images don't appear
97       *                 <p/>
98       *                 KRAD Conversion: Performs customization of an extra button.
99       */
100     protected void addExtraButton(String property, String source, String altText) {
101 
102         ExtraButton newButton = new ExtraButton();
103 
104         newButton.setExtraButtonProperty(property);
105         newButton.setExtraButtonSource(source);
106         newButton.setExtraButtonAltText(altText);
107 
108         extraButtons.add(newButton);
109     }
110 
111     /**
112      * This method builds the url for the disbursement info on the purap documents.
113      *
114      * @return the disbursement info url
115      */
116     public String getDisbursementInfoUrl() {
117         String basePath = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEConstants.APPLICATION_URL_KEY);
118         ParameterService parameterService = SpringContext.getBean(ParameterService.class);
119 
120         String orgCode = parameterService.getParameterValueAsString(OleParameterConstants.PURCHASING_BATCH.class, OLEParameterKeyConstants.PurapPdpParameterConstants.PURAP_PDP_ORG_CODE);
121         String subUnitCode = parameterService.getParameterValueAsString(OleParameterConstants.PURCHASING_BATCH.class, OLEParameterKeyConstants.PurapPdpParameterConstants.PURAP_PDP_SUB_UNIT_CODE);
122 
123         Properties parameters = new Properties();
124         parameters.put(OLEConstants.DISPATCH_REQUEST_PARAMETER, OLEConstants.SEARCH_METHOD);
125         parameters.put(OLEConstants.BACK_LOCATION, basePath + "/" + OLEConstants.MAPPING_PORTAL + ".do");
126         parameters.put(KRADConstants.DOC_FORM_KEY, "88888888");
127         parameters.put(OLEConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, PurchasingPaymentDetail.class.getName());
128         parameters.put(OLEConstants.HIDE_LOOKUP_RETURN_LINK, "true");
129         parameters.put(OLEConstants.SUPPRESS_ACTIONS, "false");
130         parameters.put(PdpPropertyConstants.PaymentDetail.PAYMENT_UNIT_CODE, orgCode);
131         parameters.put(PdpPropertyConstants.PaymentDetail.PAYMENT_SUBUNIT_CODE, subUnitCode);
132 
133         String lookupUrl = UrlFactory.parameterizeUrl(basePath + "/" + OLEConstants.LOOKUP_ACTION, parameters);
134 
135         return lookupUrl;
136     }
137 
138 }