Commit e623e977 authored by Md Suleman's avatar Md Suleman

changed validations for add resource and update resource

parent 01ed5ea1
...@@ -62,6 +62,13 @@ public class ResourceService implements IResourceService { ...@@ -62,6 +62,13 @@ public class ResourceService implements IResourceService {
} }
return latestAlloc; return latestAlloc;
} }
public Resource getFirstOfListOrNull(List<Resource> resourceList){
if(resourceList != null && !resourceList.isEmpty()){
return resourceList.get(0);
}else {
return null;
}
}
public List<Resource> getResourcesByEmployeeId(String employeeId) { public List<Resource> getResourcesByEmployeeId(String employeeId) {
return resourceRepo.findByEmployeeId(employeeId); return resourceRepo.findByEmployeeId(employeeId);
...@@ -72,7 +79,7 @@ public class ResourceService implements IResourceService { ...@@ -72,7 +79,7 @@ public class ResourceService implements IResourceService {
List<Resource> resourceAllocationList = resourceRepo.findByEmployeeId(resourceReq.getEmployeeId()); List<Resource> resourceAllocationList = resourceRepo.findByEmployeeId(resourceReq.getEmployeeId());
Resource currentAllocation = getCurrentAllocationIfNotReturnNull(resourceReq.getEmployeeId()); Resource currentAllocation = getCurrentAllocationIfNotReturnNull(resourceReq.getEmployeeId());
Resource latestAllocationn = getLatestAllocation(resourceAllocationList); Resource latestAllocation = getLatestAllocation(resourceAllocationList);
Resource resourcePers = null; Resource resourcePers = null;
if(currentAllocation != null && currentAllocation.getProjectId().equals(MyTeamUtils.BENCH_PROJECT_ID)){ if(currentAllocation != null && currentAllocation.getProjectId().equals(MyTeamUtils.BENCH_PROJECT_ID)){
...@@ -80,6 +87,9 @@ public class ResourceService implements IResourceService { ...@@ -80,6 +87,9 @@ public class ResourceService implements IResourceService {
this.updateExistedResource(currentAllocation); //updateLatestProjectAllocationToEnd this.updateExistedResource(currentAllocation); //updateLatestProjectAllocationToEnd
resourcePers = resourceRepo.save(resourceReq); //createNewProjectAllocationtoStart resourcePers = resourceRepo.save(resourceReq); //createNewProjectAllocationtoStart
}else if(isAllocationActiveToday(resourceReq)){ }else if(isAllocationActiveToday(resourceReq)){
Project project = projectService.getProjectByProjectId(latestAllocation.getProjectId());
respMap.put("statusCode", 811);
respMap.put("message", "resource is not yet released from " + project.getProjectName() + " project");
//resource is not yet released from latest project //resource is not yet released from latest project
}else{ }else{
resourcePers = resourceRepo.save(resourceReq); resourcePers = resourceRepo.save(resourceReq);
...@@ -132,14 +142,21 @@ public class ResourceService implements IResourceService { ...@@ -132,14 +142,21 @@ public class ResourceService implements IResourceService {
Resource resource = resourceRepo.findById(resourceReq.getId()); Resource resource = resourceRepo.findById(resourceReq.getId());
if (resource != null) { if (resource != null) {
if(!resourceReq.getStatus().equalsIgnoreCase(MyTeamUtils.STATUS_RELEASED)){ if(!resource.getStatus().equalsIgnoreCase(MyTeamUtils.STATUS_RELEASED)){
if(isDatesAvailableForAllocation(resourceReq)) { if(isDatesAvailableForAllocation(resourceReq)) {
Resource prevAllocation = getFirstOfListOrNull(resourceRepo.findByEmployeeId(resourceReq.getEmployeeId()).stream().
Resource latestBenchAlloc = getLatestAllocation(resourceRepo.findByEmployeeIdAndProjectId(resourceReq.getEmployeeId(),MyTeamUtils.BENCH_PROJECT_ID)); filter(a -> a.getBillingEndDate().compareTo(MyTeamDateUtils.getDayLessThanDate(resource.getBillingStartDate()))==0).collect(Collectors.toList()));
Resource nextAllocation = getFirstOfListOrNull(resourceRepo.findByEmployeeId(resourceReq.getEmployeeId()).stream().filter(a ->
a.getBillingStartDate().compareTo(MyTeamDateUtils.getDayMoreThanDate(resource.getBillingEndDate()))==0).collect(Collectors.toList()));
this.updateExistedResource(resourceReq); if(prevAllocation!=null && prevAllocation.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)){
prevAllocation.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate()));
this.updateExistedResource(prevAllocation);
}
if(nextAllocation != null && nextAllocation.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)){
nextAllocation.setBillingStartDate(MyTeamDateUtils.getDayMoreThanDate(resourceReq.getBillingEndDate()));
this.updateExistedResource(nextAllocation);
}
this.updateExistedResource(resourceReq);
} }
}else{ }else{
respMap.put("statusCode", 811); respMap.put("statusCode", 811);
...@@ -252,8 +269,9 @@ public class ResourceService implements IResourceService { ...@@ -252,8 +269,9 @@ public class ResourceService implements IResourceService {
List<Resource> allocationList = resourceRepo.findByEmployeeId(resource.getEmployeeId()); List<Resource> allocationList = resourceRepo.findByEmployeeId(resource.getEmployeeId());
List<Resource> matchedList = allocationList.stream().filter(r -> !r.getProjectId().equals(MyTeamUtils.BENCH_PROJECT_ID) && 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.getId().equals(resource.getId()) &&
(r.getBillingStartDate().compareTo(resource.getBillingEndDate())<=0 && r.getBillingEndDate().compareTo(resource.getBillingEndDate())>=0 )) ( (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()); .collect(Collectors.toList());
if(!matchedList.isEmpty()){ if(!matchedList.isEmpty()){
message = "Resource is already alocated for projects:\n"; message = "Resource is already alocated for projects:\n";
...@@ -275,11 +293,11 @@ public class ResourceService implements IResourceService { ...@@ -275,11 +293,11 @@ public class ResourceService implements IResourceService {
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 latestAllocation = getLatestAllocation(resourceAllocList);
if(latestAllocation != null && !latestAllocation.getProjectId().equals(MyTeamUtils.BENCH_PROJECT_ID) && if(latestAllocation != null && !isAllocationActiveToday(resourceReq) && !latestAllocation.getProjectId().equals(MyTeamUtils.BENCH_PROJECT_ID) &&
latestAllocation.getBillingStartDate().compareTo(new Date())>0){ latestAllocation.getBillingStartDate().compareTo(new Date())>0){
isAssigned = false; isAssigned = false;
Project project = projectService.getProjectByProjectId(latestAllocation.getProjectId()); Project project = projectService.getProjectByProjectId(latestAllocation.getProjectId());
message = "resource is already reserved in "+project.getProjectName()+" project from "+latestAllocation.getBillingStartDate()+" to "+latestAllocation.getBillingEndDate(); message = "Resource is already reserved in "+project.getProjectName()+" project from "+latestAllocation.getBillingStartDate()+" to "+latestAllocation.getBillingEndDate();
}else if(!isDatesAvailableForAllocation(resourceReq)){ }else if(!isDatesAvailableForAllocation(resourceReq)){
message = respMap.get("message").toString(); message = respMap.get("message").toString();
......
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