Search in sources :

Example 6 with MaintenanceLock

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;
}
Also used : SubAccountGlobal(edu.cornell.kfs.coa.businessobject.SubAccountGlobal) SubAccountGlobalDetail(edu.cornell.kfs.coa.businessobject.SubAccountGlobalDetail) ArrayList(java.util.ArrayList) MaintenanceLock(org.kuali.kfs.krad.maintenance.MaintenanceLock)

Example 7 with MaintenanceLock

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);
    }
}
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 8 with MaintenanceLock

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;
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) MaintenanceLock(org.kuali.kfs.krad.maintenance.MaintenanceLock)

Aggregations

ArrayList (java.util.ArrayList)8 MaintenanceLock (org.kuali.kfs.krad.maintenance.MaintenanceLock)8 AccountReversion (edu.cornell.kfs.coa.businessobject.AccountReversion)3 Maintainable (org.kuali.kfs.kns.maintenance.Maintainable)3 HashMap (java.util.HashMap)2 AccountReversionGlobal (edu.cornell.kfs.coa.businessobject.AccountReversionGlobal)1 AccountReversionGlobalAccount (edu.cornell.kfs.coa.businessobject.AccountReversionGlobalAccount)1 OrganizationGlobal (edu.cornell.kfs.coa.businessobject.OrganizationGlobal)1 OrganizationGlobalDetail (edu.cornell.kfs.coa.businessobject.OrganizationGlobalDetail)1 SubAccountGlobal (edu.cornell.kfs.coa.businessobject.SubAccountGlobal)1 SubAccountGlobalDetail (edu.cornell.kfs.coa.businessobject.SubAccountGlobalDetail)1 SubObjectCodeGlobalEdit (edu.cornell.kfs.coa.businessobject.SubObjectCodeGlobalEdit)1 SubObjectCodeGlobalEditDetail (edu.cornell.kfs.coa.businessobject.SubObjectCodeGlobalEditDetail)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Organization (org.kuali.kfs.coa.businessobject.Organization)1 SubAccount (org.kuali.kfs.coa.businessobject.SubAccount)1