Commit 2568e7cb authored by Prayas Jain's avatar Prayas Jain

Updated Resource Service

parent 9e0a776c
......@@ -20,6 +20,10 @@ import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;
......@@ -77,21 +81,15 @@ public class ResourceService implements IResourceService {
public Resource addResource(Resource resourceReq, String loginEmpId) throws MyTeamException {
List<Resource> resourceAllocationList = resourceRepo.findByEmployeeId(resourceReq.getEmployeeId());
Resource currentAllocation = getCurrentAllocationIfNotReturnNull(resourceReq.getEmployeeId());
Resource latestAllocation = getLatestAllocation(resourceAllocationList);
Resource resourcePers = null;
if(currentAllocation != null && currentAllocation.getProjectId().equals(MyTeamUtils.BENCH_PROJECT_ID)){
currentAllocation.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate()));
this.updateExistedResource(currentAllocation); //updateLatestProjectAllocationToEnd
resourcePers = resourceRepo.save(resourceReq); //createNewProjectAllocationtoStart
respMap.put("message","Resource has been created"); // added on 21-7 2019
}else if(isAllocationActiveToday(resourceReq)){
Project project = projectService.getProjectByProjectId(latestAllocation.getProjectId());
respMap.put("statusCode", 811);
respMap.put("message", "resource is not yet released from " + project.getProjectName() + " project");
//resource is not yet released from latest project
}else{
resourcePers = resourceRepo.save(resourceReq);
respMap.put("message","Resource has been created");
......@@ -279,15 +277,34 @@ public class ResourceService implements IResourceService {
}
return isValid;
}
private boolean isDateCommon(Resource e, Date fromDate, Date toDate) {
for (LocalDate datei = convert(fromDate); datei.isBefore(convert(toDate).plusDays(1)); datei = datei.plusDays(1))
for (LocalDate datej = convert(e.getBillingStartDate()); datej.isBefore(convert(e.getBillingEndDate()).plusDays(1)); datej = datej.plusDays(1))
if(datej.equals(datei))
return true;
return false;
}
private LocalDate convert(Date date) {
Instant instant = Instant.ofEpochMilli(date.getTime());
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
return localDateTime.toLocalDate();
}
public boolean isDatesAvailableForAllocation(Resource resource){
String message = "";
List<Resource> allocationList = resourceRepo.findByEmployeeId(resource.getEmployeeId());
List<Resource> matchedList = allocationList.stream().filter(r -> !r.getProjectId().equals(MyTeamUtils.BENCH_PROJECT_ID) &&
!r.getId().equals(resource.getId()) &&
( (r.getBillingStartDate().compareTo(resource.getBillingStartDate())<=0 && r.getBillingEndDate().compareTo(resource.getBillingStartDate())>=0)||
(r.getBillingStartDate().compareTo(resource.getBillingEndDate())<=0 && r.getBillingEndDate().compareTo(resource.getBillingEndDate())>=0 )))
!r.getId().equals(resource.getId()) && isDateCommon(resource,r.getBillingStartDate(),r.getBillingEndDate())
)
.collect(Collectors.toList());
if(!matchedList.isEmpty()){
message = "Resource is already alocated for projects:\n";
......@@ -303,6 +320,39 @@ public class ResourceService implements IResourceService {
return true;
}
// public boolean isDatesAvailableForAllocation(Resource resource){
//
//
//
//
//
//
//
// String message = "";
// List<Resource> allocationList = resourceRepo.findByEmployeeId(resource.getEmployeeId());
//
// List<Resource> matchedList = allocationList.stream().filter(r -> !r.getProjectId().equals(MyTeamUtils.BENCH_PROJECT_ID) &&
// !r.getId().equals(resource.getId()) &&
// ( (r.getBillingStartDate().compareTo(resource.getBillingStartDate())<=0 && r.getBillingEndDate().compareTo(resource.getBillingStartDate())>=0)||
// (r.getBillingStartDate().compareTo(resource.getBillingEndDate())<=0 && r.getBillingEndDate().compareTo(resource.getBillingEndDate())>=0 )))
// .collect(Collectors.toList());
// if(!matchedList.isEmpty()){
// message = "Resource is already alocated for projects:\n";
// for(Resource resourcel:matchedList){
// Project project = projectService.getProjectByProjectId(resourcel.getProjectId());
// message += "Project:"+project.getProjectName()+" From:"+MyTeamDateUtils.getRadableDate().format(resourcel.getBillingStartDate())+" To:"
// +MyTeamDateUtils.getRadableDate().format(resourcel.getBillingEndDate())+"\n";
// }
// respMap.put("statusCode", 815);
// respMap.put("message", message);
// return false;
// }else
// return true;
//
// }
public boolean isResourceAvailable(Resource resourceReq) {
......@@ -613,7 +663,7 @@ public class ResourceService implements IResourceService {
// Active
if (statusFlag.equals(ResourceStatus.ACTIVE.getStatus()) &&
(resource.getStatus().equals(MyTeamUtils.STATUS_ENGAGED) ||
(resource.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID) && this.isAllocationActiveToday(resource)))) {
(resource.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)))) {
resourceVO.setResourceStatus(ResourceStatus.ACTIVE.getStatus());
resourcesList.add(resourceVO);
} else if (statusFlag.equals(ResourceStatus.IN_ACTIVE.getStatus()) && resource.getStatus().equals(MyTeamUtils.STATUS_RELEASED)) {
......@@ -816,6 +866,7 @@ public class ResourceService implements IResourceService {
Resource resourcePersisted = null;
Resource resourceBench = new Resource();
resourceBench.setAuditFields(loginEmpId, MyTeamUtils.CREATE);
resourceBench.setProjectId(MyTeamUtils.BENCH_PROJECT_ID);
resourceBench.setEmployeeId(employee.getEmployeeId());
resourceBench.setResourceRole(employee.getRole());
......@@ -824,7 +875,10 @@ public class ResourceService implements IResourceService {
resourceBench.setBillableStatus(MyTeamUtils.BENCH_BILLABILITY_STATUS);
resourceBench.setEmployeeId(employee.getEmployeeId());
resourceBench.setBillingEndDate(projectService.getProjectByProjectId(MyTeamUtils.BENCH_PROJECT_ID).getProjectEndDate());
resourcePersisted = addResource(resourceBench, loginEmpId);
// resourcePersisted = addResource(resourceBench, loginEmpId);
resourcePersisted = resourceRepo.save(resourceBench);
respMap.put("message","Resource has been created");
return resourcePersisted;
......
......@@ -255,7 +255,7 @@ myApp.controller("assignRoleController",function($scope, myFactory, $mdDialog, $
if(dataToPass.action == "Add"){
$scope.empId = "";
$scope.empName = "";
$scope.gender = "";
$scope.gender;
$scope.empRole;
$scope.empEmail = "";
$scope.functionalGroup;
......
......@@ -35,9 +35,10 @@
<tr>
<td colspan="-10"><b>Gender:</b><span class="mandatory"></span></td>
<td colspan="8"><md-select ng-model="gender" ng-blur="validateMessage()" name="gender"
md-selected-text="getSelectedGender()" id="gender">
md-selected-text="getSelectedGender()" id="gender"><md-optgroup
label="Select Gender">
<md-option ng-model="gender" value="Male">Male </md-option> <md-option
ng-model="gender" value="Female">Female</md-option> </md-select></td>
ng-model="gender" value="Female">Female</md-option></md-optgroup> </md-select></td>
</tr>
<tr>
......
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