Commit 532a5f5e authored by Md Suleman's avatar Md Suleman

changed validations for adding resource to the project

parent c6881717
...@@ -71,13 +71,18 @@ public class ResourceService implements IResourceService { ...@@ -71,13 +71,18 @@ public class ResourceService implements IResourceService {
public Resource addResource(Resource resourceReq, String loginEmpId) throws MyTeamException { public Resource addResource(Resource resourceReq, String loginEmpId) throws MyTeamException {
List<Resource> resourceAllocationList = resourceRepo.findByEmployeeId(resourceReq.getEmployeeId()); List<Resource> resourceAllocationList = resourceRepo.findByEmployeeId(resourceReq.getEmployeeId());
Resource prevAllocation = getLatestAllocation(resourceAllocationList.stream().filter(r -> isAllocationActiveToday(r)).collect(Collectors.toList())); Resource currentAllocation = getCurrentAllocationIfNotReturnNull(resourceReq.getEmployeeId());
Resource latestAllocationn = getLatestAllocation(resourceAllocationList);
Resource resourcePers = null; Resource resourcePers = null;
if(prevAllocation != null){ if(currentAllocation != null && currentAllocation.getProjectId().equals(MyTeamUtils.BENCH_PROJECT_ID)){
prevAllocation.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate())); currentAllocation.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate()));
this.updateExistedResource(prevAllocation); //updateLatestProjectAllocationToEnd this.updateExistedResource(currentAllocation); //updateLatestProjectAllocationToEnd
resourcePers = resourceRepo.save(resourceReq); //createNewProjectAllocationtoStart resourcePers = resourceRepo.save(resourceReq); //createNewProjectAllocationtoStart
}else if(isAllocationActiveToday(resourceReq)){
//resource is not yet released from latest project
}else{
resourcePers = resourceRepo.save(resourceReq);
} }
return resourcePers; return resourcePers;
} }
...@@ -189,9 +194,9 @@ public class ResourceService implements IResourceService { ...@@ -189,9 +194,9 @@ public class ResourceService implements IResourceService {
List<Resource> resourceAllocList = resourceRepo.findByEmployeeIdAndProjectId(resourceReq.getEmployeeId(), resourceReq.getProjectId()); List<Resource> resourceAllocList = resourceRepo.findByEmployeeIdAndProjectId(resourceReq.getEmployeeId(), resourceReq.getProjectId());
Resource prevAllocation = this.getLatestAllocation(resourceAllocList); Resource prevAllocation = this.getLatestAllocation(resourceAllocList);
if (prevAllocation != null) { if (prevAllocation != null) {
if (!prevAllocation.getBillingStartDate().before(resourceReq.getBillingStartDate())) { if (!prevAllocation.getBillingEndDate().before(resourceReq.getBillingStartDate())) {
respMap.put("statusCode", 811); respMap.put("statusCode", 811);
respMap.put("message", "Billing start date should be after previous allocation start date"); respMap.put("message", "Billing start date should be after previous allocation billing end date in this project");
isValid = false; isValid = false;
} }
if (prevAllocation.getBillableStatus().equalsIgnoreCase(resourceReq.getBillableStatus())) { if (prevAllocation.getBillableStatus().equalsIgnoreCase(resourceReq.getBillableStatus())) {
...@@ -256,32 +261,66 @@ public class ResourceService implements IResourceService { ...@@ -256,32 +261,66 @@ public class ResourceService implements IResourceService {
return isValid; return isValid;
} }
public boolean isDatesAvailableForAllocation(Resource resource){
String message = "";
List<Resource> allocationList = resourceRepo.findByEmployeeId(resource.getEmployeeId());
List<Resource> matchedList = allocationList.stream().filter(r -> !r.getProjectId().equals(MyTeamUtils.BENCH_PROJECT_ID) &&
(r.getBillingStartDate().compareTo(resource.getBillingStartDate())<=0 && r.getBillingEndDate().compareTo(resource.getBillingStartDate())>=0)||
(r.getBillingStartDate().compareTo(resource.getBillingEndDate())<=0 && r.getBillingEndDate().compareTo(resource.getBillingEndDate())>=0 ))
.collect(Collectors.toList());
if(!matchedList.isEmpty()){
message = "Resource is already alocated for projects:\n";
for(Resource resourcel:matchedList){
Project project = projectService.getProjectByProjectId(resourcel.getProjectId());
message += "Project:"+project.getProjectName()+" From:"+resourcel.getBillingStartDate()+" To:"+resourcel.getBillingEndDate()+"\n";
}
respMap.put("statusCode", 815);
respMap.put("message", message);
return false;
}else
return true;
}
public boolean isResourceAvailable(Resource resourceReq) { public boolean isResourceAvailable(Resource resourceReq) {
boolean isAssigned = true; boolean isAssigned = true;
String message = ""; String message = "";
List<Resource> resourceAllocList = resourceRepo.findByEmployeeId(resourceReq.getEmployeeId()); //getting all allocations of employee List<Resource> resourceAllocList = resourceRepo.findByEmployeeId(resourceReq.getEmployeeId()); //getting all allocations of employee
Resource latestAllocation = getLatestAllocation(resourceAllocList);
Resource resourceLatestRecord = getLatestAllocation(resourceAllocList.stream(). if(latestAllocation != null && !latestAllocation.getProjectId().equals(MyTeamUtils.BENCH_PROJECT_ID) &&
filter(r -> r.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)).collect(Collectors.toList())); //getting latest allocation of employee in bench project latestAllocation.getBillingStartDate().compareTo(new Date())>0){
isAssigned = false;
if (resourceLatestRecord != null && !isAllocationActiveToday(resourceLatestRecord)){ Project project = projectService.getProjectByProjectId(latestAllocation.getProjectId());
Resource latestProjectResource = getLatestAllocation(resourceAllocList.stream(). message = "resource is already reserved in "+project.getProjectName()+" project from "+latestAllocation.getBillingStartDate()+" to "+latestAllocation.getBillingEndDate();
filter(r -> !r.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)).collect(Collectors.toList()));
if(!resourceReq.getProjectId().equalsIgnoreCase(latestProjectResource.getProjectId())) { }else if(!isDatesAvailableForAllocation(resourceReq)){
message = "Resource " + latestProjectResource.getEmployeeId() + " already Assigned to the " message = respMap.get("message").toString();
+ projectService.getProjectByProjectId(latestProjectResource.getProjectId()).getProjectName() isAssigned = false;
+ " Project" + " from " + latestProjectResource.getBillingStartDate() + "to " + latestProjectResource.getBillingEndDate();
isAssigned = false;
respMap.put("statusCode", 815);
respMap.put("message", message);
}
}else{
if(!validateResourceBillingEndDateAgainstBench(resourceReq)){
isAssigned = false;
}
} }
respMap.put("statusCode", 815);
respMap.put("message", message);
// Resource resourceLatestRecord = getLatestAllocation(resourceAllocList.stream().
// filter(r -> r.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)).collect(Collectors.toList())); //getting latest allocation of employee in bench project
//
// if (resourceLatestRecord != null && !isAllocationActiveToday(resourceLatestRecord)){
// Resource latestProjectResource = getLatestAllocation(resourceAllocList.stream().
// filter(r -> !r.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)).collect(Collectors.toList()));
// if(!resourceReq.getProjectId().equalsIgnoreCase(latestProjectResource.getProjectId())) {
// message = "Resource " + latestProjectResource.getEmployeeId() + " already Assigned to the "
// + projectService.getProjectByProjectId(latestProjectResource.getProjectId()).getProjectName()
// + " Project" + " from " + latestProjectResource.getBillingStartDate() + "to " + latestProjectResource.getBillingEndDate();
// isAssigned = false;
// respMap.put("statusCode", 815);
// respMap.put("message", message);
// }
// }else{
// if(!validateResourceBillingEndDateAgainstBench(resourceReq)){
// isAssigned = false;
// }
// }
return isAssigned; return isAssigned;
} }
......
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