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.gl.businessobject.inquiry;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.ole.gl.businessobject.Encumbrance;
20  import org.kuali.ole.gl.businessobject.Transaction;
21  import org.kuali.ole.sys.OLEConstants;
22  import org.kuali.ole.sys.context.SpringContext;
23  import org.kuali.rice.core.api.config.property.ConfigurationService;
24  
25  /**
26   * This class provides a placeholder that can connect General Ledger business object with financial document in the presentation
27   * tier. The typical method is to generate url for the inquirable financial document.
28   */
29  public class InquirableFinancialDocument {
30  
31      private ConfigurationService kualiConfigurationService = SpringContext.getBean(ConfigurationService.class);
32  
33      /**
34       * get the url of inquirable financial document for the given transaction
35       * 
36       * @param transaction the business object that implements Transaction interface
37       * @return the url of inquirable financial document for the given transaction if the document is inquirable; otherwise, return
38       *         empty string
39       */
40      public String getInquirableDocumentUrl(Transaction transaction) {
41          if (transaction == null) {
42              return OLEConstants.EMPTY_STRING;
43          }
44  
45          String docNumber = transaction.getDocumentNumber();
46          String originationCode = transaction.getFinancialSystemOriginationCode();
47  
48          return getUrl(originationCode, docNumber);
49      }
50  
51      /**
52       * Creates the url for a document drill down
53       * 
54       * @param originCode the originatino code of the document
55       * @param docNumber the document number of the document to drill down on
56       * @return the URL for the drill down
57       */
58      private String getUrl(String originCode, String docNumber) {
59          if (OLEConstants.ORIGIN_CODE_KUALI.equals(originCode) && !StringUtils.isBlank(docNumber)) {
60              return kualiConfigurationService.getPropertyValueAsString(OLEConstants.WORKFLOW_URL_KEY) + "/DocHandler.do?docId=" + docNumber + "&command=displayDocSearchView";
61          }
62          return OLEConstants.EMPTY_STRING;
63      }
64  
65      /**
66       * get the url of inquirable financial document for the given encumbrance
67       * 
68       * @param encumbrance the encumrbance record
69       * @return the url of inquirable financial document for the given encumbrance if the document is inquirable; otherwise, return
70       *         empty string
71       */
72      public String getInquirableDocumentUrl(Encumbrance encumbrance) {
73          if (encumbrance == null) {
74              return OLEConstants.EMPTY_STRING;
75          }
76  
77          String docNumber = encumbrance.getDocumentNumber();
78          String originationCode = encumbrance.getOriginCode();
79  
80          return getUrl(originationCode, docNumber);
81      }
82  }