Commit 3f3ed5bd authored by Md Suleman's avatar Md Suleman

Updated status propesed in resource response

parent ade1a202
...@@ -50,6 +50,7 @@ public class ResourceService implements IResourceService { ...@@ -50,6 +50,7 @@ public class ResourceService implements IResourceService {
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()) {
...@@ -70,14 +71,13 @@ public class ResourceService implements IResourceService { ...@@ -70,14 +71,13 @@ public class ResourceService implements IResourceService {
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( Resource prevAllocation = getLatestAllocation(resourceAllocationList.stream().filter(r -> isAllocationActiveToday(r)).collect(Collectors.toList()));
resourceAllocationList.stream().filter(r -> isAllocationActiveToday(r)).collect(Collectors.toList()));
Resource resourcePers = null; Resource resourcePers = null;
if (prevAllocation != null) { if(prevAllocation != null){
prevAllocation.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate())); prevAllocation.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate()));
this.updateExistedResource(prevAllocation); // updateLatestProjectAllocationToEnd this.updateExistedResource(prevAllocation); //updateLatestProjectAllocationToEnd
resourcePers = resourceRepo.save(resourceReq); // createNewProjectAllocationtoStart resourcePers = resourceRepo.save(resourceReq); //createNewProjectAllocationtoStart
} }
return resourcePers; return resourcePers;
} }
...@@ -96,6 +96,7 @@ public class ResourceService implements IResourceService { ...@@ -96,6 +96,7 @@ public class ResourceService implements IResourceService {
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());
...@@ -126,35 +127,30 @@ public class ResourceService implements IResourceService { ...@@ -126,35 +127,30 @@ public class ResourceService implements IResourceService {
Resource resource = resourceRepo.findById(resourceReq.getId()); Resource resource = resourceRepo.findById(resourceReq.getId());
if (resource != null) { if (resource != null) {
if (!resourceReq.getStatus().equalsIgnoreCase(MyTeamUtils.RELEASED_STATUS)) { if(!resourceReq.getStatus().equalsIgnoreCase(MyTeamUtils.RELEASED_STATUS)){
Resource latestAllocation = this Resource latestAllocation = this.getLatestAllocation(resourceRepo.findByEmployeeId(resourceReq.getEmployeeId()));
.getLatestAllocation(resourceRepo.findByEmployeeId(resourceReq.getEmployeeId()));
if (latestAllocation != null if(latestAllocation!=null && !latestAllocation.getProjectId().equalsIgnoreCase(resourceReq.getProjectId())&&
&& !latestAllocation.getProjectId().equalsIgnoreCase(resourceReq.getProjectId()) !latestAllocation.getBillingStartDate().after(resourceReq.getBillingEndDate())) {
&& !latestAllocation.getBillingStartDate().after(resourceReq.getBillingEndDate())) {
respMap.put("statusCode", 811); respMap.put("statusCode", 811);
respMap.put("message", respMap.put("message", "Resource is already allocated after "+latestAllocation.getBillingStartDate());
"Resource is already allocated after " + latestAllocation.getBillingStartDate()); }else{
} else {
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( resourceBench.setBillingStartDate(MyTeamDateUtils.getDayMoreThanDate(resourceReq.getBillingEndDate()));
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", 811); respMap.put("statusCode", 811);
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");
} }
...@@ -190,8 +186,7 @@ public class ResourceService implements IResourceService { ...@@ -190,8 +186,7 @@ public class ResourceService implements IResourceService {
public boolean validateAllocationAgainstPrevAllocation(Resource resourceReq) { public boolean validateAllocationAgainstPrevAllocation(Resource resourceReq) {
boolean isValid = true; boolean isValid = true;
List<Resource> resourceAllocList = resourceRepo.findByEmployeeIdAndProjectId(resourceReq.getEmployeeId(), List<Resource> resourceAllocList = resourceRepo.findByEmployeeIdAndProjectId(resourceReq.getEmployeeId(), resourceReq.getProjectId());
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())) {
...@@ -208,8 +203,7 @@ public class ResourceService implements IResourceService { ...@@ -208,8 +203,7 @@ public class ResourceService implements IResourceService {
return isValid; return isValid;
} }
public boolean validateBillingStartEndDateAgainstProjectStartEndDate(Resource resource, String loginEmpId) public boolean validateBillingStartEndDateAgainstProjectStartEndDate(Resource resource, String loginEmpId) throws MyTeamException {
throws MyTeamException {
boolean isValid = true; boolean isValid = true;
...@@ -232,10 +226,7 @@ public class ResourceService implements IResourceService { ...@@ -232,10 +226,7 @@ public class ResourceService implements IResourceService {
log.info("ResourceALloc Req::" + resource); log.info("ResourceALloc Req::" + resource);
log.info("" + project.getProjectEndDate().toString()); log.info("" + project.getProjectEndDate().toString());
// if //if (!resourceAllocation.getBillingEndDate().before(project.getProjectEndDate())|| !resourceAllocation.getBillingEndDate().equals(project.getProjectEndDate())) {
// (!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);
...@@ -247,6 +238,7 @@ public class ResourceService implements IResourceService { ...@@ -247,6 +238,7 @@ public class ResourceService implements IResourceService {
return isValid; return isValid;
} }
public boolean validateBillingStartDateAgainstDOJ(Resource resource) { public boolean validateBillingStartDateAgainstDOJ(Resource resource) {
String message = ""; String message = "";
boolean isValid = true; boolean isValid = true;
...@@ -264,58 +256,51 @@ public class ResourceService implements IResourceService { ...@@ -264,58 +256,51 @@ public class ResourceService implements IResourceService {
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 List<Resource> resourceAllocList = resourceRepo.findByEmployeeId(resourceReq.getEmployeeId()); //getting all allocations of employee
// allocations
// of employee 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
Resource resourceLatestRecord = getLatestAllocation(
resourceAllocList.stream().filter(r -> r.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)) if (resourceLatestRecord != null && !isAllocationActiveToday(resourceLatestRecord)){
.collect(Collectors.toList())); // getting latest allocation of employee in bench project Resource latestProjectResource = getLatestAllocation(resourceAllocList.stream().
filter(r -> !r.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)).collect(Collectors.toList()));
if (resourceLatestRecord != null && !isAllocationActiveToday(resourceLatestRecord)) { if(!resourceReq.getProjectId().equalsIgnoreCase(latestProjectResource.getProjectId())) {
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 " message = "Resource " + latestProjectResource.getEmployeeId() + " already Assigned to the "
+ projectService.getProjectByProjectId(latestProjectResource.getProjectId()).getProjectName() + projectService.getProjectByProjectId(latestProjectResource.getProjectId()).getProjectName()
+ " Project" + " from " + latestProjectResource.getBillingStartDate() + "to " + " Project" + " from " + latestProjectResource.getBillingStartDate() + "to " + latestProjectResource.getBillingEndDate();
+ 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(), List<Resource> resourceAllocList = resourceRepo.findByEmployeeIdAndProjectId(resourceReq.getEmployeeId(),MyTeamUtils.BENCH_PROJECT_ID);
MyTeamUtils.BENCH_PROJECT_ID);
Resource resourceBenchLatestRecord = getLatestAllocation( Resource resourceBenchLatestRecord = getLatestAllocation(resourceAllocList.stream().
resourceAllocList.stream().filter(r -> r.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)) filter(r -> r.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)).collect(Collectors.toList()));
.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 " message = "Resource is available from "+resourceBenchLatestRecord.getBillingStartDate()+" to "+resourceBenchLatestRecord.getBillingEndDate();
+ resourceBenchLatestRecord.getBillingEndDate();
isValid = false; isValid = false;
} }
respMap.put("statusCode", 810); respMap.put("statusCode", 810);
...@@ -323,36 +308,35 @@ public class ResourceService implements IResourceService { ...@@ -323,36 +308,35 @@ public class ResourceService implements IResourceService {
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) {
resourceRepo.delete(resourceReq); resourceRepo.delete(resourceReq);
} }
public void deleteAndUpdateAllocation(Resource resourceReq, String loginEmpId) { public void deleteAndUpdateAllocation(Resource resourceReq,String loginEmpId){
List<Resource> empAllAllocations = resourceRepo.findByEmployeeId(resourceReq.getEmployeeId()); List<Resource> empAllAllocations = resourceRepo.findByEmployeeId(resourceReq.getEmployeeId());
Resource latestAllocation = this.getLatestAllocation(empAllAllocations.stream() Resource latestAllocation = this.getLatestAllocation(empAllAllocations.stream().filter(r -> !r.getId().equals(resourceReq.getId())).collect(Collectors.toList()));
.filter(r -> !r.getId().equals(resourceReq.getId())).collect(Collectors.toList()));
Resource resource = resourceRepo.findById(resourceReq.getId()); Resource resource = resourceRepo.findById(resourceReq.getId());
if (resource != null) { if(resource != null) {
if (latestAllocation != null if (latestAllocation != null && latestAllocation.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)) {
&& latestAllocation.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)) { latestAllocation.setBillingEndDate(projectService.getProjectByProjectId(MyTeamUtils.BENCH_PROJECT_ID).getProjectEndDate());
latestAllocation.setBillingEndDate(
projectService.getProjectByProjectId(MyTeamUtils.BENCH_PROJECT_ID).getProjectEndDate());
this.updateExistedResource(latestAllocation); this.updateExistedResource(latestAllocation);
} }
this.deleteResource(resourceReq, loginEmpId); this.deleteResource(resourceReq, loginEmpId);
}else { }else{
respMap.put("statusCode", 811); respMap.put("statusCode", 811);
respMap.put("message", "Record Not Found"); respMap.put("message", "Record Not Found");
} }
...@@ -363,6 +347,7 @@ public class ResourceService implements IResourceService { ...@@ -363,6 +347,7 @@ public class ResourceService implements IResourceService {
return resourceRepo.findAll(); return resourceRepo.findAll();
} }
public List<ResourceVO> getAllResourcesVO() { public List<ResourceVO> getAllResourcesVO() {
return getAllResources().stream().map(resource -> { return getAllResources().stream().map(resource -> {
...@@ -395,8 +380,7 @@ public class ResourceService implements IResourceService { ...@@ -395,8 +380,7 @@ public class ResourceService implements IResourceService {
} }
} }
// Account //Account account=accountService.getAccountById(domainService.getDomainById(project.getProjectId()).getAccountId());
// account=accountService.getAccountById(domainService.getDomainById(project.getProjectId()).getAccountId());
resourceVO.setBillableStatus(resource.getBillableStatus()); resourceVO.setBillableStatus(resource.getBillableStatus());
resourceVO.setBillingStartDate(resource.getBillingStartDate()); resourceVO.setBillingStartDate(resource.getBillingStartDate());
...@@ -437,6 +421,7 @@ public class ResourceService implements IResourceService { ...@@ -437,6 +421,7 @@ public class ResourceService implements IResourceService {
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;
...@@ -476,6 +461,7 @@ public class ResourceService implements IResourceService { ...@@ -476,6 +461,7 @@ public class ResourceService implements IResourceService {
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<>();
...@@ -487,6 +473,7 @@ public class ResourceService implements IResourceService { ...@@ -487,6 +473,7 @@ public class ResourceService implements IResourceService {
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<>();
...@@ -498,8 +485,7 @@ public class ResourceService implements IResourceService { ...@@ -498,8 +485,7 @@ public class ResourceService implements IResourceService {
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 resourceVO.setProjectName(projectService.getProjectByProjectId(resource.getProjectId()).getProjectName());
.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());
...@@ -512,15 +498,18 @@ public class ResourceService implements IResourceService { ...@@ -512,15 +498,18 @@ public class ResourceService implements IResourceService {
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()) } else if (statusFlag.equals(ResourceStatus.IN_ACTIVE.getStatus()) && billingEndDate.compareTo(new Date()) < 0) {
&& 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.STATUS_PROPOSED) && resource.getStatus().equals(MyTeamUtils.STATUS_PROPOSED)){
resourceVO.setResourceStatus(MyTeamUtils.STATUS_PROPOSED);
resourcesList.add(resourceVO);
}else if (statusFlag.equals(MyTeamUtils.BOTH))
resourcesList.add(resourceVO); resourcesList.add(resourceVO);
} }
...@@ -529,6 +518,7 @@ public class ResourceService implements IResourceService { ...@@ -529,6 +518,7 @@ public class ResourceService implements IResourceService {
return resourcesList; return resourcesList;
} }
@Override @Override
public List<MyProjectAllocationVO> getWorkedProjectsForResource(String empId) { public List<MyProjectAllocationVO> getWorkedProjectsForResource(String empId) {
...@@ -540,8 +530,7 @@ public class ResourceService implements IResourceService { ...@@ -540,8 +530,7 @@ public class ResourceService implements IResourceService {
List<Resource> resourcesAllocatedList = resourceRepo.findByEmployeeId(empId); List<Resource> resourcesAllocatedList = resourceRepo.findByEmployeeId(empId);
if (null != resourcesAllocatedList && !resourcesAllocatedList.isEmpty() if (null != resourcesAllocatedList && !resourcesAllocatedList.isEmpty() && MyTeamUtils.INT_ZERO < resourcesAllocatedList.size()) {
&& MyTeamUtils.INT_ZERO < resourcesAllocatedList.size()) {
for (Resource resourceAlloc : resourcesAllocatedList) { for (Resource resourceAlloc : resourcesAllocatedList) {
project = projectService.getProjectByProjectId(resourceAlloc.getProjectId()); project = projectService.getProjectByProjectId(resourceAlloc.getProjectId());
...@@ -576,6 +565,7 @@ public class ResourceService implements IResourceService { ...@@ -576,6 +565,7 @@ public class ResourceService implements IResourceService {
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<>();
...@@ -595,17 +585,15 @@ public class ResourceService implements IResourceService { ...@@ -595,17 +585,15 @@ public class ResourceService implements IResourceService {
} }
@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 //return billingsList.stream().sorted(Comparator.comparing(Billing::getCreatedOn).reversed()).collect(Collectors.toList());
// 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);
} }
...@@ -619,14 +607,13 @@ public class ResourceService implements IResourceService { ...@@ -619,14 +607,13 @@ public class ResourceService implements IResourceService {
if (resourcesList == null || resourcesList.size() == 0) { if (resourcesList == null || resourcesList.size() == 0) {
return resourcesList; return resourcesList;
} else { } else {
// return //return billingsList.stream().sorted(Comparator.comparing(Billing::getCreatedOn).reversed()).collect(Collectors.toList());
// 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() {
...@@ -648,6 +635,7 @@ public class ResourceService implements IResourceService { ...@@ -648,6 +635,7 @@ public class ResourceService implements IResourceService {
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);
...@@ -655,6 +643,7 @@ public class ResourceService implements IResourceService { ...@@ -655,6 +643,7 @@ public class ResourceService implements IResourceService {
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<>();
...@@ -689,8 +678,7 @@ public class ResourceService implements IResourceService { ...@@ -689,8 +678,7 @@ public class ResourceService implements IResourceService {
} }
} }
// Account //Account account=accountService.getAccountById(domainService.getDomainById(project.getProjectId()).getAccountId());
// account=accountService.getAccountById(domainService.getDomainById(project.getProjectId()).getAccountId());
resourceVO.setBillableStatus(resource.getBillableStatus()); resourceVO.setBillableStatus(resource.getBillableStatus());
resourceVO.setBillingStartDate(resource.getBillingStartDate()); resourceVO.setBillingStartDate(resource.getBillingStartDate());
...@@ -709,6 +697,7 @@ public class ResourceService implements IResourceService { ...@@ -709,6 +697,7 @@ public class ResourceService implements IResourceService {
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;
...@@ -718,18 +707,17 @@ public class ResourceService implements IResourceService { ...@@ -718,18 +707,17 @@ public class ResourceService implements IResourceService {
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 resourceBench.setBillingStartDate(employee.getDateOfJoining() != null ? employee.getDateOfJoining() : new Date());
.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( resourceBench.setBillingEndDate(projectService.getProjectByProjectId(MyTeamUtils.BENCH_PROJECT_ID).getProjectEndDate());
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;
...@@ -764,14 +752,13 @@ public class ResourceService implements IResourceService { ...@@ -764,14 +752,13 @@ public class ResourceService implements IResourceService {
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 else if (employee.getShift() == null && Shifts.SHIFT1.getShiftType().equalsIgnoreCase(shift))
&& Shifts.SHIFT1.getShiftType().equalsIgnoreCase(shift))
resourcesList.add(shiftsVO); resourcesList.add(shiftsVO);
} }
} }
} // for }//for
} }
} }
...@@ -785,6 +772,7 @@ public class ResourceService implements IResourceService { ...@@ -785,6 +772,7 @@ public class ResourceService implements IResourceService {
} }
@Override @Override
public List<Resource> getResourcesByBillingStatus(String resourceStatus) { public List<Resource> getResourcesByBillingStatus(String resourceStatus) {
return resourceRepo.findByBillableStatus(resourceStatus); return resourceRepo.findByBillableStatus(resourceStatus);
...@@ -804,14 +792,12 @@ public class ResourceService implements IResourceService { ...@@ -804,14 +792,12 @@ public class ResourceService implements IResourceService {
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 reserveReportsVO.setEmployeeName(employeeService.getEmployeeById(resource.getEmployeeId()).getEmployeeName());
.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 reserveReportsVO.setAccountName(accountService.getAccountById(project.getAccountId()).getAccountName());
.setAccountName(accountService.getAccountById(project.getAccountId()).getAccountName());
} }
} }
...@@ -827,10 +813,11 @@ public class ResourceService implements IResourceService { ...@@ -827,10 +813,11 @@ public class ResourceService implements IResourceService {
} }
@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");
...@@ -868,9 +855,11 @@ public class ResourceService implements IResourceService { ...@@ -868,9 +855,11 @@ public class ResourceService implements IResourceService {
// }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) {
...@@ -889,6 +878,7 @@ public class ResourceService implements IResourceService { ...@@ -889,6 +878,7 @@ public class ResourceService implements IResourceService {
return isValidStatus; return isValidStatus;
} }
public List<Resource> getResourcesGreaterThanBillingStartDate(Date billingStartDate) { public List<Resource> getResourcesGreaterThanBillingStartDate(Date billingStartDate) {
return resourceRepo.findByBillingStartDateGreaterThan(billingStartDate); return resourceRepo.findByBillingStartDateGreaterThan(billingStartDate);
} }
...@@ -904,26 +894,23 @@ public class ResourceService implements IResourceService { ...@@ -904,26 +894,23 @@ public class ResourceService implements IResourceService {
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( allocationVO.setEmployeeName(employeeService.getEmployeeById(resource.getEmployeeId()).getEmployeeName());
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( allocationVO.setCurrentAccountName(accountService.getAccountById(project.getAccountId()).getAccountName());
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(), Resource prevBilling = resourceRepo.findOneByEmployeeIdAndBillingEndDate(resource.getEmployeeId(), MyTeamDateUtils.getDayLessThanDate(resource.getBillingStartDate()));
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) {
...@@ -931,8 +918,7 @@ public class ResourceService implements IResourceService { ...@@ -931,8 +918,7 @@ public class ResourceService implements IResourceService {
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( allocationVO.setPrevAccountName(accountService.getAccountById(project.getAccountId()).getAccountName());
accountService.getAccountById(project.getAccountId()).getAccountName());
} }
} }
allocationVO.setPrevBillingStatus(prevBilling.getBillableStatus()); allocationVO.setPrevBillingStatus(prevBilling.getBillableStatus());
...@@ -953,15 +939,13 @@ public class ResourceService implements IResourceService { ...@@ -953,15 +939,13 @@ public class ResourceService implements IResourceService {
AllocationChangeVO allocationVO = new AllocationChangeVO(); AllocationChangeVO allocationVO = new AllocationChangeVO();
allocationVO.setEmployeeId(resource.getEmployeeId()); allocationVO.setEmployeeId(resource.getEmployeeId());
allocationVO allocationVO.setEmployeeName(employeeService.getEmployeeById(resource.getEmployeeId()).getEmployeeName());
.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( allocationVO.setCurrentAccountName(accountService.getAccountById(project.getAccountId()).getAccountName());
accountService.getAccountById(project.getAccountId()).getAccountName());
} }
} }
...@@ -977,13 +961,13 @@ public class ResourceService implements IResourceService { ...@@ -977,13 +961,13 @@ public class ResourceService implements IResourceService {
return allocationList; return allocationList;
} }
@Override @Override
public Set<Resource> findByBillableStatus(String billableStatus) { public Set<Resource> findByBillableStatus(String billableStatus) {
return resourceRepo.findByBillableStatus(billableStatus).stream() return resourceRepo.findByBillableStatus(billableStatus).stream().filter(r -> r.getBillingEndDate().after(new Date())).collect(Collectors.toSet());
.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);
...@@ -995,8 +979,7 @@ public class ResourceService implements IResourceService { ...@@ -995,8 +979,7 @@ public class ResourceService implements IResourceService {
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( benchResource.setBillingEndDate(projectService.getProjectByProjectId(MyTeamUtils.BENCH_PROJECT_ID).getProjectEndDate());
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);
...@@ -1008,56 +991,66 @@ public class ResourceService implements IResourceService { ...@@ -1008,56 +991,66 @@ public class ResourceService implements IResourceService {
@Override @Override
public Resource getCurrentAllocation(String employeeId) { public Resource getCurrentAllocation(String employeeId) {
return resourceRepo.findByEmployeeId(employeeId).stream().filter(resource -> isAllocationActiveToday(resource)) return resourceRepo.findByEmployeeId(employeeId).stream().filter(resource-> isAllocationActiveToday(resource)).findAny().orElse(getLatestResourceByEmpId(employeeId));
.findAny().orElse(getLatestResourceByEmpId(employeeId));
} }
} }
//class //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) {
*
* Resource resourceAlloc=resourceList.get(0); }
*
* for (Resource resource : resourceRepo.findByEmployeeId(empId)) {
*
* ResourceVO resourceVO=new ResourceVO();
* resourceVO.setEmployeeId(resource.getEmployeeId());
*
* Employee employee=employeeService.getEmployeeById(resource.getEmployeeId());
* resourceVO.setEmployeeName(employee.getEmployeeName());
* resourceVO.setDesignation(employee.getDesignation());
* resourceVO.setEmailId(employee.getEmailId());
* resourceVO.setMobileNo(employee.getMobileNumber());
*
* resourceVO.setProjectName(projectService.getProjectByProjectId(resource.
* getProjectId()).getProjectName());
*
*
* if (resource.getBillingEndDate().compareTo(new Date()) > 0) {
* finalResourcesList.addAll(getAllResourcesForProject(resource.getProjectId()))
* ; }
*
*
* } return finalResourcesList; }
*
*/
/*
*
* @Override public List<ResourceVO> getActiveResources(String empId) {
* List<ResourceVO> finalResourcesList = new ArrayList<>(); Employee employee = /*
* null; @Override
* public List<ResourceVO> getActiveResources(String empId) {
* List<Resource> resourceList = resourceRepo.findByEmployeeId(empId); List<ResourceVO> finalResourcesList = new ArrayList<>();
* Optional<Resource> optionalResource = resourceList.stream().filter(resource
* -> resource.getBillingEndDate().compareTo(new Date()) > 0).findAny(); if List<Resource> resourceList = resourceRepo.findByEmployeeId(empId);
* (optionalResource.isPresent()) { finalResourcesList = if (resourceList != null && resourceList.size() > 0) {
* prepareProjectTeamMembersList(optionalResource.get().getProjectId()); }
* return finalResourcesList; } Resource resourceAlloc=resourceList.get(0);
* }
for (Resource resource : resourceRepo.findByEmployeeId(empId)) {
ResourceVO resourceVO=new ResourceVO();
resourceVO.setEmployeeId(resource.getEmployeeId());
Employee employee=employeeService.getEmployeeById(resource.getEmployeeId());
resourceVO.setEmployeeName(employee.getEmployeeName());
resourceVO.setDesignation(employee.getDesignation());
resourceVO.setEmailId(employee.getEmailId());
resourceVO.setMobileNo(employee.getMobileNumber());
resourceVO.setProjectName(projectService.getProjectByProjectId(resource.getProjectId()).getProjectName());
if (resource.getBillingEndDate().compareTo(new Date()) > 0) {
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);
Optional<Resource> optionalResource = resourceList.stream().filter(resource -> resource.getBillingEndDate().compareTo(new Date()) > 0).findAny();
if (optionalResource.isPresent()) {
finalResourcesList = prepareProjectTeamMembersList(optionalResource.get().getProjectId());
}
return finalResourcesList;
}
*/ */
...@@ -5,6 +5,8 @@ import java.text.SimpleDateFormat; ...@@ -5,6 +5,8 @@ import java.text.SimpleDateFormat;
public class MyTeamUtils { public class MyTeamUtils {
private MyTeamUtils() { private MyTeamUtils() {
} }
...@@ -13,6 +15,7 @@ public class MyTeamUtils { ...@@ -13,6 +15,7 @@ public class MyTeamUtils {
//public final static String msdriveUrl ="jdbc:sqlserver://"; //public final static String msdriveUrl ="jdbc:sqlserver://";
public final static String RELEASED_STATUS="Released"; public final static String RELEASED_STATUS="Released";
public final static String Engaged_STATUS="Engaged"; public final static String Engaged_STATUS="Engaged";
public static final String STATUS_PROPOSED ="Proposed" ;
public final static DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); public final static DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public final static DateFormat tdf = new SimpleDateFormat("HH:mm"); public final static DateFormat tdf = new SimpleDateFormat("HH:mm");
......
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