Commit e6847920 authored by vikram singh's avatar vikram singh

"Code changes for showing current Allocation on DashBoard."

parent 728a1070
...@@ -69,6 +69,8 @@ public interface IResourceService { ...@@ -69,6 +69,8 @@ public interface IResourceService {
public List<Resource> getResourceByProjectId(String projectId); public List<Resource> getResourceByProjectId(String projectId);
Resource getCurrentAllocation(String employeeId);
// List<Resource> getAllResourcesForProject(String projectId, String status); // List<Resource> getAllResourcesForProject(String projectId, String status);
......
...@@ -148,7 +148,7 @@ public class DashboardService implements IDashboardService { ...@@ -148,7 +148,7 @@ public class DashboardService implements IDashboardService {
public List<EmployeeDashboardVO> getDashBoardData() throws MyTeamException { public List<EmployeeDashboardVO> getDashBoardData() throws MyTeamException {
List<EmployeeDashboardVO> employeeDashboard = new ArrayList<>(); List<EmployeeDashboardVO> employeeDashboard = new ArrayList<>();
List<Employee> allEmployees = employeeService.getActiveEmployees(); List<Employee> allEmployees = employeeService.getActiveEmployees();
List<ResourceVO> resources = resourceService.getAllResourcesVO(); // List<ResourceVO> resources = resourceService.getAllResourcesVO();
for (Employee employee:allEmployees){ for (Employee employee:allEmployees){
EmployeeDashboardVO employeeDashboardVO = new EmployeeDashboardVO(); EmployeeDashboardVO employeeDashboardVO = new EmployeeDashboardVO();
...@@ -157,7 +157,8 @@ public class DashboardService implements IDashboardService { ...@@ -157,7 +157,8 @@ public class DashboardService implements IDashboardService {
} }
employeeDashboard.stream().forEach(emp -> { employeeDashboard.stream().forEach(emp -> {
Resource resource=resourceService.getLatestResourceByEmpId(emp.getEmployeeId()); Resource resource=resourceService.getCurrentAllocation(emp.getEmployeeId());
//resourceService.getLatestResourceByEmpId(emp.getEmployeeId());
Project resourceProject = projectService.getProjectByProjectId(resource.getProjectId()); Project resourceProject = projectService.getProjectByProjectId(resource.getProjectId());
if(!resourceProject.getStatus().equals("Completed")){ if(!resourceProject.getStatus().equals("Completed")){
emp.setProjectId(resourceProject.getProjectId()); emp.setProjectId(resourceProject.getProjectId());
......
package com.nisum.myteam.service.impl; package com.nisum.myteam.service.impl;
import com.nisum.myteam.exception.handler.MyTeamException; import com.nisum.myteam.exception.handler.MyTeamException;
import com.nisum.myteam.model.dao.*; import com.nisum.myteam.model.dao.*;
import com.nisum.myteam.model.vo.*; import com.nisum.myteam.model.vo.*;
import com.nisum.myteam.repository.ResourceRepo; import com.nisum.myteam.repository.ResourceRepo;
import com.nisum.myteam.service.*; import com.nisum.myteam.service.*;
import com.nisum.myteam.statuscodes.ResourceAllocationStatus; import com.nisum.myteam.statuscodes.ResourceAllocationStatus;
import com.nisum.myteam.statuscodes.ResourceStatus; import com.nisum.myteam.statuscodes.ResourceStatus;
import com.nisum.myteam.utils.MyTeamDateUtils; import com.nisum.myteam.utils.MyTeamDateUtils;
import com.nisum.myteam.utils.MyTeamUtils; import com.nisum.myteam.utils.MyTeamUtils;
import com.nisum.myteam.utils.constants.Shifts; import com.nisum.myteam.utils.constants.Shifts;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
@Slf4j @Slf4j
public class ResourceService implements IResourceService { public class ResourceService implements IResourceService {
@Autowired @Autowired
private MongoTemplate mongoTemplate; private MongoTemplate mongoTemplate;
@Autowired @Autowired
private ResourceRepo resourceRepo; private ResourceRepo resourceRepo;
@Autowired @Autowired
private IAccountService accountService; private IAccountService accountService;
@Autowired @Autowired
private IDomainService domainService; private IDomainService domainService;
@Autowired @Autowired
private IProjectService projectService; private IProjectService projectService;
@Autowired @Autowired
private IEmployeeService employeeService; private IEmployeeService employeeService;
@Autowired @Autowired
private IEmployeeShiftService empShiftService; private IEmployeeShiftService empShiftService;
public HashMap<String, Object> respMap = new HashMap<>(); public HashMap<String, Object> respMap = new HashMap<>();
private Resource getLatestAllocation(List<Resource> resourceAllocList) { private Resource getLatestAllocation(List<Resource> resourceAllocList) {
Resource latestAlloc = null; Resource latestAlloc = null;
if (!resourceAllocList.isEmpty()) { if (!resourceAllocList.isEmpty()) {
latestAlloc = resourceAllocList.get(0); latestAlloc = resourceAllocList.get(0);
for (Resource resource : resourceAllocList) { for (Resource resource : resourceAllocList) {
if (latestAlloc.getBillingEndDate().before(resource.getBillingEndDate())) if (latestAlloc.getBillingEndDate().before(resource.getBillingEndDate()))
latestAlloc = resource; latestAlloc = resource;
} }
} }
return latestAlloc; return latestAlloc;
} }
public List<Resource> getResourcesByEmployeeId(String employeeId) { public List<Resource> getResourcesByEmployeeId(String employeeId) {
return resourceRepo.findByEmployeeId(employeeId); return resourceRepo.findByEmployeeId(employeeId);
} }
public Resource addResource(Resource resourceReq, String loginEmpId) throws MyTeamException { public Resource addResource(Resource resourceReq, String loginEmpId) throws MyTeamException {
List<Resource> resourceAllocationList = resourceRepo.findByEmployeeId(resourceReq.getEmployeeId()); List<Resource> resourceAllocationList = resourceRepo.findByEmployeeId(resourceReq.getEmployeeId());
Resource prevAllocation = getLatestAllocation(resourceAllocationList.stream().filter(r -> isAllocationActiveToday(r)).collect(Collectors.toList())); Resource prevAllocation = getLatestAllocation(resourceAllocationList.stream().filter(r -> isAllocationActiveToday(r)).collect(Collectors.toList()));
Resource resourcePers = null; Resource resourcePers = null;
if(prevAllocation != null){ if(prevAllocation != null){
// Resource projectPrevAllocation = this.getLatestAllocation(resourceAllocationList.stream(). // Resource projectPrevAllocation = this.getLatestAllocation(resourceAllocationList.stream().
// filter(r -> !r.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)).collect(Collectors.toList())); // filter(r -> !r.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)).collect(Collectors.toList()));
// projectPrevAllocation.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate())); // projectPrevAllocation.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate()));
// updateExistedResource(projectPrevAllocation); // updateExistedResource(projectPrevAllocation);
// prevAllocation.setBillingStartDate(MyTeamDateUtils.getDayMoreThanDate(resourceReq.getBillingEndDate())); // prevAllocation.setBillingStartDate(MyTeamDateUtils.getDayMoreThanDate(resourceReq.getBillingEndDate()));
prevAllocation.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate())); prevAllocation.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate()));
updateExistedResource(prevAllocation); //updateLatestProjectAllocationToEnd updateExistedResource(prevAllocation); //updateLatestProjectAllocationToEnd
resourcePers = resourceRepo.save(resourceReq); //createNewProjectAllocationtoStart resourcePers = resourceRepo.save(resourceReq); //createNewProjectAllocationtoStart
} }
return resourcePers; return resourcePers;
} }
public boolean isResourceExistsForProject(String employeeId, String projectId) { public boolean isResourceExistsForProject(String employeeId, String projectId) {
boolean isExists = false; boolean isExists = false;
List<Resource> resourceList = resourceRepo.findByEmployeeIdAndProjectId(employeeId, projectId); List<Resource> resourceList = resourceRepo.findByEmployeeIdAndProjectId(employeeId, projectId);
if (resourceList != null && resourceList.size() > 0) { if (resourceList != null && resourceList.size() > 0) {
isExists = true; isExists = true;
respMap.put("message", "Resourse is already in the project"); respMap.put("message", "Resourse is already in the project");
return isExists; return isExists;
} }
respMap.put("statusCode", 810); respMap.put("statusCode", 810);
respMap.put("message", "Resource Not Found"); respMap.put("message", "Resource Not Found");
return isExists; return isExists;
} }
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 { // }else {
// resourcePrev.setResourceRole(resourceReq.getResourceRole()); // resourcePrev.setResourceRole(resourceReq.getResourceRole());
// resourcePrev.setBillingStartDate(resourceReq.getBillingStartDate()); // resourcePrev.setBillingStartDate(resourceReq.getBillingStartDate());
// resourcePrev.setBillingEndDate(resourceReq.getBillingEndDate()); // resourcePrev.setBillingEndDate(resourceReq.getBillingEndDate());
// //resourceAllocPrev.setBillingEndDate(); //adding resource. // //resourceAllocPrev.setBillingEndDate(); //adding resource.
// } // }
// log.info("After setting the date:::before saving the Resource::" + resourcePrev); // log.info("After setting the date:::before saving the Resource::" + resourcePrev);
// this.updateExistedResource(resourcePrev); // this.updateExistedResource(resourcePrev);
// } // }
Resource resource = resourceRepo.findById(resourceReq.getId()); Resource resource = resourceRepo.findById(resourceReq.getId());
if (resource != null) { if (resource != null) {
if(resourceReq.getStatus().equalsIgnoreCase(MyTeamUtils.Engaged_STATUS)){ if(resourceReq.getStatus().equalsIgnoreCase(MyTeamUtils.Engaged_STATUS)){
if(resourceReq.getBillingEndDate().compareTo(new Date())<0){ if(resourceReq.getBillingEndDate().compareTo(new Date())<0){
resourceReq.setStatus(MyTeamUtils.RELEASED_STATUS);//update Status of allocation resourceReq.setStatus(MyTeamUtils.RELEASED_STATUS);//update Status of allocation
Resource resourceBench = new Resource(); Resource resourceBench = new Resource();
resourceBench.setProjectId(MyTeamUtils.BENCH_PROJECT_ID); resourceBench.setProjectId(MyTeamUtils.BENCH_PROJECT_ID);
resourceBench.setEmployeeId(resourceReq.getEmployeeId()); resourceBench.setEmployeeId(resourceReq.getEmployeeId());
resourceBench.setResourceRole(resourceReq.getResourceRole()); resourceBench.setResourceRole(resourceReq.getResourceRole());
resourceBench.setStatus(MyTeamUtils.RELEASED_STATUS);//add alocation status as Released resourceBench.setStatus(MyTeamUtils.RELEASED_STATUS);//add alocation status as Released
resourceBench.setBillingStartDate(MyTeamDateUtils.getDayMoreThanDate(resourceReq.getBillingEndDate())); resourceBench.setBillingStartDate(MyTeamDateUtils.getDayMoreThanDate(resourceReq.getBillingEndDate()));
resourceBench.setBillingEndDate(projectService.getProjectByProjectId(MyTeamUtils.BENCH_PROJECT_ID).getProjectEndDate()); resourceBench.setBillingEndDate(projectService.getProjectByProjectId(MyTeamUtils.BENCH_PROJECT_ID).getProjectEndDate());
resourceBench.setBillableStatus(MyTeamUtils.BENCH_BILLABILITY_STATUS); resourceBench.setBillableStatus(MyTeamUtils.BENCH_BILLABILITY_STATUS);
resourceBench.setAuditFields(loginEmpId, MyTeamUtils.CREATE); resourceBench.setAuditFields(loginEmpId, MyTeamUtils.CREATE);
resourceRepo.save(resourceBench); resourceRepo.save(resourceBench);
} }
this.updateExistedResource(resourceReq); this.updateExistedResource(resourceReq);
}else{ }else{
respMap.put("statusCode", 801); respMap.put("statusCode", 801);
respMap.put("message", "Resource is already released from you, And you can't update this allocation"); respMap.put("message", "Resource is already released from you, And you can't update this allocation");
//>>>>>>> Stashed changes //>>>>>>> Stashed changes
} }
} else { } else {
respMap.put("statusCode", 801); respMap.put("statusCode", 801);
respMap.put("message", "Record Not Found"); respMap.put("message", "Record Not Found");
} }
} }
public void updateExistedResource(Resource resource) { public void updateExistedResource(Resource resource) {
if (resource != null) { if (resource != null) {
Resource resourcePers = resourceRepo.save(resource); Resource resourcePers = resourceRepo.save(resource);
respMap.put("statusCode", 801); respMap.put("statusCode", 801);
respMap.put("message", "Resource updated successfully"); respMap.put("message", "Resource updated successfully");
respMap.put("resourceObj", resourcePers); respMap.put("resourceObj", resourcePers);
} }
} }
public void insertNewResourceWithNewStatus(Resource resourceReq, String loginEmpId) throws MyTeamException { public void insertNewResourceWithNewStatus(Resource resourceReq, String loginEmpId) throws MyTeamException {
resourceReq.setId(null); resourceReq.setId(null);
Resource resourcePers = resourceRepo.insert(resourceReq); Resource resourcePers = resourceRepo.insert(resourceReq);
respMap.put("statusCode", 801); respMap.put("statusCode", 801);
respMap.put("message", "Resource updated successfully"); respMap.put("message", "Resource updated successfully");
respMap.put("resourceObj", resourcePers); respMap.put("resourceObj", resourcePers);
} }
public boolean validateAllocationAgainstPrevAllocation(Resource resourceReq) { public boolean validateAllocationAgainstPrevAllocation(Resource resourceReq) {
boolean isValid = true; boolean isValid = true;
List<Resource> resourceAllocList = resourceRepo.findByEmployeeIdAndProjectId(resourceReq.getEmployeeId(), resourceReq.getProjectId()); List<Resource> resourceAllocList = resourceRepo.findByEmployeeIdAndProjectId(resourceReq.getEmployeeId(), resourceReq.getProjectId());
Resource prevAllocation = this.getLatestAllocation(resourceAllocList); Resource prevAllocation = this.getLatestAllocation(resourceAllocList);
if (prevAllocation != null) { if (prevAllocation != null) {
if (!prevAllocation.getBillingStartDate().before(resourceReq.getBillingStartDate())) { if (!prevAllocation.getBillingStartDate().before(resourceReq.getBillingStartDate())) {
respMap.put("statusCode", 811); respMap.put("statusCode", 811);
respMap.put("message", "Billing start date should be after previous allocation start date"); respMap.put("message", "Billing start date should be after previous allocation start date");
isValid = false; isValid = false;
} }
if (prevAllocation.getBillableStatus().equalsIgnoreCase(resourceReq.getBillableStatus())) { if (prevAllocation.getBillableStatus().equalsIgnoreCase(resourceReq.getBillableStatus())) {
respMap.put("statusCode", 811); respMap.put("statusCode", 811);
respMap.put("message", "Resource is already in " + prevAllocation.getBillableStatus() + " status only"); respMap.put("message", "Resource is already in " + prevAllocation.getBillableStatus() + " status only");
isValid = false; isValid = false;
} }
} }
return isValid; 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;
Project project = projectService.getProjectByProjectId(resource.getProjectId()); Project project = projectService.getProjectByProjectId(resource.getProjectId());
log.info("Project::" + project); log.info("Project::" + project);
if (!resource.getBillingStartDate().after(project.getProjectStartDate())) { if (!resource.getBillingStartDate().after(project.getProjectStartDate())) {
log.info("Billing start date should be after Project start date"); log.info("Billing start date should be after Project start date");
respMap.put("statusCode", 811); respMap.put("statusCode", 811);
respMap.put("message", "Billing start date should be after Project start date"); respMap.put("message", "Billing start date should be after Project start date");
isValid = false; isValid = false;
} }
if (!resource.getBillingStartDate().before(resource.getBillingEndDate())) { if (!resource.getBillingStartDate().before(resource.getBillingEndDate())) {
log.info("Billing start date should be before Billing End Date."); log.info("Billing start date should be before Billing End Date.");
respMap.put("statusCode", 812); respMap.put("statusCode", 812);
respMap.put("message", "Billing start date should be before Billing End Date."); respMap.put("message", "Billing start date should be before Billing End Date.");
isValid = false; isValid = false;
} }
log.info("ResourceALloc Req::" + resource); log.info("ResourceALloc Req::" + resource);
log.info("" + project.getProjectEndDate().toString()); log.info("" + project.getProjectEndDate().toString());
//if (!resourceAllocation.getBillingEndDate().before(project.getProjectEndDate())|| !resourceAllocation.getBillingEndDate().equals(project.getProjectEndDate())) { //if (!resourceAllocation.getBillingEndDate().before(project.getProjectEndDate())|| !resourceAllocation.getBillingEndDate().equals(project.getProjectEndDate())) {
if (!(resource.getBillingEndDate().compareTo(project.getProjectEndDate()) <= 0)) { if (!(resource.getBillingEndDate().compareTo(project.getProjectEndDate()) <= 0)) {
log.info("Billing end date should be on or before Project End Date."); log.info("Billing end date should be on or before Project End Date.");
respMap.put("statusCode", 813); respMap.put("statusCode", 813);
respMap.put("message", "Billing end date should be before Project End Date."); respMap.put("message", "Billing end date should be before Project End Date.");
isValid = false; isValid = false;
} }
respMap.put("resourceObj", resource); respMap.put("resourceObj", resource);
return isValid; return isValid;
} }
public boolean validateBillingStartDateAgainstDOJ(Resource resource) { public boolean validateBillingStartDateAgainstDOJ(Resource resource) {
String message = ""; String message = "";
boolean isValid = true; boolean isValid = true;
Employee employee = employeeService.getEmployeeById(resource.getEmployeeId()); Employee employee = employeeService.getEmployeeById(resource.getEmployeeId());
Date empDoj = employeeService.getEmployeeById(resource.getEmployeeId()).getDateOfJoining(); Date empDoj = employeeService.getEmployeeById(resource.getEmployeeId()).getDateOfJoining();
if (resource.getBillingStartDate().compareTo(empDoj) < 0) { if (resource.getBillingStartDate().compareTo(empDoj) < 0) {
message = "Resource Billing Start Date (" + resource.getBillingStartDate() + " ) in " message = "Resource Billing Start Date (" + resource.getBillingStartDate() + " ) in "
+ projectService.getProjectByProjectId(resource.getProjectId()).getProjectName() + projectService.getProjectByProjectId(resource.getProjectId()).getProjectName()
+ " project should not be before Date of Joining ( " + empDoj + ")."; + " project should not be before Date of Joining ( " + empDoj + ").";
isValid = false; isValid = false;
respMap.put("statusCode", 814); respMap.put("statusCode", 814);
respMap.put("message", message); respMap.put("message", message);
} }
return isValid; return isValid;
} }
public boolean isResourceAvailable(Resource resourceReq) { public boolean isResourceAvailable(Resource resourceReq) {
boolean isAssigned = true; boolean isAssigned = true;
String message = ""; String message = "";
List<Resource> resourceAllocList = resourceRepo.findByEmployeeId(resourceReq.getEmployeeId()); //getting all allocations of employee List<Resource> resourceAllocList = resourceRepo.findByEmployeeId(resourceReq.getEmployeeId()); //getting all allocations of employee
Resource resourceLatestRecord = getLatestAllocation(resourceAllocList.stream(). Resource resourceLatestRecord = getLatestAllocation(resourceAllocList.stream().
filter(r -> r.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)).collect(Collectors.toList())); //getting latest allocation of employee in bench project 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)){ if (resourceLatestRecord != null && !isAllocationActiveToday(resourceLatestRecord)){
Resource latestProjectResource = getLatestAllocation(resourceAllocList.stream(). Resource latestProjectResource = getLatestAllocation(resourceAllocList.stream().
filter(r -> !r.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)).collect(Collectors.toList())); filter(r -> !r.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)).collect(Collectors.toList()));
if(!resourceReq.getProjectId().equalsIgnoreCase(latestProjectResource.getProjectId())) { if(!resourceReq.getProjectId().equalsIgnoreCase(latestProjectResource.getProjectId())) {
message = "Resource " + latestProjectResource.getEmployeeId() + " already Assigned to the " message = "Resource " + latestProjectResource.getEmployeeId() + " already Assigned to the "
+ projectService.getProjectByProjectId(latestProjectResource.getProjectId()).getProjectName() + projectService.getProjectByProjectId(latestProjectResource.getProjectId()).getProjectName()
+ " Project" + " from " + latestProjectResource.getBillingStartDate() + "to " + latestProjectResource.getBillingEndDate(); + " Project" + " from " + latestProjectResource.getBillingStartDate() + "to " + latestProjectResource.getBillingEndDate();
isAssigned = false; isAssigned = false;
respMap.put("statusCode", 815); respMap.put("statusCode", 815);
respMap.put("message", message); respMap.put("message", message);
} }
}else{ }else{
if(!validateResourceBillingEndDateAgainstBench(resourceReq)){ if(!validateResourceBillingEndDateAgainstBench(resourceReq)){
isAssigned = false; isAssigned = false;
} }
} }
return isAssigned; return isAssigned;
} }
public boolean validateResourceBillingEndDateAgainstBench(Resource resourceReq){ public boolean validateResourceBillingEndDateAgainstBench(Resource resourceReq){
boolean isValid = true; boolean isValid = true;
String message = ""; String message = "";
List<Resource> resourceAllocList = resourceRepo.findByEmployeeIdAndProjectId(resourceReq.getEmployeeId(),MyTeamUtils.BENCH_PROJECT_ID); List<Resource> resourceAllocList = resourceRepo.findByEmployeeIdAndProjectId(resourceReq.getEmployeeId(),MyTeamUtils.BENCH_PROJECT_ID);
Resource resourceBenchLatestRecord = getLatestAllocation(resourceAllocList.stream(). Resource resourceBenchLatestRecord = getLatestAllocation(resourceAllocList.stream().
filter(r -> r.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)).collect(Collectors.toList())); filter(r -> r.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)).collect(Collectors.toList()));
if(!isAllocationActiveToday(resourceBenchLatestRecord)){ if(!isAllocationActiveToday(resourceBenchLatestRecord)){
isValid = false; isValid = false;
message = "Resource is not available for allocation"; message = "Resource is not available for allocation";
}else if(!(resourceReq.getBillingEndDate().before(resourceBenchLatestRecord.getBillingEndDate()) && }else if(!(resourceReq.getBillingEndDate().before(resourceBenchLatestRecord.getBillingEndDate()) &&
resourceReq.getBillingStartDate().after(resourceBenchLatestRecord.getBillingStartDate()))){ resourceReq.getBillingStartDate().after(resourceBenchLatestRecord.getBillingStartDate()))){
message = "Resource is available from "+resourceBenchLatestRecord.getBillingStartDate()+" to "+resourceBenchLatestRecord.getBillingEndDate(); message = "Resource is available from "+resourceBenchLatestRecord.getBillingStartDate()+" to "+resourceBenchLatestRecord.getBillingEndDate();
isValid = false; isValid = false;
} }
respMap.put("statusCode", 810); respMap.put("statusCode", 810);
respMap.put("message", message); respMap.put("message", message);
return isValid; return isValid;
} }
public boolean isAllocationActiveToday(Resource resource){ public boolean isAllocationActiveToday(Resource resource){
boolean isActive = true; boolean isActive = true;
if(resource.getBillingStartDate().compareTo(new Date()) <=0 && if(resource.getBillingStartDate().compareTo(new Date()) <=0 &&
resource.getBillingEndDate().compareTo(new Date())>=0){ resource.getBillingEndDate().compareTo(new Date())>=0){
isActive = true; isActive = true;
}else{ }else{
isActive = false; isActive = false;
} }
return isActive; return isActive;
} }
public void deleteResource(Resource resourceReq, String loginEmpId) { public void deleteResource(Resource resourceReq, String loginEmpId) {
List<Resource> resourcesList = resourceRepo.findByEmployeeIdAndProjectId(resourceReq.getEmployeeId(), resourceReq.getProjectId()); List<Resource> resourcesList = resourceRepo.findByEmployeeIdAndProjectId(resourceReq.getEmployeeId(), resourceReq.getProjectId());
resourcesList.forEach(resource -> resourceRepo.delete(resource)); resourcesList.forEach(resource -> resourceRepo.delete(resource));
} }
@Override @Override
public List<Resource> getAllResources() { public List<Resource> getAllResources() {
return resourceRepo.findAll(); return resourceRepo.findAll();
} }
public List<ResourceVO> getAllResourcesVO() { public List<ResourceVO> getAllResourcesVO() {
return getAllResources().stream().map(resource -> { return getAllResources().stream().map(resource -> {
ResourceVO resourceVO = new ResourceVO(); ResourceVO resourceVO = new ResourceVO();
resourceVO.setId(resource.getId()); resourceVO.setId(resource.getId());
resourceVO.setProjectId(resource.getProjectId()); resourceVO.setProjectId(resource.getProjectId());
resourceVO.setEmployeeId(resource.getEmployeeId()); resourceVO.setEmployeeId(resource.getEmployeeId());
resourceVO.setStatus(resource.getStatus()); resourceVO.setStatus(resource.getStatus());
Employee employee = employeeService.getEmployeeById(resource.getEmployeeId()); Employee employee = employeeService.getEmployeeById(resource.getEmployeeId());
if (employee != null) { if (employee != null) {
resourceVO.setEmployeeName(employee.getEmployeeName()); resourceVO.setEmployeeName(employee.getEmployeeName());
resourceVO.setDesignation(employee.getDesignation()); resourceVO.setDesignation(employee.getDesignation());
resourceVO.setEmailId(employee.getEmailId()); resourceVO.setEmailId(employee.getEmailId());
resourceVO.setMobileNo(employee.getMobileNumber()); resourceVO.setMobileNo(employee.getMobileNumber());
} }
Project project = projectService.getProjectByProjectId(resource.getProjectId()); Project project = projectService.getProjectByProjectId(resource.getProjectId());
if (project != null) { if (project != null) {
resourceVO.setProjectName(project.getProjectName()); resourceVO.setProjectName(project.getProjectName());
resourceVO.setProjectStartDate(project.getProjectStartDate()); resourceVO.setProjectStartDate(project.getProjectStartDate());
resourceVO.setProjectEndDate(project.getProjectEndDate()); resourceVO.setProjectEndDate(project.getProjectEndDate());
resourceVO.setProjectStatus(project.getStatus()); resourceVO.setProjectStatus(project.getStatus());
if (project.getAccountId() != null) { if (project.getAccountId() != null) {
Account account = accountService.getAccountById(project.getAccountId()); Account account = accountService.getAccountById(project.getAccountId());
if (account != null) { if (account != null) {
resourceVO.setAccountName(account.getAccountName()); resourceVO.setAccountName(account.getAccountName());
} }
} }
} }
//Account account=accountService.getAccountById(domainService.getDomainById(project.getProjectId()).getAccountId()); //Account account=accountService.getAccountById(domainService.getDomainById(project.getProjectId()).getAccountId());
resourceVO.setBillableStatus(resource.getBillableStatus()); resourceVO.setBillableStatus(resource.getBillableStatus());
resourceVO.setBillingStartDate(resource.getBillingStartDate()); resourceVO.setBillingStartDate(resource.getBillingStartDate());
resourceVO.setBillingEndDate(resource.getBillingEndDate()); resourceVO.setBillingEndDate(resource.getBillingEndDate());
resourceVO.setResourceRole(resource.getResourceRole()); resourceVO.setResourceRole(resource.getResourceRole());
if (resource.getBillingEndDate().compareTo(new Date()) > 0) { if (resource.getBillingEndDate().compareTo(new Date()) > 0) {
resourceVO.setResourceStatus(ResourceStatus.ACTIVE.getStatus()); resourceVO.setResourceStatus(ResourceStatus.ACTIVE.getStatus());
} else { } else {
resourceVO.setResourceStatus(ResourceStatus.IN_ACTIVE.getStatus()); resourceVO.setResourceStatus(ResourceStatus.IN_ACTIVE.getStatus());
} }
return resourceVO; return resourceVO;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
} }
public List<Resource> getResourcesSortByBillingStartDate(String employeeId) { public List<Resource> getResourcesSortByBillingStartDate(String employeeId) {
Query query = prepareQuery(employeeId, MyTeamUtils.BILLING_START_DATE); Query query = prepareQuery(employeeId, MyTeamUtils.BILLING_START_DATE);
return mongoTemplate.find(query, Resource.class); return mongoTemplate.find(query, Resource.class);
} }
private Query prepareQuery(String employeeId, String dateColumn) { private Query prepareQuery(String employeeId, String dateColumn) {
Query query = new Query(); Query query = new Query();
query.addCriteria(Criteria.where(MyTeamUtils.EMPLOYEE_ID).is(employeeId)); query.addCriteria(Criteria.where(MyTeamUtils.EMPLOYEE_ID).is(employeeId));
query.limit(MyTeamUtils.ONE); query.limit(MyTeamUtils.ONE);
query.with(new Sort(Sort.Direction.DESC, dateColumn)); query.with(new Sort(Sort.Direction.DESC, dateColumn));
return query; return query;
} }
@Override @Override
public List<ResourceVO> getActiveResources(String empId) { public List<ResourceVO> getActiveResources(String empId) {
List<ResourceVO> resourcesList = new ArrayList<>(); List<ResourceVO> resourcesList = new ArrayList<>();
for (Resource resource : resourceRepo.findByEmployeeId(empId)) { for (Resource resource : resourceRepo.findByEmployeeId(empId)) {
if (resource.getBillingEndDate().compareTo(new Date()) > 0) { if (resource.getBillingEndDate().compareTo(new Date()) > 0) {
resourcesList.addAll(prepareProjectTeamMembersList(resource.getProjectId())); resourcesList.addAll(prepareProjectTeamMembersList(resource.getProjectId()));
} }
} }
return resourcesList; return resourcesList;
} }
public List<ResourceVO> prepareProjectTeamMembersList(String projectId) { public List<ResourceVO> prepareProjectTeamMembersList(String projectId) {
List<ResourceVO> finalResourcesList = new ArrayList<>(); List<ResourceVO> finalResourcesList = new ArrayList<>();
Employee employee = null; Employee employee = null;
for (Resource resource : getAllResourcesForProject(projectId)) { for (Resource resource : getAllResourcesForProject(projectId)) {
ResourceVO resourceVO = new ResourceVO(); ResourceVO resourceVO = new ResourceVO();
resourceVO.setId(resource.getId()); resourceVO.setId(resource.getId());
resourceVO.setProjectId(resource.getProjectId()); resourceVO.setProjectId(resource.getProjectId());
resourceVO.setEmployeeId(resource.getEmployeeId()); resourceVO.setEmployeeId(resource.getEmployeeId());
resourceVO.setStatus(resource.getStatus()); resourceVO.setStatus(resource.getStatus());
employee = employeeService.getEmployeeById(resource.getEmployeeId()); employee = employeeService.getEmployeeById(resource.getEmployeeId());
resourceVO.setEmployeeName(employee.getEmployeeName()); resourceVO.setEmployeeName(employee.getEmployeeName());
resourceVO.setDesignation(employee.getDesignation()); resourceVO.setDesignation(employee.getDesignation());
resourceVO.setEmailId(employee.getEmailId()); resourceVO.setEmailId(employee.getEmailId());
resourceVO.setMobileNo(employee.getMobileNumber()); resourceVO.setMobileNo(employee.getMobileNumber());
resourceVO.setProjectName(projectService.getProjectByProjectId(resource.getProjectId()).getProjectName()); resourceVO.setProjectName(projectService.getProjectByProjectId(resource.getProjectId()).getProjectName());
resourceVO.setBillableStatus(resource.getBillableStatus()); resourceVO.setBillableStatus(resource.getBillableStatus());
resourceVO.setBillingStartDate(resource.getBillingStartDate()); resourceVO.setBillingStartDate(resource.getBillingStartDate());
resourceVO.setBillingEndDate(resource.getBillingEndDate()); resourceVO.setBillingEndDate(resource.getBillingEndDate());
resourceVO.setResourceRole(resource.getResourceRole()); resourceVO.setResourceRole(resource.getResourceRole());
if (resource.getBillingEndDate().compareTo(new Date()) > 0) { if (resource.getBillingEndDate().compareTo(new Date()) > 0) {
resourceVO.setResourceStatus(ResourceStatus.ACTIVE.getStatus()); resourceVO.setResourceStatus(ResourceStatus.ACTIVE.getStatus());
} else { } else {
resourceVO.setResourceStatus(ResourceStatus.IN_ACTIVE.getStatus()); resourceVO.setResourceStatus(ResourceStatus.IN_ACTIVE.getStatus());
} }
finalResourcesList.add(resourceVO); finalResourcesList.add(resourceVO);
} }
return finalResourcesList; return finalResourcesList;
} }
public List<Resource> getAllResourcesForProject(String projectId) { public List<Resource> getAllResourcesForProject(String projectId) {
return resourceRepo.findByProjectId(projectId); return resourceRepo.findByProjectId(projectId);
} }
@Override @Override
public List<Resource> getAllResourcesForAllActiveProjects() { public List<Resource> getAllResourcesForAllActiveProjects() {
List<Resource> resourceList = new ArrayList<>(); List<Resource> resourceList = new ArrayList<>();
for (Project activeProject : projectService.getOnlyActiveProjects()) { for (Project activeProject : projectService.getOnlyActiveProjects()) {
resourceList.addAll(getAllResourcesForProject(activeProject.getProjectId())); resourceList.addAll(getAllResourcesForProject(activeProject.getProjectId()));
} }
return resourceList; return resourceList;
} }
@Override @Override
public List<ResourceVO> getResourcesForProject(String projectId, String statusFlag) { public List<ResourceVO> getResourcesForProject(String projectId, String statusFlag) {
List<ResourceVO> resourcesList = new ArrayList<>(); List<ResourceVO> resourcesList = new ArrayList<>();
for (Resource resource : resourceRepo.findByProjectId(projectId)) { for (Resource resource : resourceRepo.findByProjectId(projectId)) {
Date billingEndDate = resource.getBillingEndDate(); Date billingEndDate = resource.getBillingEndDate();
if (billingEndDate != null) { if (billingEndDate != null) {
ResourceVO resourceVO = new ResourceVO(); ResourceVO resourceVO = new ResourceVO();
resourceVO.setId(resource.getId()); resourceVO.setId(resource.getId());
resourceVO.setProjectId(resource.getProjectId()); resourceVO.setProjectId(resource.getProjectId());
resourceVO.setProjectName(projectService.getProjectByProjectId(resource.getProjectId()).getProjectName()); resourceVO.setProjectName(projectService.getProjectByProjectId(resource.getProjectId()).getProjectName());
resourceVO.setResourceRole(resource.getResourceRole()); resourceVO.setResourceRole(resource.getResourceRole());
resourceVO.setBillingStartDate(resource.getBillingStartDate()); resourceVO.setBillingStartDate(resource.getBillingStartDate());
resourceVO.setBillingEndDate(resource.getBillingEndDate()); resourceVO.setBillingEndDate(resource.getBillingEndDate());
resourceVO.setBillableStatus(resource.getBillableStatus()); resourceVO.setBillableStatus(resource.getBillableStatus());
resourceVO.setEmployeeId(resource.getEmployeeId()); resourceVO.setEmployeeId(resource.getEmployeeId());
resourceVO.setStatus(resource.getStatus()); resourceVO.setStatus(resource.getStatus());
Employee employee = employeeService.getEmployeeById(resource.getEmployeeId()); Employee employee = employeeService.getEmployeeById(resource.getEmployeeId());
resourceVO.setEmailId(employee.getEmailId()); resourceVO.setEmailId(employee.getEmailId());
resourceVO.setEmployeeName(employee.getEmployeeName()); resourceVO.setEmployeeName(employee.getEmployeeName());
resourceVO.setDesignation(employee.getDesignation()); resourceVO.setDesignation(employee.getDesignation());
// Active // Active
if (statusFlag.equals(ResourceStatus.ACTIVE.getStatus()) && billingEndDate.compareTo(new Date()) >= 0) { if (statusFlag.equals(ResourceStatus.ACTIVE.getStatus()) && billingEndDate.compareTo(new Date()) >= 0) {
resourceVO.setResourceStatus(ResourceStatus.ACTIVE.getStatus()); resourceVO.setResourceStatus(ResourceStatus.ACTIVE.getStatus());
resourcesList.add(resourceVO); resourcesList.add(resourceVO);
} else if (statusFlag.equals(ResourceStatus.IN_ACTIVE.getStatus()) && billingEndDate.compareTo(new Date()) < 0) { } else if (statusFlag.equals(ResourceStatus.IN_ACTIVE.getStatus()) && billingEndDate.compareTo(new Date()) < 0) {
resourceVO.setResourceStatus(ResourceStatus.IN_ACTIVE.getStatus()); resourceVO.setResourceStatus(ResourceStatus.IN_ACTIVE.getStatus());
resourcesList.add(resourceVO); resourcesList.add(resourceVO);
} else if (statusFlag.equals(MyTeamUtils.BOTH)) } else if (statusFlag.equals(MyTeamUtils.BOTH))
resourcesList.add(resourceVO); resourcesList.add(resourceVO);
} }
} }
return resourcesList; return resourcesList;
} }
@Override @Override
public List<MyProjectAllocationVO> getWorkedProjectsForResource(String empId) { public List<MyProjectAllocationVO> getWorkedProjectsForResource(String empId) {
Project project = null; Project project = null;
Account account = null; Account account = null;
Domain domain = null; Domain domain = null;
Employee employee = null; Employee employee = null;
List<MyProjectAllocationVO> myProjectList = new ArrayList<>(); List<MyProjectAllocationVO> myProjectList = new ArrayList<>();
List<Resource> resourcesAllocatedList = resourceRepo.findByEmployeeId(empId); List<Resource> resourcesAllocatedList = resourceRepo.findByEmployeeId(empId);
if (null != resourcesAllocatedList && !resourcesAllocatedList.isEmpty() && MyTeamUtils.INT_ZERO < resourcesAllocatedList.size()) { if (null != resourcesAllocatedList && !resourcesAllocatedList.isEmpty() && MyTeamUtils.INT_ZERO < resourcesAllocatedList.size()) {
for (Resource resourceAlloc : resourcesAllocatedList) { for (Resource resourceAlloc : resourcesAllocatedList) {
project = projectService.getProjectByProjectId(resourceAlloc.getProjectId()); project = projectService.getProjectByProjectId(resourceAlloc.getProjectId());
account = accountService.getAccountById(project.getAccountId()); account = accountService.getAccountById(project.getAccountId());
domain = domainService.getDomainById(project.getDomainId()); domain = domainService.getDomainById(project.getDomainId());
employee = employeeService.getEmployeeById(resourceAlloc.getEmployeeId()); employee = employeeService.getEmployeeById(resourceAlloc.getEmployeeId());
MyProjectAllocationVO myProject = new MyProjectAllocationVO(); MyProjectAllocationVO myProject = new MyProjectAllocationVO();
myProject.setProjectId(project.getProjectId()); myProject.setProjectId(project.getProjectId());
myProject.setProjectName(project.getProjectName()); myProject.setProjectName(project.getProjectName());
myProject.setProjectStartDate(project.getProjectStartDate()); myProject.setProjectStartDate(project.getProjectStartDate());
myProject.setProjectEndDate(project.getProjectEndDate()); myProject.setProjectEndDate(project.getProjectEndDate());
myProject.setProjectStatus(project.getStatus()); myProject.setProjectStatus(project.getStatus());
myProject.setAccountName(account.getAccountName()); myProject.setAccountName(account.getAccountName());
myProject.setBillableStatus(resourceAlloc.getBillableStatus()); myProject.setBillableStatus(resourceAlloc.getBillableStatus());
myProject.setBillingStartDate(resourceAlloc.getBillingStartDate()); myProject.setBillingStartDate(resourceAlloc.getBillingStartDate());
myProject.setBillingEndDate(resourceAlloc.getBillingEndDate()); myProject.setBillingEndDate(resourceAlloc.getBillingEndDate());
myProject.setShift(employee.getShift()); myProject.setShift(employee.getShift());
if (resourceAlloc.getBillingEndDate().compareTo(new Date()) > 0) { if (resourceAlloc.getBillingEndDate().compareTo(new Date()) > 0) {
myProject.setResourceStatus(ResourceStatus.ACTIVE.getStatus()); myProject.setResourceStatus(ResourceStatus.ACTIVE.getStatus());
} else { } else {
myProject.setResourceStatus(ResourceStatus.IN_ACTIVE.getStatus()); myProject.setResourceStatus(ResourceStatus.IN_ACTIVE.getStatus());
} }
if (project.getDeliveryLeadIds() != null) { if (project.getDeliveryLeadIds() != null) {
myProject.setDeliveryLeadIds(employeeService.getDeliveryManagerMap(project.getDeliveryLeadIds())); myProject.setDeliveryLeadIds(employeeService.getDeliveryManagerMap(project.getDeliveryLeadIds()));
} }
myProjectList.add(myProject); myProjectList.add(myProject);
} }
} }
return myProjectList; return myProjectList;
} }
@Override @Override
public List<Resource> getResourcesUnderDeliveryLead(String deliveryLeadId) { public List<Resource> getResourcesUnderDeliveryLead(String deliveryLeadId) {
List<String> projectIdsList = new ArrayList<>(); List<String> projectIdsList = new ArrayList<>();
List<Resource> resourcesList = new ArrayList<>(); List<Resource> resourcesList = new ArrayList<>();
for (Project project : projectService.getProjectsForDeliveryLead(deliveryLeadId)) for (Project project : projectService.getProjectsForDeliveryLead(deliveryLeadId))
projectIdsList.add(project.getProjectId()); projectIdsList.add(project.getProjectId());
Query query = new Query(Criteria.where("projectId").in(projectIdsList)); Query query = new Query(Criteria.where("projectId").in(projectIdsList));
List<Resource> resourcesListPersisted = mongoTemplate.find(query, Resource.class); List<Resource> resourcesListPersisted = mongoTemplate.find(query, Resource.class);
for (Resource resourceAlloc : resourcesListPersisted) { for (Resource resourceAlloc : resourcesListPersisted) {
if (!resourceAlloc.getEmployeeId().equals(deliveryLeadId)) if (!resourceAlloc.getEmployeeId().equals(deliveryLeadId))
resourcesList.add(resourceAlloc); resourcesList.add(resourceAlloc);
} }
return resourcesList; return resourcesList;
} }
@Override @Override
public List<ResourceVO> getBillingsForEmployee(String empId) { public List<ResourceVO> getBillingsForEmployee(String empId) {
List<ResourceVO> finalList = new ArrayList<>(); List<ResourceVO> finalList = new ArrayList<>();
List<Resource> resourcesList = resourceRepo.findByEmployeeId(empId); List<Resource> resourcesList = resourceRepo.findByEmployeeId(empId);
if (resourcesList != null && resourcesList.size() > 0) { if (resourcesList != null && resourcesList.size() > 0) {
log.info("The resources billing list before sorting::" + resourcesList); log.info("The resources billing list before sorting::" + resourcesList);
//return billingsList.stream().sorted(Comparator.comparing(Billing::getCreatedOn).reversed()).collect(Collectors.toList()); //return billingsList.stream().sorted(Comparator.comparing(Billing::getCreatedOn).reversed()).collect(Collectors.toList());
List<Resource> sortedList = resourcesList.stream().sorted(Comparator.comparing(Resource::getBillingStartDate).reversed()).collect(Collectors.toList()); List<Resource> sortedList = resourcesList.stream().sorted(Comparator.comparing(Resource::getBillingStartDate).reversed()).collect(Collectors.toList());
finalList = convertResourcesToResourcesVO(sortedList); finalList = convertResourcesToResourcesVO(sortedList);
} }
return finalList; return finalList;
} }
@Override @Override
public List<Resource> getBillingsForProject(String empId, String projectId) { public List<Resource> getBillingsForProject(String empId, String projectId) {
List<Resource> resourcesList = resourceRepo.findByEmployeeIdAndProjectId(empId, projectId); List<Resource> resourcesList = resourceRepo.findByEmployeeIdAndProjectId(empId, projectId);
if (resourcesList == null || resourcesList.size() == 0) { if (resourcesList == null || resourcesList.size() == 0) {
return resourcesList; return resourcesList;
} else { } else {
//return billingsList.stream().sorted(Comparator.comparing(Billing::getCreatedOn).reversed()).collect(Collectors.toList()); //return billingsList.stream().sorted(Comparator.comparing(Billing::getCreatedOn).reversed()).collect(Collectors.toList());
return resourcesList.stream().sorted(Comparator.comparing(Resource::getBillingStartDate).reversed()).collect(Collectors.toList()); return resourcesList.stream().sorted(Comparator.comparing(Resource::getBillingStartDate).reversed()).collect(Collectors.toList());
} }
} }
@Override @Override
public List<Employee> getUnAssignedEmployees() { public List<Employee> getUnAssignedEmployees() {
List<Employee> notAssignedEmployees = new ArrayList<>(); List<Employee> notAssignedEmployees = new ArrayList<>();
List<String> resourceIdsList = new ArrayList<>(); List<String> resourceIdsList = new ArrayList<>();
for (Resource resource : this.getAllResources()) { for (Resource resource : this.getAllResources()) {
Project project = projectService.getProjectByProjectId(resource.getProjectId()); Project project = projectService.getProjectByProjectId(resource.getProjectId());
if (project != null && project.getStatus() != null && !"Completed".equalsIgnoreCase(project.getStatus())) { if (project != null && project.getStatus() != null && !"Completed".equalsIgnoreCase(project.getStatus())) {
resourceIdsList.add(resource.getEmployeeId()); resourceIdsList.add(resource.getEmployeeId());
} }
} }
for (Employee employee : employeeService.getAllEmployees()) { for (Employee employee : employeeService.getAllEmployees()) {
if (!resourceIdsList.contains(employee.getEmployeeId())) { if (!resourceIdsList.contains(employee.getEmployeeId())) {
notAssignedEmployees.add(employee); notAssignedEmployees.add(employee);
} }
} }
return notAssignedEmployees; return notAssignedEmployees;
} }
public void deleteResourcesUnderProject(String projectId) { public void deleteResourcesUnderProject(String projectId) {
Query query = new Query(Criteria.where("projectId").is(projectId)); Query query = new Query(Criteria.where("projectId").is(projectId));
List<Resource> list = mongoTemplate.find(query, Resource.class); List<Resource> list = mongoTemplate.find(query, Resource.class);
resourceRepo.delete(list); resourceRepo.delete(list);
} }
private List<ResourceVO> convertResourcesToResourcesVO(List<Resource> resourcesList) { private List<ResourceVO> convertResourcesToResourcesVO(List<Resource> resourcesList) {
List<ResourceVO> finalList = new ArrayList<>(); List<ResourceVO> finalList = new ArrayList<>();
if (resourcesList != null && resourcesList.size() > 0) { if (resourcesList != null && resourcesList.size() > 0) {
finalList = resourcesList.stream().map(resource -> { finalList = resourcesList.stream().map(resource -> {
ResourceVO resourceVO = new ResourceVO(); ResourceVO resourceVO = new ResourceVO();
resourceVO.setId(resource.getId()); resourceVO.setId(resource.getId());
resourceVO.setProjectId(resource.getProjectId()); resourceVO.setProjectId(resource.getProjectId());
resourceVO.setEmployeeId(resource.getEmployeeId()); resourceVO.setEmployeeId(resource.getEmployeeId());
resourceVO.setStatus(resource.getStatus()); resourceVO.setStatus(resource.getStatus());
Employee employee = employeeService.getEmployeeById(resource.getEmployeeId()); Employee employee = employeeService.getEmployeeById(resource.getEmployeeId());
if (employee != null) { if (employee != null) {
resourceVO.setEmployeeName(employee.getEmployeeName()); resourceVO.setEmployeeName(employee.getEmployeeName());
resourceVO.setDesignation(employee.getDesignation()); resourceVO.setDesignation(employee.getDesignation());
resourceVO.setEmailId(employee.getEmailId()); resourceVO.setEmailId(employee.getEmailId());
resourceVO.setMobileNo(employee.getMobileNumber()); resourceVO.setMobileNo(employee.getMobileNumber());
} }
Project project = projectService.getProjectByProjectId(resource.getProjectId()); Project project = projectService.getProjectByProjectId(resource.getProjectId());
if (project != null) { if (project != null) {
resourceVO.setProjectName(project.getProjectName()); resourceVO.setProjectName(project.getProjectName());
resourceVO.setProjectStartDate(project.getProjectStartDate()); resourceVO.setProjectStartDate(project.getProjectStartDate());
resourceVO.setProjectEndDate(project.getProjectEndDate()); resourceVO.setProjectEndDate(project.getProjectEndDate());
resourceVO.setProjectStatus(project.getStatus()); resourceVO.setProjectStatus(project.getStatus());
if (project.getAccountId() != null) { if (project.getAccountId() != null) {
Account account = accountService.getAccountById(project.getAccountId()); Account account = accountService.getAccountById(project.getAccountId());
if (account != null) { if (account != null) {
resourceVO.setAccountName(account.getAccountName()); resourceVO.setAccountName(account.getAccountName());
} }
} }
} }
//Account account=accountService.getAccountById(domainService.getDomainById(project.getProjectId()).getAccountId()); //Account account=accountService.getAccountById(domainService.getDomainById(project.getProjectId()).getAccountId());
resourceVO.setBillableStatus(resource.getBillableStatus()); resourceVO.setBillableStatus(resource.getBillableStatus());
resourceVO.setBillingStartDate(resource.getBillingStartDate()); resourceVO.setBillingStartDate(resource.getBillingStartDate());
resourceVO.setBillingEndDate(resource.getBillingEndDate()); resourceVO.setBillingEndDate(resource.getBillingEndDate());
resourceVO.setResourceRole(resource.getResourceRole()); resourceVO.setResourceRole(resource.getResourceRole());
if (resource.getBillingEndDate().compareTo(new Date()) > 0) { if (resource.getBillingEndDate().compareTo(new Date()) > 0) {
resourceVO.setResourceStatus(ResourceStatus.ACTIVE.getStatus()); resourceVO.setResourceStatus(ResourceStatus.ACTIVE.getStatus());
} else { } else {
resourceVO.setResourceStatus(ResourceStatus.IN_ACTIVE.getStatus()); resourceVO.setResourceStatus(ResourceStatus.IN_ACTIVE.getStatus());
} }
return resourceVO; return resourceVO;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
} }
return finalList; return finalList;
} }
@Override @Override
public Resource addResourceToBenchProject(Employee employee, String loginEmpId) throws MyTeamException { public Resource addResourceToBenchProject(Employee employee, String loginEmpId) throws MyTeamException {
Resource resourcePersisted = null; Resource resourcePersisted = null;
Resource resourceBench = new Resource(); Resource resourceBench = new Resource();
resourceBench.setProjectId(MyTeamUtils.BENCH_PROJECT_ID); resourceBench.setProjectId(MyTeamUtils.BENCH_PROJECT_ID);
resourceBench.setEmployeeId(employee.getEmployeeId()); resourceBench.setEmployeeId(employee.getEmployeeId());
resourceBench.setResourceRole(employee.getRole()); resourceBench.setResourceRole(employee.getRole());
resourceBench.setStatus(MyTeamUtils.RELEASED_STATUS); resourceBench.setStatus(MyTeamUtils.RELEASED_STATUS);
resourceBench.setBillingStartDate(employee.getDateOfJoining() != null ? employee.getDateOfJoining() : new Date()); resourceBench.setBillingStartDate(employee.getDateOfJoining() != null ? employee.getDateOfJoining() : new Date());
resourceBench.setBillableStatus(MyTeamUtils.BENCH_BILLABILITY_STATUS); resourceBench.setBillableStatus(MyTeamUtils.BENCH_BILLABILITY_STATUS);
resourceBench.setEmployeeId(employee.getEmployeeId()); resourceBench.setEmployeeId(employee.getEmployeeId());
resourceBench.setBillingEndDate(projectService.getProjectByProjectId(MyTeamUtils.BENCH_PROJECT_ID).getProjectEndDate()); resourceBench.setBillingEndDate(projectService.getProjectByProjectId(MyTeamUtils.BENCH_PROJECT_ID).getProjectEndDate());
resourcePersisted = addResource(resourceBench, loginEmpId); resourcePersisted = addResource(resourceBench, loginEmpId);
return resourcePersisted; return resourcePersisted;
} }
@Override @Override
public List<EmployeeShiftsVO> getResourcesForShift(String shift) { public List<EmployeeShiftsVO> getResourcesForShift(String shift) {
List<Resource> resourcesListPers = null; List<Resource> resourcesListPers = null;
List<EmployeeShiftsVO> resourcesList = new ArrayList<>(); List<EmployeeShiftsVO> resourcesList = new ArrayList<>();
List<Project> projects = projectService.getAllProjects(); List<Project> projects = projectService.getAllProjects();
for (Project project : projects) { for (Project project : projects) {
if ("Active".equalsIgnoreCase(project.getStatus())) { if ("Active".equalsIgnoreCase(project.getStatus())) {
resourcesListPers = getAllResourcesForProject(project.getProjectId()); resourcesListPers = getAllResourcesForProject(project.getProjectId());
for (Resource resource : resourcesListPers) { for (Resource resource : resourcesListPers) {
// EmployeeShift empShift = empShiftService.getEmployeeShift(resource.getEmployeeId()); // EmployeeShift empShift = empShiftService.getEmployeeShift(resource.getEmployeeId());
// if (empShift != null) { // if (empShift != null) {
// if (empShift.getShift() != null && empShift.getShift().equalsIgnoreCase(shift)) // if (empShift.getShift() != null && empShift.getShift().equalsIgnoreCase(shift))
// resourcesList.add(resource); // resourcesList.add(resource);
// else if (empShift.getShift() == null && Shifts.SHIFT1.getShiftType().equalsIgnoreCase(shift)) // else if (empShift.getShift() == null && Shifts.SHIFT1.getShiftType().equalsIgnoreCase(shift))
// resourcesList.add(resource); // resourcesList.add(resource);
// //
// } // }
if (resource.getBillingEndDate().compareTo(new Date()) >= 0) { if (resource.getBillingEndDate().compareTo(new Date()) >= 0) {
Employee employee = employeeService.getEmployeeById(resource.getEmployeeId()); Employee employee = employeeService.getEmployeeById(resource.getEmployeeId());
EmployeeShiftsVO shiftsVO = new EmployeeShiftsVO(); EmployeeShiftsVO shiftsVO = new EmployeeShiftsVO();
shiftsVO.setEmployeeId(employee.getEmployeeId()); shiftsVO.setEmployeeId(employee.getEmployeeId());
shiftsVO.setEmployeeName(employee.getEmployeeName()); shiftsVO.setEmployeeName(employee.getEmployeeName());
shiftsVO.setEmailId(employee.getEmailId()); shiftsVO.setEmailId(employee.getEmailId());
shiftsVO.setMobileNo(employee.getMobileNumber()); shiftsVO.setMobileNo(employee.getMobileNumber());
shiftsVO.setProjectName(project.getProjectName()); shiftsVO.setProjectName(project.getProjectName());
if (employee != null) { if (employee != null) {
if (shift.equalsIgnoreCase(employee.getShift())) if (shift.equalsIgnoreCase(employee.getShift()))
resourcesList.add(shiftsVO); resourcesList.add(shiftsVO);
else if (employee.getShift() == null && Shifts.SHIFT1.getShiftType().equalsIgnoreCase(shift)) else if (employee.getShift() == null && Shifts.SHIFT1.getShiftType().equalsIgnoreCase(shift))
resourcesList.add(shiftsVO); resourcesList.add(shiftsVO);
} }
} }
}//for }//for
} }
} }
return resourcesList; return resourcesList;
} }
@Override @Override
public Resource getLatestResourceByEmpId(String employeeId) { public Resource getLatestResourceByEmpId(String employeeId) {
return getLatestAllocation(resourceRepo.findByEmployeeId(employeeId)); return getLatestAllocation(resourceRepo.findByEmployeeId(employeeId));
} }
@Override @Override
public List<Resource> getResourcesByBillingStatus(String resourceStatus) { public List<Resource> getResourcesByBillingStatus(String resourceStatus) {
return resourceRepo.findByBillableStatus(resourceStatus); return resourceRepo.findByBillableStatus(resourceStatus);
} }
@Override @Override
public List<ReserveReportsVO> getResourceReportsByBillingStatus(String resourceStatus) { public List<ReserveReportsVO> getResourceReportsByBillingStatus(String resourceStatus) {
return prepareReserveReports(getResourcesByBillingStatus(resourceStatus)); return prepareReserveReports(getResourcesByBillingStatus(resourceStatus));
} }
@Override @Override
public List<ReserveReportsVO> prepareReserveReports(List<Resource> resourcesList) { public List<ReserveReportsVO> prepareReserveReports(List<Resource> resourcesList) {
List<ReserveReportsVO> reserveReportsList = new ArrayList<>(); List<ReserveReportsVO> reserveReportsList = new ArrayList<>();
if (resourcesList != null && resourcesList.size() > 0) { if (resourcesList != null && resourcesList.size() > 0) {
Project project = null; Project project = null;
for (Resource resource : resourcesList) { for (Resource resource : resourcesList) {
ReserveReportsVO reserveReportsVO = new ReserveReportsVO(); ReserveReportsVO reserveReportsVO = new ReserveReportsVO();
reserveReportsVO.setEmployeeId(resource.getEmployeeId()); reserveReportsVO.setEmployeeId(resource.getEmployeeId());
reserveReportsVO.setEmployeeName(employeeService.getEmployeeById(resource.getEmployeeId()).getEmployeeName()); reserveReportsVO.setEmployeeName(employeeService.getEmployeeById(resource.getEmployeeId()).getEmployeeName());
if (StringUtils.isNotBlank(resource.getProjectId())) { if (StringUtils.isNotBlank(resource.getProjectId())) {
project = projectService.getProjectByProjectId(resource.getProjectId()); project = projectService.getProjectByProjectId(resource.getProjectId());
if (project != null) { if (project != null) {
reserveReportsVO.setProjectName(project.getProjectName()); reserveReportsVO.setProjectName(project.getProjectName());
reserveReportsVO.setAccountName(accountService.getAccountById(project.getAccountId()).getAccountName()); reserveReportsVO.setAccountName(accountService.getAccountById(project.getAccountId()).getAccountName());
} }
} }
reserveReportsVO.setBillingStartDate(resource.getBillingStartDate()); reserveReportsVO.setBillingStartDate(resource.getBillingStartDate());
reserveReportsVO.setBillingEndDate(resource.getBillingEndDate()); reserveReportsVO.setBillingEndDate(resource.getBillingEndDate());
reserveReportsList.add(reserveReportsVO); reserveReportsList.add(reserveReportsVO);
} }
} }
return reserveReportsList; return reserveReportsList;
} }
@Override @Override
public List<Resource> getResourceByProjectId(String projectId){ public List<Resource> getResourceByProjectId(String projectId){
return resourceRepo.findByProjectId(projectId); return resourceRepo.findByProjectId(projectId);
} }
public List<ChangedResourceVO> getChangedResourceByDate(String fromDatestr, String toDatestr) { public List<ChangedResourceVO> getChangedResourceByDate(String fromDatestr, String toDatestr) {
// List<ChangedResourceVO> changedResourceVOList = new ArrayList(); // List<ChangedResourceVO> changedResourceVOList = new ArrayList();
// SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy"); // SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
// //
// try { // try {
// final Date fromDate = format.parse(fromDatestr); // final Date fromDate = format.parse(fromDatestr);
// final Date toDate = format.parse(toDatestr); // final Date toDate = format.parse(toDatestr);
// resourceRepo.findAll().stream(). // resourceRepo.findAll().stream().
// filter(r -> r.getBillingStartDate().before(toDate)&&r.getBillingEndDate().after(fromDate)).forEach(r -> { // filter(r -> r.getBillingStartDate().before(toDate)&&r.getBillingEndDate().after(fromDate)).forEach(r -> {
// ChangedResourceVO crv = new ChangedResourceVO(); // ChangedResourceVO crv = new ChangedResourceVO();
// Project project = projectService.getProjectByProjectId(r.getProjectId()); // Project project = projectService.getProjectByProjectId(r.getProjectId());
// Employee emp = employeeService.getEmployeeById(r.getEmployeeId()); // Employee emp = employeeService.getEmployeeById(r.getEmployeeId());
// Account account = accountService.getAccountById(project.getAccountId()); // Account account = accountService.getAccountById(project.getAccountId());
// //
// //
// if(changedResourceVOList.isEmpty()){ // if(changedResourceVOList.isEmpty()){
// crv.setEmplyeeId(r.getEmployeeId()); // crv.setEmplyeeId(r.getEmployeeId());
// crv.setEmployeeName(emp.getEmployeeName()); // crv.setEmployeeName(emp.getEmployeeName());
// crv.setPrevBillingStatus(r.getBillableStatus()); // crv.setPrevBillingStatus(r.getBillableStatus());
// crv.setPrevBillingStartingDate(r.getBillingStartDate()); // crv.setPrevBillingStartingDate(r.getBillingStartDate());
// crv.setPrevBillingEndDate(r.getBillingEndDate()); // crv.setPrevBillingEndDate(r.getBillingEndDate());
// crv.setPrevClient(account.getAccountName()); // crv.setPrevClient(account.getAccountName());
// crv.setPrevProject(project.getProjectName()); // crv.setPrevProject(project.getProjectName());
// }else { // }else {
// //
// if(!crvList.isEmpty()){ // if(!crvList.isEmpty()){
// //
// }else{ // }else{
// //
// } // }
// } // }
// changedResourceVOList.add(crv); // changedResourceVOList.add(crv);
// }); // });
// //
// }catch (Exception e){} // }catch (Exception e){}
// //
return null; return null;
} }
public boolean validateResourceAllocationStatus(ResourceAllocationStatus resourceStatus) { public boolean validateResourceAllocationStatus(ResourceAllocationStatus resourceStatus) {
boolean isValidStatus = false; boolean isValidStatus = false;
switch (resourceStatus) { switch (resourceStatus) {
case TRAINEE: case TRAINEE:
case BILLABLE: case BILLABLE:
case NON_BILLABLE: case NON_BILLABLE:
case RESERVED: case RESERVED:
isValidStatus = true; isValidStatus = true;
break; break;
} }
return isValidStatus; return isValidStatus;
} }
public List<Resource> getResourcesGreaterThanBillingStartDate(Date billingStartDate) { public List<Resource> getResourcesGreaterThanBillingStartDate(Date billingStartDate) {
return resourceRepo.findByBillingStartDateGreaterThan(billingStartDate); return resourceRepo.findByBillingStartDateGreaterThan(billingStartDate);
} }
public List<Resource> getResourcesBetweenBillingStartDates(Date fromDate, Date toDate) { public List<Resource> getResourcesBetweenBillingStartDates(Date fromDate, Date toDate) {
return resourceRepo.findByBillingStartDateBetween(fromDate, toDate); return resourceRepo.findByBillingStartDateBetween(fromDate, toDate);
} }
public List<AllocationChangeVO> getAllocationReports(Date fromDate, Date toDate) { public List<AllocationChangeVO> getAllocationReports(Date fromDate, Date toDate) {
return getResourcesBetweenBillingStartDates(fromDate, toDate).stream() return getResourcesBetweenBillingStartDates(fromDate, toDate).stream()
.filter(resource -> resource.getBillingEndDate().compareTo(new Date()) >= 0).map(resource -> { .filter(resource -> resource.getBillingEndDate().compareTo(new Date()) >= 0).map(resource -> {
Project project = null; Project project = null;
//Setting Current Billing details. //Setting Current Billing details.
AllocationChangeVO allocationVO = new AllocationChangeVO(); AllocationChangeVO allocationVO = new AllocationChangeVO();
allocationVO.setEmployeeId(resource.getEmployeeId()); allocationVO.setEmployeeId(resource.getEmployeeId());
allocationVO.setEmployeeName(employeeService.getEmployeeById(resource.getEmployeeId()).getEmployeeName()); allocationVO.setEmployeeName(employeeService.getEmployeeById(resource.getEmployeeId()).getEmployeeName());
if (StringUtils.isNotBlank(resource.getProjectId())) { if (StringUtils.isNotBlank(resource.getProjectId())) {
project = projectService.getProjectByProjectId(resource.getProjectId()); project = projectService.getProjectByProjectId(resource.getProjectId());
if (project != null) { if (project != null) {
allocationVO.setCurrentProjectName(project.getProjectName()); allocationVO.setCurrentProjectName(project.getProjectName());
allocationVO.setCurrentAccountName(accountService.getAccountById(project.getAccountId()).getAccountName()); allocationVO.setCurrentAccountName(accountService.getAccountById(project.getAccountId()).getAccountName());
} }
} }
allocationVO.setCurrentBillingStatus(resource.getBillableStatus()); allocationVO.setCurrentBillingStatus(resource.getBillableStatus());
allocationVO.setCurrentBillingStartDate(resource.getBillingStartDate()); allocationVO.setCurrentBillingStartDate(resource.getBillingStartDate());
allocationVO.setCurrentBillingEndDate(resource.getBillingEndDate()); allocationVO.setCurrentBillingEndDate(resource.getBillingEndDate());
Resource prevBilling = resourceRepo.findOneByEmployeeIdAndBillingEndDate(resource.getEmployeeId(), MyTeamDateUtils.getDayLessThanDate(resource.getBillingStartDate())); Resource prevBilling = resourceRepo.findOneByEmployeeIdAndBillingEndDate(resource.getEmployeeId(), MyTeamDateUtils.getDayLessThanDate(resource.getBillingStartDate()));
log.info("\n\n\n The prev billing info is::" + prevBilling); log.info("\n\n\n The prev billing info is::" + prevBilling);
if (prevBilling != null) { if (prevBilling != null) {
if (StringUtils.isNotBlank(prevBilling.getProjectId())) { if (StringUtils.isNotBlank(prevBilling.getProjectId())) {
project = projectService.getProjectByProjectId(prevBilling.getProjectId()); project = projectService.getProjectByProjectId(prevBilling.getProjectId());
if (project != null) { if (project != null) {
allocationVO.setPrevProjectName(project.getProjectName()); allocationVO.setPrevProjectName(project.getProjectName());
allocationVO.setPrevAccountName(accountService.getAccountById(project.getAccountId()).getAccountName()); allocationVO.setPrevAccountName(accountService.getAccountById(project.getAccountId()).getAccountName());
} }
} }
allocationVO.setPrevBillingStatus(prevBilling.getBillableStatus()); allocationVO.setPrevBillingStatus(prevBilling.getBillableStatus());
allocationVO.setPrevBillingStartDate(prevBilling.getBillingStartDate()); allocationVO.setPrevBillingStartDate(prevBilling.getBillingStartDate());
allocationVO.setPrevBillingEndDate(prevBilling.getBillingEndDate()); allocationVO.setPrevBillingEndDate(prevBilling.getBillingEndDate());
} }
return allocationVO; return allocationVO;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
} }
public List<AllocationChangeVO> prepareAllocationResources(List<Resource> resourcesList) { public List<AllocationChangeVO> prepareAllocationResources(List<Resource> resourcesList) {
List<AllocationChangeVO> allocationList = new ArrayList<>(); List<AllocationChangeVO> allocationList = new ArrayList<>();
if (resourcesList != null && resourcesList.size() > 0) { if (resourcesList != null && resourcesList.size() > 0) {
Project project = null; Project project = null;
for (Resource resource : resourcesList) { for (Resource resource : resourcesList) {
AllocationChangeVO allocationVO = new AllocationChangeVO(); AllocationChangeVO allocationVO = new AllocationChangeVO();
allocationVO.setEmployeeId(resource.getEmployeeId()); allocationVO.setEmployeeId(resource.getEmployeeId());
allocationVO.setEmployeeName(employeeService.getEmployeeById(resource.getEmployeeId()).getEmployeeName()); allocationVO.setEmployeeName(employeeService.getEmployeeById(resource.getEmployeeId()).getEmployeeName());
if (StringUtils.isNotBlank(resource.getProjectId())) { if (StringUtils.isNotBlank(resource.getProjectId())) {
project = projectService.getProjectByProjectId(resource.getProjectId()); project = projectService.getProjectByProjectId(resource.getProjectId());
if (project != null) { if (project != null) {
allocationVO.setCurrentProjectName(project.getProjectName()); allocationVO.setCurrentProjectName(project.getProjectName());
allocationVO.setCurrentAccountName(accountService.getAccountById(project.getAccountId()).getAccountName()); allocationVO.setCurrentAccountName(accountService.getAccountById(project.getAccountId()).getAccountName());
} }
} }
allocationVO.setCurrentBillingStatus(resource.getBillableStatus()); allocationVO.setCurrentBillingStatus(resource.getBillableStatus());
allocationVO.setCurrentBillingStartDate(resource.getBillingStartDate()); allocationVO.setCurrentBillingStartDate(resource.getBillingStartDate());
allocationVO.setCurrentBillingEndDate(resource.getBillingEndDate()); allocationVO.setCurrentBillingEndDate(resource.getBillingEndDate());
allocationList.add(allocationVO); allocationList.add(allocationVO);
} }
} }
return allocationList; return allocationList;
} }
@Override @Override
public Set<Resource> findByBillableStatus(String billableStatus) { public Set<Resource> findByBillableStatus(String billableStatus) {
return resourceRepo.findByBillableStatus(billableStatus).stream().filter(r -> r.getBillingEndDate().after(new Date())).collect(Collectors.toSet()); return resourceRepo.findByBillableStatus(billableStatus).stream().filter(r -> r.getBillingEndDate().after(new Date())).collect(Collectors.toSet());
} }
public Resource sendResourceToOpenPool(Resource resource,String loginId) { public Resource sendResourceToOpenPool(Resource resource,String loginId) {
Resource existingresource = resourceRepo.findById(resource.getId()); Resource existingresource = resourceRepo.findById(resource.getId());
existingresource.setStatus(MyTeamUtils.RELEASED_STATUS); existingresource.setStatus(MyTeamUtils.RELEASED_STATUS);
this.updateExistedResource(existingresource); this.updateExistedResource(existingresource);
// isResourceAvailableinBenchbygraterthanEndDate= // isResourceAvailableinBenchbygraterthanEndDate=
Resource benchResource = new Resource(); Resource benchResource = new Resource();
benchResource.setProjectId(MyTeamUtils.BENCH_PROJECT_ID); benchResource.setProjectId(MyTeamUtils.BENCH_PROJECT_ID);
benchResource.setEmployeeId(resource.getEmployeeId()); benchResource.setEmployeeId(resource.getEmployeeId());
benchResource.setResourceRole(resource.getResourceRole()); benchResource.setResourceRole(resource.getResourceRole());
benchResource.setBillingStartDate(MyTeamDateUtils.getDayMoreThanDate(resource.getBillingEndDate())); benchResource.setBillingStartDate(MyTeamDateUtils.getDayMoreThanDate(resource.getBillingEndDate()));
benchResource.setBillingEndDate(projectService.getProjectByProjectId(MyTeamUtils.BENCH_PROJECT_ID).getProjectEndDate()); benchResource.setBillingEndDate(projectService.getProjectByProjectId(MyTeamUtils.BENCH_PROJECT_ID).getProjectEndDate());
benchResource.setBillableStatus(MyTeamUtils.BENCH_BILLABILITY_STATUS); benchResource.setBillableStatus(MyTeamUtils.BENCH_BILLABILITY_STATUS);
benchResource.setStatus(MyTeamUtils.RELEASED_STATUS); benchResource.setStatus(MyTeamUtils.RELEASED_STATUS);
benchResource.setAuditFields(loginId, MyTeamUtils.CREATE); benchResource.setAuditFields(loginId, MyTeamUtils.CREATE);
Resource resourcePers = resourceRepo.save(benchResource); Resource resourcePers = resourceRepo.save(benchResource);
respMap.put("statusCode", 801); respMap.put("statusCode", 801);
respMap.put("message", "Resource is moved to Bench Successfully"); respMap.put("message", "Resource is moved to Bench Successfully");
return resourcePers; return resourcePers;
} }
}
//class @Override
public Resource getCurrentAllocation(String employeeId) {
return resourceRepo.findByEmployeeId(employeeId).stream().filter(resource-> isAllocationActiveToday(resource)).findAny().orElse(getLatestResourceByEmpId(employeeId));
}
}
//class
/*
@Override
public List<ResourceVO> getActiveResources(String empId) {
List<ResourceVO> finalResourcesList = new ArrayList<>();
List<Resource> resourceList = resourceRepo.findByEmployeeId(empId); /*
if (resourceList != null && resourceList.size() > 0) { @Override
public List<ResourceVO> getActiveResources(String empId) {
Resource resourceAlloc=resourceList.get(0); List<ResourceVO> finalResourcesList = new ArrayList<>();
}
List<Resource> resourceList = resourceRepo.findByEmployeeId(empId);
for (Resource resource : resourceRepo.findByEmployeeId(empId)) { if (resourceList != null && resourceList.size() > 0) {
ResourceVO resourceVO=new ResourceVO(); Resource resourceAlloc=resourceList.get(0);
resourceVO.setEmployeeId(resource.getEmployeeId()); }
Employee employee=employeeService.getEmployeeById(resource.getEmployeeId()); for (Resource resource : resourceRepo.findByEmployeeId(empId)) {
resourceVO.setEmployeeName(employee.getEmployeeName());
resourceVO.setDesignation(employee.getDesignation()); ResourceVO resourceVO=new ResourceVO();
resourceVO.setEmailId(employee.getEmailId()); resourceVO.setEmployeeId(resource.getEmployeeId());
resourceVO.setMobileNo(employee.getMobileNumber());
Employee employee=employeeService.getEmployeeById(resource.getEmployeeId());
resourceVO.setProjectName(projectService.getProjectByProjectId(resource.getProjectId()).getProjectName()); resourceVO.setEmployeeName(employee.getEmployeeName());
resourceVO.setDesignation(employee.getDesignation());
resourceVO.setEmailId(employee.getEmailId());
if (resource.getBillingEndDate().compareTo(new Date()) > 0) { resourceVO.setMobileNo(employee.getMobileNumber());
finalResourcesList.addAll(getAllResourcesForProject(resource.getProjectId()));
} resourceVO.setProjectName(projectService.getProjectByProjectId(resource.getProjectId()).getProjectName());
} if (resource.getBillingEndDate().compareTo(new Date()) > 0) {
return finalResourcesList; finalResourcesList.addAll(getAllResourcesForProject(resource.getProjectId()));
} }
*/
}
/* return finalResourcesList;
}
@Override
public List<ResourceVO> getActiveResources(String empId) { */
List<ResourceVO> finalResourcesList = new ArrayList<>();
Employee employee = null; /*
List<Resource> resourceList = resourceRepo.findByEmployeeId(empId); @Override
Optional<Resource> optionalResource = resourceList.stream().filter(resource -> resource.getBillingEndDate().compareTo(new Date()) > 0).findAny(); public List<ResourceVO> getActiveResources(String empId) {
if (optionalResource.isPresent()) { List<ResourceVO> finalResourcesList = new ArrayList<>();
finalResourcesList = prepareProjectTeamMembersList(optionalResource.get().getProjectId()); Employee employee = null;
}
return finalResourcesList; List<Resource> resourceList = resourceRepo.findByEmployeeId(empId);
} Optional<Resource> optionalResource = resourceList.stream().filter(resource -> resource.getBillingEndDate().compareTo(new Date()) > 0).findAny();
if (optionalResource.isPresent()) {
*/ finalResourcesList = prepareProjectTeamMembersList(optionalResource.get().getProjectId());
}
return finalResourcesList;
}
*/
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