Commit 0861416c authored by Vijay Akula's avatar Vijay Akula

Added response format for the get methods of resource controller

parent 97c144c6
...@@ -28,180 +28,236 @@ import java.util.stream.Collectors; ...@@ -28,180 +28,236 @@ import java.util.stream.Collectors;
@RequestMapping @RequestMapping
public class ResourceController { public class ResourceController {
@Autowired @Autowired
private IEmployeeService employeeService; private IEmployeeService employeeService;
@Autowired @Autowired
private IProjectService projectService; private IProjectService projectService;
@Autowired @Autowired
private EmployeeVisaRepo employeeVisaRepo; private EmployeeVisaRepo employeeVisaRepo;
@Autowired @Autowired
private IResourceService resourceService; private IResourceService resourceService;
// @RequestMapping(value = "/addEmployeeToTeam" // @RequestMapping(value = "/addEmployeeToTeam"
@RequestMapping(value = "/resources", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/resources", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> addResourceToTeam(@RequestBody Resource resourceReq, public ResponseEntity<?> addResourceToTeam(@RequestBody Resource resourceReq,
@RequestParam(value = "loginEmpId", required = true) String loginEmpId, HttpServletRequest request) throws MyTeamException { @RequestParam(value = "loginEmpId", required = true) String loginEmpId, HttpServletRequest request) throws MyTeamException {
if (StringUtils.isNotBlank(loginEmpId)) { if (StringUtils.isNotBlank(loginEmpId)) {
resourceReq.setActive(true); resourceReq.setActive(true);
resourceReq.setAuditFields(loginEmpId, MyTeamUtils.CREATE); resourceReq.setAuditFields(loginEmpId, MyTeamUtils.CREATE);
Resource resourcePersisted = resourceService.addResource(resourceReq, loginEmpId); Resource resourcePersisted = resourceService.addResource(resourceReq, loginEmpId);
ResponseDetails createResponseDetails = new ResponseDetails(new Date(), 601, "Resource has been created", ResponseDetails createResponseDetails = new ResponseDetails(new Date(), 601, "Resource has been created",
"Resource description", null, request.getContextPath(), "details", resourcePersisted); "Resource description", null, request.getContextPath(), "details", resourcePersisted);
return new ResponseEntity<ResponseDetails>(createResponseDetails, HttpStatus.OK); return new ResponseEntity<ResponseDetails>(createResponseDetails, HttpStatus.OK);
} }
ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Please provide the valid Employee Id", ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Please provide the valid Employee Id",
"Employee Id is not valid", null, request.getRequestURI(), "Resource details", resourceReq); "Employee Id is not valid", null, request.getRequestURI(), "Resource details", resourceReq);
return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK); return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
} }
// @RequestMapping(value = "/updateTeammate" // @RequestMapping(value = "/updateTeammate"
@RequestMapping(value = "/resources", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/resources", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> updateResource(@RequestBody Resource resourceReq, public ResponseEntity<?> updateResource(@RequestBody Resource resourceReq,
@RequestParam(value = "loginEmpId") String loginEmpId, HttpServletRequest request) throws MyTeamException { @RequestParam(value = "loginEmpId") String loginEmpId, HttpServletRequest request) throws MyTeamException {
if (StringUtils.isNotBlank(loginEmpId)) { if (StringUtils.isNotBlank(loginEmpId)) {
resourceReq.setAuditFields(loginEmpId, MyTeamUtils.UPDATE); resourceReq.setAuditFields(loginEmpId, MyTeamUtils.UPDATE);
String responseMessage = resourceService.updateResource(resourceReq, loginEmpId); String responseMessage = resourceService.updateResource(resourceReq, loginEmpId);
ResponseDetails createResponseDetails = new ResponseDetails(new Date(), 601, responseMessage, ResponseDetails createResponseDetails = new ResponseDetails(new Date(), 601, responseMessage,
"Resource description", null, request.getContextPath(), "Resource details", resourceReq); "Resource description", null, request.getContextPath(), "Resource details", resourceReq);
return new ResponseEntity<ResponseDetails>(createResponseDetails, HttpStatus.OK); return new ResponseEntity<ResponseDetails>(createResponseDetails, HttpStatus.OK);
} }
ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Please provide the valid Employee Id", ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Please provide the valid Employee Id",
"Employee Id is not valid", null, request.getRequestURI(), "Resource details", resourceReq); "Employee Id is not valid", null, request.getRequestURI(), "Resource details", resourceReq);
return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK); return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
} }
// @RequestMapping(value = "/deleteTeammate" // @RequestMapping(value = "/deleteTeammate"
@RequestMapping(value = "/resources", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/resources", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> deleteResource(@RequestBody Resource resourceReq, public ResponseEntity<?> deleteResource(@RequestBody Resource resourceReq,
@RequestParam(value = "loginEmpId", required = true) String loginEmpId, HttpServletRequest request) throws MyTeamException { @RequestParam(value = "loginEmpId", required = true) String loginEmpId, HttpServletRequest request) throws MyTeamException {
if (StringUtils.isNotBlank(loginEmpId)) { if (StringUtils.isNotBlank(loginEmpId)) {
Resource resourceDeleted = resourceService.deleteResource(resourceReq.getEmployeeId(), resourceReq.getProjectId(), resourceReq.getId(), loginEmpId); Resource resourceDeleted = resourceService.deleteResource(resourceReq.getEmployeeId(), resourceReq.getProjectId(), resourceReq.getId(), loginEmpId);
ResponseDetails createResponseDetails = new ResponseDetails(new Date(), 601, "Resource has been deleted", ResponseDetails createResponseDetails = new ResponseDetails(new Date(), 601, "Resource has been deleted",
"Resource description", null, request.getContextPath(), "Resource details", resourceDeleted); "Resource description", null, request.getContextPath(), "Resource details", resourceDeleted);
return new ResponseEntity<ResponseDetails>(createResponseDetails, HttpStatus.OK); return new ResponseEntity<ResponseDetails>(createResponseDetails, HttpStatus.OK);
} }
ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Please provide the valid Employee Id", ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Please provide the valid Employee Id",
"Employee Id is not valid", null, request.getRequestURI(), "Resource details", resourceReq); "Employee Id is not valid", null, request.getRequestURI(), "Resource details", resourceReq);
return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK); return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
} }
// @RequestMapping(value = "/getEmployeeProjectInfo" // @RequestMapping(value = "/getEmployeeProjectInfo"
@RequestMapping(value = "/resources/employeeId/{employeeId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/resources/employeeId/{employeeId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<Resource>> getResourcesSortByStartDate(@PathVariable(value = "employeeId",required = true) String employeeId) public ResponseEntity<?> getResourcesSortByStartDate(@PathVariable(value = "employeeId", required = true) String employeeId, HttpServletRequest request)
throws MyTeamException { throws MyTeamException {
List<Resource> projectInfo = resourceService.getResourcesSortByStartDate(employeeId);
return new ResponseEntity<>(projectInfo, HttpStatus.OK); if (StringUtils.isNotBlank(employeeId)) {
} List<Resource> resourcesList = resourceService.getResourcesSortByStartDate(employeeId);
ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Resources have been retrieved successfully",
//@RequestMapping(value = "/getMyTeamDetails" "List of Resources for an employee", resourcesList, request.getRequestURI(), "Resource List details", null);
@RequestMapping(value = "/resources/active", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
public ResponseEntity<List<Resource>> getActiveResources(@RequestParam("employeeId") String employeeId) }
throws MyTeamException {
List<Resource> employeesRoles = resourceService.getActiveResources(employeeId); ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Please provide the valid Employee Id",
return new ResponseEntity<>(employeesRoles, HttpStatus.OK); "Employee Id is not valid", null, request.getRequestURI(), "Resource details", null);
} return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
}
// @RequestMapping(value = "/getShiftDetails" //@RequestMapping(value = "/getMyTeamDetails"
@RequestMapping(value = "/resources/shifts/{shift}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/resources/active", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<Resource>> getResourcesForShift(@PathVariable("shift") String shift) public ResponseEntity<?> getActiveResources(@RequestParam(value = "employeeId", required = false) String employeeId, HttpServletRequest request)
throws MyTeamException { throws MyTeamException {
List<Resource> resourcesList = resourceService.getResourcesForShift(shift); if (StringUtils.isNotBlank(employeeId)) {
return new ResponseEntity<>(resourcesList, HttpStatus.OK); List<Resource> employeesRoles = resourceService.getActiveResources(employeeId);
}
ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Resources have been retrieved successfully",
// @RequestMapping(value = "/getProjectAllocations" "List of Resources who are active in the projects", employeesRoles, request.getRequestURI(), "Resource List details", null);
@RequestMapping(value = "/resources/projects", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
public ResponseEntity<List<Resource>> getResourcesAllocatedForAllProjects() throws MyTeamException {
List<Resource> resourcesList = resourceService.getResourcesForActiveProjects(); }
return new ResponseEntity<>(resourcesList, HttpStatus.OK); ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Please provide the valid Employee Id",
} "Employee Id is not valid", null, request.getRequestURI(), "Resource details", null);
return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
// @RequestMapping(value = "/getProjectDetails" }
@RequestMapping(value = "/resources/project/{projectId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<Resource>> getResourcesForProject(@PathVariable("projectId") String projectId,
@RequestParam(value = "status", required = false, defaultValue = MyTeamUtils.ACTIVE) String status) // @RequestMapping(value = "/getShiftDetails"
throws MyTeamException { @RequestMapping(value = "/resources/shifts/{shift}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
List<Resource> resourcesList = resourceService.getResourcesForProject(projectId, status); public ResponseEntity<?> getResourcesForShift(@PathVariable(value = "shift", required = true) String shift, HttpServletRequest request)
return new ResponseEntity<>(resourcesList, HttpStatus.OK); throws MyTeamException {
}
if (StringUtils.isNotBlank(shift)) {
List<Resource> resourcesList = resourceService.getResourcesForShift(shift);
//@RequestMapping(value = "/getTeamDetails" ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Resources have been retrieved successfully",
@RequestMapping(value = "/resources/deliverylead/{deliveryLeadId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) "List of Resources for the provided shift", resourcesList, request.getRequestURI(), "Resource List for shift", null);
public ResponseEntity<List<Resource>> getTeamDetails(@PathVariable("deliveryLeadId") String deliveryLeadId) return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
throws MyTeamException { }
List<Resource> resourcesList = resourceService.getResourcesUnderDeliveryLead(deliveryLeadId); ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Please provide the valid Shift value",
return new ResponseEntity<>(resourcesList, HttpStatus.OK); "List of Resources for the provided shift", null, request.getRequestURI(), "Resource details", null);
} return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
}
@RequestMapping(value = "resources/unAssignedEmployees", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) // @RequestMapping(value = "/getProjectAllocations"
public ResponseEntity<List<Employee>> getUnAssignedEmployees() throws MyTeamException { @RequestMapping(value = "/resources/projects", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
List<Employee> employeesList = projectService.getUnAssignedEmployees(); public ResponseEntity<?> getResourcesAllocatedForAllProjects(HttpServletRequest request) throws MyTeamException {
return new ResponseEntity<>(employeesList, HttpStatus.OK);
} List<Resource> resourcesList = resourceService.getResourcesForActiveProjects();
ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Resources have been retrieved successfully",
"List of Resources for the projects", resourcesList, request.getRequestURI(), "Resource details", null);
return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
@RequestMapping(value = "/getEmployeesDashBoard", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<EmployeeDashboardVO>> getEmployeesDashBoard() throws MyTeamException { }
List<EmployeeDashboardVO> employeeDashBoardList = projectService.getEmployeesDashBoard();
return new ResponseEntity<>(employeeDashBoardList, HttpStatus.OK); // @RequestMapping(value = "/getProjectDetails"
} @RequestMapping(value = "/resources/project/{projectId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getResourcesForProject(@PathVariable(value = "projectId", required = true) String projectId,
@RequestMapping(value = "/getEmployeesHavingVisa", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @RequestParam(value = "status", required = false, defaultValue = MyTeamUtils.ACTIVE) String status,
public ResponseEntity<List<Employee>> getEmployeesHavingVisa(@RequestParam("visa") String passport) HttpServletRequest request)
throws MyTeamException { throws MyTeamException {
List<Employee> employees = new ArrayList<>();
if (passport != null && !"passport".equalsIgnoreCase(passport)) { if (StringUtils.isNotBlank(projectId)) {
List<EmployeeVisa> employeeVisas = employeeVisaRepo.findByVisaName(passport); List<Resource> resourcesList = resourceService.getResourcesForProject(projectId, status);
List<String> employeeIds = null; ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Resources have been retrieved successfully",
if (employeeVisas != null) { "List of Resources for a project", resourcesList, request.getRequestURI(), "Resource details", null);
employeeIds = employeeVisas.stream().map(EmployeeVisa::getEmployeeId).collect(Collectors.toList()); return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
}
if (employeeIds != null && !employeeIds.isEmpty()) { }
List<Employee> emps = employeeService.getActiveEmployees(); ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Please provide ProjectId",
for (Employee emp : emps) { "List of Resources for a project", null, request.getRequestURI(), "Resource details", null);
if (employeeIds.contains(emp.getEmployeeId())) { return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
employees.add(emp); }
}
}
} //@RequestMapping(value = "/getTeamDetails"
return new ResponseEntity<>(employees, HttpStatus.OK); @RequestMapping(value = "/resources/deliverylead/{deliveryLeadId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
} else { public ResponseEntity<?> getTeamDetails(@PathVariable(value = "deliveryLeadId", required = true) String deliveryLeadId, HttpServletRequest request)
// List<EmployeeRoles> employees = new ArrayList<>(); throws MyTeamException {
if (employeeService.getActiveEmployees() != null) {
employees = employeeService.getActiveEmployees().stream() if (StringUtils.isNotBlank(deliveryLeadId)) {
.sorted((o1, o2) -> o1.getEmployeeName().compareTo(o2.getEmployeeName())) List<Resource> resourcesList = resourceService.getResourcesUnderDeliveryLead(deliveryLeadId);
.collect(Collectors.toList());
} ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Resources have been retrieved successfully",
return new ResponseEntity<>(employees, HttpStatus.OK); "List of Resources for a project", resourcesList, request.getRequestURI(), "Resource details", null);
} }
} ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Please provide ProjectId",
"List of Resources for DeliveryLead", null, request.getRequestURI(), "Resource details", null);
return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
}
@RequestMapping(value = "/addEmployeeToTeamWithCheck", method = RequestMethod.POST, produces = MediaType.TEXT_PLAIN_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> addEmployeeToTeamWithCheck(@RequestBody Resource resource,
@RequestParam(value = "loginEmpId") String loginEmpId) throws MyTeamException { @RequestMapping(value = "resources/unAssignedEmployees", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
String response = projectService.addProjectTeamMateWithCheck(resource, loginEmpId); public ResponseEntity<?> getUnAssignedEmployees(HttpServletRequest request) throws MyTeamException {
return new ResponseEntity<>(response, HttpStatus.OK); List<Employee> employeesList = projectService.getUnAssignedEmployees();
}
ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Resources have been retrieved successfully",
"List of Resources who are not assigned to project", employeesList, request.getRequestURI(), "Resource details", null);
return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
}
@RequestMapping(value = "/getEmployeesDashBoard", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getEmployeesDashBoard(HttpServletRequest request) throws MyTeamException {
List<EmployeeDashboardVO> employeeDashBoardList = projectService.getEmployeesDashBoard();
ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Resources have been retrieved successfully",
"List of Resources for dashboard", employeeDashBoardList, request.getRequestURI(), "Resource details", null);
return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
}
@RequestMapping(value = "/getEmployeesHavingVisa", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getEmployeesHavingVisa(@RequestParam("visa") String passport,HttpServletRequest request)
throws MyTeamException {
List<Employee> employees = new ArrayList<>();
if (passport != null && !"passport".equalsIgnoreCase(passport)) {
List<EmployeeVisa> employeeVisas = employeeVisaRepo.findByVisaName(passport);
List<String> employeeIds = null;
if (employeeVisas != null) {
employeeIds = employeeVisas.stream().map(EmployeeVisa::getEmployeeId).collect(Collectors.toList());
}
if (employeeIds != null && !employeeIds.isEmpty()) {
List<Employee> emps = employeeService.getActiveEmployees();
for (Employee emp : emps) {
if (employeeIds.contains(emp.getEmployeeId())) {
employees.add(emp);
}
}
}
} else {
if (employeeService.getActiveEmployees() != null) {
employees = employeeService.getActiveEmployees().stream()
.sorted((o1, o2) -> o1.getEmployeeName().compareTo(o2.getEmployeeName()))
.collect(Collectors.toList());
}
}
ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Resources have been retrieved successfully",
"List of Resources who has visa", employees, request.getRequestURI(), "Resource details", null);
return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
}
@RequestMapping(value = "/addEmployeeToTeamWithCheck", method = RequestMethod.POST, produces = MediaType.TEXT_PLAIN_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> addEmployeeToTeamWithCheck(@RequestBody Resource resource,
@RequestParam(value = "loginEmpId") String loginEmpId) throws MyTeamException {
String response = projectService.addProjectTeamMateWithCheck(resource, loginEmpId);
return new ResponseEntity<>(response, HttpStatus.OK);
}
} }
......
...@@ -127,22 +127,25 @@ public class ResourceService implements IResourceService { ...@@ -127,22 +127,25 @@ public class ResourceService implements IResourceService {
} }
@Override @Override
public String updateResource(Resource resource, String loginEmpId) throws MyTeamException { public String updateResource(Resource resourceReq, String loginEmpId) throws MyTeamException {
// String result = null; // String result = null;
MyTeamResultDTO myResultDto = new MyTeamResultDTO(); MyTeamResultDTO myResultDto = new MyTeamResultDTO();
myResultDto.setResultCode(MyTeamResultDTO.SUCCESS_CODE); myResultDto.setResultCode(MyTeamResultDTO.SUCCESS_CODE);
myResultDto.setResultData("TeamMate updated successfuly"); myResultDto.setResultData("TeamMate updated successfuly");
Resource existingTeammate = resourceRepo.findById(resource.getId()); Resource existingResource = resourceRepo.findById(resourceReq.getId());
log.info("From database: Resource Details::"+existingResource);
List<Billing> listBD = billingService.getActiveBillings(resource.getEmployeeId(), resource.getProjectId());
Date resEndDate = resource.getEndDate(); Date resEndDate = resourceReq.getEndDate();
log.info("ResEndDate::"+resEndDate);
List<Billing> listBD = billingService.getActiveBillings(resourceReq.getEmployeeId(), resourceReq.getProjectId());
// Handling past or present endDate (To "Inactive" the Resource) // Handling past or present endDate (To "Inactive" the Resource)
if (resEndDate.compareTo(new Date()) <= 0 && resEndDate.compareTo(existingTeammate.getEndDate()) != 0) { if (resEndDate.compareTo(new Date()) <= 0 && resEndDate.compareTo(existingResource.getEndDate()) != 0) {
existingTeammate.setActive(false); existingResource.setActive(false);
existingTeammate.setEndDate(resEndDate); existingResource.setEndDate(resEndDate);
if (listBD != null && !listBD.isEmpty()) { if (listBD != null && !listBD.isEmpty()) {
Billing billingDetailsExisting = listBD.get(0); Billing billingDetailsExisting = listBD.get(0);
Date actualEndDate = resEndDate; Date actualEndDate = resEndDate;
...@@ -159,8 +162,8 @@ public class ResourceService implements IResourceService { ...@@ -159,8 +162,8 @@ public class ResourceService implements IResourceService {
billingDetails.setBillingStartDate(resEndDate); billingDetails.setBillingStartDate(resEndDate);
billingDetails.setAccount(MyTeamUtils.BENCH_ACCOUNT); billingDetails.setAccount(MyTeamUtils.BENCH_ACCOUNT);
billingDetails.setActive(true); billingDetails.setActive(true);
billingDetails.setEmployeeId(existingTeammate.getEmployeeId()); billingDetails.setEmployeeId(existingResource.getEmployeeId());
billingDetails.setEmployeeName(existingTeammate.getEmployeeName()); billingDetails.setEmployeeName(existingResource.getEmployeeName());
// billingDetails.setCreateDate(new Date());// Commented as added // billingDetails.setCreateDate(new Date());// Commented as added
// common audit fields // common audit fields
billingDetails.setProjectId(MyTeamUtils.BENCH_PROJECT_ID); billingDetails.setProjectId(MyTeamUtils.BENCH_PROJECT_ID);
...@@ -175,14 +178,14 @@ public class ResourceService implements IResourceService { ...@@ -175,14 +178,14 @@ public class ResourceService implements IResourceService {
billingService.addBilling(billingDetails, loginEmpId); billingService.addBilling(billingDetails, loginEmpId);
newBenchAllocation.setBillableStatus(MyTeamUtils.BENCH_BILLABILITY_STATUS); newBenchAllocation.setBillableStatus(MyTeamUtils.BENCH_BILLABILITY_STATUS);
newBenchAllocation.setDesignation(existingTeammate.getDesignation()); newBenchAllocation.setDesignation(existingResource.getDesignation());
newBenchAllocation.setEmailId(existingTeammate.getEmailId()); newBenchAllocation.setEmailId(existingResource.getEmailId());
newBenchAllocation.setEmployeeId(existingTeammate.getEmployeeId()); newBenchAllocation.setEmployeeId(existingResource.getEmployeeId());
newBenchAllocation.setActive(true); newBenchAllocation.setActive(true);
newBenchAllocation.setEmployeeName(existingTeammate.getEmployeeName()); newBenchAllocation.setEmployeeName(existingResource.getEmployeeName());
newBenchAllocation.setProjectId(MyTeamUtils.BENCH_PROJECT_ID); newBenchAllocation.setProjectId(MyTeamUtils.BENCH_PROJECT_ID);
newBenchAllocation.setShift(existingTeammate.getShift()); newBenchAllocation.setShift(existingResource.getShift());
newBenchAllocation.setRole(existingTeammate.getRole()); newBenchAllocation.setRole(existingResource.getRole());
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
cal.setTime(resEndDate); cal.setTime(resEndDate);
...@@ -197,11 +200,17 @@ public class ResourceService implements IResourceService { ...@@ -197,11 +200,17 @@ public class ResourceService implements IResourceService {
myResultDto.setResultCode(MyTeamResultDTO.SUCCESS_CODE); myResultDto.setResultCode(MyTeamResultDTO.SUCCESS_CODE);
myResultDto.setResultData( myResultDto.setResultData(
"Resource Successfully moved from " + resource.getProjectName() + " project to Bench."); "Resource Successfully moved from " + resourceReq.getProjectName() + " project to Bench.");
} else { } else {
log.info("Before compare billable status::");
log.info("Existing Resource:::"+existingResource);
log.info("Resource Request Details::"+resourceReq);
// Handling Resource Project Billability Status change // Handling Resource Project Billability Status change
if (resource.getBillableStatus() != null && existingTeammate.getBillableStatus() != null if (resourceReq.getBillableStatus() != null && existingResource.getBillableStatus() != null
&& !existingTeammate.getBillableStatus().equalsIgnoreCase(resource.getBillableStatus())) { && !existingResource.getBillableStatus().equalsIgnoreCase(resourceReq.getBillableStatus())) {
/* /*
* List<BillingDetails> bDetailsList = * List<BillingDetails> bDetailsList =
* teamMatesBillingRepo.findByEmployeeId(projectTeamMate. * teamMatesBillingRepo.findByEmployeeId(projectTeamMate.
...@@ -209,20 +218,20 @@ public class ResourceService implements IResourceService { ...@@ -209,20 +218,20 @@ public class ResourceService implements IResourceService {
* (!e.isActive())).sorted(Comparator.comparing(BillingDetails:: * (!e.isActive())).sorted(Comparator.comparing(BillingDetails::
* getBillingEndDate).reversed()) .collect(Collectors.toList()); * getBillingEndDate).reversed()) .collect(Collectors.toList());
*/ */
String result = validateBillabilityStartDate(listBD, resource); String result = validateBillabilityStartDate(listBD, resourceReq);
if (result != null) { // Invalid Billability Start date if (result != null) { // Invalid Billability Start date
return result; return result;
} }
if (listBD != null && !listBD.isEmpty()) { if (listBD != null && !listBD.isEmpty()) {
Billing billingDetails = listBD.get(0); Billing billingDetails = listBD.get(0);
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
cal.setTime(resource.getNewBillingStartDate()); cal.setTime(resourceReq.getNewBillingStartDate());
cal.add(Calendar.DAY_OF_MONTH, -1); cal.add(Calendar.DAY_OF_MONTH, -1);
Date startDate = existingTeammate.getNewBillingStartDate() != null Date startDate = existingResource.getNewBillingStartDate() != null
? existingTeammate.getNewBillingStartDate() : existingTeammate.getStartDate(); ? existingResource.getNewBillingStartDate() : existingResource.getStartDate();
if (startDate.getDate() == resource.getNewBillingStartDate().getDate()) { if (startDate.getDate() == resourceReq.getNewBillingStartDate().getDate()) {
billingDetails.setBillingEndDate( billingDetails.setBillingEndDate(
DateUtils.truncate(resource.getNewBillingStartDate(), Calendar.DATE)); DateUtils.truncate(resourceReq.getNewBillingStartDate(), Calendar.DATE));
} else { } else {
billingDetails.setBillingEndDate(DateUtils.truncate(cal.getTime(), Calendar.DATE)); billingDetails.setBillingEndDate(DateUtils.truncate(cal.getTime(), Calendar.DATE));
} }
...@@ -230,41 +239,41 @@ public class ResourceService implements IResourceService { ...@@ -230,41 +239,41 @@ public class ResourceService implements IResourceService {
billingService.updateBilling(billingDetails, loginEmpId); billingService.updateBilling(billingDetails, loginEmpId);
} }
Billing billings = new Billing(); Billing billings = new Billing();
billings.setEmployeeId(resource.getEmployeeId()); billings.setEmployeeId(resourceReq.getEmployeeId());
billings.setEmployeeName(resource.getEmployeeName()); billings.setEmployeeName(resourceReq.getEmployeeName());
billings.setProjectId(resource.getProjectId()); billings.setProjectId(resourceReq.getProjectId());
billings.setAccount(existingTeammate.getAccount()); billings.setAccount(existingResource.getAccount());
billings.setProjectName(resource.getProjectName()); billings.setProjectName(resourceReq.getProjectName());
billings.setBillableStatus(resource.getBillableStatus()); billings.setBillableStatus(resourceReq.getBillableStatus());
billings.setActive(true); billings.setActive(true);
billings.setBillingStartDate(DateUtils.truncate(resource.getNewBillingStartDate(), Calendar.DATE)); billings.setBillingStartDate(DateUtils.truncate(resourceReq.getNewBillingStartDate(), Calendar.DATE));
billings.setBillingEndDate(DateUtils.truncate(resEndDate, Calendar.DATE)); billings.setBillingEndDate(DateUtils.truncate(resEndDate, Calendar.DATE));
// billings.setCreateDate(new Date());// Commented as added // billings.setCreateDate(new Date());// Commented as added
// common audit fields // common audit fields
billingService.addBilling(billings, loginEmpId); billingService.addBilling(billings, loginEmpId);
existingTeammate.setBillableStatus(resource.getBillableStatus()); existingResource.setBillableStatus(resourceReq.getBillableStatus());
existingTeammate existingResource
.setNewBillingStartDate(DateUtils.truncate(resource.getNewBillingStartDate(), Calendar.DATE)); .setNewBillingStartDate(DateUtils.truncate(resourceReq.getNewBillingStartDate(), Calendar.DATE));
} else {// Handling Billability Start Date change } else {// Handling Billability Start Date change
List<Billing> bDetailsList = billingRepo.findByEmployeeId(resource.getEmployeeId()).stream() List<Billing> bDetailsList = billingRepo.findByEmployeeId(resourceReq.getEmployeeId()).stream()
.filter(e -> (!e.isActive())) .filter(e -> (!e.isActive()))
.sorted(Comparator.comparing(Billing::getBillingEndDate).reversed()) .sorted(Comparator.comparing(Billing::getBillingEndDate).reversed())
.collect(Collectors.toList()); .collect(Collectors.toList());
String result = validateBillabilityStartDate(bDetailsList, resource); String result = validateBillabilityStartDate(bDetailsList, resourceReq);
if (result != null) { // Invalid Billability Start date if (result != null) { // Invalid Billability Start date
return result; return result;
} }
if (bDetailsList != null && !bDetailsList.isEmpty()) { if (bDetailsList != null && !bDetailsList.isEmpty()) {
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
cal.setTime(resource.getNewBillingStartDate()); cal.setTime(resourceReq.getNewBillingStartDate());
cal.add(Calendar.DAY_OF_MONTH, -1); cal.add(Calendar.DAY_OF_MONTH, -1);
Billing preBillingDetails = bDetailsList.get(0); Billing preBillingDetails = bDetailsList.get(0);
if (preBillingDetails.getBillingStartDate().getDate() == resource.getNewBillingStartDate() if (preBillingDetails.getBillingStartDate().getDate() == resourceReq.getNewBillingStartDate()
.getDate()) { .getDate()) {
preBillingDetails.setBillingEndDate( preBillingDetails.setBillingEndDate(
DateUtils.truncate(resource.getNewBillingStartDate(), Calendar.DATE)); DateUtils.truncate(resourceReq.getNewBillingStartDate(), Calendar.DATE));
} else { } else {
preBillingDetails.setBillingEndDate(DateUtils.truncate(cal.getTime(), Calendar.DATE)); preBillingDetails.setBillingEndDate(DateUtils.truncate(cal.getTime(), Calendar.DATE));
} }
...@@ -273,46 +282,46 @@ public class ResourceService implements IResourceService { ...@@ -273,46 +282,46 @@ public class ResourceService implements IResourceService {
if (listBD != null && !listBD.isEmpty()) { if (listBD != null && !listBD.isEmpty()) {
Billing billingDetails = listBD.get(0); Billing billingDetails = listBD.get(0);
billingDetails billingDetails
.setBillingStartDate(DateUtils.truncate(resource.getNewBillingStartDate(), Calendar.DATE)); .setBillingStartDate(DateUtils.truncate(resourceReq.getNewBillingStartDate(), Calendar.DATE));
billingDetails.setBillingEndDate(DateUtils.truncate(resEndDate, Calendar.DATE)); billingDetails.setBillingEndDate(DateUtils.truncate(resEndDate, Calendar.DATE));
billingService.addBilling(billingDetails, loginEmpId); billingService.addBilling(billingDetails, loginEmpId);
} }
existingTeammate existingResource
.setNewBillingStartDate(DateUtils.truncate(resource.getNewBillingStartDate(), Calendar.DATE)); .setNewBillingStartDate(DateUtils.truncate(resourceReq.getNewBillingStartDate(), Calendar.DATE));
} }
if (resEndDate.compareTo(existingTeammate.getEndDate()) != 0) { if (resEndDate.compareTo(existingResource.getEndDate()) != 0) {
existingTeammate.setEndDate(resEndDate); existingResource.setEndDate(resEndDate);
} }
} }
if (MyTeamResultDTO.SUCCESS_CODE.equals(myResultDto.getResultCode())) { if (MyTeamResultDTO.SUCCESS_CODE.equals(myResultDto.getResultCode())) {
// Handling Role change // Handling Role change
if ((existingTeammate.getRole() != null && !existingTeammate.getRole().equalsIgnoreCase(resource.getRole())) if ((existingResource.getRole() != null && !existingResource.getRole().equalsIgnoreCase(resourceReq.getRole()))
|| (resource.getRole() != null) || (resourceReq.getRole() != null)
&& !resource.getRole().equalsIgnoreCase(existingTeammate.getRole())) { && !resourceReq.getRole().equalsIgnoreCase(existingResource.getRole())) {
existingTeammate.setRole(resource.getRole()); existingResource.setRole(resourceReq.getRole());
addOrUpdateTeamMateRole(resource.getRole(), resource.getProjectId(), resource.getEmployeeId(), true, addOrUpdateTeamMateRole(resourceReq.getRole(), resourceReq.getProjectId(), resourceReq.getEmployeeId(), true,
loginEmpId); loginEmpId);
} }
// Handling Shift change // Handling Shift change
if ((existingTeammate.getShift() != null if ((existingResource.getShift() != null
&& !existingTeammate.getShift().equalsIgnoreCase(resource.getShift())) && !existingResource.getShift().equalsIgnoreCase(resourceReq.getShift()))
|| (resource.getShift() != null) || (resourceReq.getShift() != null)
&& !resource.getShift().equalsIgnoreCase(existingTeammate.getShift())) { && !resourceReq.getShift().equalsIgnoreCase(existingResource.getShift())) {
empShiftService.updateEmployeeShift(existingTeammate, loginEmpId); empShiftService.updateEmployeeShift(existingResource, loginEmpId);
existingTeammate.setShift(resource.getShift()); existingResource.setShift(resourceReq.getShift());
Employee employeeDB = employeeRoleRepo.findByEmployeeId(resource.getEmployeeId()); Employee employeeDB = employeeRoleRepo.findByEmployeeId(resourceReq.getEmployeeId());
employeeDB.setShift(resource.getShift()); employeeDB.setShift(resourceReq.getShift());
employeeDB.setModifiedBy(loginEmpId); employeeDB.setModifiedBy(loginEmpId);
employeeDB.setLastModifiedOn(new Date()); employeeDB.setLastModifiedOn(new Date());
employeeRoleRepo.save(employeeDB); employeeRoleRepo.save(employeeDB);
} }
existingTeammate.setAuditFields(loginEmpId, MyTeamUtils.UPDATE);// Setting existingResource.setAuditFields(loginEmpId, MyTeamUtils.UPDATE);// Setting
// audit // audit
// fields // fields
resourceRepo.save(existingTeammate); resourceRepo.save(existingResource);
} }
return myResultDto.getResultData()[myResultDto.getDataArrayCounter()]; return myResultDto.getResultData()[myResultDto.getDataArrayCounter()];
} }
......
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