use of org.kuali.kfs.krad.maintenance.MaintenanceLock in project cu-kfs by CU-CommunityApps.
the class SubAccountGlobalMaintainableImpl method generateMaintenanceLocks.
/**
* This creates the particular locking representation for this global document.
*
* @see org.kuali.kfs.kns.maintenance.Maintainable#generateMaintenanceLocks()
*/
@Override
public List<MaintenanceLock> generateMaintenanceLocks() {
SubAccountGlobal subAccountGlobal = (SubAccountGlobal) getBusinessObject();
List<MaintenanceLock> maintenanceLocks = new ArrayList();
for (SubAccountGlobalDetail detail : subAccountGlobal.getSubAccountGlobalDetails()) {
MaintenanceLock maintenanceLock = new MaintenanceLock();
StringBuffer lockrep = new StringBuffer();
lockrep.append(Account.class.getName() + KFSConstants.Maintenance.AFTER_CLASS_DELIM);
lockrep.append(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE + KFSConstants.Maintenance.AFTER_FIELDNAME_DELIM);
lockrep.append(detail.getChartOfAccountsCode() + KFSConstants.Maintenance.AFTER_VALUE_DELIM);
lockrep.append(KFSPropertyConstants.ACCOUNT_NUMBER + KFSConstants.Maintenance.AFTER_FIELDNAME_DELIM);
lockrep.append(detail.getAccountNumber());
lockrep.append(KFSPropertyConstants.SUB_ACCOUNT_NUMBER + KFSConstants.Maintenance.AFTER_FIELDNAME_DELIM);
lockrep.append(detail.getSubAccountNumber());
maintenanceLock.setDocumentNumber(subAccountGlobal.getDocumentNumber());
maintenanceLock.setLockingRepresentation(lockrep.toString());
maintenanceLocks.add(maintenanceLock);
}
return maintenanceLocks;
}
use of org.kuali.kfs.krad.maintenance.MaintenanceLock 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.krad.maintenance.MaintenanceLock in project cu-kfs by CU-CommunityApps.
the class CuVendorMaintainableImpl method generateMaintenanceLocks.
@Override
public List<MaintenanceLock> generateMaintenanceLocks() {
if (ObjectUtils.isNull(((VendorDetail) getBusinessObject()).getVendorDetailAssignedIdentifier())) {
return new ArrayList();
}
List<MaintenanceLock> maintenanceLocks = new ArrayList<MaintenanceLock>();
Class dataObjectClass = this.getDataObjectClass();
StringBuffer lockRepresentation = new StringBuffer(dataObjectClass.getName());
lockRepresentation.append(KRADConstants.Maintenance.LOCK_AFTER_CLASS_DELIM);
Object bo = getDataObject();
List keyFieldNames = getDocumentDictionaryService().getLockingKeys(getDocumentTypeName());
StringBuffer old = new StringBuffer();
old.append(lockRepresentation);
for (Iterator i = keyFieldNames.iterator(); i.hasNext(); ) {
String fieldName = (String) i.next();
Object fieldValue = ObjectUtils.getPropertyValue(bo, fieldName);
if (fieldValue == null) {
fieldValue = "";
}
if (!i.hasNext()) {
// lock will be on the Vendor Header
break;
}
lockRepresentation.append(fieldName);
lockRepresentation.append(KRADConstants.Maintenance.LOCK_AFTER_FIELDNAME_DELIM);
lockRepresentation.append(String.valueOf(fieldValue));
if (i.hasNext()) {
lockRepresentation.append(KRADConstants.Maintenance.LOCK_AFTER_VALUE_DELIM);
}
}
MaintenanceLock maintenanceLock = new MaintenanceLock();
maintenanceLock.setDocumentNumber(this.getDocumentNumber());
maintenanceLock.setLockingRepresentation(lockRepresentation.toString());
maintenanceLocks.add(maintenanceLock);
return maintenanceLocks;
}
Aggregations