Commit 9f0e55f0 authored by Md Suleman's avatar Md Suleman

Added deleting functionality for future allocation

parent 18cfe357
......@@ -101,7 +101,7 @@ public class ResourceController {
public ResponseEntity<?> deleteResource(@RequestBody Resource resourceReq,
@RequestParam(value = "loginEmpId", required = true) String loginEmpId, HttpServletRequest request) throws MyTeamException {
if (StringUtils.isNotBlank(loginEmpId)) {
resourceService.deleteResource(resourceReq, loginEmpId);
resourceService.deleteAndUpdateAllocation(resourceReq, loginEmpId);
ResponseDetails createResponseDetails = new ResponseDetails(new Date(), 601, "Resource has been deleted",
"Resource description", null, request.getContextPath(), "Resource details", resourceReq);
......
......@@ -75,15 +75,9 @@ public class ResourceService implements IResourceService {
Resource resourcePers = null;
if(prevAllocation != null){
// Resource projectPrevAllocation = this.getLatestAllocation(resourceAllocationList.stream().
// filter(r -> !r.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)).collect(Collectors.toList()));
// projectPrevAllocation.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate()));
// updateExistedResource(projectPrevAllocation);
// prevAllocation.setBillingStartDate(MyTeamDateUtils.getDayMoreThanDate(resourceReq.getBillingEndDate()));
prevAllocation.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate()));
updateExistedResource(prevAllocation); //updateLatestProjectAllocationToEnd
resourcePers = resourceRepo.save(resourceReq); //createNewProjectAllocationtoStart
this.updateExistedResource(prevAllocation); //updateLatestProjectAllocationToEnd
resourcePers = resourceRepo.save(resourceReq); //createNewProjectAllocationtoStart
}
return resourcePers;
}
......@@ -133,7 +127,7 @@ public class ResourceService implements IResourceService {
Resource resource = resourceRepo.findById(resourceReq.getId());
if (resource != null) {
if(resourceReq.getStatus().equalsIgnoreCase(MyTeamUtils.Engaged_STATUS)){
if(!resourceReq.getStatus().equalsIgnoreCase(MyTeamUtils.RELEASED_STATUS)){
Resource latestAllocation = this.getLatestAllocation(resourceRepo.findByEmployeeId(resourceReq.getEmployeeId()));
if(latestAllocation!=null && !latestAllocation.getProjectId().equalsIgnoreCase(resourceReq.getProjectId())&&
......@@ -327,9 +321,18 @@ public class ResourceService implements IResourceService {
public void deleteResource(Resource resourceReq, String loginEmpId) {
List<Resource> resourcesList = resourceRepo.findByEmployeeIdAndProjectId(resourceReq.getEmployeeId(), resourceReq.getProjectId());
resourcesList.forEach(resource -> resourceRepo.delete(resource));
resourceRepo.delete(resourceReq);
}
public void deleteAndUpdateAllocation(Resource resourceReq,String loginEmpId){
List<Resource> empAllAllocations = resourceRepo.findByEmployeeId(resourceReq.getEmployeeId());
Resource latestAllocation = this.getLatestAllocation(empAllAllocations.stream().filter(r -> !r.getId().equals(resourceReq.getId())).collect(Collectors.toList()));
if(latestAllocation != null && latestAllocation.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)){
latestAllocation.setBillingEndDate(projectService.getProjectByProjectId(MyTeamUtils.BENCH_PROJECT_ID).getProjectEndDate());
this.updateExistedResource(latestAllocation);
this.deleteResource(resourceReq,loginEmpId);
}
}
@Override
......
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