Commit 88dd77ec authored by Md Suleman's avatar Md Suleman

Updated validation for adding new allocation and corrected previos logic

parent 2c553eb6
...@@ -50,6 +50,7 @@ public class ResourceController { ...@@ -50,6 +50,7 @@ public class ResourceController {
if (resourceService.validateBillingStartEndDateAgainstProjectStartEndDate(resourceAllocationReq, loginEmpId)) { if (resourceService.validateBillingStartEndDateAgainstProjectStartEndDate(resourceAllocationReq, loginEmpId)) {
if (resourceService.validateBillingStartDateAgainstDOJ(resourceAllocationReq)) { if (resourceService.validateBillingStartDateAgainstDOJ(resourceAllocationReq)) {
if (!resourceService.isResourceAssignedToAnyProject(resourceAllocationReq)) { if (!resourceService.isResourceAssignedToAnyProject(resourceAllocationReq)) {
if(resourceService.validateAllocationAgainstPrevAllocation(resourceAllocationReq)) {
Resource resourcePersisted = resourceService.addResource(resourceAllocationReq, loginEmpId); Resource resourcePersisted = resourceService.addResource(resourceAllocationReq, loginEmpId);
ResponseDetails createResponseDetails = new ResponseDetails(new Date(), 800, "Resource has been created", ResponseDetails createResponseDetails = new ResponseDetails(new Date(), 800, "Resource has been created",
...@@ -58,6 +59,7 @@ public class ResourceController { ...@@ -58,6 +59,7 @@ public class ResourceController {
} }
} }
} }
}
ResponseDetails responseDetails = new ResponseDetails(new Date(), Integer.parseInt(resourceService.respMap.get("statusCode").toString()), resourceService.respMap.get("message").toString(), ResponseDetails responseDetails = new ResponseDetails(new Date(), Integer.parseInt(resourceService.respMap.get("statusCode").toString()), resourceService.respMap.get("message").toString(),
"Error message desc", null, request.getRequestURI(), "Resource details", resourceAllocationReq); "Error message desc", null, request.getRequestURI(), "Resource details", resourceAllocationReq);
......
...@@ -50,19 +50,26 @@ public class ResourceService implements IResourceService { ...@@ -50,19 +50,26 @@ public class ResourceService implements IResourceService {
public HashMap<String, Object> respMap = new HashMap<>(); public HashMap<String, Object> respMap = new HashMap<>();
private Resource getLatestAllocation(List<Resource> resourceAllocList){
Resource latestAlloc = resourceAllocList.get(0);
for (Resource resource:resourceAllocList){
if(latestAlloc.getBillingEndDate().before(resource.getBillingEndDate()))
latestAlloc = resource;
}
return latestAlloc;
}
public Resource addResource(Resource resourceReq, String loginEmpId) throws MyTeamException { public Resource addResource(Resource resourceReq, String loginEmpId) throws MyTeamException {
List<Resource> resourceAllocList = resourceRepo.findByEmployeeIdAndProjectId(resourceReq.getEmployeeId(), resourceReq.getProjectId()); List<Resource> resourceAllocList = resourceRepo.findByEmployeeIdAndProjectId(resourceReq.getEmployeeId(), resourceReq.getProjectId());
// //
List<Resource> resourceListWithLatestRecord = resourceAllocList.stream().filter(res -> res.getBillingEndDate().compareTo(new Date()) >= 0).collect(Collectors.toList()); Resource prevAllocation = this.getLatestAllocation(resourceAllocList);
if (resourceListWithLatestRecord != null && resourceListWithLatestRecord.size() > 0) { if (prevAllocation != null) {
Resource resourcePrev = resourceListWithLatestRecord.get(0); if (prevAllocation.getBillingEndDate().compareTo(new Date()) == 0) {
if (resourcePrev.getBillingEndDate().compareTo(new Date()) == 0) { prevAllocation.setBillingEndDate(new Date());
resourcePrev.setBillingEndDate(new Date());
} else { } else {
resourcePrev.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate())); //adding resource. prevAllocation.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate())); //adding resource.
} }
this.updateExistedResource(resourcePrev); this.updateExistedResource(prevAllocation);
} }
return resourceRepo.save(resourceReq); return resourceRepo.save(resourceReq);
} }
...@@ -142,7 +149,24 @@ public class ResourceService implements IResourceService { ...@@ -142,7 +149,24 @@ public class ResourceService implements IResourceService {
respMap.put("resourceObj", resourcePers); respMap.put("resourceObj", resourcePers);
} }
public boolean validateAllocationAgainstPrevAllocation(Resource resourceReq){
boolean isValid = true;
List<Resource> resourceAllocList = resourceRepo.findByEmployeeIdAndProjectId(resourceReq.getEmployeeId(), resourceReq.getProjectId());
Resource prevAllocation = this.getLatestAllocation(resourceAllocList);
if (prevAllocation != null) {
if(!prevAllocation.getBillingStartDate().before(resourceReq.getBillingStartDate())){
respMap.put("statusCode", 811);
respMap.put("message", "Billing start date should be after previous allocation start date");
isValid = false;
}
if(prevAllocation.getBillableStatus().equalsIgnoreCase(resourceReq.getBillableStatus())){
respMap.put("statusCode", 811);
respMap.put("message", "Resource is already in "+prevAllocation.getBillableStatus()+" status only");
isValid = false;
}
}
return isValid;
}
public boolean validateBillingStartEndDateAgainstProjectStartEndDate(Resource resource, String loginEmpId) throws MyTeamException { public boolean validateBillingStartEndDateAgainstProjectStartEndDate(Resource resource, String loginEmpId) throws MyTeamException {
boolean isValid = true; boolean isValid = true;
...@@ -209,7 +233,7 @@ public class ResourceService implements IResourceService { ...@@ -209,7 +233,7 @@ public class ResourceService implements IResourceService {
if (resourceListWithLatestRecord != null && resourceListWithLatestRecord.size() > 0) { if (resourceListWithLatestRecord != null && resourceListWithLatestRecord.size() > 0) {
Resource resourcePrev = resourceListWithLatestRecord.get(0);//latest resource record. Resource resourcePrev = resourceListWithLatestRecord.get(0);//latest resource record.
if (!resourcePrev.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)) { if (!resourcePrev.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID) && !resourceReq.getProjectId().equalsIgnoreCase(resourcePrev.getProjectId())) {
message = "Resource " + resourcePrev.getEmployeeId() + " already Assigned to the " message = "Resource " + resourcePrev.getEmployeeId() + " already Assigned to the "
+ projectService.getProjectByProjectId(resourcePrev.getProjectId()).getProjectName() + projectService.getProjectByProjectId(resourcePrev.getProjectId()).getProjectName()
+ " Project" + " from " + resourcePrev.getBillingStartDate() + "to " + resourcePrev.getBillingEndDate(); + " Project" + " from " + resourcePrev.getBillingStartDate() + "to " + resourcePrev.getBillingEndDate();
......
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