Commit 8c7f0083 authored by bsatyanarayana-nisum-com's avatar bsatyanarayana-nisum-com Committed by rbonthala-nisum-com

MT-97_9 : SNS :: Update_RoleTable_While_Account_CRUD_operations (#87)

* MT-97_9 : SNS :: Update_RoleTable_While_Account_CRUD_operations

* MT-97_9 : SNS :: Update_RoleTable_While_Account_CRUD_operations

* MT-97_9 : SNS :: Update_RoleTable_While_Account_CRUD_operations

* MT-97_9 : SNS :: Update_RoleTable_While_Account_CRUD_operations
parent 9916edd2
...@@ -8,7 +8,6 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -8,7 +8,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
...@@ -56,15 +55,4 @@ public class AccountController { ...@@ -56,15 +55,4 @@ public class AccountController {
accountServiceImpl.deleteAccount(accountId); accountServiceImpl.deleteAccount(accountId);
return new ResponseEntity<>("Deleted Successfully", HttpStatus.OK); return new ResponseEntity<>("Deleted Successfully", HttpStatus.OK);
} }
@RequestMapping(value = "/accounts/{accountName}", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE)
public ResponseEntity<String> validateAccounts(@PathVariable("accountName") String accountName) throws MyTimeException {
String response ="";
List<Account> acounts = accountServiceImpl.validateAccounts(accountName);
if(acounts.size()>0){
response ="Account already exist";
}
return new ResponseEntity<>(response, HttpStatus.OK);
}
} }
\ No newline at end of file
...@@ -13,4 +13,6 @@ public interface AccountRepo extends MongoRepository<Account, String> { ...@@ -13,4 +13,6 @@ public interface AccountRepo extends MongoRepository<Account, String> {
Account findByAccountId(String accountId); Account findByAccountId(String accountId);
List<Account> findByaccountNameAndAccountId(String accountName,String accountId); List<Account> findByaccountNameAndAccountId(String accountName,String accountId);
Account findByAccountNameIgnoreCase(String accountName);
} }
\ No newline at end of file
...@@ -12,8 +12,5 @@ public interface AccountService { ...@@ -12,8 +12,5 @@ public interface AccountService {
List<Account> getAccounts() throws MyTimeException; List<Account> getAccounts() throws MyTimeException;
List<Map<Object, Object>> getAccountsList() throws MyTimeException; List<Map<Object, Object>> getAccountsList() throws MyTimeException;
List<Account> validateAccounts(String accountName) throws MyTimeException;
} }
...@@ -16,7 +16,6 @@ import org.springframework.stereotype.Service; ...@@ -16,7 +16,6 @@ import org.springframework.stereotype.Service;
import com.nisum.mytime.exception.handler.MyTimeException; import com.nisum.mytime.exception.handler.MyTimeException;
import com.nisum.mytime.model.Account; import com.nisum.mytime.model.Account;
import com.nisum.mytime.model.Domains;
import com.nisum.mytime.model.EmployeeRoles; import com.nisum.mytime.model.EmployeeRoles;
import com.nisum.mytime.repository.AccountRepo; import com.nisum.mytime.repository.AccountRepo;
import com.nisum.mytime.utils.CommomUtil; import com.nisum.mytime.utils.CommomUtil;
...@@ -43,31 +42,19 @@ public class AccountServiceImpl implements AccountService { ...@@ -43,31 +42,19 @@ public class AccountServiceImpl implements AccountService {
Account accountResult= null; Account accountResult= null;
String roleId = roleInfoService.getRole(MyTimeUtils.ACCOUNT); final String roleId = roleInfoService.getRole(MyTimeUtils.ACCOUNT);
if( action != null && action.equals(MyTimeUtils.STRING_N)) {//N means adding New Account if( action != null && action.trim().equals(MyTimeUtils.STRING_N)) {//N means adding New Account
boolean flag = false;
List<Account> accounts = accountRepo.findAll();
if(accounts!= null && !accounts.isEmpty() && accounts.size()>0 ){
for(Account accObj : accounts){
flag = accObj.getAccountName().trim().equalsIgnoreCase(account.getAccountName().trim());
if(flag){
break;
}
}
}
if(flag){ if(accountRepo.findByAccountNameIgnoreCase(account.getAccountName().trim()) != null) {
response ="Account already exist"; response ="Account already exist";
return response; return response;
} }
List<String> accDms = account.getDeliveryManagers(); List<String> accDms = account.getDeliveryManagers();
account.setAccountId(generateAccountId()); account.setAccountId(generateAccountId());
account.setAccountName(account.getAccountName().trim()); account.setAccountName(account.getAccountName().trim());
account.setClientAddress(account.getClientAddress().trim());
account.setStatus(MyTimeUtils.STRING_Y); account.setStatus(MyTimeUtils.STRING_Y);
accountResult = accountRepo.save(account); accountResult = accountRepo.save(account);
...@@ -80,23 +67,22 @@ public class AccountServiceImpl implements AccountService { ...@@ -80,23 +67,22 @@ public class AccountServiceImpl implements AccountService {
}else { }else {
response = "Error occured while account creating"; response = "Error occured while account creating";
} }
}else if(action != null && action.equals("U")){ }else if(action != null && action.trim().equals("U")){// U means updating existing Account
List<String> employeeIds = null; List<String> employeeIds = null;
List<String> dmsAddedByUser = null; List<String> dmsAddedByUser = null;
List<String> dmsDeletedByUser = null; List<String> dmsDeletedByUser = null;
Map<String, Integer> dmsCount = new HashMap<String,Integer>(); Map<String, Integer> dmsCount = new HashMap<String,Integer>();
boolean dupAccChkFlag = duplicateAccountCheck(account); Account accountBeforeUpdate = accountRepo.findByAccountId(account.getAccountId());
boolean dupAccChkFlag = duplicateAccountCheck(account,accountBeforeUpdate);
if(dupAccChkFlag) { if(dupAccChkFlag) {
response ="Account already exist"; response ="Account already exist";
return response; return response;
} }
Account accountBeforeUpdate = accountRepo.findByAccountId(account.getAccountId());
List<String> updatedAccDms = account.getDeliveryManagers(); List<String> updatedAccDms = account.getDeliveryManagers();
List<String> beforeAccUpdateDms = accountBeforeUpdate.getDeliveryManagers(); List<String> beforeAccUpdateDms = accountBeforeUpdate.getDeliveryManagers();
...@@ -156,14 +142,6 @@ public class AccountServiceImpl implements AccountService { ...@@ -156,14 +142,6 @@ public class AccountServiceImpl implements AccountService {
return updatedAccountList; return updatedAccountList;
} }
@Override
public List<Account> validateAccounts(String accountName) throws MyTimeException {
List<Account> accountList = mongoTemplate.find(new Query(Criteria.where(MyTimeUtils.ACCOUNT_NAME).is(accountName.trim())), Account.class);
return accountList;
}
// fetching the employee details using employeeId. // fetching the employee details using employeeId.
private List<EmployeeRoles> getEmployeeDetails(Account account) { private List<EmployeeRoles> getEmployeeDetails(Account account) {
List<EmployeeRoles> employeeRoles = mongoTemplate.find( List<EmployeeRoles> employeeRoles = mongoTemplate.find(
...@@ -236,24 +214,19 @@ public class AccountServiceImpl implements AccountService { ...@@ -236,24 +214,19 @@ public class AccountServiceImpl implements AccountService {
return (MyTimeUtils.ACC + MyTimeUtils.ZERO_) + (getAccounts().size() + MyTimeUtils.ONE); return (MyTimeUtils.ACC + MyTimeUtils.ZERO_) + (getAccounts().size() + MyTimeUtils.ONE);
} }
private boolean duplicateAccountCheck(Account UpdatedAccount ) { private boolean duplicateAccountCheck(Account UpdatedAccount, Account accountBeforeUpdate ) throws MyTimeException {
boolean flag = false; boolean accDuplicateflag = false;
String updateAccName = UpdatedAccount.getAccountName().trim();
Account accbeforeUpdate = accountRepo.findByAccountId(UpdatedAccount.getAccountId()); if(accountBeforeUpdate.getAccountName().trim().equalsIgnoreCase(updateAccName)) {
accDuplicateflag = false;
boolean nameFlag = accbeforeUpdate.getAccountName().equals(UpdatedAccount.getAccountName()); }else {
boolean addrFlag = accbeforeUpdate.getClientAddress().equals(UpdatedAccount.getClientAddress()); if(accountRepo.findByAccountNameIgnoreCase(updateAccName) != null) {
boolean industryFlag = accbeforeUpdate.getIndustryType().equals(UpdatedAccount.getIndustryType()); accDuplicateflag = true;
boolean dmsFlag=accbeforeUpdate.getDeliveryManagers().toString().contentEquals(UpdatedAccount.getDeliveryManagers().toString()); }
}
boolean ignoreFlag = accbeforeUpdate.getAccountName().equalsIgnoreCase(UpdatedAccount.getAccountName()); return accDuplicateflag;
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