Search in sources :

Example 1 with AccountDelegateGlobalDetail

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);
}
Also used : Account(org.kuali.kfs.coa.businessobject.Account) AccountDelegateGlobalDetail(org.kuali.kfs.coa.businessobject.AccountDelegateGlobalDetail) HashMap(java.util.HashMap) AccountDelegate(org.kuali.kfs.coa.businessobject.AccountDelegate) ArrayList(java.util.ArrayList) Date(java.sql.Date) BusinessObjectService(org.kuali.kfs.krad.service.BusinessObjectService) AccountGlobalDetail(org.kuali.kfs.coa.businessobject.AccountGlobalDetail) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Date (java.sql.Date)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Account (org.kuali.kfs.coa.businessobject.Account)1 AccountDelegate (org.kuali.kfs.coa.businessobject.AccountDelegate)1 AccountDelegateGlobalDetail (org.kuali.kfs.coa.businessobject.AccountDelegateGlobalDetail)1 AccountGlobalDetail (org.kuali.kfs.coa.businessobject.AccountGlobalDetail)1 BusinessObjectService (org.kuali.kfs.krad.service.BusinessObjectService)1