Commit 1bead970 authored by Sridhar Sathu's avatar Sridhar Sathu

ProjectDuplicateNameCheck

parent 35fe87d0
...@@ -18,6 +18,7 @@ import com.nisum.mytime.model.Account; ...@@ -18,6 +18,7 @@ import com.nisum.mytime.model.Account;
import com.nisum.mytime.model.EmployeeRoles; import com.nisum.mytime.model.EmployeeRoles;
import com.nisum.mytime.model.Project; import com.nisum.mytime.model.Project;
import com.nisum.mytime.repository.AccountRepo; import com.nisum.mytime.repository.AccountRepo;
import com.nisum.mytime.repository.ProjectRepo;
import com.nisum.mytime.service.ProjectService; import com.nisum.mytime.service.ProjectService;
import com.nisum.mytime.service.UserService; import com.nisum.mytime.service.UserService;
import com.nisum.mytime.utils.MyTimeUtils; import com.nisum.mytime.utils.MyTimeUtils;
...@@ -34,7 +35,8 @@ public class ProjectController { ...@@ -34,7 +35,8 @@ public class ProjectController {
@Autowired @Autowired
private AccountRepo accountRepo; private AccountRepo accountRepo;
@Autowired
private ProjectRepo projectRepo;
@RequestMapping(value = "/employee", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/employee", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<EmployeeRoles> getEmployeeRole(@RequestParam("emailId") String emailId) public ResponseEntity<EmployeeRoles> getEmployeeRole(@RequestParam("emailId") String emailId)
throws MyTimeException { throws MyTimeException {
...@@ -43,7 +45,22 @@ public class ProjectController { ...@@ -43,7 +45,22 @@ public class ProjectController {
} }
@RequestMapping(value = "/addProject", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/addProject", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Project> addProject(@RequestBody Project projectAdded) throws MyTimeException { public ResponseEntity<?> addProject(@RequestBody Project projectAdded) throws MyTimeException {
// checking project duplicateName
int projectNameCount=0;
if (projectAdded.getAccountId() != null) {
List<Project> projects = projectRepo.findByAccountId(projectAdded.getAccountId());
for (Project existproject : projects) {
if (projectAdded.getProjectName().equalsIgnoreCase(existproject.getProjectName()))
projectNameCount++; }
}
if (projectNameCount>0)
{
MyTimeException myTimeException= new MyTimeException("Project name already exist !!! try with new");
return new ResponseEntity<>(myTimeException, HttpStatus.OK);
}
else
{
String accountName=""; String accountName="";
String accountId=projectAdded.getAccountId(); String accountId=projectAdded.getAccountId();
// String accountName=projectAdded.getAccount(); // String accountName=projectAdded.getAccount();
...@@ -57,10 +74,24 @@ public class ProjectController { ...@@ -57,10 +74,24 @@ public class ProjectController {
projectAdded.setProjectId(projectId); projectAdded.setProjectId(projectId);
Project project = projectService.addProject(projectAdded); Project project = projectService.addProject(projectAdded);
return new ResponseEntity<>(project, HttpStatus.OK); return new ResponseEntity<>(project, HttpStatus.OK);
}
} }
@RequestMapping(value = "/updateProject", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/updateProject", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Project> updateEmployeeRole(@RequestBody Project project) throws MyTimeException { public ResponseEntity<?> updateEmployeeRole(@RequestBody Project project) throws MyTimeException {
// checking project duplicateName
int projectNameCount=0;
if (project.getAccountId() != null) {
List<Project> projects = projectRepo.findByAccountId(project.getAccountId());
for (Project existproject : projects) {
if (project.getProjectName().equalsIgnoreCase(existproject.getProjectName()))
projectNameCount++; }
}
if (projectNameCount>1)
{
MyTimeException myTimeException= new MyTimeException("Project name already exist !!! try with new");
return new ResponseEntity<>(myTimeException, HttpStatus.OK);
}
Project updatedProject = projectService.updateProject(project); Project updatedProject = projectService.updateProject(project);
return new ResponseEntity<>(updatedProject, HttpStatus.OK); return new ResponseEntity<>(updatedProject, HttpStatus.OK);
} }
......
...@@ -16,4 +16,8 @@ public interface ProjectRepo extends MongoRepository<Project, String> { ...@@ -16,4 +16,8 @@ public interface ProjectRepo extends MongoRepository<Project, String> {
// List<Project> findByManagerId(String managerId); // List<Project> findByManagerId(String managerId);
List<Project> findByAccountIdIn(Set<String> accIdsSet); List<Project> findByAccountIdIn(Set<String> accIdsSet);
List<Project> findByAccountId(String accountId);
} }
\ No newline at end of file
...@@ -30,7 +30,7 @@ public interface ProjectService { ...@@ -30,7 +30,7 @@ public interface ProjectService {
void deleteProject(String projectId); void deleteProject(String projectId);
Project updateProject(Project project); Project updateProject(Project project)throws MyTimeException;
EmployeeRoles getEmployeesRoleData(String empId); EmployeeRoles getEmployeesRoleData(String empId);
......
package com.nisum.mytime.service; package com.nisum.mytime.service;
import java.time.LocalDate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
...@@ -155,7 +156,7 @@ public class ProjectServiceImpl implements ProjectService { ...@@ -155,7 +156,7 @@ public class ProjectServiceImpl implements ProjectService {
} }
@Override @Override
public Project addProject(Project project) throws MyTimeException { public Project addProject(Project project) throws MyTimeException {
if (project.getDomainId() == null) { if (project.getDomainId() == null) {
Domains domain = new Domains(); Domains domain = new Domains();
domain.setAccountId(project.getAccountId()); domain.setAccountId(project.getAccountId());
...@@ -169,6 +170,7 @@ public class ProjectServiceImpl implements ProjectService { ...@@ -169,6 +170,7 @@ public class ProjectServiceImpl implements ProjectService {
project.setDomainId(savedDomain.getDomainId()); project.setDomainId(savedDomain.getDomainId());
project.setDomain(savedDomain.getDomainName()); project.setDomain(savedDomain.getDomainName());
} }
return projectRepo.save(project); return projectRepo.save(project);
} }
...@@ -189,7 +191,64 @@ public class ProjectServiceImpl implements ProjectService { ...@@ -189,7 +191,64 @@ public class ProjectServiceImpl implements ProjectService {
} }
@Override @Override
public Project updateProject(Project project) { public Project updateProject(Project project) throws MyTimeException {
//Inactivate the Project based on endDate
Project existingProject = projectRepo.findByProjectId(project.getProjectId());
List<ProjectTeamMate> existingTeammates = projectTeamMatesRepo.findByProjectId(project.getProjectId());
if (project.getProjectEndDate().compareTo(new Date()) <= 0
&& project.getProjectEndDate().compareTo(existingProject.getProjectEndDate()) != 0) {
existingProject.setStatus(MyTimeUtils.IN_ACTIVE);
existingProject.setProjectEndDate(project.getProjectEndDate());
projectRepo.save(existingProject);
for (ProjectTeamMate existingTeammate : existingTeammates) {
existingTeammate.setActive(false);
existingTeammate.setEndDate(project.getProjectEndDate());
BillingDetails billingDetails = new BillingDetails();
billingDetails.setBillableStatus(MyTimeUtils.BENCH_BILLABILITY_STATUS);
List<BillingDetails> listBD = getEmployeeActiveBillingDetails(existingTeammate.getEmployeeId(),
existingTeammate.getProjectId());
if (listBD != null && !listBD.isEmpty()) {
BillingDetails billingDetailsExisting = listBD.get(0);
billingDetailsExisting.setBillingEndDate(project.getProjectEndDate());
billingDetailsExisting.setActive(false);
updateEmployeeBilling(billingDetailsExisting);
}
Date sd = project.getProjectEndDate();
billingDetails.setBillingStartDate(sd);
billingDetails.setAccount(MyTimeUtils.BENCH_ACCOUNT);
billingDetails.setActive(true);
billingDetails.setEmployeeId(existingTeammate.getEmployeeId());
billingDetails.setEmployeeName(existingTeammate.getEmployeeName());
billingDetails.setCreateDate(new Date());
billingDetails.setProjectId(MyTimeUtils.BENCH_PROJECT_ID);
billingDetails.setProjectName(MyTimeUtils.FREE_POLL);
addEmployeeBillingDetails(billingDetails);
projectTeamMatesRepo.save(existingTeammate);
ProjectTeamMate newBenchAllocation = new ProjectTeamMate();
Project benchProject = projectRepo.findByProjectId(MyTimeUtils.BENCH_PROJECT_ID);
if (benchProject != null)
newBenchAllocation.setAccountId(benchProject.getAccountId());
newBenchAllocation.setBillableStatus(MyTimeUtils.BENCH_BILLABILITY_STATUS);
newBenchAllocation.setDesignation(existingTeammate.getDesignation());
newBenchAllocation.setEmailId(existingTeammate.getEmailId());
newBenchAllocation.setEmployeeId(existingTeammate.getEmployeeId());
newBenchAllocation.setActive(true);
newBenchAllocation.setEmployeeName(existingTeammate.getEmployeeName());
newBenchAllocation.setProjectId(MyTimeUtils.BENCH_PROJECT_ID);
newBenchAllocation.setStartDate(sd);
newBenchAllocation.setProjectName(benchProject.getProjectName());
projectTeamMatesRepo.save(newBenchAllocation);
updateShiftDetails(existingTeammate);
}
return existingProject;
}
else
{
Query query = new Query( Query query = new Query(
Criteria.where("projectId").is(project.getProjectId())); Criteria.where("projectId").is(project.getProjectId()));
Update update = new Update(); Update update = new Update();
...@@ -229,6 +288,7 @@ public class ProjectServiceImpl implements ProjectService { ...@@ -229,6 +288,7 @@ public class ProjectServiceImpl implements ProjectService {
} }
} }
return projectDB; return projectDB;
}
} }
@Override @Override
......
...@@ -156,19 +156,24 @@ public class UserServiceImpl implements UserService { ...@@ -156,19 +156,24 @@ public class UserServiceImpl implements UserService {
} }
ProjectTeamMate newBenchAllocation = new ProjectTeamMate(); ProjectTeamMate newBenchAllocation = new ProjectTeamMate();
newBenchAllocation.setAccount("Nisum"); newBenchAllocation.setAccount(MyTimeUtils.BENCH_ACCOUNT);
newBenchAllocation.setBillableStatus("Non-Billable"); newBenchAllocation.setBillableStatus(MyTimeUtils.BENCH_BILLABILITY_STATUS);
newBenchAllocation.setDesignation(employeeRoles.getDesignation()); newBenchAllocation.setDesignation(employeeRoles.getDesignation());
newBenchAllocation.setEmailId(employeeRoles.getEmailId()); newBenchAllocation.setEmailId(employeeRoles.getEmailId());
newBenchAllocation.setEmployeeId(employeeRoles.getEmployeeId()); newBenchAllocation.setEmployeeId(employeeRoles.getEmployeeId());
newBenchAllocation.setMobileNumber(employeeRoles.getMobileNumber());
newBenchAllocation.setActive(true); newBenchAllocation.setActive(true);
newBenchAllocation.setEmployeeName(employeeRoles.getEmployeeName()); newBenchAllocation.setEmployeeName(employeeRoles.getEmployeeName());
newBenchAllocation.setProjectId("Nisum0000"); newBenchAllocation.setProjectId(MyTimeUtils.BENCH_PROJECT_ID);
newBenchAllocation.setStartDate(employeeRoles.getDateOfJoining() != null newBenchAllocation.setStartDate(employeeRoles.getDateOfJoining() != null
? employeeRoles.getDateOfJoining() ? employeeRoles.getDateOfJoining()
: new Date()); : new Date());
Project p = projectRepo.findByProjectId("Nisum0000"); Project p = projectRepo.findByProjectId(MyTimeUtils.BENCH_PROJECT_ID);
newBenchAllocation.setProjectName(p.getProjectName()); newBenchAllocation.setProjectName(p.getProjectName());
newBenchAllocation.setAccountId(p.getAccountId());
newBenchAllocation.setDomainId(p.getDomainId());
newBenchAllocation.setEndDate(employeeRoles.getEndDate());
newBenchAllocation.setRole(employeeRoles.getRole());
// newBenchAllocation.setManagerId(p.getManagerId()); // newBenchAllocation.setManagerId(p.getManagerId());
//newBenchAllocation.setManagerName(p.getManagerName()); //newBenchAllocation.setManagerName(p.getManagerName());
try { try {
......
...@@ -157,6 +157,7 @@ public class VisaServiceImpl implements VisaService { ...@@ -157,6 +157,7 @@ public class VisaServiceImpl implements VisaService {
* log.info("Inserted Employee record with Id: {}", * log.info("Inserted Employee record with Id: {}",
* employee.getEmployeeId()); * employee.getEmployeeId());
*/ */
if(employee.getRole()!=null)
employee.setRole("Employee"); employee.setRole("Employee");
EmployeeRoles emp = userService EmployeeRoles emp = userService
......
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