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 {
public Resource addResource(Resource resourceReq, String loginEmpId) throws MyTeamException {
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;
if(prevAllocation != null){
prevAllocation.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate()));
this.updateExistedResource(prevAllocation); //updateLatestProjectAllocationToEnd
if(currentAllocation != null && currentAllocation.getProjectId().equals(MyTeamUtils.BENCH_PROJECT_ID)){
currentAllocation.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate()));
this.updateExistedResource(currentAllocation); //updateLatestProjectAllocationToEnd
resourcePers = resourceRepo.save(resourceReq); //createNewProjectAllocationtoStart
}else if(isAllocationActiveToday(resourceReq)){
//resource is not yet released from latest project
}else{
resourcePers = resourceRepo.save(resourceReq);
}
return resourcePers;
}
......@@ -189,9 +194,9 @@ public class ResourceService implements IResourceService {
List<Resource> resourceAllocList = resourceRepo.findByEmployeeIdAndProjectId(resourceReq.getEmployeeId(), resourceReq.getProjectId());
Resource prevAllocation = this.getLatestAllocation(resourceAllocList);
if (prevAllocation != null) {
if (!prevAllocation.getBillingStartDate().before(resourceReq.getBillingStartDate())) {
if (!prevAllocation.getBillingEndDate().before(resourceReq.getBillingStartDate())) {
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;
}
if (prevAllocation.getBillableStatus().equalsIgnoreCase(resourceReq.getBillableStatus())) {
......@@ -256,32 +261,66 @@ public class ResourceService implements IResourceService {
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) {
boolean isAssigned = true;
String message = "";
List<Resource> resourceAllocList = resourceRepo.findByEmployeeId(resourceReq.getEmployeeId()); //getting all allocations of employee
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;
}
Resource latestAllocation = getLatestAllocation(resourceAllocList);
if(latestAllocation != null && !latestAllocation.getProjectId().equals(MyTeamUtils.BENCH_PROJECT_ID) &&
latestAllocation.getBillingStartDate().compareTo(new Date())>0){
isAssigned = false;
Project project = projectService.getProjectByProjectId(latestAllocation.getProjectId());
message = "resource is already reserved in "+project.getProjectName()+" project from "+latestAllocation.getBillingStartDate()+" to "+latestAllocation.getBillingEndDate();
}else if(!isDatesAvailableForAllocation(resourceReq)){
message = respMap.get("message").toString();
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;
}
......
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