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;
}
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);
}
}
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);
}
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);
}
}
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();
}
}
Aggregations