Commit f1fd8a15 authored by bsatyanarayana-nisum-com's avatar bsatyanarayana-nisum-com Committed by tdutta-nisum-com

MT-97_8 : SNS :: Update_RoleTable_While_Account_CRUD_operations (#85)

parent d07aff9a
......@@ -16,6 +16,7 @@ import org.springframework.stereotype.Service;
import com.nisum.mytime.exception.handler.MyTimeException;
import com.nisum.mytime.model.Account;
import com.nisum.mytime.model.Domains;
import com.nisum.mytime.model.EmployeeRoles;
import com.nisum.mytime.repository.AccountRepo;
import com.nisum.mytime.utils.CommomUtil;
......@@ -79,50 +80,30 @@ public class AccountServiceImpl implements AccountService {
}else {
response = "Error occured while account creating";
}
}else if(action != null && action.equals("U")){//U means updating existing Account
boolean flag = false;
boolean nameFlag = false;
boolean accountExistFlag = false;
List<Account> accounts = accountRepo.findAll();
Account accountBeforeUpdate = accountRepo.findByAccountId(account.getAccountId());
}else if(action != null && action.equals("U")){
List<String> employeeIds = null;
List<String> dmsAddedByUser = null;
List<String> dmsDeletedByUser = null;
nameFlag = accountBeforeUpdate.getAccountName().equalsIgnoreCase(account.getAccountName());
Map<String, Integer> dmsCount = new HashMap<String,Integer>();
if(accounts!= null && !accounts.isEmpty() && accounts.size()>0 ){
for(Account accObj : accounts){
accountExistFlag = accObj.getAccountName().trim().equalsIgnoreCase(account.getAccountName().trim());
if(accountExistFlag){
break;
}
}
}
boolean dupAccChkFlag = duplicateAccountCheck(account);
if( nameFlag && accountExistFlag) {
if(dupAccChkFlag) {
response ="Account already exist";
return response;
}
//if(accountBeforeUpdate.getAccountName().equalsIgnoreCase(account.getAccountName())) {
List<String> employeeIds = null;
List<Account> accountList = null;
List<String> dmsAddedByUser = null;
List<String> dmsDeletedByUser = null;
Map<String, Integer> dmsCount = new HashMap<String,Integer>();
Account accountBeforeUpdate = accountRepo.findByAccountId(account.getAccountId());
List<String> updatedAccDms = account.getDeliveryManagers();
List<String> beforeAccUpdateDms = accountBeforeUpdate.getDeliveryManagers();
dmsAddedByUser = CommomUtil.getAddedManagersList(beforeAccUpdateDms, updatedAccDms);
dmsDeletedByUser = CommomUtil.getDeletedManagersList(beforeAccUpdateDms, updatedAccDms);
accountList = accountRepo.findAll();
List<Account> accountList = accountRepo.findAll();
if(accountList != null && !accountList.isEmpty() && accountList.size() >0) {
for (Account acc : accountList) {
......@@ -153,12 +134,6 @@ public class AccountServiceImpl implements AccountService {
response="Updated succesfully";
return response;
}
//}
return response;
}
......@@ -261,12 +236,24 @@ public class AccountServiceImpl implements AccountService {
return (MyTimeUtils.ACC + MyTimeUtils.ZERO_) + (getAccounts().size() + MyTimeUtils.ONE);
}
private boolean duplicateCheck(String accountName,String accountId){
boolean check=false;
List<Account> accountList=accountRepo.findByaccountNameAndAccountId(accountName, accountId);
if(accountList.size()>0)
check= true;
return check;
private boolean duplicateAccountCheck(Account UpdatedAccount ) {
boolean flag = false;
Account accbeforeUpdate = accountRepo.findByAccountId(UpdatedAccount.getAccountId());
boolean nameFlag = accbeforeUpdate.getAccountName().equals(UpdatedAccount.getAccountName());
boolean addrFlag = accbeforeUpdate.getClientAddress().equals(UpdatedAccount.getClientAddress());
boolean industryFlag = accbeforeUpdate.getIndustryType().equals(UpdatedAccount.getIndustryType());
boolean dmsFlag=accbeforeUpdate.getDeliveryManagers().toString().contentEquals(UpdatedAccount.getDeliveryManagers().toString());
boolean ignoreFlag = accbeforeUpdate.getAccountName().equalsIgnoreCase(UpdatedAccount.getAccountName());
if( nameFlag || !addrFlag || !industryFlag || !dmsFlag ) {
flag = false;
}else if(ignoreFlag){
flag = true;
}
return flag;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment