Search in sources :

Example 11 with FavoriteAccount

use of edu.cornell.kfs.sys.businessobject.FavoriteAccount in project cu-kfs by CU-CommunityApps.

the class UserFavoriteAccountServiceImpl method getFavoriteAccount.

/**
 * get user's primary favorite account
 */
public FavoriteAccount getFavoriteAccount(String principalId) {
    Map<String, String> fieldValues = new HashMap<String, String>();
    fieldValues.put("principalId", principalId);
    List<UserProcurementProfile> userProfiles = (List<UserProcurementProfile>) businessObjectService.findMatching(UserProcurementProfile.class, fieldValues);
    if (CollectionUtils.isNotEmpty(userProfiles) && CollectionUtils.isNotEmpty(userProfiles.get(0).getFavoriteAccounts())) {
        for (FavoriteAccount account : userProfiles.get(0).getFavoriteAccounts()) {
            if (account.getPrimaryInd()) {
                return account;
            }
        }
    }
    return null;
}
Also used : FavoriteAccount(edu.cornell.kfs.sys.businessobject.FavoriteAccount) HashMap(java.util.HashMap) List(java.util.List) UserProcurementProfile(edu.cornell.kfs.sys.businessobject.UserProcurementProfile)

Example 12 with FavoriteAccount

use of edu.cornell.kfs.sys.businessobject.FavoriteAccount in project cu-kfs by CU-CommunityApps.

the class UserProcurementProfileValidationServiceImpl method validateAccounts.

/**
 * validate the favorite accounts in maint doc
 * @param favoriteAccounts
 * @return
 */
public boolean validateAccounts(List<FavoriteAccount> favoriteAccounts) {
    // GlobalVariables.getMessageMap().clearErrorMessages();
    if (CollectionUtils.isNotEmpty(favoriteAccounts)) {
        String propertyPreFix = "document.newMaintainableObject.favoriteAccounts[";
        int i = 0;
        boolean hasPrimary = false;
        for (FavoriteAccount account : favoriteAccounts) {
            validateAccount(propertyPreFix + i + "]", account, hasPrimary);
            hasPrimary = hasPrimary || account.getPrimaryInd();
            GlobalVariables.getMessageMap().removeFromErrorPath(propertyPreFix + i + "]");
            i++;
        }
        validateDuplicateAccount(favoriteAccounts);
    }
    return GlobalVariables.getMessageMap().hasNoErrors();
}
Also used : FavoriteAccount(edu.cornell.kfs.sys.businessobject.FavoriteAccount)

Example 13 with FavoriteAccount

use of edu.cornell.kfs.sys.businessobject.FavoriteAccount in project cu-kfs by CU-CommunityApps.

the class UserProcurementProfileValidationServiceImpl method validateDuplicateAccount.

/*
	 * check if the favorite accounts has any duplicate
	 */
private boolean validateDuplicateAccount(List<FavoriteAccount> favoriteAccounts) {
    String propertyPreFix = "document.newMaintainableObject.favoriteAccounts[";
    for (FavoriteAccount account : favoriteAccounts) {
        int i = 0;
        for (FavoriteAccount account1 : favoriteAccounts) {
            GlobalVariables.getMessageMap().addToErrorPath(propertyPreFix + i + "]");
            if (account != account1) {
                if (StringUtils.isNotBlank(account.getDescription()) && StringUtils.isNotBlank(account1.getDescription()) && StringUtils.equals(account.getDescription(), account1.getDescription())) {
                    GlobalVariables.getMessageMap().putError(KFSPropertyConstants.DESCRIPTION, CUKFSKeyConstants.ERROR_DUPLICATE_FAVORITE_ACCOUNT_DESCRIPTION);
                }
                if (account.equals(account1)) {
                    GlobalVariables.getMessageMap().putError(KFSPropertyConstants.ACCOUNT_NUMBER, CUKFSKeyConstants.ERROR_DUPLICATE_ACCOUNTINGLINE);
                }
            }
            GlobalVariables.getMessageMap().removeFromErrorPath(propertyPreFix + i + "]");
            i++;
        }
    }
    return GlobalVariables.getMessageMap().hasNoErrors();
}
Also used : FavoriteAccount(edu.cornell.kfs.sys.businessobject.FavoriteAccount)

Example 14 with FavoriteAccount

use of edu.cornell.kfs.sys.businessobject.FavoriteAccount in project cu-kfs by CU-CommunityApps.

the class UserProcurementProfileMaintainableImpl method saveBusinessObject.

@Override
public void saveBusinessObject() {
    // TODO Auto-generated method stub
    if (StringUtils.equals(getMaintenanceAction(), KRADConstants.MAINTENANCE_EDIT_ACTION)) {
        Map<String, Object> pkMap = new HashMap<String, Object>();
        pkMap.put("userProfileId", ((UserProcurementProfile) getBusinessObject()).getUserProfileId());
        UserProcurementProfile userProfile = (UserProcurementProfile) getBusinessObjectService().findByPrimaryKey(UserProcurementProfile.class, pkMap);
        List<FavoriteAccount> deletedAccounts = new ArrayList<FavoriteAccount>();
        if (ObjectUtils.isNotNull(userProfile) && CollectionUtils.isNotEmpty(userProfile.getFavoriteAccounts())) {
            for (FavoriteAccount account : userProfile.getFavoriteAccounts()) {
                boolean accountFound = false;
                if (CollectionUtils.isNotEmpty(((UserProcurementProfile) getBusinessObject()).getFavoriteAccounts())) {
                    for (FavoriteAccount account1 : ((UserProcurementProfile) getBusinessObject()).getFavoriteAccounts()) {
                        if (account1.getAccountLineIdentifier() != null && account.getAccountLineIdentifier().equals(account1.getAccountLineIdentifier())) {
                            accountFound = true;
                            break;
                        }
                    }
                }
                if (!accountFound) {
                    deletedAccounts.add(account);
                }
            }
            if (CollectionUtils.isNotEmpty(deletedAccounts)) {
                getBusinessObjectService().delete(deletedAccounts);
            }
        }
    }
    super.saveBusinessObject();
}
Also used : FavoriteAccount(edu.cornell.kfs.sys.businessobject.FavoriteAccount) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UserProcurementProfile(edu.cornell.kfs.sys.businessobject.UserProcurementProfile)

Aggregations

FavoriteAccount (edu.cornell.kfs.sys.businessobject.FavoriteAccount)14 ArrayList (java.util.ArrayList)5 UserProcurementProfile (edu.cornell.kfs.sys.businessobject.UserProcurementProfile)4 HashMap (java.util.HashMap)3 List (java.util.List)3 IWantAccount (edu.cornell.kfs.module.purap.businessobject.IWantAccount)2 Test (org.junit.Test)2 PersistableBusinessObject (org.kuali.kfs.krad.bo.PersistableBusinessObject)2 CuRequisitionDocument (edu.cornell.kfs.module.purap.document.CuRequisitionDocument)1 IWantDocument (edu.cornell.kfs.module.purap.document.IWantDocument)1 PurApFavoriteAccountLineBuilderForIWantDocument (edu.cornell.kfs.module.purap.util.PurApFavoriteAccountLineBuilderForIWantDocument)1 UserFavoriteAccountService (edu.cornell.kfs.sys.service.UserFavoriteAccountService)1 UserProcurementProfileValidationServiceImpl (edu.cornell.kfs.sys.service.impl.UserProcurementProfileValidationServiceImpl)1 BigDecimal (java.math.BigDecimal)1 Comparator (java.util.Comparator)1 BeforeClass (org.junit.BeforeClass)1 MessageMap (org.kuali.kfs.krad.util.MessageMap)1 PurApAccountingLine (org.kuali.kfs.module.purap.businessobject.PurApAccountingLine)1 PurApAccountingLineBase (org.kuali.kfs.module.purap.businessobject.PurApAccountingLineBase)1 PurchaseOrderItem (org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem)1