Commit fc54bb12 authored by Md Suleman's avatar Md Suleman

Updated_Resourse_Allocation(Add_And_Update)

parent 2f30a641
...@@ -50,7 +50,6 @@ public class ResourceController { ...@@ -50,7 +50,6 @@ 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.isResourceExistsForProject(resourceAllocationReq.getEmployeeId(),resourceAllocationReq.getProjectId())) {
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",
...@@ -59,7 +58,6 @@ public class ResourceController { ...@@ -59,7 +58,6 @@ 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,9 +50,21 @@ public class ResourceService implements IResourceService { ...@@ -50,9 +50,21 @@ public class ResourceService implements IResourceService {
public HashMap<String, Object> respMap = new HashMap<>(); public HashMap<String, Object> respMap = new HashMap<>();
public Resource addResource(Resource resource, String loginEmpId) throws MyTeamException { public Resource addResource(Resource resourceReq, String loginEmpId) throws MyTeamException {
return resourceRepo.save(resource); 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());
} else {
resourcePrev.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate())); //adding resource.
}
this.updateExistedResource(resourcePrev);
}
return resourceRepo.save(resourceReq);
} }
public boolean isResourceExistsForProject(String employeeId, String projectId) { public boolean isResourceExistsForProject(String employeeId, String projectId) {
...@@ -74,30 +86,37 @@ public class ResourceService implements IResourceService { ...@@ -74,30 +86,37 @@ public class ResourceService implements IResourceService {
public void updateResourceDetails(Resource resourceReq, String loginEmpId) throws MyTeamException { public void updateResourceDetails(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(resource -> resource.getBillingEndDate().compareTo(new Date()) >= 0).collect(Collectors.toList()); // List<Resource> resourceListWithLatestRecord = resourceAllocList.stream().filter(resource -> resource.getBillingEndDate().compareTo(new Date()) >= 0).collect(Collectors.toList());
//
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.
log.info("Requsting Resource Allocation BillingStart Date::::"+resourceReq.getBillingStartDate()); // log.info("Requsting Resource Allocation BillingStart Date::::"+resourceReq.getBillingStartDate());
log.info("The before date is::" + MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate())); // log.info("The before date is::" + MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate()));
if(!resourcePrev.getBillableStatus().equals(resourceReq.getBillableStatus())) { // if(!resourcePrev.getBillableStatus().equals(resourceReq.getBillableStatus())) {
if (resourcePrev.getBillingEndDate().compareTo(new Date()) == 0) { // if (resourcePrev.getBillingEndDate().compareTo(new Date()) == 0) {
resourcePrev.setBillingEndDate(new Date()); // resourcePrev.setBillingEndDate(new Date());
} else { // } else {
resourcePrev.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate())); //adding resource. // resourcePrev.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate())); //adding resource.
} // }
insertNewResourceWithNewStatus(resourceReq,loginEmpId); // insertNewResourceWithNewStatus(resourceReq,loginEmpId);
// }else {
// resourcePrev.setResourceRole(resourceReq.getResourceRole());
// resourcePrev.setBillingStartDate(resourceReq.getBillingStartDate());
// resourcePrev.setBillingEndDate(resourceReq.getBillingEndDate());
// //resourceAllocPrev.setBillingEndDate(); //adding resource.
// }
// log.info("After setting the date:::before saving the Resource::" + resourcePrev);
// this.updateExistedResource(resourcePrev);
// }
Resource resource = resourceRepo.findById(resourceReq.getId());
if(resource!=null){
this.updateExistedResource(resourceReq);
}else { }else {
resourcePrev.setResourceRole(resourceReq.getResourceRole()); respMap.put("statusCode", 801);
resourcePrev.setBillingStartDate(resourceReq.getBillingStartDate()); respMap.put("message", "Record Not Found");
resourcePrev.setBillingEndDate(resourceReq.getBillingEndDate());
//resourceAllocPrev.setBillingEndDate(); //adding resource.
}
log.info("After setting the date:::before saving the Resource::" + resourcePrev);
this.updateExistedResource(resourcePrev);
} }
} }
......
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