Commit fc54bb12 authored by Md Suleman's avatar Md Suleman

Updated_Resourse_Allocation(Add_And_Update)

parent 2f30a641
......@@ -50,13 +50,11 @@ public class ResourceController {
if (resourceService.validateBillingStartEndDateAgainstProjectStartEndDate(resourceAllocationReq, loginEmpId)) {
if (resourceService.validateBillingStartDateAgainstDOJ(resourceAllocationReq)) {
if (!resourceService.isResourceAssignedToAnyProject(resourceAllocationReq)) {
if(!resourceService.isResourceExistsForProject(resourceAllocationReq.getEmployeeId(),resourceAllocationReq.getProjectId())) {
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,9 +50,21 @@ public class ResourceService implements IResourceService {
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) {
......@@ -74,30 +86,37 @@ public class ResourceService implements IResourceService {
public void updateResourceDetails(Resource resourceReq, String loginEmpId) throws MyTeamException {
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());
if (resourceListWithLatestRecord != null && resourceListWithLatestRecord.size() > 0) {
Resource resourcePrev = resourceListWithLatestRecord.get(0); //latest resource record.
log.info("Requsting Resource Allocation BillingStart Date::::"+resourceReq.getBillingStartDate());
log.info("The before date is::" + MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate()));
if(!resourcePrev.getBillableStatus().equals(resourceReq.getBillableStatus())) {
if (resourcePrev.getBillingEndDate().compareTo(new Date()) == 0) {
resourcePrev.setBillingEndDate(new Date());
} else {
resourcePrev.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate())); //adding resource.
}
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);
// 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());
//
// if (resourceListWithLatestRecord != null && resourceListWithLatestRecord.size() > 0) {
//
// Resource resourcePrev = resourceListWithLatestRecord.get(0); //latest resource record.
// log.info("Requsting Resource Allocation BillingStart Date::::"+resourceReq.getBillingStartDate());
// log.info("The before date is::" + MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate()));
// if(!resourcePrev.getBillableStatus().equals(resourceReq.getBillableStatus())) {
// if (resourcePrev.getBillingEndDate().compareTo(new Date()) == 0) {
// resourcePrev.setBillingEndDate(new Date());
// } else {
// resourcePrev.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate())); //adding resource.
// }
// 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 {
respMap.put("statusCode", 801);
respMap.put("message", "Record Not Found");
}
}
......
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