Search in sources :

Example 1 with MaintenanceLock

use of org.kuali.kfs.krad.maintenance.MaintenanceLock in project cu-kfs by CU-CommunityApps.

the class OrganizationGlobalMaintainableImpl method generateMaintenanceLocks.

@Override
public List<MaintenanceLock> generateMaintenanceLocks() {
    /*
         * Generate the maintenance locks in a similar manner as the account global maintainable.
         */
    OrganizationGlobal orgGlobal = (OrganizationGlobal) getBusinessObject();
    List<MaintenanceLock> maintenanceLocks = new ArrayList<MaintenanceLock>();
    final int BUILDER_SIZE = 100;
    for (OrganizationGlobalDetail detail : orgGlobal.getOrganizationGlobalDetails()) {
        MaintenanceLock maintenanceLock = new MaintenanceLock();
        maintenanceLock.setDocumentNumber(orgGlobal.getDocumentNumber());
        maintenanceLock.setLockingRepresentation(new StringBuilder(BUILDER_SIZE).append(Organization.class.getName()).append(KFSConstants.Maintenance.AFTER_CLASS_DELIM).append("chartOfAccountsCode").append(KFSConstants.Maintenance.AFTER_FIELDNAME_DELIM).append(detail.getChartOfAccountsCode()).append(KFSConstants.Maintenance.AFTER_VALUE_DELIM).append("organizationCode").append(KFSConstants.Maintenance.AFTER_FIELDNAME_DELIM).append(detail.getOrganizationCode()).toString());
        maintenanceLocks.add(maintenanceLock);
    }
    return maintenanceLocks;
}
Also used : Organization(org.kuali.kfs.coa.businessobject.Organization) OrganizationGlobal(edu.cornell.kfs.coa.businessobject.OrganizationGlobal) ArrayList(java.util.ArrayList) OrganizationGlobalDetail(edu.cornell.kfs.coa.businessobject.OrganizationGlobalDetail) MaintenanceLock(org.kuali.kfs.krad.maintenance.MaintenanceLock)

Example 2 with MaintenanceLock

use of org.kuali.kfs.krad.maintenance.MaintenanceLock in project cu-kfs by CU-CommunityApps.

the class SubObjectCodeGlobalEditMaintainableImpl method generateMaintenanceLocks.

/**
 * This generates maintenance locks on {@link SubObjCd}
 *
 * @see org.kuali.kfs.kns.maintenance.Maintainable#generateMaintenanceLocks()
 */
@Override
public List<MaintenanceLock> generateMaintenanceLocks() {
    // create locking rep for each combination of account and object code
    List<MaintenanceLock> maintenanceLocks = new ArrayList();
    SubObjectCodeGlobalEdit subObjCdGlobal = (SubObjectCodeGlobalEdit) getBusinessObject();
    for (SubObjectCodeGlobalEditDetail subObjCdGlobalDetail : subObjCdGlobal.getSubObjCdGlobalEditDetails()) {
        MaintenanceLock maintenanceLock = new MaintenanceLock();
        maintenanceLock.setDocumentNumber(subObjCdGlobal.getDocumentNumber());
        StringBuffer lockrep = new StringBuffer();
        lockrep.append(SubObjectCode.class.getName() + KFSConstants.Maintenance.AFTER_CLASS_DELIM);
        lockrep.append("fiscalYear" + KFSConstants.Maintenance.AFTER_FIELDNAME_DELIM);
        lockrep.append(subObjCdGlobalDetail.getUniversityFiscalYear() + KFSConstants.Maintenance.AFTER_VALUE_DELIM);
        lockrep.append("chartOfAccountsCode" + KFSConstants.Maintenance.AFTER_FIELDNAME_DELIM);
        lockrep.append(subObjCdGlobalDetail.getChartOfAccountsCode() + KFSConstants.Maintenance.AFTER_VALUE_DELIM);
        lockrep.append("accountNumber" + KFSConstants.Maintenance.AFTER_FIELDNAME_DELIM);
        lockrep.append(subObjCdGlobalDetail.getAccountNumber() + KFSConstants.Maintenance.AFTER_VALUE_DELIM);
        lockrep.append("financialObjectCode" + KFSConstants.Maintenance.AFTER_FIELDNAME_DELIM);
        lockrep.append(subObjCdGlobalDetail.getFinancialObjectCode() + KFSConstants.Maintenance.AFTER_VALUE_DELIM);
        lockrep.append("financialSubObjectCode" + KFSConstants.Maintenance.AFTER_FIELDNAME_DELIM);
        lockrep.append(subObjCdGlobal.getFinancialSubObjectCode());
        maintenanceLock.setLockingRepresentation(lockrep.toString());
        maintenanceLocks.add(maintenanceLock);
    }
    return maintenanceLocks;
}
Also used : ArrayList(java.util.ArrayList) SubObjectCodeGlobalEdit(edu.cornell.kfs.coa.businessobject.SubObjectCodeGlobalEdit) SubObjectCodeGlobalEditDetail(edu.cornell.kfs.coa.businessobject.SubObjectCodeGlobalEditDetail) MaintenanceLock(org.kuali.kfs.krad.maintenance.MaintenanceLock)

Example 3 with MaintenanceLock

use of org.kuali.kfs.krad.maintenance.MaintenanceLock 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 4 with MaintenanceLock

use of org.kuali.kfs.krad.maintenance.MaintenanceLock 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 5 with MaintenanceLock

use of org.kuali.kfs.krad.maintenance.MaintenanceLock in project cu-kfs by CU-CommunityApps.

the class AccountReversionGlobalMaintainableImpl method generateMaintenanceLocks.

/**
 * This implementation locks all account reversions that would be accessed by this global account reversion. It does
 * not lock any AccountReversionDetail objects, as we expect that those will be inaccessible
 *
 * @see org.kuali.kfs.kns.maintenance.KualiGlobalMaintainableImpl#generateMaintenaceLocks()
 */
@Override
public List<MaintenanceLock> generateMaintenanceLocks() {
    List<MaintenanceLock> locks = new ArrayList<MaintenanceLock>();
    AccountReversionGlobal globalAcctRev = (AccountReversionGlobal) this.getBusinessObject();
    if (globalAcctRev.getUniversityFiscalYear() != null && globalAcctRev.getAccountReversionGlobalAccounts() != null && globalAcctRev.getAccountReversionGlobalAccounts().size() > 0) {
        // only generate locks if we're going to have primary keys
        for (AccountReversionGlobalAccount acctRevAcct : globalAcctRev.getAccountReversionGlobalAccounts()) {
            MaintenanceLock maintenanceLock = new MaintenanceLock();
            maintenanceLock.setDocumentNumber(globalAcctRev.getDocumentNumber());
            StringBuffer lockRep = new StringBuffer();
            lockRep.append(AccountReversion.class.getName());
            lockRep.append(KFSConstants.Maintenance.AFTER_CLASS_DELIM);
            lockRep.append("chartOfAccountsCode");
            lockRep.append(KFSConstants.Maintenance.AFTER_FIELDNAME_DELIM);
            lockRep.append(acctRevAcct.getChartOfAccountsCode());
            lockRep.append(KFSConstants.Maintenance.AFTER_VALUE_DELIM);
            lockRep.append("universityFiscalYear");
            lockRep.append(KFSConstants.Maintenance.AFTER_FIELDNAME_DELIM);
            lockRep.append(globalAcctRev.getUniversityFiscalYear().toString());
            lockRep.append(KFSConstants.Maintenance.AFTER_VALUE_DELIM);
            lockRep.append("accountNumber");
            lockRep.append(KFSConstants.Maintenance.AFTER_FIELDNAME_DELIM);
            lockRep.append(acctRevAcct.getAccountNumber());
            lockRep.append(KFSConstants.Maintenance.AFTER_VALUE_DELIM);
            maintenanceLock.setLockingRepresentation(lockRep.toString());
            locks.add(maintenanceLock);
        }
    }
    return locks;
}
Also used : AccountReversion(edu.cornell.kfs.coa.businessobject.AccountReversion) AccountReversionGlobal(edu.cornell.kfs.coa.businessobject.AccountReversionGlobal) ArrayList(java.util.ArrayList) MaintenanceLock(org.kuali.kfs.krad.maintenance.MaintenanceLock) AccountReversionGlobalAccount(edu.cornell.kfs.coa.businessobject.AccountReversionGlobalAccount)

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