Commit 2f30a641 authored by Vijay Akula's avatar Vijay Akula

Removed the duplicated method in account service

parent d11c5abe
...@@ -96,7 +96,7 @@ public class AccountController { ...@@ -96,7 +96,7 @@ public class AccountController {
@RequestMapping(value = "/accounts/names", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/accounts/names", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getAccountNames(HttpServletRequest request) throws MyTeamException { public ResponseEntity<?> getAccountNames(HttpServletRequest request) throws MyTeamException {
List<Account> acountsList = accountService.getAccounts(); List<Account> acountsList = accountService.getAllAccounts();
List<String> accountNamesList = new ArrayList<>(); List<String> accountNamesList = new ArrayList<>();
for (Account account : acountsList) { for (Account account : acountsList) {
...@@ -116,7 +116,7 @@ public class AccountController { ...@@ -116,7 +116,7 @@ public class AccountController {
//get the accounts based on status(Active or inactive) //get the accounts based on status(Active or inactive)
@RequestMapping(value = "/accounts/status", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/accounts/status", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<Account>> getAccounts(@RequestParam("status") String status) throws MyTeamException { public ResponseEntity<List<Account>> getAccounts(@RequestParam("status") String status) throws MyTeamException {
List<Account> accountsList = accountService.getAccountsAll().stream() List<Account> accountsList = accountService.getAllAccounts().stream()
.filter(e -> "Active".equalsIgnoreCase(e.getStatus())).collect(Collectors.toList()); .filter(e -> "Active".equalsIgnoreCase(e.getStatus())).collect(Collectors.toList());
return new ResponseEntity<>(accountsList, HttpStatus.OK); return new ResponseEntity<>(accountsList, HttpStatus.OK);
} }
......
...@@ -23,14 +23,10 @@ public interface IAccountService { ...@@ -23,14 +23,10 @@ public interface IAccountService {
public Account getAccountById(String accountId); public Account getAccountById(String accountId);
List<Account> getAccounts() throws MyTeamException; List<Account> getAllAccounts() throws MyTeamException;
List<Map<Object, Object>> getAccountsList() throws MyTeamException; List<Map<Object, Object>> getAccountsList() throws MyTeamException;
Account deleteAccount(String accountId) throws MyTeamException; Account deleteAccount(String accountId) throws MyTeamException;
public List<Account> getAccountsAll() throws MyTeamException;
} }
...@@ -31,10 +31,10 @@ public class AccountService implements IAccountService { ...@@ -31,10 +31,10 @@ public class AccountService implements IAccountService {
private MongoTemplate mongoTemplate; private MongoTemplate mongoTemplate;
@Autowired @Autowired
private IRoleService roleInfoService; private IRoleService roleService;
@Autowired @Autowired
private IEmployeeRoleService roleMappingService; private IEmployeeRoleService empRoleService;
@Override @Override
...@@ -51,9 +51,9 @@ public class AccountService implements IAccountService { ...@@ -51,9 +51,9 @@ public class AccountService implements IAccountService {
if (accountPersisted != null) { if (accountPersisted != null) {
List<String> accountDmsList = accountReq.getDeliveryManagers(); List<String> accountDmsList = accountReq.getDeliveryManagers();
if (accountDmsList != null && !accountDmsList.isEmpty() && accountDmsList.size() > 0) { if (accountDmsList != null && !accountDmsList.isEmpty() && accountDmsList.size() > 0) {
String roleId = roleInfoService.getRole(MyTeamUtils.ACCOUNT); String roleId = roleService.getRole(MyTeamUtils.ACCOUNT);
log.info("Going to add DM role id for account delivery managers::::" + accountDmsList); log.info("Going to add DM role id for account delivery managers::::" + accountDmsList);
roleMappingService.saveUniqueEmployeeAndRole(accountDmsList, roleId); empRoleService.saveUniqueEmployeeAndRole(accountDmsList, roleId);
log.info("Added roleids for delivery managers in rolemapping collection"); log.info("Added roleids for delivery managers in rolemapping collection");
} }
...@@ -71,7 +71,7 @@ public class AccountService implements IAccountService { ...@@ -71,7 +71,7 @@ public class AccountService implements IAccountService {
accountUpdating.setAccountName(accountUpdating.getAccountName().trim()); accountUpdating.setAccountName(accountUpdating.getAccountName().trim());
log.info("Updating the roleids of DeliveryManagers in RoleMapping Collection"); log.info("Updating the roleids of DeliveryManagers in RoleMapping Collection");
final String roleId = roleInfoService.getRole(MyTeamUtils.ACCOUNT); final String roleId = roleService.getRole(MyTeamUtils.ACCOUNT);
updateRoleIdsForDeliveryManager(accountUpdating, roleId); updateRoleIdsForDeliveryManager(accountUpdating, roleId);
log.info("Deleting the roleids of DeliveryManagers in RoleMapping Collection"); log.info("Deleting the roleids of DeliveryManagers in RoleMapping Collection");
...@@ -125,7 +125,7 @@ public class AccountService implements IAccountService { ...@@ -125,7 +125,7 @@ public class AccountService implements IAccountService {
@Override @Override
public List<Account> getAccounts() throws MyTeamException { public List<Account> getAllAccounts() throws MyTeamException {
return accountRepo.findAll(); return accountRepo.findAll();
} }
...@@ -166,7 +166,7 @@ public class AccountService implements IAccountService { ...@@ -166,7 +166,7 @@ public class AccountService implements IAccountService {
// generating the account id. // generating the account id.
// accountId format is "Acc001" // accountId format is "Acc001"
private String generateAccountId() throws MyTeamException { private String generateAccountId() throws MyTeamException {
return (MyTeamUtils.ACC + MyTeamUtils.ZERO_) + (getAccounts().size() + MyTeamUtils.ONE); return (MyTeamUtils.ACC + MyTeamUtils.ZERO_) + (getAllAccounts().size() + MyTeamUtils.ONE);
} }
private void updateRoleIdsForDeliveryManager(Account accountReq, String roleId) throws MyTeamException { private void updateRoleIdsForDeliveryManager(Account accountReq, String roleId) throws MyTeamException {
...@@ -175,7 +175,7 @@ public class AccountService implements IAccountService { ...@@ -175,7 +175,7 @@ public class AccountService implements IAccountService {
List<String> persistedDmsList = accountRepo.findByAccountId(accountReq.getAccountId()).getDeliveryManagers(); List<String> persistedDmsList = accountRepo.findByAccountId(accountReq.getAccountId()).getDeliveryManagers();
List<String> dmsAddedByUser = CommomUtil.getAddedManagersList(persistedDmsList, updatingDmsList); List<String> dmsAddedByUser = CommomUtil.getAddedManagersList(persistedDmsList, updatingDmsList);
roleMappingService.saveUniqueEmployeeAndRole(dmsAddedByUser, roleId); empRoleService.saveUniqueEmployeeAndRole(dmsAddedByUser, roleId);
} }
private void deleteRoleIdsForDeliveryManager(Account accountUpdating, String roleId) throws MyTeamException { private void deleteRoleIdsForDeliveryManager(Account accountUpdating, String roleId) throws MyTeamException {
...@@ -206,7 +206,7 @@ public class AccountService implements IAccountService { ...@@ -206,7 +206,7 @@ public class AccountService implements IAccountService {
for (String empId : dmsListDeletedByUser) { for (String empId : dmsListDeletedByUser) {
if (dmsCountMap.get(empId) == 1) { if (dmsCountMap.get(empId) == 1) {
// Service call for RoleMapping // Service call for RoleMapping
roleMappingService.deleteRole(empId, roleId); empRoleService.deleteRole(empId, roleId);
} }
} }
} }
...@@ -244,7 +244,7 @@ public class AccountService implements IAccountService { ...@@ -244,7 +244,7 @@ public class AccountService implements IAccountService {
List<String> accountDms = null; List<String> accountDms = null;
List<String> tempDmsList = new ArrayList<String>(); List<String> tempDmsList = new ArrayList<String>();
String roleId = roleInfoService.getRole(MyTeamUtils.ACCOUNT); String roleId = roleService.getRole(MyTeamUtils.ACCOUNT);
allAccountsList = accountRepo.findAll(); allAccountsList = accountRepo.findAll();
List<String> accountDmsList = accountRepo.findByAccountId(accountId).getDeliveryManagers(); List<String> accountDmsList = accountRepo.findByAccountId(accountId).getDeliveryManagers();
...@@ -262,18 +262,12 @@ public class AccountService implements IAccountService { ...@@ -262,18 +262,12 @@ public class AccountService implements IAccountService {
occurrences = Collections.frequency(tempDmsList, dmId); occurrences = Collections.frequency(tempDmsList, dmId);
if (occurrences == 1) { if (occurrences == 1) {
// Service call for RoleMapping // Service call for RoleMapping
roleMappingService.deleteRole(dmId, roleId); empRoleService.deleteRole(dmId, roleId);
} }
} }
} }
@Override
public List<Account> getAccountsAll() throws MyTeamException {
return accountRepo.findAll();
}
} }
...@@ -38,10 +38,10 @@ public class DomainService implements IDomainService { ...@@ -38,10 +38,10 @@ public class DomainService implements IDomainService {
private MongoTemplate mongoTemplate; private MongoTemplate mongoTemplate;
@Autowired @Autowired
private IRoleService roleInfoService; private IRoleService roleService;
@Autowired @Autowired
private IEmployeeRoleService roleMappingService; private IEmployeeRoleService empRoleService;
@Autowired @Autowired
private IAccountService accountService; private IAccountService accountService;
...@@ -83,7 +83,7 @@ public class DomainService implements IDomainService { ...@@ -83,7 +83,7 @@ public class DomainService implements IDomainService {
public Domain update(Domain domainReq) throws MyTeamException { public Domain update(Domain domainReq) throws MyTeamException {
log.info("updating the roles for DeliveryManager in EmployeeRoleMapping collection"); log.info("updating the roles for DeliveryManager in EmployeeRoleMapping collection");
final String roleId = roleInfoService.getRole(MyTeamUtils.DOMAIN); final String roleId = roleService.getRole(MyTeamUtils.DOMAIN);
updateRoleIdsForDMs(domainReq, roleId); updateRoleIdsForDMs(domainReq, roleId);
log.info("deleting roleids for DeliveryManagers in EmployeeRoleMapping collection"); log.info("deleting roleids for DeliveryManagers in EmployeeRoleMapping collection");
deleteRoleIdsForDMs(domainReq, roleId); deleteRoleIdsForDMs(domainReq, roleId);
...@@ -104,7 +104,7 @@ public class DomainService implements IDomainService { ...@@ -104,7 +104,7 @@ public class DomainService implements IDomainService {
List dmsListReq = domainReq.getDeliveryManagers(); List dmsListReq = domainReq.getDeliveryManagers();
List<String> managersAddedByUser = managersAddedByUser = CommomUtil.getAddedManagersListForDM(dmssListDAO, List<String> managersAddedByUser = managersAddedByUser = CommomUtil.getAddedManagersListForDM(dmssListDAO,
dmsListReq); dmsListReq);
roleMappingService.saveUniqueEmployeeAndRole(managersAddedByUser, roleId); empRoleService.saveUniqueEmployeeAndRole(managersAddedByUser, roleId);
} }
...@@ -131,7 +131,7 @@ public class DomainService implements IDomainService { ...@@ -131,7 +131,7 @@ public class DomainService implements IDomainService {
for (String managerId : managersDeletedByUser) { for (String managerId : managersDeletedByUser) {
if (managersDomainCount.get(managerId) == 1) { if (managersDomainCount.get(managerId) == 1) {
// Call service to delete manager // Call service to delete manager
roleMappingService.deleteRole(managerId, roleId); empRoleService.deleteRole(managerId, roleId);
} }
} }
} }
...@@ -178,7 +178,7 @@ public class DomainService implements IDomainService { ...@@ -178,7 +178,7 @@ public class DomainService implements IDomainService {
@Override @Override
public WriteResult delete(String domainId) throws MyTeamException { public WriteResult delete(String domainId) throws MyTeamException {
List<String> domEmpIds = new ArrayList<String>(); List<String> domEmpIds = new ArrayList<String>();
String roleId = roleInfoService.getRole(MyTeamUtils.DOMAIN); String roleId = roleService.getRole(MyTeamUtils.DOMAIN);
List<Domain> domainsPersistedList = domainRepo.findAll(); List<Domain> domainsPersistedList = domainRepo.findAll();
Query selectedDomainQuery = new Query( Query selectedDomainQuery = new Query(
Criteria.where(MyTeamUtils.DOMAIN_ID).in(domainId).and(MyTeamUtils.STATUS).in(MyTeamUtils.ACTIVE)); Criteria.where(MyTeamUtils.DOMAIN_ID).in(domainId).and(MyTeamUtils.STATUS).in(MyTeamUtils.ACTIVE));
...@@ -194,7 +194,7 @@ public class DomainService implements IDomainService { ...@@ -194,7 +194,7 @@ public class DomainService implements IDomainService {
int occurrences = Collections.frequency(domEmpIds, empId.toString()); int occurrences = Collections.frequency(domEmpIds, empId.toString());
if (occurrences == 1) { if (occurrences == 1) {
// Service call for RoleMapping // Service call for RoleMapping
roleMappingService.deleteRole(empId.toString(), roleId); empRoleService.deleteRole(empId.toString(), roleId);
} }
} }
Update update = new Update(); Update update = new Update();
...@@ -203,9 +203,9 @@ public class DomainService implements IDomainService { ...@@ -203,9 +203,9 @@ public class DomainService implements IDomainService {
} }
private void saveEmployeeRole(Domain domainReq) throws MyTeamException { private void saveEmployeeRole(Domain domainReq) throws MyTeamException {
String roleId = roleInfoService.getRole(MyTeamUtils.DOMAIN); String roleId = roleService.getRole(MyTeamUtils.DOMAIN);
List dmsList = domainReq.getDeliveryManagers(); List dmsList = domainReq.getDeliveryManagers();
roleMappingService.saveUniqueEmployeeAndRole(dmsList, roleId); empRoleService.saveUniqueEmployeeAndRole(dmsList, roleId);
} }
private List<HashMap<String, String>> prepareEmployeeList(Domain domainPersisted) { private List<HashMap<String, String>> prepareEmployeeList(Domain domainPersisted) {
......
...@@ -223,7 +223,7 @@ public class EmployeeService implements IEmployeeService { ...@@ -223,7 +223,7 @@ public class EmployeeService implements IEmployeeService {
@Override @Override
public List<Account> getAccounts() throws MyTeamException { public List<Account> getAccounts() throws MyTeamException {
return accountService.getAccounts(); return accountService.getAllAccounts();
} }
......
...@@ -3,12 +3,8 @@ package com.nisum.myteam.service.impl; ...@@ -3,12 +3,8 @@ package com.nisum.myteam.service.impl;
import com.nisum.myteam.exception.handler.MyTeamException; import com.nisum.myteam.exception.handler.MyTeamException;
import com.nisum.myteam.model.dao.*; import com.nisum.myteam.model.dao.*;
import com.nisum.myteam.repository.ProjectRepo; import com.nisum.myteam.repository.ProjectRepo;
import com.nisum.myteam.service.IAccountService; import com.nisum.myteam.service.*;
import com.nisum.myteam.service.IDomainService;
import com.nisum.myteam.service.IEmployeeService;
import com.nisum.myteam.service.IProjectService;
import com.nisum.myteam.utils.MyTeamUtils; import com.nisum.myteam.utils.MyTeamUtils;
import com.nisum.myteam.service.PdfReportGenerator;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -40,57 +36,15 @@ public class ProjectService implements IProjectService { ...@@ -40,57 +36,15 @@ public class ProjectService implements IProjectService {
private IDomainService domainService; private IDomainService domainService;
@Autowired @Autowired
private ResourceService resourceService; private IResourceService resourceService;
@Autowired @Autowired
private IEmployeeService employeeService; private IEmployeeService employeeService;
@Autowired @Autowired
private IAccountService accountService; private IAccountService accountService;
@Override
public List<Project> getProjectsUnderDomain(String domainId) {
return projectRepo.findByDomainId(domainId);
}
public boolean isProjectExistsByName(String projectName) {
boolean isProjectExists = false;
if (projectName != null && !"".equalsIgnoreCase(projectName)) {
Project project = projectRepo.findByProjectName(projectName);
isProjectExists = (project == null) ? false : true;
}
return isProjectExists;
}
public boolean isProjectExistsById(String projectId) {
boolean isProjectExists = false;
if (projectId != null && !"".equalsIgnoreCase(projectId)) {
Project project = projectRepo.findByProjectId(projectId);
isProjectExists = (project == null) ? false : true;
}
return isProjectExists;
}
public long getProjectsCount() {
return projectRepo.count();
}
public Account getProjectAccount(String accountId) {
Account account = null;
if (accountId != null && !"".equalsIgnoreCase(accountId)) {
return accountService.getAccountById(accountId);
}
return account;
}
public Account updateProjSeqinAccount(Account account) throws MyTeamException {
return accountService.updateAccountSequence(account);
}
@Override @Override
public Project createProject(Project project, String loginEmpId) throws MyTeamException { public Project createProject(Project project, String loginEmpId) throws MyTeamException {
if (project.getDomainId() == null) { if (project.getDomainId() == null) {
...@@ -104,7 +58,6 @@ public class ProjectService implements IProjectService { ...@@ -104,7 +58,6 @@ public class ProjectService implements IProjectService {
return projectRepo.save(project); return projectRepo.save(project);
} }
@Override @Override
public Project updateProject(Project project, String loginEmpId) throws MyTeamException { public Project updateProject(Project project, String loginEmpId) throws MyTeamException {
Project existingProject = projectRepo.findByProjectId(project.getProjectId()); Project existingProject = projectRepo.findByProjectId(project.getProjectId());
...@@ -122,8 +75,9 @@ public class ProjectService implements IProjectService { ...@@ -122,8 +75,9 @@ public class ProjectService implements IProjectService {
return existingProject; return existingProject;
} }
public Account updateProjSeqinAccount(Account account) throws MyTeamException {
return accountService.updateAccountSequence(account);
}
@Override @Override
public void deleteProject(String projectId) { public void deleteProject(String projectId) {
...@@ -133,6 +87,67 @@ public class ProjectService implements IProjectService { ...@@ -133,6 +87,67 @@ public class ProjectService implements IProjectService {
resourceService.deleteResourcesUnderProject(projectId); resourceService.deleteResourcesUnderProject(projectId);
} }
public boolean isProjectExistsByName(String projectName) {
boolean isProjectExists = false;
if (projectName != null && !"".equalsIgnoreCase(projectName)) {
Project project = projectRepo.findByProjectName(projectName);
isProjectExists = (project == null) ? false : true;
}
return isProjectExists;
}
public boolean isProjectExistsById(String projectId) {
boolean isProjectExists = false;
if (projectId != null && !"".equalsIgnoreCase(projectId)) {
Project project = projectRepo.findByProjectId(projectId);
isProjectExists = (project == null) ? false : true;
}
return isProjectExists;
}
@Override
public List<Project> getAllProjects() {
return projectRepo.findAll();
}
public long getProjectsCount() {
return projectRepo.count();
}
public Project getProjectByProjectId(String projectId) {
Project project = null;
if (StringUtils.isNotBlank(projectId)) {
project = projectRepo.findByProjectId(projectId);
}
return project;
}
public List<Project> getActiveProjects() throws MyTeamException {
List<Project> projects = projectRepo.findAll();
return projects.stream().filter(project -> project.getStatus().equalsIgnoreCase(MyTeamUtils.ACTIVE)).collect(Collectors.toList());
}
public List<Project> getProjectsForDeliveryLead(String deliveryLeadId) {
List<Project> projectsList = projectRepo.findByDeliveryLeadIds(deliveryLeadId);
return projectsList;
}
@Override
public List<Project> getProjectsUnderDomain(String domainId) {
return projectRepo.findByDomainId(domainId);
}
public Account getProjectAccount(String accountId) {
Account account = null;
if (accountId != null && !"".equalsIgnoreCase(accountId)) {
return accountService.getAccountById(accountId);
}
return account;
}
@Override @Override
public List<HashMap<Object, Object>> getProjects() throws MyTeamException { public List<HashMap<Object, Object>> getProjects() throws MyTeamException {
...@@ -233,12 +248,6 @@ public class ProjectService implements IProjectService { ...@@ -233,12 +248,6 @@ public class ProjectService implements IProjectService {
return projectList; return projectList;
} }
@Override
public List<Project> getAllProjects() {
return projectRepo.findAll();
}
@Override @Override
public List<Project> getOnlyActiveProjects() { public List<Project> getOnlyActiveProjects() {
return getAllProjects().stream() return getAllProjects().stream()
...@@ -246,7 +255,6 @@ public class ProjectService implements IProjectService { ...@@ -246,7 +255,6 @@ public class ProjectService implements IProjectService {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
private String validateAgainstDOJ(Resource resource) { private String validateAgainstDOJ(Resource resource) {
String response = null; String response = null;
Date empDoj = employeeService.getEmployeeById(resource.getEmployeeId()).getDateOfJoining(); Date empDoj = employeeService.getEmployeeById(resource.getEmployeeId()).getDateOfJoining();
...@@ -375,29 +383,6 @@ public class ProjectService implements IProjectService { ...@@ -375,29 +383,6 @@ public class ProjectService implements IProjectService {
} }
public List<Project> getActiveProjects() throws MyTeamException {
List<Project> projects = projectRepo.findAll();
return projects.stream().filter(project -> project.getStatus().equalsIgnoreCase(MyTeamUtils.ACTIVE)).collect(Collectors.toList());
}
public Project getProjectByProjectId(String projectId) {
Project project = null;
if (StringUtils.isNotBlank(projectId)) {
project = projectRepo.findByProjectId(projectId);
}
return project;
}
public List<Project> getProjectsForDeliveryLead(String deliveryLeadId) {
List<Project> projectsList = projectRepo.findByDeliveryLeadIds(deliveryLeadId);
return projectsList;
}
} }
......
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