use of org.kuali.kfs.coa.businessobject.AccountDelegateGlobalDetail in project cu-kfs by CU-CommunityApps.
the class CuAccountDelegateGlobal method generateGlobalChangesToPersist.
/**
* @see org.kuali.kfs.krad.document.GlobalBusinessObject#applyGlobalChanges(org.kuali.rice.krad.bo.BusinessObject)
*/
@SuppressWarnings("deprecation")
public List<PersistableBusinessObject> generateGlobalChangesToPersist() {
BusinessObjectService boService = SpringContext.getBean(BusinessObjectService.class);
List<AccountDelegate> persistables = new ArrayList();
List<AccountDelegateGlobalDetail> changeDocuments = this.getDelegateGlobals();
List<AccountGlobalDetail> accountDetails = this.getAccountGlobalDetails();
for (AccountDelegateGlobalDetail changeDocument : changeDocuments) {
for (AccountGlobalDetail accountDetail : accountDetails) {
Account account = (Account) boService.findByPrimaryKey(Account.class, accountDetail.getPrimaryKeys());
// the busines rules for this document should have caught this.
if (account == null) {
throw new RuntimeException("Account [" + accountDetail.getChartOfAccountsCode() + "-" + accountDetail.getAccountNumber() + "] was not present in the database. " + "This should never happen under normal circumstances, as an invalid account should have " + "been caught by the Business Rules infrastructure.");
}
// attempt to load the existing Delegate from the DB, if it exists. we do this to avoid
// versionNumber conflicts if we tried to just insert a new record that already existed.
Map pkMap = new HashMap();
// chartOfAccountsCode & accountNumber
pkMap.putAll(accountDetail.getPrimaryKeys());
pkMap.put("financialDocumentTypeCode", changeDocument.getFinancialDocumentTypeCode());
pkMap.put("accountDelegateSystemId", changeDocument.getAccountDelegateUniversalId());
AccountDelegate delegate = (AccountDelegate) boService.findByPrimaryKey(AccountDelegate.class, pkMap);
// so lets populate it with the primary keys
if (delegate == null) {
delegate = new AccountDelegate();
delegate.setChartOfAccountsCode(accountDetail.getChartOfAccountsCode());
delegate.setAccountNumber(accountDetail.getAccountNumber());
delegate.setAccountDelegateSystemId(changeDocument.getAccountDelegateUniversalId());
delegate.setFinancialDocumentTypeCode(changeDocument.getFinancialDocumentTypeCode());
delegate.setActive(true);
} else {
delegate.setActive(true);
}
// APPROVAL FROM AMOUNT
delegate.setFinDocApprovalFromThisAmt(changeDocument.getApprovalFromThisAmount());
// APPROVAL TO AMOUNT
delegate.setFinDocApprovalToThisAmount(changeDocument.getApprovalToThisAmount());
// PRIMARY ROUTING
delegate.setAccountsDelegatePrmrtIndicator(changeDocument.getAccountDelegatePrimaryRoutingIndicator());
// START DATE
if (changeDocument.getAccountDelegateStartDate() != null) {
delegate.setAccountDelegateStartDate(new Date(changeDocument.getAccountDelegateStartDate().getTime()));
}
persistables.add(delegate);
}
}
return new ArrayList<PersistableBusinessObject>(persistables);
}
Aggregations