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