1 package org.kuali.ole.module.purap.service.impl;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.kuali.ole.coa.businessobject.*;
5 import org.kuali.ole.select.OleSelectConstant;
6 import org.kuali.ole.sys.OLEConstants;
7 import org.kuali.ole.sys.OLEKeyConstants;
8 import org.kuali.ole.sys.businessobject.AccountingLine;
9 import org.kuali.ole.sys.businessobject.OriginationCode;
10 import org.kuali.ole.sys.businessobject.SourceAccountingLine;
11 import org.kuali.ole.sys.context.SpringContext;
12 import org.kuali.rice.core.api.config.property.ConfigurationService;
13 import org.kuali.rice.kew.doctype.bo.DocumentTypeEBO;
14 import org.kuali.rice.krad.datadictionary.DataDictionary;
15 import org.kuali.rice.krad.util.GlobalVariables;
16 import org.kuali.rice.krad.util.ObjectUtils;
17
18
19
20
21
22
23
24
25 public class OLEPurchasingAccountingLineRuleHelperServiceImpl extends PurchasingAccountingLineRuleHelperServiceImpl{
26
27 @Override
28 public boolean validateAccountingLine(AccountingLine accountingLine) {
29 if (accountingLine == null) {
30 throw new IllegalStateException(SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEKeyConstants.ERROR_DOCUMENT_NULL_ACCOUNTING_LINE));
31 }
32 DataDictionary dd = getDataDictionaryService().getDataDictionary();
33 org.kuali.rice.krad.datadictionary.BusinessObjectEntry accountingLineEntry = dd.getBusinessObjectEntry(SourceAccountingLine.class.getName());
34 String accountIdentifyingPropertyName = getAccountIdentifyingPropertyName(accountingLine);
35 accountingLine.refreshReferenceObject(OLEConstants.CHART_PROPERTY_NAME);
36 Chart chart = accountingLine.getChart();
37 accountingLine.refreshReferenceObject(OLEConstants.ACCOUNT_PROPERTY_NAME);
38 String accountNumber = accountingLine.getAccountNumber();
39 Account account = accountingLine.getAccount();
40 accountingLine.refreshReferenceObject(OLEConstants.OrderQueue.ORDQ_OBJ_CODE);
41 ObjectCode objectCode = accountingLine.getObjectCode();
42 boolean valid = true;
43 valid &= isValidChart(accountIdentifyingPropertyName, chart, dd);
44 valid &= isValidAccount(accountIdentifyingPropertyName, account, accountNumber, dd);
45 if (StringUtils.isNotBlank(accountingLine.getSubAccountNumber())) {
46 accountingLine.refreshReferenceObject(OLEConstants.SUB_ACCOUNT_PROPERTY_NAME);
47 SubAccount subAccount = accountingLine.getSubAccount();
48 valid &= isValidSubAccount(accountIdentifyingPropertyName, subAccount, dd);
49 }
50 valid &= isValidObjectCode(accountIdentifyingPropertyName, objectCode, dd);
51 if (StringUtils.isNotBlank(accountingLine.getFinancialSubObjectCode())) {
52 accountingLine.refreshReferenceObject(OLEConstants.SUB_OBJECT_CODE_PROPERTY_NAME);
53 SubObjectCode subObjectCode = accountingLine.getSubObjectCode();
54 valid &= isValidSubObjectCode(accountIdentifyingPropertyName, subObjectCode, dd);
55 }
56 if (StringUtils.isNotBlank(accountingLine.getProjectCode())) {
57 accountingLine.refreshReferenceObject(OLEConstants.PROJECT_PROPERTY_NAME);
58 ProjectCode projectCode = accountingLine.getProject();
59 valid &= isValidProjectCode(accountIdentifyingPropertyName, projectCode, dd);
60 }
61 if (StringUtils.isNotBlank(accountingLine.getReferenceOriginCode())) {
62 accountingLine.refreshReferenceObject(OLEConstants.REF_ORIGIN_PROPERTY_NAME);
63 OriginationCode referenceOrigin = accountingLine.getReferenceOrigin();
64 valid &= isValidReferenceOriginCode(accountIdentifyingPropertyName, referenceOrigin, accountingLineEntry);
65 }
66 if (StringUtils.isNotBlank(accountingLine.getReferenceTypeCode())) {
67 DocumentTypeEBO referenceType = accountingLine.getReferenceFinancialSystemDocumentTypeCode();
68 valid &= isValidReferenceTypeCode(accountingLine.getReferenceTypeCode(), referenceType, accountingLineEntry, accountIdentifyingPropertyName);
69 }
70 valid &= hasRequiredOverrides(accountingLine, accountingLine.getOverrideCode());
71 return valid;
72 }
73
74 private boolean isValidAccount(String accountIdentifyingPropertyName, Account account, String accountNumber, DataDictionary dataDictionary) {
75 return isValidAccount(account, accountNumber, dataDictionary, OLEConstants.ACCOUNT_NUMBER_PROPERTY_NAME, accountIdentifyingPropertyName);
76 }
77
78 private boolean isValidAccount(Account account, String accountNumber, DataDictionary dataDictionary, String errorPropertyName, String accountIdentifyingPropertyName) {
79 String label = getAccountLabel();
80 if (ObjectUtils.isNull(account)) {
81 GlobalVariables.getMessageMap().putError(errorPropertyName, OLEKeyConstants.ERROR_EXISTING_WITH_IDENTIFYING_ACCOUNTING_LINE, label, accountNumber);
82 return false;
83 }
84 if (!account.isActive()) {
85 GlobalVariables.getMessageMap().putError(errorPropertyName, OLEKeyConstants.ERROR_DOCUMENT_ACCOUNT_CLOSED_WITH_IDENTIFYING_ACCOUNTING_LINE, label);
86 return false;
87 }
88 if (ObjectUtils.isNotNull(account.getAccountRestrictedStatusCode())) {
89 if (account.getAccountRestrictedStatusCode().equalsIgnoreCase(OleSelectConstant.ACCOUNT_TEMPORARY_RESTRICTED_CODE)) {
90 GlobalVariables.getMessageMap().putError(errorPropertyName, OLEKeyConstants.ERROR_DOCUMENT_ACCOUNT_IS_TEMPORARY_RESTRICTED, label);
91 return false;
92 } else if (account.getAccountRestrictedStatusCode().equalsIgnoreCase(OleSelectConstant.ACCOUNT_RESTRICTED_CODE)) {
93 GlobalVariables.getMessageMap().putError(errorPropertyName, OLEKeyConstants.ERROR_DOCUMENT_ACCOUNT_IS_RESTRICTED, accountNumber);
94 return false;
95 }
96 }
97 return true;
98 }
99 }