Search in sources :

Example 6 with AccountReversion

use of edu.cornell.kfs.coa.businessobject.AccountReversion in project cu-kfs by CU-CommunityApps.

the class AccountReversionMaintainableImpl method retrieveExistingAccountReversion.

/**
 * Grabs the old version of this org reversion from the database
 * @return the old version of this organization reversion
 */
protected AccountReversion retrieveExistingAccountReversion() {
    final AccountReversion acctRev = (AccountReversion) getBusinessObject();
    final AccountReversion oldAcctRev = SpringContext.getBean(AccountReversionService.class).getByPrimaryId(acctRev.getUniversityFiscalYear(), acctRev.getChartOfAccountsCode(), acctRev.getAccountNumber());
    return oldAcctRev;
}
Also used : AccountReversion(edu.cornell.kfs.coa.businessobject.AccountReversion) AccountReversionService(edu.cornell.kfs.coa.service.AccountReversionService)

Example 7 with AccountReversion

use of edu.cornell.kfs.coa.businessobject.AccountReversion in project cu-kfs by CU-CommunityApps.

the class AccountReversionMaintainableImpl method processAfterNew.

@Override
public void processAfterNew(MaintenanceDocument document, Map<String, String[]> requestParameters) {
    super.processAfterNew(document, requestParameters);
    AccountReversion accountReversion = (AccountReversion) getBusinessObject();
    List<AccountReversionDetail> details = accountReversion.getAccountReversionDetails();
    if (details == null) {
        details = new ArrayList<AccountReversionDetail>();
        accountReversion.setAccountReversionDetails(details);
    }
    if (details.size() == 0) {
        Collection<ReversionCategory> categories = SpringContext.getBean(AccountReversionService.class).getCategoryList();
        for (ReversionCategory category : categories) {
            if (category.isActive()) {
                AccountReversionDetail detail = new AccountReversionDetail();
                detail.setAccountReversionCategoryCode(category.getReversionCategoryCode());
                detail.setReversionCategory(category);
                details.add(detail);
            }
        }
        Collections.sort(details, new categoryComparator());
    }
}
Also used : AccountReversion(edu.cornell.kfs.coa.businessobject.AccountReversion) AccountReversionDetail(edu.cornell.kfs.coa.businessobject.AccountReversionDetail) ReversionCategory(edu.cornell.kfs.coa.businessobject.ReversionCategory) AccountReversionService(edu.cornell.kfs.coa.service.AccountReversionService)

Example 8 with AccountReversion

use of edu.cornell.kfs.coa.businessobject.AccountReversion in project cu-kfs by CU-CommunityApps.

the class AccountReversionPreRules method doCustomPreRules.

/**
 * This calls the {@link AccountReversionPreRules#copyKeyAttributesToDetail(OrganizationReversion)}
 * @see org.kuali.kfs.coa.document.validation.impl.MaintenancePreRulesBase#doCustomPreRules(org.kuali.kfs.kns.document.MaintenanceDocument)
 */
@Override
protected boolean doCustomPreRules(MaintenanceDocument document) {
    AccountReversion acctRev = (AccountReversion) document.getNewMaintainableObject().getBusinessObject();
    // copy year and chart to detail records
    copyKeyAttributesToDetail(acctRev);
    return true;
}
Also used : AccountReversion(edu.cornell.kfs.coa.businessobject.AccountReversion)

Example 9 with AccountReversion

use of edu.cornell.kfs.coa.businessobject.AccountReversion in project cu-kfs by CU-CommunityApps.

the class AccountReversionTrickleDownInactivationServiceImpl method addMaintenanceLockedNotes.

/**
 * Adds notes about any maintence locks on Account Reversions.
 *
 * @param documentNumber
 * @param lockedAccountReversions
 * @param messageKey
 * @param noteParent
 * @param noteTemplate
 */
protected void addMaintenanceLockedNotes(String documentNumber, Map<AccountReversion, String> lockedAccountReversions, String messageKey, PersistableBusinessObject noteParent, Note noteTemplate) {
    for (Map.Entry<AccountReversion, String> entry : lockedAccountReversions.entrySet()) {
        try {
            AccountReversion accountReversion = entry.getKey();
            String accountReversionString = accountReversion.getUniversityFiscalYear() + " - " + accountReversion.getChartOfAccountsCode() + " - " + accountReversion.getAccountNumber();
            if (StringUtils.isNotBlank(accountReversionString)) {
                String noteTextTemplate = kualiConfigurationService.getPropertyValueAsString(messageKey);
                String noteText = MessageFormat.format(noteTextTemplate, accountReversionString, entry.getValue());
                Note note = noteService.createNote(noteTemplate, noteParent, GlobalVariables.getUserSession().getPrincipalId());
                note.setNoteText(noteText);
                noteService.save(note);
            }
        } catch (Exception e) {
            LOG.error("Unable to create/save notes for document " + documentNumber, e);
            throw new RuntimeException("Unable to create/save notes for document " + documentNumber, e);
        }
    }
}
Also used : AccountReversion(edu.cornell.kfs.coa.businessobject.AccountReversion) Note(org.kuali.kfs.krad.bo.Note) HashMap(java.util.HashMap) Map(java.util.Map)

Example 10 with AccountReversion

use of edu.cornell.kfs.coa.businessobject.AccountReversion in project cu-kfs by CU-CommunityApps.

the class AccountReversionTrickleDownInactivationServiceImpl method trickleDownInactivateAccountReversions.

/**
 * Inactivates all related AccountReversion rules.
 *
 * @see edu.cornell.kfs.coa.service.AccountReversionTrickleDownInactivationService#trickleDownInactivateAccountReversions(org.kuali.kfs.coa.businessobject.Account, java.lang.String)
 */
public void trickleDownInactivateAccountReversions(Account inactivatedAccount, String documentNumber) {
    List<AccountReversion> inactivatedAccountReversions = new ArrayList<AccountReversion>();
    Map<AccountReversion, String> alreadyLockedAccountReversions = new HashMap<AccountReversion, String>();
    List<AccountReversion> errorPersistingAccountReversions = new ArrayList<AccountReversion>();
    Maintainable accountReversionMaintainable;
    try {
        accountReversionMaintainable = (Maintainable) maintenanceDocumentDictionaryService.getMaintainableClass(AccountReversion.class.getName()).newInstance();
        accountReversionMaintainable.setBoClass(AccountReversion.class);
        accountReversionMaintainable.setDocumentNumber(documentNumber);
    } catch (Exception e) {
        LOG.error("Unable to instantiate accountReversionMaintainable Maintainable", e);
        throw new RuntimeException("Unable to instantiate accountReversionMaintainable Maintainable", e);
    }
    Integer universityFiscalYear = universityDateService.getCurrentFiscalYear() - 1;
    List<AccountReversion> accountReversionRules = new ArrayList<AccountReversion>();
    List<AccountReversion> matchingAccountReversionRules = accountReversionService.getAccountReversionsByChartAndAccount(inactivatedAccount.getChartOfAccountsCode(), inactivatedAccount.getAccountNumber());
    if (ObjectUtils.isNotNull(matchingAccountReversionRules) && CollectionUtils.isNotEmpty(matchingAccountReversionRules)) {
        accountReversionRules.addAll(matchingAccountReversionRules);
    }
    List<AccountReversion> cashAccountReversionRules = accountReversionService.getAccountReversionsByCashReversionAcount(inactivatedAccount.getChartOfAccountsCode(), inactivatedAccount.getAccountNumber());
    if (ObjectUtils.isNotNull(cashAccountReversionRules) && cashAccountReversionRules.size() > 0) {
        accountReversionRules.addAll(cashAccountReversionRules);
    }
    List<AccountReversion> budgetAccountReversionRules = accountReversionService.getAccountReversionsByBudgetReversionAcount(inactivatedAccount.getChartOfAccountsCode(), inactivatedAccount.getAccountNumber());
    if (ObjectUtils.isNotNull(budgetAccountReversionRules) && budgetAccountReversionRules.size() > 0) {
        accountReversionRules.addAll(budgetAccountReversionRules);
    }
    if (ObjectUtils.isNotNull(accountReversionRules) && !accountReversionRules.isEmpty()) {
        for (AccountReversion accountReversion : accountReversionRules) {
            if (accountReversion.isActive()) {
                accountReversionMaintainable.setBusinessObject(accountReversion);
                List<MaintenanceLock> accountReversionLocks = accountReversionMaintainable.generateMaintenanceLocks();
                MaintenanceLock failedLock = verifyAllLocksFromThisDocument(accountReversionLocks, documentNumber);
                if (failedLock != null) {
                    // another document has locked this AccountReversion, so we don't try to inactivate the account
                    alreadyLockedAccountReversions.put(accountReversion, failedLock.getDocumentNumber());
                } else {
                    // no locks other than our own (but there may have been no locks at all), just go ahead and try to update
                    accountReversion.setActive(false);
                    try {
                        accountReversionMaintainable.saveBusinessObject();
                        inactivatedAccountReversions.add(accountReversion);
                    } catch (RuntimeException e) {
                        LOG.error("Unable to trickle-down inactivate accountReversion " + accountReversion.toString(), e);
                        errorPersistingAccountReversions.add(accountReversion);
                    }
                }
            }
        }
        addNotesToDocument(documentNumber, inactivatedAccountReversions, alreadyLockedAccountReversions, errorPersistingAccountReversions);
    }
}
Also used : AccountReversion(edu.cornell.kfs.coa.businessobject.AccountReversion) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MaintenanceLock(org.kuali.kfs.krad.maintenance.MaintenanceLock) Maintainable(org.kuali.kfs.kns.maintenance.Maintainable)

Aggregations

AccountReversion (edu.cornell.kfs.coa.businessobject.AccountReversion)12 HashMap (java.util.HashMap)4 AccountReversionDetail (edu.cornell.kfs.coa.businessobject.AccountReversionDetail)3 AccountReversionService (edu.cornell.kfs.coa.service.AccountReversionService)3 ReversionCategory (edu.cornell.kfs.coa.businessobject.ReversionCategory)2 ArrayList (java.util.ArrayList)2 Maintainable (org.kuali.kfs.kns.maintenance.Maintainable)2 MaintenanceLock (org.kuali.kfs.krad.maintenance.MaintenanceLock)2 CSVReader (au.com.bytecode.opencsv.CSVReader)1 FileReader (java.io.FileReader)1 Map (java.util.Map)1 Criteria (org.apache.ojb.broker.query.Criteria)1 QueryByCriteria (org.apache.ojb.broker.query.QueryByCriteria)1 Account (org.kuali.kfs.coa.businessobject.Account)1 Note (org.kuali.kfs.krad.bo.Note)1 BusinessObjectService (org.kuali.kfs.krad.service.BusinessObjectService)1