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.sys.document.service.impl;
017
018 import org.apache.commons.lang.StringUtils;
019 import org.apache.log4j.Logger;
020 import org.kuali.kfs.coa.businessobject.Account;
021 import org.kuali.kfs.coa.businessobject.Chart;
022 import org.kuali.kfs.coa.businessobject.FundGroup;
023 import org.kuali.kfs.coa.businessobject.ObjectCode;
024 import org.kuali.kfs.coa.businessobject.ObjectSubType;
025 import org.kuali.kfs.coa.businessobject.ObjectType;
026 import org.kuali.kfs.coa.businessobject.Organization;
027 import org.kuali.kfs.coa.businessobject.ProjectCode;
028 import org.kuali.kfs.coa.businessobject.SubAccount;
029 import org.kuali.kfs.coa.businessobject.SubFundGroup;
030 import org.kuali.kfs.coa.businessobject.SubObjectCode;
031 import org.kuali.kfs.coa.service.AccountService;
032 import org.kuali.kfs.sys.KFSConstants;
033 import org.kuali.kfs.sys.KFSKeyConstants;
034 import org.kuali.kfs.sys.KFSPropertyConstants;
035 import org.kuali.kfs.sys.businessobject.AccountingLine;
036 import org.kuali.kfs.sys.businessobject.AccountingLineOverride;
037 import org.kuali.kfs.sys.businessobject.OriginationCode;
038 import org.kuali.kfs.sys.businessobject.SourceAccountingLine;
039 import org.kuali.kfs.sys.context.SpringContext;
040 import org.kuali.kfs.sys.document.service.AccountingLineRuleHelperService;
041 import org.kuali.kfs.sys.document.service.FinancialSystemDocumentService;
042 import org.kuali.kfs.sys.document.service.FinancialSystemDocumentTypeService;
043 import org.kuali.rice.kew.doctype.bo.DocumentTypeEBO;
044 import org.kuali.rice.kns.datadictionary.BusinessObjectEntry;
045 import org.kuali.rice.kns.datadictionary.DataDictionary;
046 import org.kuali.rice.kns.service.DataDictionaryService;
047 import org.kuali.rice.kns.service.KualiConfigurationService;
048 import org.kuali.rice.kns.util.GlobalVariables;
049 import org.kuali.rice.kns.util.ObjectUtils;
050
051 public class AccountingLineRuleHelperServiceImpl implements AccountingLineRuleHelperService {
052 private static Logger LOG = Logger.getLogger(AccountingLineRuleHelperServiceImpl.class);
053 private DataDictionaryService dataDictionaryService;
054 private FinancialSystemDocumentTypeService financialSystemDocumentTypeService;
055
056 /**
057 * @see org.kuali.kfs.sys.document.service.AccountingLineRuleHelperService#getAccountLabel()
058 */
059 public String getAccountLabel() {
060 return dataDictionaryService.getDataDictionary().getBusinessObjectEntry(Account.class.getName()).getAttributeDefinition(KFSConstants.ACCOUNT_NUMBER_PROPERTY_NAME).getShortLabel();
061 }
062
063 /**
064 * @see org.kuali.kfs.sys.document.service.AccountingLineRuleHelperService#getChartLabel()
065 */
066 public String getChartLabel() {
067 return dataDictionaryService.getDataDictionary().getBusinessObjectEntry(Chart.class.getName()).getAttributeDefinition(KFSConstants.CHART_OF_ACCOUNTS_CODE_PROPERTY_NAME).getShortLabel();
068 }
069
070 /**
071 * @see org.kuali.kfs.sys.document.service.AccountingLineRuleHelperService#getFundGroupCodeLabel()
072 */
073 public String getFundGroupCodeLabel() {
074 return dataDictionaryService.getDataDictionary().getBusinessObjectEntry(FundGroup.class.getName()).getAttributeDefinition(KFSPropertyConstants.CODE).getShortLabel();
075 }
076
077 /**
078 * @see org.kuali.kfs.sys.document.service.AccountingLineRuleHelperService#getObjectCodeLabel()
079 */
080 public String getObjectCodeLabel() {
081 return dataDictionaryService.getDataDictionary().getBusinessObjectEntry(ObjectCode.class.getName()).getAttributeDefinition(KFSConstants.FINANCIAL_OBJECT_CODE_PROPERTY_NAME).getShortLabel();
082 }
083
084 /**
085 * @see org.kuali.kfs.sys.document.service.AccountingLineRuleHelperService#getObjectSubTypeCodeLabel()
086 */
087 public String getObjectSubTypeCodeLabel() {
088 return dataDictionaryService.getDataDictionary().getBusinessObjectEntry(ObjectSubType.class.getName()).getAttributeDefinition(KFSPropertyConstants.CODE).getShortLabel();
089 }
090
091 /**
092 * @see org.kuali.kfs.sys.document.service.AccountingLineRuleHelperService#getObjectTypeCodeLabel()
093 */
094 public String getObjectTypeCodeLabel() {
095 return dataDictionaryService.getDataDictionary().getBusinessObjectEntry(ObjectType.class.getName()).getAttributeDefinition(KFSConstants.GENERIC_CODE_PROPERTY_NAME).getShortLabel();
096 }
097
098 /**
099 * @see org.kuali.kfs.sys.document.service.AccountingLineRuleHelperService#getOrganizationCodeLabel()
100 */
101 public String getOrganizationCodeLabel() {
102 return dataDictionaryService.getDataDictionary().getBusinessObjectEntry(Organization.class.getName()).getAttributeDefinition(KFSPropertyConstants.ORGANIZATION_CODE).getShortLabel();
103 }
104
105 /**
106 * @see org.kuali.kfs.sys.document.service.AccountingLineRuleHelperService#getProjectCodeLabel()
107 */
108 public String getProjectCodeLabel() {
109 return dataDictionaryService.getDataDictionary().getBusinessObjectEntry(ProjectCode.class.getName()).getAttributeDefinition(KFSPropertyConstants.CODE).getShortLabel();
110 }
111
112 /**
113 * @see org.kuali.kfs.sys.document.service.AccountingLineRuleHelperService#getSubAccountLabel()
114 */
115 public String getSubAccountLabel() {
116 return dataDictionaryService.getDataDictionary().getBusinessObjectEntry(SubAccount.class.getName()).getAttributeDefinition(KFSConstants.SUB_ACCOUNT_NUMBER_PROPERTY_NAME).getShortLabel();
117 }
118
119 /**
120 * @see org.kuali.kfs.sys.document.service.AccountingLineRuleHelperService#getSubFundGroupCodeLabel()
121 */
122 public String getSubFundGroupCodeLabel() {
123 return dataDictionaryService.getDataDictionary().getBusinessObjectEntry(SubFundGroup.class.getName()).getAttributeDefinition(KFSPropertyConstants.SUB_FUND_GROUP_CODE).getShortLabel();
124 }
125
126 /**
127 * @see org.kuali.kfs.sys.document.service.AccountingLineRuleHelperService#getSubObjectCodeLabel()
128 */
129 public String getSubObjectCodeLabel() {
130 return dataDictionaryService.getDataDictionary().getBusinessObjectEntry(SubObjectCode.class.getName()).getAttributeDefinition(KFSConstants.FINANCIAL_SUB_OBJECT_CODE_PROPERTY_NAME).getShortLabel();
131 }
132
133 /**
134 * @see org.kuali.kfs.sys.document.service.AccountingLineRuleHelperService#hasRequiredOverrides(org.kuali.kfs.sys.businessobject.AccountingLine, java.lang.String)
135 */
136 public boolean hasRequiredOverrides(AccountingLine line, String overrideCode) {
137 return hasAccountRequiredOverrides(line, overrideCode) && hasObjectBudgetRequiredOverrides(line, overrideCode);
138
139 }
140
141 public boolean hasAccountRequiredOverrides(AccountingLine line, String overrideCode) {
142 boolean retVal = true;
143 AccountingLineOverride override = AccountingLineOverride.valueOf(overrideCode);
144 Account account = line.getAccount();
145 if (AccountingLineOverride.needsExpiredAccountOverride(account) && !override.hasComponent(AccountingLineOverride.COMPONENT.EXPIRED_ACCOUNT)) {
146 Account continuation = getUnexpiredContinuationAccountOrNull(account);
147 if (continuation == null) {
148 GlobalVariables.getMessageMap().putError(KFSConstants.ACCOUNT_NUMBER_PROPERTY_NAME, KFSKeyConstants.ERROR_DOCUMENT_ACCOUNT_EXPIRED_NO_CONTINUATION, new String[] { account.getAccountNumber() });
149 }
150 else {
151 GlobalVariables.getMessageMap().putError(KFSConstants.ACCOUNT_NUMBER_PROPERTY_NAME, KFSKeyConstants.ERROR_DOCUMENT_ACCOUNT_EXPIRED, new String[] { account.getAccountNumber(), continuation.getChartOfAccountsCode(), continuation.getAccountNumber() });
152 // todo: ... args in JDK 1.5
153 }
154 retVal = false;
155 }
156 return retVal;
157 }
158
159 public boolean hasObjectBudgetRequiredOverrides(AccountingLine line, String overrideCode) {
160 boolean retVal = true;
161 ObjectCode objectCode = line.getObjectCode();
162 AccountingLineOverride override = AccountingLineOverride.valueOf(overrideCode);
163 Account account = line.getAccount();
164 if (AccountingLineOverride.needsObjectBudgetOverride(account, objectCode) && !override.hasComponent(AccountingLineOverride.COMPONENT.NON_BUDGETED_OBJECT)) {
165 GlobalVariables.getMessageMap().putError(KFSConstants.FINANCIAL_OBJECT_CODE_PROPERTY_NAME, KFSKeyConstants.ERROR_DOCUMENT_ACCOUNT_PRESENCE_NON_BUDGETED_OBJECT_CODE, new String[] { account.getAccountNumber(), objectCode.getFinancialObjectCode() });
166 retVal = false;
167 }
168 return retVal;
169 }
170
171 /**
172 * @param account
173 * @return an unexpired continuation account for the given account, or, if one cannot be found, null
174 */
175 protected Account getUnexpiredContinuationAccountOrNull(Account account) {
176 int count = 0;
177 while (count++ < 10) { // prevents infinite loops
178 String continuationChartCode = account.getContinuationFinChrtOfAcctCd();
179 String continuationAccountNumber = account.getContinuationAccountNumber();
180 // todo: does AccountService already handle blank keys this way?
181 if (StringUtils.isBlank(continuationChartCode) || StringUtils.isBlank(continuationAccountNumber)) {
182 return null;
183 }
184 account = SpringContext.getBean(AccountService.class).getByPrimaryId(continuationChartCode, continuationAccountNumber);
185 if (ObjectUtils.isNull(account)) {
186 return null;
187 }
188 if (account.isActive() && !account.isExpired()) {
189 return account;
190 }
191 }
192 return null;
193 }
194
195 /**
196 * @see org.kuali.kfs.sys.document.service.AccountingLineRuleHelperService#isValidAccount(org.kuali.kfs.coa.businessobject.Account, org.kuali.rice.kns.datadictionary.DataDictionary)
197 */
198 public boolean isValidAccount(Account account, DataDictionary dataDictionary) {
199 return isValidAccount(account, dataDictionary, KFSConstants.ACCOUNT_NUMBER_PROPERTY_NAME);
200 }
201
202 /**
203 * @see org.kuali.kfs.sys.document.service.AccountingLineRuleHelperService#isValidAccount(org.kuali.kfs.coa.businessobject.Account, org.kuali.rice.kns.datadictionary.DataDictionary, java.lang.String)
204 */
205 public boolean isValidAccount(Account account, DataDictionary dataDictionary, String errorPropertyName) {
206 String label = getAccountLabel();
207
208 // make sure it exists
209 if (ObjectUtils.isNull(account)) {
210 GlobalVariables.getMessageMap().putError(errorPropertyName, KFSKeyConstants.ERROR_EXISTENCE, label);
211 return false;
212 }
213
214 // make sure it's active for usage
215 if (!account.isActive()) {
216 GlobalVariables.getMessageMap().putError(errorPropertyName, KFSKeyConstants.ERROR_DOCUMENT_ACCOUNT_CLOSED, label);
217 return false;
218 }
219
220 return true;
221 }
222
223 /**
224 * @see org.kuali.kfs.sys.document.service.AccountingLineRuleHelperService#isValidChart(org.kuali.kfs.coa.businessobject.Chart, org.kuali.rice.kns.datadictionary.DataDictionary)
225 */
226 public boolean isValidChart(Chart chart, DataDictionary dataDictionary) {
227 return isValidChart(chart, dataDictionary, KFSConstants.CHART_OF_ACCOUNTS_CODE_PROPERTY_NAME);
228 }
229
230 /**
231 * @see org.kuali.kfs.sys.document.service.AccountingLineRuleHelperService#isValidChart(org.kuali.kfs.coa.businessobject.Chart, org.kuali.rice.kns.datadictionary.DataDictionary, java.lang.String)
232 */
233 public boolean isValidChart(Chart chart, DataDictionary dataDictionary, String errorPropertyName) {
234 String label = getChartLabel();
235
236 // make sure it exists
237 if (ObjectUtils.isNull(chart)) {
238 GlobalVariables.getMessageMap().putError(errorPropertyName, KFSKeyConstants.ERROR_EXISTENCE, label);
239 return false;
240 }
241
242 // make sure it's active for usage
243 if (!chart.isActive()) {
244 GlobalVariables.getMessageMap().putError(errorPropertyName, KFSKeyConstants.ERROR_INACTIVE, label);
245 return false;
246 }
247
248 return true;
249 }
250
251 /**
252 * @see org.kuali.kfs.sys.document.service.AccountingLineRuleHelperService#isValidObjectCode(org.kuali.kfs.coa.businessobject.ObjectCode, org.kuali.rice.kns.datadictionary.DataDictionary)
253 */
254 public boolean isValidObjectCode(ObjectCode objectCode, DataDictionary dataDictionary) {
255 return isValidObjectCode(objectCode, dataDictionary, KFSConstants.FINANCIAL_OBJECT_CODE_PROPERTY_NAME);
256 }
257
258 /**
259 * @see org.kuali.kfs.sys.document.service.AccountingLineRuleHelperService#isValidObjectCode(org.kuali.kfs.coa.businessobject.ObjectCode, org.kuali.rice.kns.datadictionary.DataDictionary, java.lang.String)
260 */
261 public boolean isValidObjectCode(ObjectCode objectCode, DataDictionary dataDictionary, String errorPropertyName) {
262 String label = getObjectCodeLabel();
263
264 // make sure it exists
265 if (ObjectUtils.isNull(objectCode)) {
266 GlobalVariables.getMessageMap().putError(errorPropertyName, KFSKeyConstants.ERROR_EXISTENCE, label);
267 return false;
268 }
269
270 // check active status
271 if (!objectCode.isFinancialObjectActiveCode()) {
272 GlobalVariables.getMessageMap().putError(errorPropertyName, KFSKeyConstants.ERROR_INACTIVE, label);
273 return false;
274 }
275
276 return true;
277 }
278
279 /**
280 * @see org.kuali.kfs.sys.document.service.AccountingLineRuleHelperService#isValidObjectTypeCode(org.kuali.kfs.coa.businessobject.ObjectType, org.kuali.rice.kns.datadictionary.DataDictionary)
281 */
282 public boolean isValidObjectTypeCode(ObjectType objectTypeCode, DataDictionary dataDictionary) {
283 return isValidObjectTypeCode(objectTypeCode, dataDictionary, KFSConstants.OBJECT_TYPE_CODE_PROPERTY_NAME);
284 }
285
286 /**
287 * @see org.kuali.kfs.sys.document.service.AccountingLineRuleHelperService#isValidObjectTypeCode(org.kuali.kfs.coa.businessobject.ObjectType, org.kuali.rice.kns.datadictionary.DataDictionary, java.lang.String)
288 */
289 public boolean isValidObjectTypeCode(ObjectType objectTypeCode, DataDictionary dataDictionary, String errorPropertyName) {
290 // note that the errorPropertyName does not match the actual attribute name
291 String label = getObjectTypeCodeLabel();
292
293 // make sure it exists
294 if (ObjectUtils.isNull(objectTypeCode)) {
295 GlobalVariables.getMessageMap().putError(errorPropertyName, KFSKeyConstants.ERROR_EXISTENCE, label);
296 return false;
297 }
298
299 // check activity
300 if (!objectTypeCode.isActive()) {
301 GlobalVariables.getMessageMap().putError(errorPropertyName, KFSKeyConstants.ERROR_INACTIVE, label);
302 return false;
303 }
304
305 return true;
306 }
307
308 /**
309 * @see org.kuali.kfs.sys.document.service.AccountingLineRuleHelperService#isValidProjectCode(org.kuali.kfs.coa.businessobject.ProjectCode, org.kuali.rice.kns.datadictionary.DataDictionary)
310 */
311 public boolean isValidProjectCode(ProjectCode projectCode, DataDictionary dataDictionary) {
312 return isValidProjectCode(projectCode, dataDictionary, KFSConstants.PROJECT_CODE_PROPERTY_NAME);
313 }
314
315 /**
316 * @see org.kuali.kfs.sys.document.service.AccountingLineRuleHelperService#isValidProjectCode(org.kuali.kfs.coa.businessobject.ProjectCode, org.kuali.rice.kns.datadictionary.DataDictionary, java.lang.String)
317 */
318 public boolean isValidProjectCode(ProjectCode projectCode, DataDictionary dataDictionary, String errorPropertyName) {
319 // note that the errorPropertyName does not match the actual attribute name
320 String label = getProjectCodeLabel();
321
322 // make sure it exists
323 if (ObjectUtils.isNull(projectCode)) {
324 GlobalVariables.getMessageMap().putError(errorPropertyName, KFSKeyConstants.ERROR_EXISTENCE, label);
325 return false;
326 }
327
328 // check activity
329 if (!projectCode.isActive()) {
330 GlobalVariables.getMessageMap().putError(errorPropertyName, KFSKeyConstants.ERROR_INACTIVE, label);
331 return false;
332 }
333
334 return true;
335 }
336
337 /**
338 * @see org.kuali.kfs.sys.document.service.AccountingLineRuleHelperService#isValidSubAccount(org.kuali.kfs.coa.businessobject.SubAccount, org.kuali.rice.kns.datadictionary.DataDictionary)
339 */
340 public boolean isValidSubAccount(SubAccount subAccount, DataDictionary dataDictionary) {
341 return isValidSubAccount(subAccount, dataDictionary, KFSConstants.SUB_ACCOUNT_NUMBER_PROPERTY_NAME);
342 }
343
344 /**
345 * @see org.kuali.kfs.sys.document.service.AccountingLineRuleHelperService#isValidSubAccount(org.kuali.kfs.coa.businessobject.SubAccount, org.kuali.rice.kns.datadictionary.DataDictionary, java.lang.String)
346 */
347 public boolean isValidSubAccount(SubAccount subAccount, DataDictionary dataDictionary, String errorPropertyName) {
348 String label = getSubAccountLabel();
349
350 // make sure it exists
351 if (ObjectUtils.isNull(subAccount)) {
352 GlobalVariables.getMessageMap().putError(errorPropertyName, KFSKeyConstants.ERROR_EXISTENCE, label);
353 return false;
354 }
355
356 // check to make sure it is active
357 if (!subAccount.isActive()) {
358 GlobalVariables.getMessageMap().putError(errorPropertyName, KFSKeyConstants.ERROR_DOCUMENT_SUB_ACCOUNT_INACTIVE, label);
359 return false;
360 }
361
362 return true;
363 }
364
365 /**
366 * @see org.kuali.kfs.sys.document.service.AccountingLineRuleHelperService#isValidSubObjectCode(org.kuali.kfs.coa.businessobject.SubObjCd, org.kuali.rice.kns.datadictionary.DataDictionary)
367 */
368 public boolean isValidSubObjectCode(SubObjectCode subObjectCode, DataDictionary dataDictionary) {
369 return isValidSubObjectCode(subObjectCode, dataDictionary, KFSConstants.FINANCIAL_SUB_OBJECT_CODE_PROPERTY_NAME);
370 }
371
372 /**
373 * @see org.kuali.kfs.sys.document.service.AccountingLineRuleHelperService#isValidSubObjectCode(org.kuali.kfs.coa.businessobject.SubObjCd, org.kuali.rice.kns.datadictionary.DataDictionary, java.lang.String)
374 */
375 public boolean isValidSubObjectCode(SubObjectCode subObjectCode, DataDictionary dataDictionary, String errorPropertyName) {
376 String label = getSubObjectCodeLabel();
377
378 // make sure it exists
379 if (ObjectUtils.isNull(subObjectCode)) {
380 GlobalVariables.getMessageMap().putError(errorPropertyName, KFSKeyConstants.ERROR_EXISTENCE, label);
381 return false;
382 }
383
384 // check active flag
385 if (!subObjectCode.isActive()) {
386 GlobalVariables.getMessageMap().putError(errorPropertyName, KFSKeyConstants.ERROR_INACTIVE, label);
387 return false;
388 }
389 return true;
390 }
391
392 /**
393 * @see org.kuali.kfs.sys.document.service.AccountingLineRuleHelperService#validateAccountingLine(org.kuali.kfs.sys.businessobject.AccountingLine)
394 */
395 public boolean validateAccountingLine(AccountingLine accountingLine) {
396 if (accountingLine == null) {
397 throw new IllegalStateException(SpringContext.getBean(KualiConfigurationService.class).getPropertyString(KFSKeyConstants.ERROR_DOCUMENT_NULL_ACCOUNTING_LINE));
398 }
399
400 // grab the two service instances that will be needed by all the validate methods
401 DataDictionary dd = dataDictionaryService.getDataDictionary();
402
403 BusinessObjectEntry accountingLineEntry = dd.getBusinessObjectEntry(SourceAccountingLine.class.getName());
404
405 // retrieve accounting line objects to validate
406 accountingLine.refreshReferenceObject("chart");
407 Chart chart = accountingLine.getChart();
408 accountingLine.refreshReferenceObject("account");
409 Account account = accountingLine.getAccount();
410 accountingLine.refreshReferenceObject("objectCode");
411 ObjectCode objectCode = accountingLine.getObjectCode();
412
413 boolean valid = true;
414 valid &= isValidChart(chart, dd);
415 valid &= isValidAccount(account, dd);
416 // sub account is not required
417 if (StringUtils.isNotBlank(accountingLine.getSubAccountNumber())) {
418 accountingLine.refreshReferenceObject("subAccount");
419 SubAccount subAccount = accountingLine.getSubAccount();
420 valid &= isValidSubAccount(subAccount, dd);
421 }
422 valid &= isValidObjectCode(objectCode, dd);
423 // sub object is not required
424 if (StringUtils.isNotBlank(accountingLine.getFinancialSubObjectCode())) {
425 accountingLine.refreshReferenceObject("subObjectCode");
426 SubObjectCode subObjectCode = accountingLine.getSubObjectCode();
427 valid &= isValidSubObjectCode(subObjectCode, dd);
428 }
429 // project code is not required
430 if (StringUtils.isNotBlank(accountingLine.getProjectCode())) {
431 accountingLine.refreshReferenceObject("project");
432 ProjectCode projectCode = accountingLine.getProject();
433 valid &= isValidProjectCode(projectCode, dd);
434 }
435 if (StringUtils.isNotBlank(accountingLine.getReferenceOriginCode())) {
436 accountingLine.refreshReferenceObject("referenceOrigin");
437 OriginationCode referenceOrigin = accountingLine.getReferenceOrigin();
438 valid &= isValidReferenceOriginCode(referenceOrigin, accountingLineEntry);
439 }
440 if (StringUtils.isNotBlank(accountingLine.getReferenceTypeCode())) {
441 DocumentTypeEBO referenceType = accountingLine.getReferenceFinancialSystemDocumentTypeCode();
442 valid &= isValidReferenceTypeCode(accountingLine.getReferenceTypeCode(), referenceType, accountingLineEntry);
443 }
444 valid &= hasRequiredOverrides(accountingLine, accountingLine.getOverrideCode());
445 return valid;
446 }
447
448 /**
449 * This method will check the reference origin code for existence in the system and whether it can actively be used.
450 *
451 * @param referenceOriginCode
452 * @param accountingLineEntry
453 * @return boolean True if the object is valid; false otherwise.
454 */
455 protected boolean isValidReferenceOriginCode(OriginationCode referenceOriginCode, BusinessObjectEntry accountingLineEntry) {
456 return checkExistence(referenceOriginCode, accountingLineEntry, KFSPropertyConstants.REFERENCE_ORIGIN_CODE, KFSPropertyConstants.REFERENCE_ORIGIN_CODE);
457 }
458
459 /**
460 * This method will check the reference type code for existence in the system and whether it can actively be used.
461 *
462 * @param documentTypeCode the document type name of the reference document type
463 * @param referenceType
464 * @param accountingLineEntry
465 * @return boolean True if the object is valid; false otherwise.
466 */
467 protected boolean isValidReferenceTypeCode(String documentTypeCode, DocumentTypeEBO referenceType, BusinessObjectEntry accountingLineEntry) {
468 if (!StringUtils.isBlank(documentTypeCode) && !getFinancialSystemDocumentTypeService().isCurrentActiveAccountingDocumentType(documentTypeCode)) {
469 GlobalVariables.getMessageMap().putError(KFSPropertyConstants.REFERENCE_TYPE_CODE, KFSKeyConstants.ERROR_DOCUMENT_ACCOUNTING_LINE_NON_ACTIVE_CURRENT_ACCOUNTING_DOCUMENT_TYPE, documentTypeCode);
470 return false;
471 }
472 return checkExistence(referenceType, accountingLineEntry, KFSPropertyConstants.REFERENCE_TYPE_CODE, KFSPropertyConstants.REFERENCE_TYPE_CODE);
473 }
474
475 /**
476 * Checks for the existence of the given Object. This is doing an OJB-proxy-smart check, so assuming the given Object is not in
477 * need of a refresh(), this method adds an ERROR_EXISTENCE to the global error map if the given Object is not in the database.
478 *
479 * @param toCheck the Object to check for existence
480 * @param accountingLineEntry to get the property's label for the error message parameter.
481 * @param attributeName the name of the SourceAccountingLine attribute in the DataDictionary accountingLineEntry
482 * @param propertyName the name of the property within the global error path.
483 * @return whether the given Object exists or not
484 */
485 protected boolean checkExistence(Object toCheck, BusinessObjectEntry accountingLineEntry, String attributeName, String propertyName) {
486 String label = accountingLineEntry.getAttributeDefinition(attributeName).getShortLabel();
487 if (ObjectUtils.isNull(toCheck)) {
488 GlobalVariables.getMessageMap().putError(propertyName, KFSKeyConstants.ERROR_EXISTENCE, label);
489 return false;
490 }
491 return true;
492 }
493
494 /**
495 * Sets the dataDictionaryService attribute value.
496 * @param dataDictionaryService The dataDictionaryService to set.
497 */
498 public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
499 this.dataDictionaryService = dataDictionaryService;
500 }
501
502 public DataDictionaryService getDataDictionaryService() {
503 return this.dataDictionaryService;
504 }
505
506 /**
507 * Gets the financialSystemDocumentTypeService attribute.
508 * @return Returns the financialSystemDocumentTypeService.
509 */
510 public FinancialSystemDocumentTypeService getFinancialSystemDocumentTypeService() {
511 return financialSystemDocumentTypeService;
512 }
513
514 /**
515 * Sets the financialSystemDocumentTypeService attribute value.
516 * @param financialSystemDocumentTypeService The financialSystemDocumentTypeService to set.
517 */
518 public void setFinancialSystemDocumentTypeService(FinancialSystemDocumentTypeService financialSystemDocumentTypeService) {
519 this.financialSystemDocumentTypeService = financialSystemDocumentTypeService;
520 }
521 }