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.batch.service.impl; 017 018 import java.util.ArrayList; 019 import java.util.List; 020 021 import org.apache.commons.lang.StringUtils; 022 import org.kuali.kfs.gl.GeneralLedgerConstants; 023 import org.kuali.kfs.gl.batch.service.VerifyTransaction; 024 import org.kuali.kfs.gl.businessobject.Transaction; 025 import org.kuali.kfs.sys.KFSConstants; 026 import org.kuali.kfs.sys.KFSKeyConstants; 027 import org.kuali.kfs.sys.Message; 028 import org.kuali.rice.kns.service.KualiConfigurationService; 029 030 /** 031 * A general use implementation of VerifyTransaction 032 */ 033 public class VerifyTransactionImpl implements VerifyTransaction { 034 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(VerifyTransactionImpl.class); 035 private KualiConfigurationService kualiConfigurationService; 036 037 /** 038 * Constructs a VerifyTransactionImpl instance 039 */ 040 public VerifyTransactionImpl() { 041 super(); 042 } 043 044 /** 045 * Determines if the given transaction qualifies for posting 046 * 047 * @param t the transaction to verify 048 * @return a List of String error messages 049 * @see org.kuali.kfs.gl.batch.service.VerifyTransaction#verifyTransaction(org.kuali.kfs.gl.businessobject.Transaction) 050 */ 051 public List<Message> verifyTransaction(Transaction t) { 052 LOG.debug("verifyTransaction() started"); 053 054 // List of error messages for the current transaction 055 List<Message> errors = new ArrayList(); 056 057 // Check the chart of accounts code 058 if (t.getChart() == null) { 059 errors.add(new Message(kualiConfigurationService.getPropertyString(KFSKeyConstants.ERROR_CHART_NOT_FOUND), Message.TYPE_FATAL)); 060 } 061 062 // Check the account 063 if (t.getAccount() == null) { 064 errors.add(new Message(kualiConfigurationService.getPropertyString(KFSKeyConstants.ERROR_ACCOUNT_NOT_FOUND), Message.TYPE_FATAL)); 065 } 066 067 // Check the object type 068 if (t.getObjectType() == null) { 069 errors.add(new Message(kualiConfigurationService.getPropertyString(KFSKeyConstants.ERROR_OBJECT_TYPE_NOT_FOUND), Message.TYPE_FATAL)); 070 } 071 072 // Check the balance type 073 if (t.getBalanceType() == null) { 074 errors.add(new Message(kualiConfigurationService.getPropertyString(KFSKeyConstants.ERROR_BALANCE_TYPE_NOT_FOUND), Message.TYPE_FATAL)); 075 } 076 077 // Check the fiscal year 078 if (t.getOption() == null) { 079 errors.add(new Message(kualiConfigurationService.getPropertyString(KFSKeyConstants.ERROR_UNIV_FISCAL_YR_NOT_FOUND), Message.TYPE_FATAL)); 080 } 081 082 // Check the debit/credit code (only if we have a valid balance type code) 083 if (t.getTransactionDebitCreditCode() == null) { 084 errors.add(new Message(kualiConfigurationService.getPropertyString(KFSKeyConstants.ERROR_DEDIT_CREDIT_CODE_NOT_BE_NULL), Message.TYPE_FATAL)); 085 } 086 else { 087 if (t.getBalanceType() != null) { 088 if (t.getBalanceType().isFinancialOffsetGenerationIndicator()) { 089 if ((!KFSConstants.GL_DEBIT_CODE.equals(t.getTransactionDebitCreditCode())) && (!KFSConstants.GL_CREDIT_CODE.equals(t.getTransactionDebitCreditCode()))) { 090 errors.add(new Message(kualiConfigurationService.getPropertyString(KFSKeyConstants.MSG_DEDIT_CREDIT_CODE_MUST_BE) + " '" + KFSConstants.GL_DEBIT_CODE + " or " + KFSConstants.GL_CREDIT_CODE + kualiConfigurationService.getPropertyString(KFSKeyConstants.MSG_FOR_BALANCE_TYPE), Message.TYPE_FATAL)); 091 } 092 } 093 else { 094 if (!KFSConstants.GL_BUDGET_CODE.equals(t.getTransactionDebitCreditCode())) { 095 errors.add(new Message(kualiConfigurationService.getPropertyString(KFSKeyConstants.MSG_DEDIT_CREDIT_CODE_MUST_BE) + KFSConstants.GL_BUDGET_CODE + kualiConfigurationService.getPropertyString(KFSKeyConstants.MSG_FOR_BALANCE_TYPE), Message.TYPE_FATAL)); 096 } 097 } 098 } 099 } 100 101 // KULGL-58 Make sure all GL entry primary key fields are not null 102 if ((t.getSubAccountNumber() == null) || (t.getSubAccountNumber().trim().length() == 0)) { 103 errors.add(new Message(kualiConfigurationService.getPropertyString(KFSKeyConstants.ERROR_SUB_ACCOUNT_NOT_BE_NULL), Message.TYPE_FATAL)); 104 } 105 if ((t.getFinancialObjectCode() == null) || (t.getFinancialObjectCode().trim().length() == 0)) { 106 errors.add(new Message(kualiConfigurationService.getPropertyString(KFSKeyConstants.ERROR_OBJECT_CODE_NOT_BE_NULL), Message.TYPE_FATAL)); 107 } 108 if ((t.getFinancialSubObjectCode() == null) || (t.getFinancialSubObjectCode().trim().length() == 0)) { 109 errors.add(new Message(kualiConfigurationService.getPropertyString(KFSKeyConstants.ERROR_SUB_OBJECT_CODE_NOT_BE_NULL), Message.TYPE_FATAL)); 110 } 111 if ((t.getUniversityFiscalPeriodCode() == null) || (t.getUniversityFiscalPeriodCode().trim().length() == 0)) { 112 errors.add(new Message(kualiConfigurationService.getPropertyString(KFSKeyConstants.ERROR_FISCAL_PERIOD_CODE_NOT_BE_NULL), Message.TYPE_FATAL)); 113 } 114 if ((t.getFinancialDocumentTypeCode() == null) || (t.getFinancialDocumentTypeCode().trim().length() == 0)) { 115 errors.add(new Message(kualiConfigurationService.getPropertyString(KFSKeyConstants.ERROR_DOCUMENT_TYPE_NOT_BE_NULL), Message.TYPE_FATAL)); 116 } 117 if ((t.getFinancialSystemOriginationCode() == null) || (t.getFinancialSystemOriginationCode().trim().length() == 0)) { 118 errors.add(new Message(kualiConfigurationService.getPropertyString(KFSKeyConstants.ERROR_ORIGIN_CODE_NOT_BE_NULL), Message.TYPE_FATAL)); 119 } 120 if ((t.getDocumentNumber() == null) || (t.getDocumentNumber().trim().length() == 0)) { 121 errors.add(new Message(kualiConfigurationService.getPropertyString(KFSKeyConstants.ERROR_DOCUMENT_NUMBER_NOT_BE_NULL), Message.TYPE_FATAL)); 122 } 123 124 // Don't need to check SequenceNumber because it sets in PosterServiceImpl, so commented out 125 // if (t.getTransactionLedgerEntrySequenceNumber() == null) { 126 // errors.add(new Message(kualiConfigurationService.getPropertyString(KFSKeyConstants.ERROR_SEQUENCE_NUMBER_NOT_BE_NULL), Message.TYPE_FATAL)); 127 // } 128 129 if (t.getBalanceType() != null && t.getBalanceType().isFinBalanceTypeEncumIndicator() && !t.getObjectType().isFundBalanceIndicator()){ 130 if (t.getTransactionEncumbranceUpdateCode().trim().equals(GeneralLedgerConstants.EMPTY_CODE)){ 131 errors.add(new Message(kualiConfigurationService.getPropertyString(KFSKeyConstants.ERROR_ENCUMBRANCE_UPDATE_CODE_CANNOT_BE_BLANK_FOR_BALANCE_TYPE) + " " + t.getFinancialBalanceTypeCode(), Message.TYPE_FATAL)); 132 } 133 } 134 135 // The encumbrance update code can only be space, N, R or D. Nothing else 136 if ((StringUtils.isNotBlank(t.getTransactionEncumbranceUpdateCode())) && (!" ".equals(t.getTransactionEncumbranceUpdateCode())) && (!KFSConstants.ENCUMB_UPDT_NO_ENCUMBRANCE_CD.equals(t.getTransactionEncumbranceUpdateCode())) && (!KFSConstants.ENCUMB_UPDT_REFERENCE_DOCUMENT_CD.equals(t.getTransactionEncumbranceUpdateCode())) && (!KFSConstants.ENCUMB_UPDT_DOCUMENT_CD.equals(t.getTransactionEncumbranceUpdateCode()))) { 137 errors.add(new Message("Invalid Encumbrance Update Code (" + t.getTransactionEncumbranceUpdateCode() + ")", Message.TYPE_FATAL)); 138 } 139 140 141 142 return errors; 143 } 144 145 /** 146 * Sets the kualiConfigurationService attribute value. 147 * 148 * @param kualiConfigurationService The kualiConfigurationService to set. 149 */ 150 public void setKualiConfigurationService(KualiConfigurationService kualiConfigurationService) { 151 this.kualiConfigurationService = kualiConfigurationService; 152 } 153 }