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