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.module.ld.document.validation.impl; 017 018 import org.apache.commons.lang.StringUtils; 019 import org.kuali.kfs.module.ld.LaborConstants ; 020 import org.kuali.kfs.module.ld.LaborKeyConstants; 021 import org.kuali.kfs.module.ld.businessobject.ExpenseTransferAccountingLine; 022 import org.kuali.kfs.module.ld.businessobject.LaborObject; 023 import org.kuali.kfs.module.ld.document.SalaryExpenseTransferDocument; 024 import org.kuali.kfs.sys.KFSPropertyConstants; 025 import org.kuali.kfs.sys.businessobject.AccountingLine; 026 import org.kuali.kfs.sys.document.validation.GenericValidation; 027 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent; 028 import org.kuali.rice.kns.util.GlobalVariables; 029 import org.kuali.rice.kns.util.ObjectUtils; 030 031 /** 032 * Validates that an accounting line has salary object code 033 */ 034 public class SalaryExpenseTransferSalaryObjectCodeValidation extends GenericValidation { 035 private AccountingLine accountingLineForValidation; 036 037 /** 038 * Validates that an accounting line does not have a salary object code 039 * <strong>Expects an accounting line as the first a parameter</strong> 040 * @see org.kuali.kfs.validation.Validation#validate(java.lang.Object[]) 041 */ 042 public boolean validate(AttributedDocumentEvent event) { 043 boolean result = true; 044 AccountingLine accountingLine = getAccountingLineForValidation(); 045 046 if (!isSalaryObjectCode(accountingLine)) { 047 GlobalVariables.getMessageMap().putError(KFSPropertyConstants.OBJECT_CODE, LaborKeyConstants.INVALID_SALARY_OBJECT_CODE_ERROR ); 048 result = false; 049 } 050 return result; 051 } 052 053 /** 054 * Checks whether the given AccountingLine's Object Code is a salary object code. 055 * 056 * @param accountingLine The accounting line the salary object code will be retrieved from. 057 * @return True if the given accounting line's object code is a salary object code, false otherwise. 058 */ 059 protected boolean isSalaryObjectCode(AccountingLine accountingLine) { 060 boolean salaryObjectCode = true; 061 062 ExpenseTransferAccountingLine expenseTransferAccountingLine = (ExpenseTransferAccountingLine) accountingLine; 063 expenseTransferAccountingLine.refreshReferenceObject(KFSPropertyConstants.LABOR_OBJECT); 064 065 LaborObject laborObject = expenseTransferAccountingLine.getLaborObject(); 066 if (ObjectUtils.isNull(laborObject)) { 067 return false; 068 } 069 070 boolean isItSalaryObjectCode = LaborConstants.SalaryExpenseTransfer.LABOR_LEDGER_SALARY_CODE.equals(laborObject.getFinancialObjectFringeOrSalaryCode()); 071 if (!isItSalaryObjectCode) { 072 salaryObjectCode = false ; 073 } 074 075 return salaryObjectCode ; 076 } 077 078 /** 079 * Gets the accountingLineForValidation attribute. 080 * @return Returns the accountingLineForValidation. 081 */ 082 public AccountingLine getAccountingLineForValidation() { 083 return accountingLineForValidation; 084 } 085 086 /** 087 * Sets the accountingLineForValidation attribute value. 088 * @param accountingLineForValidation The accountingLineForValidation to set. 089 */ 090 public void setAccountingLineForValidation(AccountingLine accountingLineForValidation) { 091 this.accountingLineForValidation = accountingLineForValidation; 092 } 093 }