001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.kfs.gl.businessobject.inquiry;
017
018 import org.apache.commons.lang.StringUtils;
019 import org.kuali.kfs.gl.businessobject.Encumbrance;
020 import org.kuali.kfs.gl.businessobject.Transaction;
021 import org.kuali.kfs.sys.KFSConstants;
022 import org.kuali.kfs.sys.context.SpringContext;
023 import org.kuali.rice.kns.service.KualiConfigurationService;
024
025 /**
026 * This class provides a placeholder that can connect General Ledger business object with financial document in the presentation
027 * tier. The typical method is to generate url for the inquirable financial document.
028 */
029 public class InquirableFinancialDocument {
030
031 private KualiConfigurationService kualiConfigurationService = SpringContext.getBean(KualiConfigurationService.class);
032
033 /**
034 * get the url of inquirable financial document for the given transaction
035 *
036 * @param transaction the business object that implements Transaction interface
037 * @return the url of inquirable financial document for the given transaction if the document is inquirable; otherwise, return
038 * empty string
039 */
040 public String getInquirableDocumentUrl(Transaction transaction) {
041 if (transaction == null) {
042 return KFSConstants.EMPTY_STRING;
043 }
044
045 String docNumber = transaction.getDocumentNumber();
046 String originationCode = transaction.getFinancialSystemOriginationCode();
047
048 return getUrl(originationCode, docNumber);
049 }
050
051 /**
052 * Creates the url for a document drill down
053 *
054 * @param originCode the originatino code of the document
055 * @param docNumber the document number of the document to drill down on
056 * @return the URL for the drill down
057 */
058 private String getUrl(String originCode, String docNumber) {
059 if (KFSConstants.ORIGIN_CODE_KUALI.equals(originCode) && !StringUtils.isBlank(docNumber)) {
060 return kualiConfigurationService.getPropertyString(KFSConstants.WORKFLOW_URL_KEY) + "/DocHandler.do?docId=" + docNumber + "&command=displayDocSearchView";
061 }
062 return KFSConstants.EMPTY_STRING;
063 }
064
065 /**
066 * get the url of inquirable financial document for the given encumbrance
067 *
068 * @param encumbrance the encumrbance record
069 * @return the url of inquirable financial document for the given encumbrance if the document is inquirable; otherwise, return
070 * empty string
071 */
072 public String getInquirableDocumentUrl(Encumbrance encumbrance) {
073 if (encumbrance == null) {
074 return KFSConstants.EMPTY_STRING;
075 }
076
077 String docNumber = encumbrance.getDocumentNumber();
078 String originationCode = encumbrance.getOriginCode();
079
080 return getUrl(originationCode, docNumber);
081 }
082 }