Search in sources :

Example 1 with Maintainable

use of org.kuali.kfs.kns.maintenance.Maintainable in project cu-kfs by CU-CommunityApps.

the class AccountReversionTrickleDownInactivationServiceImpl method generateTrickleDownMaintenanceLocks.

/**
 * Will generate Maintenance Locks for all (active or not) AccountReversions in the system related to the inactivated account using the AccountReversion
 * maintainable registered for the AccountReversion maintenance document
 *
 * @see edu.cornell.kfs.coa.service.AccountReversionTrickleDownInactivationService#generateTrickleDownMaintenanceLocks(org.kuali.kfs.coa.businessobject.Account, java.lang.String)
 */
public List<MaintenanceLock> generateTrickleDownMaintenanceLocks(Account inactivatedAccount, String documentNumber) {
    List<MaintenanceLock> maintenanceLocks = new ArrayList<MaintenanceLock>();
    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 Account Reversion Maintainable", e);
        throw new RuntimeException("Unable to instantiate Account Reversion Maintainable", e);
    }
    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) {
            accountReversionMaintainable.setBusinessObject(accountReversion);
            maintenanceLocks.addAll(accountReversionMaintainable.generateMaintenanceLocks());
        }
    }
    return maintenanceLocks;
}
Also used : AccountReversion(edu.cornell.kfs.coa.businessobject.AccountReversion) ArrayList(java.util.ArrayList) MaintenanceLock(org.kuali.kfs.krad.maintenance.MaintenanceLock) Maintainable(org.kuali.kfs.kns.maintenance.Maintainable)

Example 2 with Maintainable

use of org.kuali.kfs.kns.maintenance.Maintainable in project cu-kfs by CU-CommunityApps.

the class CuSubAccountTrickleDownInactivationServiceImpl method trickleDownInactivateSubAccounts.

/**
 * @see org.kuali.kfs.coa.service.impl.SubAccountTrickleDownInactivationServiceImpl#trickleDownInactivateSubAccounts(org.kuali.kfs.coa.businessobject.Account, java.lang.String)
 */
public void trickleDownInactivateSubAccounts(Account inactivatedAccount, String documentNumber) {
    List<SubAccount> inactivatedSubAccounts = new ArrayList<SubAccount>();
    Map<SubAccount, String> alreadyLockedSubAccounts = new HashMap<SubAccount, String>();
    List<SubAccount> errorPersistingSubAccounts = new ArrayList<SubAccount>();
    Maintainable subAccountMaintainable;
    try {
        subAccountMaintainable = (Maintainable) maintenanceDocumentDictionaryService.getMaintainableClass(SubAccount.class.getName()).newInstance();
        subAccountMaintainable.setBoClass(SubAccount.class);
        subAccountMaintainable.setDocumentNumber(documentNumber);
    } catch (Exception e) {
        LOG.error("Unable to instantiate SubAccount Maintainable", e);
        throw new RuntimeException("Unable to instantiate SubAccount Maintainable", e);
    }
    inactivatedAccount.refreshReferenceObject(KFSPropertyConstants.SUB_ACCOUNTS);
    if (ObjectUtils.isNotNull(inactivatedAccount.getSubAccounts()) && !inactivatedAccount.getSubAccounts().isEmpty()) {
        for (Iterator<SubAccount> i = inactivatedAccount.getSubAccounts().iterator(); i.hasNext(); ) {
            SubAccount subAccount = i.next();
            if (subAccount.isActive()) {
                subAccountMaintainable.setBusinessObject(subAccount);
                List<MaintenanceLock> subAccountLocks = subAccountMaintainable.generateMaintenanceLocks();
                MaintenanceLock failedLock = verifyAllLocksFromThisDocument(subAccountLocks, documentNumber);
                if (failedLock != null) {
                    // another document has locked this sub account, so we don't try to inactivate the account
                    alreadyLockedSubAccounts.put(subAccount, 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
                    subAccount.setActive(false);
                    try {
                        subAccountMaintainable.saveBusinessObject();
                        inactivatedSubAccounts.add(subAccount);
                    } catch (RuntimeException e) {
                        LOG.error("Unable to trickle-down inactivate sub-account " + subAccount.toString(), e);
                        errorPersistingSubAccounts.add(subAccount);
                    }
                }
            }
        }
        // KFSPTS-3877 add note to object level instead of document
        addNotesToAccountObject(documentNumber, inactivatedAccount, inactivatedSubAccounts, alreadyLockedSubAccounts, errorPersistingSubAccounts);
    }
}
Also used : HashMap(java.util.HashMap) SubAccount(org.kuali.kfs.coa.businessobject.SubAccount) ArrayList(java.util.ArrayList) MaintenanceLock(org.kuali.kfs.krad.maintenance.MaintenanceLock) Maintainable(org.kuali.kfs.kns.maintenance.Maintainable)

Example 3 with Maintainable

use of org.kuali.kfs.kns.maintenance.Maintainable in project cu-kfs by CU-CommunityApps.

the class CuFinancialMaintenanceDocumentActionTest method setupMockMaintenanceDocument.

protected void setupMockMaintenanceDocument(Class<? extends PersistableBusinessObject> dataObjectClass, DocumentStatus documentStatus, String objectId) {
    Maintainable mockMaintainable = createMockMaintainable(dataObjectClass, objectId);
    PersistableBusinessObject mockDataObject = (PersistableBusinessObject) mockMaintainable.getDataObject();
    DocumentHeader mockDocumentHeader = createMockDocumentHeader(documentStatus);
    testDocument = mock(FinancialSystemMaintenanceDocument.class);
    when(((FinancialSystemMaintenanceDocument) testDocument).getNewMaintainableObject()).thenReturn(mockMaintainable);
    when(testDocument.getNoteTarget()).thenReturn(mockDataObject);
    when(testDocument.getDocumentHeader()).thenReturn(mockDocumentHeader);
}
Also used : PersistableBusinessObject(org.kuali.kfs.krad.bo.PersistableBusinessObject) FinancialSystemMaintenanceDocument(org.kuali.kfs.sys.document.FinancialSystemMaintenanceDocument) FinancialSystemDocumentHeader(org.kuali.kfs.sys.businessobject.FinancialSystemDocumentHeader) DocumentHeader(org.kuali.kfs.krad.bo.DocumentHeader) Maintainable(org.kuali.kfs.kns.maintenance.Maintainable) FinancialSystemMaintainable(org.kuali.kfs.sys.document.FinancialSystemMaintainable)

Example 4 with Maintainable

use of org.kuali.kfs.kns.maintenance.Maintainable 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)

Example 5 with Maintainable

use of org.kuali.kfs.kns.maintenance.Maintainable in project cu-kfs by CU-CommunityApps.

the class EzraServiceImpl method routeAgencyDocument.

private void routeAgencyDocument(Agency agency, Agency oldAgency) {
    GlobalVariables.clear();
    GlobalVariables.setUserSession(new UserSession(KFSConstants.SYSTEM_USER));
    // DocumentService docService = SpringContext.getBean(DocumentService.class);
    MaintenanceDocument agencyDoc = null;
    try {
        agencyDoc = (MaintenanceDocument) documentService.getNewDocument("AGCY");
    } catch (WorkflowException we) {
        we.printStackTrace();
    }
    agencyDoc.getDocumentHeader().setDocumentDescription("Auto creation of new agency: " + agency.getAgencyNumber());
    if (ObjectUtils.isNotNull(oldAgency)) {
        agencyDoc.getOldMaintainableObject().setBusinessObject(oldAgency);
        agencyDoc.getDocumentHeader().setDocumentDescription(agency.getAgencyNumber() + " by auto edit");
    }
    Maintainable agencyMaintainable = agencyDoc.getNewMaintainableObject();
    agencyMaintainable.setBusinessObject(agency);
    agencyDoc.setNewMaintainableObject(agencyMaintainable);
    try {
        documentService.saveDocument(agencyDoc);
        agencyDoc.getDocumentHeader().getWorkflowDocument().route("Automatically created and routed");
    } catch (WorkflowException we) {
        we.printStackTrace();
    }
    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : MaintenanceDocument(org.kuali.kfs.kns.document.MaintenanceDocument) UserSession(org.kuali.kfs.krad.UserSession) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) Maintainable(org.kuali.kfs.kns.maintenance.Maintainable)

Aggregations

Maintainable (org.kuali.kfs.kns.maintenance.Maintainable)6 ArrayList (java.util.ArrayList)3 MaintenanceLock (org.kuali.kfs.krad.maintenance.MaintenanceLock)3 AccountReversion (edu.cornell.kfs.coa.businessobject.AccountReversion)2 HashMap (java.util.HashMap)2 PersistableBusinessObject (org.kuali.kfs.krad.bo.PersistableBusinessObject)2 FinancialSystemMaintainable (org.kuali.kfs.sys.document.FinancialSystemMaintainable)2 SubAccount (org.kuali.kfs.coa.businessobject.SubAccount)1 MaintenanceDocument (org.kuali.kfs.kns.document.MaintenanceDocument)1 UserSession (org.kuali.kfs.krad.UserSession)1 DocumentHeader (org.kuali.kfs.krad.bo.DocumentHeader)1 FinancialSystemDocumentHeader (org.kuali.kfs.sys.businessobject.FinancialSystemDocumentHeader)1 FinancialSystemMaintenanceDocument (org.kuali.kfs.sys.document.FinancialSystemMaintenanceDocument)1 WorkflowException (org.kuali.rice.kew.api.exception.WorkflowException)1