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

Updated validation for adding new allocation and corrected previos logic

parent 2c553eb6
......@@ -50,11 +50,13 @@ public class ResourceController {
if (resourceService.validateBillingStartEndDateAgainstProjectStartEndDate(resourceAllocationReq, loginEmpId)) {
if (resourceService.validateBillingStartDateAgainstDOJ(resourceAllocationReq)) {
if (!resourceService.isResourceAssignedToAnyProject(resourceAllocationReq)) {
if(resourceService.validateAllocationAgainstPrevAllocation(resourceAllocationReq)) {
Resource resourcePersisted = resourceService.addResource(resourceAllocationReq, loginEmpId);
ResponseDetails createResponseDetails = new ResponseDetails(new Date(), 800, "Resource has been created",
"Resource description", null, request.getContextPath(), "details", resourcePersisted);
return new ResponseEntity<ResponseDetails>(createResponseDetails, HttpStatus.OK);
}
}
}
}
......
......@@ -50,19 +50,26 @@ public class ResourceService implements IResourceService {
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 {
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());
if (resourceListWithLatestRecord != null && resourceListWithLatestRecord.size() > 0) {
Resource resourcePrev = resourceListWithLatestRecord.get(0);
if (resourcePrev.getBillingEndDate().compareTo(new Date()) == 0) {
resourcePrev.setBillingEndDate(new Date());
Resource prevAllocation = this.getLatestAllocation(resourceAllocList);
if (prevAllocation != null) {
if (prevAllocation.getBillingEndDate().compareTo(new Date()) == 0) {
prevAllocation.setBillingEndDate(new Date());
} 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);
}
......@@ -142,7 +149,24 @@ public class ResourceService implements IResourceService {
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 {
boolean isValid = true;
......@@ -209,7 +233,7 @@ public class ResourceService implements IResourceService {
if (resourceListWithLatestRecord != null && resourceListWithLatestRecord.size() > 0) {
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 "
+ projectService.getProjectByProjectId(resourcePrev.getProjectId()).getProjectName()
+ " 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