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.batch.service.impl;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.kuali.ole.gl.GeneralLedgerConstants;
23  import org.kuali.ole.gl.batch.service.VerifyTransaction;
24  import org.kuali.ole.gl.businessobject.Transaction;
25  import org.kuali.ole.sys.OLEConstants;
26  import org.kuali.ole.sys.OLEKeyConstants;
27  import org.kuali.ole.sys.Message;
28  import org.kuali.rice.core.api.config.property.ConfigurationService;
29  
30  /**
31   * A general use implementation of VerifyTransaction
32   */
33  public class VerifyTransactionImpl implements VerifyTransaction {
34      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(VerifyTransactionImpl.class);
35      private ConfigurationService kualiConfigurationService;
36  
37      /**
38       * Constructs a VerifyTransactionImpl instance
39       */
40      public VerifyTransactionImpl() {
41          super();
42      }
43  
44      /**
45       * Determines if the given transaction qualifies for posting
46       * 
47       * @param t the transaction to verify
48       * @return a List of String error messages
49       * @see org.kuali.ole.gl.batch.service.VerifyTransaction#verifyTransaction(org.kuali.ole.gl.businessobject.Transaction)
50       */
51      public List<Message> verifyTransaction(Transaction t) {
52          LOG.debug("verifyTransaction() started");
53  
54          // List of error messages for the current transaction
55          List<Message> errors = new ArrayList();
56  
57          // Check the chart of accounts code
58          if (t.getChart() == null) {
59              errors.add(new Message(kualiConfigurationService.getPropertyValueAsString(OLEKeyConstants.ERROR_CHART_NOT_FOUND), Message.TYPE_FATAL));
60          }
61  
62          // Check the account
63          if (t.getAccount() == null) {
64              errors.add(new Message(kualiConfigurationService.getPropertyValueAsString(OLEKeyConstants.ERROR_ACCOUNT_NOT_FOUND), Message.TYPE_FATAL));
65          }
66  
67          // Check the object type
68          if (t.getObjectType() == null) {
69              errors.add(new Message(kualiConfigurationService.getPropertyValueAsString(OLEKeyConstants.ERROR_OBJECT_TYPE_NOT_FOUND), Message.TYPE_FATAL));
70          }
71  
72          // Check the balance type
73          if (t.getBalanceType() == null) {
74              errors.add(new Message(kualiConfigurationService.getPropertyValueAsString(OLEKeyConstants.ERROR_BALANCE_TYPE_NOT_FOUND), Message.TYPE_FATAL));
75          }
76  
77          // Check the fiscal year
78          if (t.getOption() == null) {
79              errors.add(new Message(kualiConfigurationService.getPropertyValueAsString(OLEKeyConstants.ERROR_UNIV_FISCAL_YR_NOT_FOUND), Message.TYPE_FATAL));
80          }
81  
82          // Check the debit/credit code (only if we have a valid balance type code)
83          if (t.getTransactionDebitCreditCode() == null) {
84              errors.add(new Message(kualiConfigurationService.getPropertyValueAsString(OLEKeyConstants.ERROR_DEDIT_CREDIT_CODE_NOT_BE_NULL), Message.TYPE_FATAL));
85          }
86          else {
87              if (t.getBalanceType() != null) {
88                  if (t.getBalanceType().isFinancialOffsetGenerationIndicator()) {
89                      if ((!OLEConstants.GL_DEBIT_CODE.equals(t.getTransactionDebitCreditCode())) && (!OLEConstants.GL_CREDIT_CODE.equals(t.getTransactionDebitCreditCode()))) {
90                          errors.add(new Message(kualiConfigurationService.getPropertyValueAsString(OLEKeyConstants.MSG_DEDIT_CREDIT_CODE_MUST_BE) + " '" + OLEConstants.GL_DEBIT_CODE + " or " + OLEConstants.GL_CREDIT_CODE + kualiConfigurationService.getPropertyValueAsString(OLEKeyConstants.MSG_FOR_BALANCE_TYPE), Message.TYPE_FATAL));
91                      }
92                  }
93                  else {
94                      if (!OLEConstants.GL_BUDGET_CODE.equals(t.getTransactionDebitCreditCode())) {
95                          errors.add(new Message(kualiConfigurationService.getPropertyValueAsString(OLEKeyConstants.MSG_DEDIT_CREDIT_CODE_MUST_BE) + OLEConstants.GL_BUDGET_CODE + kualiConfigurationService.getPropertyValueAsString(OLEKeyConstants.MSG_FOR_BALANCE_TYPE), Message.TYPE_FATAL));
96                      }
97                  }
98              }
99          }
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.getPropertyValueAsString(OLEKeyConstants.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.getPropertyValueAsString(OLEKeyConstants.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.getPropertyValueAsString(OLEKeyConstants.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.getPropertyValueAsString(OLEKeyConstants.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.getPropertyValueAsString(OLEKeyConstants.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.getPropertyValueAsString(OLEKeyConstants.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.getPropertyValueAsString(OLEKeyConstants.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.getPropertyValueAsString(OLEKeyConstants.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.getPropertyValueAsString(OLEKeyConstants.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())) && (!OLEConstants.ENCUMB_UPDT_NO_ENCUMBRANCE_CD.equals(t.getTransactionEncumbranceUpdateCode())) && (!OLEConstants.ENCUMB_UPDT_REFERENCE_DOCUMENT_CD.equals(t.getTransactionEncumbranceUpdateCode())) && (!OLEConstants.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 setConfigurationService(ConfigurationService kualiConfigurationService) {
151         this.kualiConfigurationService = kualiConfigurationService;
152     }
153 }