Unverified Commit 4ac1c2dd authored by mshaik-nisum-com's avatar mshaik-nisum-com Committed by GitHub

Merge pull request #146 from nisum-inc/FEATURE/ProjectDuplicateNameCheck

ProjectDuplicateNameCheck
parents 35fe87d0 1bead970
......@@ -18,6 +18,7 @@ import com.nisum.mytime.model.Account;
import com.nisum.mytime.model.EmployeeRoles;
import com.nisum.mytime.model.Project;
import com.nisum.mytime.repository.AccountRepo;
import com.nisum.mytime.repository.ProjectRepo;
import com.nisum.mytime.service.ProjectService;
import com.nisum.mytime.service.UserService;
import com.nisum.mytime.utils.MyTimeUtils;
......@@ -34,7 +35,8 @@ public class ProjectController {
@Autowired
private AccountRepo accountRepo;
@Autowired
private ProjectRepo projectRepo;
@RequestMapping(value = "/employee", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<EmployeeRoles> getEmployeeRole(@RequestParam("emailId") String emailId)
throws MyTimeException {
......@@ -43,7 +45,22 @@ public class ProjectController {
}
@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 accountId=projectAdded.getAccountId();
// String accountName=projectAdded.getAccount();
......@@ -57,10 +74,24 @@ public class ProjectController {
projectAdded.setProjectId(projectId);
Project project = projectService.addProject(projectAdded);
return new ResponseEntity<>(project, HttpStatus.OK);
}
}
@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);
return new ResponseEntity<>(updatedProject, HttpStatus.OK);
}
......
......@@ -16,4 +16,8 @@ public interface ProjectRepo extends MongoRepository<Project, String> {
// List<Project> findByManagerId(String managerId);
List<Project> findByAccountIdIn(Set<String> accIdsSet);
List<Project> findByAccountId(String accountId);
}
\ No newline at end of file
......@@ -30,7 +30,7 @@ public interface ProjectService {
void deleteProject(String projectId);
Project updateProject(Project project);
Project updateProject(Project project)throws MyTimeException;
EmployeeRoles getEmployeesRoleData(String empId);
......
package com.nisum.mytime.service;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
......@@ -155,7 +156,7 @@ public class ProjectServiceImpl implements ProjectService {
}
@Override
public Project addProject(Project project) throws MyTimeException {
public Project addProject(Project project) throws MyTimeException {
if (project.getDomainId() == null) {
Domains domain = new Domains();
domain.setAccountId(project.getAccountId());
......@@ -169,6 +170,7 @@ public class ProjectServiceImpl implements ProjectService {
project.setDomainId(savedDomain.getDomainId());
project.setDomain(savedDomain.getDomainName());
}
return projectRepo.save(project);
}
......@@ -189,7 +191,64 @@ public class ProjectServiceImpl implements ProjectService {
}
@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(
Criteria.where("projectId").is(project.getProjectId()));
Update update = new Update();
......@@ -229,6 +288,7 @@ public class ProjectServiceImpl implements ProjectService {
}
}
return projectDB;
}
}
@Override
......
......@@ -156,19 +156,24 @@ public class UserServiceImpl implements UserService {
}
ProjectTeamMate newBenchAllocation = new ProjectTeamMate();
newBenchAllocation.setAccount("Nisum");
newBenchAllocation.setBillableStatus("Non-Billable");
newBenchAllocation.setAccount(MyTimeUtils.BENCH_ACCOUNT);
newBenchAllocation.setBillableStatus(MyTimeUtils.BENCH_BILLABILITY_STATUS);
newBenchAllocation.setDesignation(employeeRoles.getDesignation());
newBenchAllocation.setEmailId(employeeRoles.getEmailId());
newBenchAllocation.setEmployeeId(employeeRoles.getEmployeeId());
newBenchAllocation.setMobileNumber(employeeRoles.getMobileNumber());
newBenchAllocation.setActive(true);
newBenchAllocation.setEmployeeName(employeeRoles.getEmployeeName());
newBenchAllocation.setProjectId("Nisum0000");
newBenchAllocation.setProjectId(MyTimeUtils.BENCH_PROJECT_ID);
newBenchAllocation.setStartDate(employeeRoles.getDateOfJoining() != null
? employeeRoles.getDateOfJoining()
: new Date());
Project p = projectRepo.findByProjectId("Nisum0000");
Project p = projectRepo.findByProjectId(MyTimeUtils.BENCH_PROJECT_ID);
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.setManagerName(p.getManagerName());
try {
......
......@@ -157,6 +157,7 @@ public class VisaServiceImpl implements VisaService {
* log.info("Inserted Employee record with Id: {}",
* employee.getEmployeeId());
*/
if(employee.getRole()!=null)
employee.setRole("Employee");
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