001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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.module.labor.rules;
017:
018: import static org.kuali.kfs.KFSConstants.GENERIC_CODE_PROPERTY_NAME;
019:
020: import java.util.Collection;
021: import java.util.HashMap;
022: import java.util.Map;
023:
024: import org.apache.commons.lang.StringUtils;
025: import org.kuali.core.service.BusinessObjectService;
026: import org.kuali.core.service.DataDictionaryService;
027: import org.kuali.core.service.UniversalUserService;
028: import org.kuali.core.util.GeneralLedgerPendingEntrySequenceHelper;
029: import org.kuali.core.util.GlobalVariables;
030: import org.kuali.kfs.KFSConstants;
031: import org.kuali.kfs.KFSKeyConstants;
032: import org.kuali.kfs.KFSPropertyConstants;
033: import org.kuali.kfs.bo.AccountingLine;
034: import org.kuali.kfs.context.SpringContext;
035: import org.kuali.kfs.document.AccountingDocument;
036: import org.kuali.kfs.rules.AccountingDocumentRuleUtil;
037: import org.kuali.module.chart.bo.codes.BalanceTyp;
038: import org.kuali.module.financial.rules.JournalVoucherDocumentRule;
039: import org.kuali.module.labor.bo.LaborJournalVoucherDetail;
040: import org.kuali.module.labor.bo.LaborLedgerPendingEntry;
041: import org.kuali.module.labor.bo.PositionData;
042: import org.kuali.module.labor.document.LaborJournalVoucherDocument;
043: import org.kuali.module.labor.document.LaborLedgerPostingDocument;
044: import org.kuali.module.labor.rule.GenerateLaborLedgerPendingEntriesRule;
045: import org.kuali.module.labor.util.ObjectUtil;
046:
047: /**
048: * Business rule class for the Labor Journal Voucher Document.
049: */
050: public class LaborJournalVoucherDocumentRule extends
051: JournalVoucherDocumentRule
052: implements
053: GenerateLaborLedgerPendingEntriesRule<LaborLedgerPostingDocument> {
054: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
055: .getLogger(LaborJournalVoucherDocumentRule.class);
056:
057: /**
058: * @see org.kuali.module.financial.rules.JournalVoucherDocumentRule#processCustomUpdateAccountingLineBusinessRules(org.kuali.kfs.document.AccountingDocument,
059: * org.kuali.kfs.bo.AccountingLine, org.kuali.kfs.bo.AccountingLine)
060: */
061: @Override
062: public boolean processCustomUpdateAccountingLineBusinessRules(
063: AccountingDocument document,
064: AccountingLine originalAccountingLine,
065: AccountingLine updatedAccountingLine) {
066: return processCustomAddAccountingLineBusinessRules(document,
067: updatedAccountingLine);
068: }
069:
070: /**
071: * Adds an accounting line to the labor journal voucher document
072: *
073: * @param document Accounting document where a new accounting line is added
074: * @param accountingLine line that is going to be added
075: * @return boolean
076: * @see org.kuali.module.financial.rules.JournalVoucherDocumentRule#processCustomAddAccountingLineBusinessRules(org.kuali.kfs.document.AccountingDocument,
077: * org.kuali.kfs.bo.AccountingLine)
078: */
079: @Override
080: public boolean processCustomAddAccountingLineBusinessRules(
081: AccountingDocument document, AccountingLine accountingLine) {
082: boolean isValid = super
083: .processCustomAddAccountingLineBusinessRules(document,
084: accountingLine);
085:
086: LaborJournalVoucherDetail laborVoucherAccountingLine = (LaborJournalVoucherDetail) accountingLine;
087:
088: // position code existence check
089: String positionNumber = laborVoucherAccountingLine
090: .getPositionNumber();
091: if (!StringUtils.isBlank(positionNumber)
092: && !KFSConstants.getDashPositionNumber().equals(
093: positionNumber)) {
094: Map criteria = new HashMap();
095: criteria.put(KFSPropertyConstants.POSITION_NUMBER,
096: positionNumber);
097:
098: Collection positionMatches = SpringContext.getBean(
099: BusinessObjectService.class).findMatching(
100: PositionData.class, criteria);
101: if (positionMatches == null || positionMatches.isEmpty()) {
102: String label = SpringContext.getBean(
103: DataDictionaryService.class)
104: .getDataDictionary().getBusinessObjectEntry(
105: PositionData.class.getName())
106: .getAttributeDefinition(
107: KFSPropertyConstants.POSITION_NUMBER)
108: .getLabel();
109: GlobalVariables.getErrorMap().putError(
110: KFSPropertyConstants.POSITION_NUMBER,
111: KFSKeyConstants.ERROR_EXISTENCE, label);
112: isValid = false;
113: }
114: }
115:
116: // emplid existence check
117: String emplid = laborVoucherAccountingLine.getEmplid();
118: if (!StringUtils.isBlank(emplid)
119: && !KFSConstants.getDashEmplId().equals(emplid)) {
120: Map criteria = new HashMap();
121: criteria.put(
122: KFSPropertyConstants.PERSON_PAYROLL_IDENTIFIER,
123: emplid);
124:
125: Collection emplidMatches = SpringContext.getBean(
126: UniversalUserService.class).findUniversalUsers(
127: criteria);
128: if (emplidMatches == null || emplidMatches.isEmpty()) {
129: String label = SpringContext.getBean(
130: DataDictionaryService.class)
131: .getDataDictionary().getBusinessObjectEntry(
132: LaborJournalVoucherDetail.class
133: .getName())
134: .getAttributeDefinition(
135: KFSPropertyConstants.EMPLID).getLabel();
136: GlobalVariables.getErrorMap().putError(
137: KFSPropertyConstants.EMPLID,
138: KFSKeyConstants.ERROR_EXISTENCE, label);
139: isValid = false;
140: }
141: }
142:
143: return isValid;
144: }
145:
146: /**
147: * @see org.kuali.module.financial.rules.JournalVoucherDocumentRule#isExternalEncumbranceSpecificBusinessRulesValid(org.kuali.kfs.bo.AccountingLine)
148: */
149: @Override
150: protected boolean isExternalEncumbranceSpecificBusinessRulesValid(
151: AccountingLine accountingLine) {
152: boolean encumbranceValid = true;
153:
154: BalanceTyp balanceType = accountingLine.getBalanceTyp();
155: if (!AccountingDocumentRuleUtil.isValidBalanceType(balanceType,
156: GENERIC_CODE_PROPERTY_NAME)) {
157: encumbranceValid = false;
158: } else if (balanceType.isFinBalanceTypeEncumIndicator()
159: && KFSConstants.ENCUMB_UPDT_REFERENCE_DOCUMENT_CD
160: .equals(accountingLine
161: .getEncumbranceUpdateCode())) {
162: encumbranceValid = isRequiredReferenceFieldsValid(accountingLine);
163: }
164:
165: return encumbranceValid;
166: }
167:
168: /**
169: * Processes the G.L. pending entries
170: *
171: * @param accountingDocument
172: * @param accountingLine
173: * @param sequenceHelper
174: * @return boolean
175: * @see org.kuali.core.rule.GenerateGeneralLedgerPendingEntriesRule#processGenerateGeneralLedgerPendingEntries(org.kuali.core.document.AccountingDocument,
176: * org.kuali.core.bo.AccountingLine, org.kuali.core.util.GeneralLedgerPendingEntrySequenceHelper)
177: */
178: @Override
179: public boolean processGenerateGeneralLedgerPendingEntries(
180: AccountingDocument accountingDocument,
181: AccountingLine accountingLine,
182: GeneralLedgerPendingEntrySequenceHelper sequenceHelper) {
183: return true;
184: }
185:
186: /**
187: * @param accountingDocument
188: * @param accountingLine
189: * @param sequenceHelper
190: * @return boolean
191: * @see org.kuali.module.labor.rule.GenerateLaborLedgerPendingEntriesRule#processGenerateLaborLedgerPendingEntries(org.kuali.module.labor.document.LaborLedgerPostingDocument,
192: * org.kuali.kfs.bo.AccountingLine, org.kuali.core.util.GeneralLedgerPendingEntrySequenceHelper)
193: */
194: public boolean processGenerateLaborLedgerPendingEntries(
195: LaborLedgerPostingDocument accountingDocument,
196: AccountingLine accountingLine,
197: GeneralLedgerPendingEntrySequenceHelper sequenceHelper) {
198: LOG.debug("processGenerateLaborLedgerPendingEntries() started");
199:
200: try {
201: LaborJournalVoucherDocument laborJournalVoucherDocument = (LaborJournalVoucherDocument) accountingDocument;
202: LaborLedgerPendingEntry pendingLedgerEntry = new LaborLedgerPendingEntry();
203:
204: // populate the explicit entry
205: ObjectUtil.buildObject(pendingLedgerEntry, accountingLine);
206: populateExplicitGeneralLedgerPendingEntry(
207: laborJournalVoucherDocument, accountingLine,
208: sequenceHelper, pendingLedgerEntry);
209:
210: // apply the labor JV specific information
211: customizeExplicitGeneralLedgerPendingEntry(
212: laborJournalVoucherDocument, accountingLine,
213: pendingLedgerEntry);
214: pendingLedgerEntry
215: .setFinancialDocumentTypeCode(laborJournalVoucherDocument
216: .getOffsetTypeCode());
217:
218: if (StringUtils
219: .isBlank(((LaborJournalVoucherDetail) accountingLine)
220: .getEmplid())) {
221: pendingLedgerEntry.setEmplid(KFSConstants
222: .getDashEmplId());
223: }
224:
225: if (StringUtils
226: .isBlank(((LaborJournalVoucherDetail) accountingLine)
227: .getPositionNumber())) {
228: pendingLedgerEntry.setPositionNumber(KFSConstants
229: .getDashPositionNumber());
230: }
231:
232: laborJournalVoucherDocument.getLaborLedgerPendingEntries()
233: .add(pendingLedgerEntry);
234: sequenceHelper.increment();
235: } catch (Exception e) {
236: LOG
237: .error("Cannot add a Labor Ledger Pending Entry into the list");
238: return false;
239: }
240:
241: return true;
242: }
243: }
|