Commit dc35fcc2 authored by Md Suleman's avatar Md Suleman

updated resource allocation service and controller

parent 743d5b79
......@@ -293,5 +293,23 @@ public class ResourceController {
}
@RequestMapping(value = "/resources/moveToOpenPool", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> moveResourceToOpenPool(@RequestBody Resource resource, @RequestParam(value = "loginEmpId") String loginEmpId, HttpServletRequest request) throws MyTeamException {
ResponseDetails responseDetails;
if (StringUtils.isNotBlank(loginEmpId)) {
Resource result= resourceService.sendResourceToOpenPool(resource,loginEmpId);
responseDetails = new ResponseDetails(new Date(), Integer.parseInt(resourceService.respMap.get("statusCode").toString()),
resourceService.respMap.get("message").toString(), "Resource description", null, request.getContextPath(),
"Resource details", result);
}
else {
responseDetails = new ResponseDetails(new Date(), 820, "Please provide the valid Employee Id",
"Employee Id is not valid", null, request.getRequestURI(), "Resource details", resource);
}
return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
}
}
......@@ -23,6 +23,7 @@ public class ResourceVO {
private String emailId;
private String projectId;
private String projectName;
private String status;
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
private String billableStatus;
......
......@@ -71,43 +71,21 @@ public class ResourceService implements IResourceService {
public Resource addResource(Resource resourceReq, String loginEmpId) throws MyTeamException {
List<Resource> resourceAllocationList = resourceRepo.findByEmployeeId(resourceReq.getEmployeeId());
Resource prevAllocation = this.getLatestAllocation(resourceAllocationList);
Resource prevAllocation = getLatestAllocation(resourceAllocationList.stream().filter(r -> isAllocationActiveToday(r)).collect(Collectors.toList()));
Resource resourcePers = null;
if(prevAllocation != null){
if(prevAllocation.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID) &&
prevAllocation.getBillingStartDate().compareTo(employeeService.getEmployeeById(prevAllocation.getEmployeeId()).getDateOfJoining()) != 0){
Resource projectPrevAllocation = this.getLatestAllocation(resourceAllocationList.stream().
filter(r -> !r.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)).collect(Collectors.toList()));
projectPrevAllocation.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate()));
updateExistedResource(projectPrevAllocation);
prevAllocation.setBillingStartDate(MyTeamDateUtils.getDayMoreThanDate(resourceReq.getBillingEndDate()));
updateExistedResource(prevAllocation);
}else {
prevAllocation.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate()));
updateExistedResource(prevAllocation);
}
// Resource projectPrevAllocation = this.getLatestAllocation(resourceAllocationList.stream().
// filter(r -> !r.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)).collect(Collectors.toList()));
// projectPrevAllocation.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate()));
// updateExistedResource(projectPrevAllocation);
// prevAllocation.setBillingStartDate(MyTeamDateUtils.getDayMoreThanDate(resourceReq.getBillingEndDate()));
prevAllocation.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate()));
updateExistedResource(prevAllocation); //updateLatestProjectAllocationToEnd
resourcePers = resourceRepo.save(resourceReq); //createNewProjectAllocationtoStart
}
// List<Resource> resourceAllocList = resourceRepo.findByEmployeeIdAndProjectId(resourceReq.getEmployeeId(), resourceReq.getProjectId());
//
// Resource prevAllocation = this.getLatestAllocation(resourceAllocList);
// if (prevAllocation != null) {
// if (prevAllocation.getBillingEndDate().compareTo(new Date()) == 0) {
// prevAllocation.setBillingEndDate(new Date());
// } else {
// prevAllocation.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate())); //adding resource.
// }
// this.updateExistedResource(prevAllocation);
// } else {
// List<Resource> resourceAllocationList = resourceRepo.findByEmployeeId(resourceReq.getEmployeeId());
// if (!resourceAllocationList.isEmpty()) {
// Resource resourceBench = resourceAllocationList.get(0);
// resourceBench.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate()));
// resourceRepo.save(resourceBench);
// }
// }
return resourceRepo.save(resourceReq);
return resourcePers;
}
public boolean isResourceExistsForProject(String employeeId, String projectId) {
......@@ -154,24 +132,29 @@ public class ResourceService implements IResourceService {
// }
Resource resource = resourceRepo.findById(resourceReq.getId());
if (resource != null) {
this.updateExistedResource(resourceReq);
Resource latestAllocation = this.getLatestAllocation(resourceRepo.findByEmployeeId(resourceReq.getEmployeeId()));
if(latestAllocation != null && latestAllocation.getId().equals(resourceReq.getId()) &&
!latestAllocation.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)){
Resource resourceBench = new Resource();
resourceBench.setProjectId(MyTeamUtils.BENCH_PROJECT_ID);
resourceBench.setEmployeeId(resourceReq.getEmployeeId());
resourceBench.setResourceRole(resourceReq.getResourceRole());
resourceBench.setBillingStartDate(MyTeamDateUtils.getDayMoreThanDate(resourceReq.getBillingEndDate()));
resourceBench.setBillingEndDate(projectService.getProjectByProjectId(MyTeamUtils.BENCH_PROJECT_ID).getProjectEndDate());
resourceBench.setBillableStatus(MyTeamUtils.BENCH_BILLABILITY_STATUS);
resourceBench.setAuditFields(loginEmpId, MyTeamUtils.CREATE);
resourceRepo.save(resourceBench);
}else if(latestAllocation != null && latestAllocation.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)){
latestAllocation.setBillingStartDate(MyTeamDateUtils.getDayMoreThanDate(resourceReq.getBillingEndDate()));
updateExistedResource(latestAllocation);
if(resourceReq.getStatus().equalsIgnoreCase(MyTeamUtils.Engaged_STATUS)){
if(resourceReq.getBillingEndDate().compareTo(new Date())<0){
resourceReq.setStatus(MyTeamUtils.RELEASED_STATUS);//update Status of allocation
Resource resourceBench = new Resource();
resourceBench.setProjectId(MyTeamUtils.BENCH_PROJECT_ID);
resourceBench.setEmployeeId(resourceReq.getEmployeeId());
resourceBench.setResourceRole(resourceReq.getResourceRole());
resourceBench.setStatus(MyTeamUtils.RELEASED_STATUS);//add alocation status as Released
resourceBench.setBillingStartDate(MyTeamDateUtils.getDayMoreThanDate(resourceReq.getBillingEndDate()));
resourceBench.setBillingEndDate(projectService.getProjectByProjectId(MyTeamUtils.BENCH_PROJECT_ID).getProjectEndDate());
resourceBench.setBillableStatus(MyTeamUtils.BENCH_BILLABILITY_STATUS);
resourceBench.setAuditFields(loginEmpId, MyTeamUtils.CREATE);
resourceRepo.save(resourceBench);
}
this.updateExistedResource(resourceReq);
}else{
respMap.put("statusCode", 801);
respMap.put("message", "Resource is already released from you, And you can't update this allocation");
//>>>>>>> Stashed changes
}
} else {
respMap.put("statusCode", 801);
respMap.put("message", "Record Not Found");
......@@ -274,33 +257,68 @@ public class ResourceService implements IResourceService {
}
public boolean isResourceAssignedToAnyProject(Resource resourceReq) {
public boolean isResourceAvailable(Resource resourceReq) {
boolean isAssigned = false;
boolean isAssigned = true;
String message = "";
//List<Resource> resourceAllocList = resourceRepo.findByEmployeeIdAndProjectId(resourceAllocReq.getEmployeeId(), resourceAllocReq.getProjectId());
List<Resource> resourceAllocList = resourceRepo.findByEmployeeId(resourceReq.getEmployeeId());
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()));
// resourceAllocList.stream().filter(resource -> resource.getBillingEndDate().compareTo(new Date()) >= 0).collect(Collectors.toList());
if (resourceLatestRecord != null &&
resourceLatestRecord.getBillableStatus().equalsIgnoreCase(MyTeamUtils.BILLABLE_TEXT) ) {
if(!resourceLatestRecord.getProjectId().equalsIgnoreCase(resourceReq.getProjectId())){
message = "Resource " + resourceLatestRecord.getEmployeeId() + " already Assigned to the "
+ projectService.getProjectByProjectId(resourceLatestRecord.getProjectId()).getProjectName()
+ " Project" + " from " + resourceLatestRecord.getBillingStartDate() + "to " + resourceLatestRecord.getBillingEndDate();
isAssigned = true;
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;
}
public boolean validateResourceBillingEndDateAgainstBench(Resource resourceReq){
boolean isValid = true;
String message = "";
List<Resource> resourceAllocList = resourceRepo.findByEmployeeIdAndProjectId(resourceReq.getEmployeeId(),MyTeamUtils.BENCH_PROJECT_ID);
Resource resourceBenchLatestRecord = getLatestAllocation(resourceAllocList.stream().
filter(r -> r.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)).collect(Collectors.toList()));
if(!isAllocationActiveToday(resourceBenchLatestRecord)){
isValid = false;
message = "Resource is not available for allocation";
}else if(!(resourceReq.getBillingEndDate().before(resourceBenchLatestRecord.getBillingEndDate()) &&
resourceReq.getBillingStartDate().after(resourceBenchLatestRecord.getBillingStartDate()))){
message = "Resource is available from "+resourceBenchLatestRecord.getBillingStartDate()+" to "+resourceBenchLatestRecord.getBillingEndDate();
isValid = false;
}
respMap.put("statusCode", 810);
respMap.put("message", message);
return isValid;
}
public boolean isAllocationActiveToday(Resource resource){
boolean isActive = true;
if(resource.getBillingStartDate().compareTo(new Date()) <=0 &&
resource.getBillingEndDate().compareTo(new Date())>=0){
isActive = true;
}else{
isActive = false;
}
return isActive;
}
public void deleteResource(Resource resourceReq, String loginEmpId) {
List<Resource> resourcesList = resourceRepo.findByEmployeeIdAndProjectId(resourceReq.getEmployeeId(), resourceReq.getProjectId());
......@@ -315,13 +333,14 @@ public class ResourceService implements IResourceService {
public List<ResourceVO> getAllResourcesVO() {
return getAllResources().stream().map(resource -> {
ResourceVO resourceVO = new ResourceVO();
resourceVO.setId(resource.getId());
resourceVO.setProjectId(resource.getProjectId());
resourceVO.setEmployeeId(resource.getEmployeeId());
resourceVO.setStatus(resource.getStatus());
Employee employee = employeeService.getEmployeeById(resource.getEmployeeId());
if (employee != null) {
......@@ -397,6 +416,7 @@ public class ResourceService implements IResourceService {
resourceVO.setId(resource.getId());
resourceVO.setProjectId(resource.getProjectId());
resourceVO.setEmployeeId(resource.getEmployeeId());
resourceVO.setStatus(resource.getStatus());
employee = employeeService.getEmployeeById(resource.getEmployeeId());
resourceVO.setEmployeeName(employee.getEmployeeName());
......@@ -455,6 +475,7 @@ public class ResourceService implements IResourceService {
resourceVO.setBillingEndDate(resource.getBillingEndDate());
resourceVO.setBillableStatus(resource.getBillableStatus());
resourceVO.setEmployeeId(resource.getEmployeeId());
resourceVO.setStatus(resource.getStatus());
Employee employee = employeeService.getEmployeeById(resource.getEmployeeId());
resourceVO.setEmailId(employee.getEmailId());
......@@ -614,6 +635,7 @@ public class ResourceService implements IResourceService {
resourceVO.setId(resource.getId());
resourceVO.setProjectId(resource.getProjectId());
resourceVO.setEmployeeId(resource.getEmployeeId());
resourceVO.setStatus(resource.getStatus());
Employee employee = employeeService.getEmployeeById(resource.getEmployeeId());
if (employee != null) {
......@@ -665,6 +687,7 @@ public class ResourceService implements IResourceService {
resourceBench.setProjectId(MyTeamUtils.BENCH_PROJECT_ID);
resourceBench.setEmployeeId(employee.getEmployeeId());
resourceBench.setResourceRole(employee.getRole());
resourceBench.setStatus(MyTeamUtils.RELEASED_STATUS);
resourceBench.setBillingStartDate(employee.getDateOfJoining() != null ? employee.getDateOfJoining() : new Date());
resourceBench.setBillableStatus(MyTeamUtils.BENCH_BILLABILITY_STATUS);
resourceBench.setEmployeeId(employee.getEmployeeId());
......
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