Commit b661afcb authored by Vijay Akula's avatar Vijay Akula

Fixed Update Resource issue

parent a108af67
......@@ -7,7 +7,9 @@ import com.nisum.myteam.model.ReportSeriesRecord;
import com.nisum.myteam.model.dao.Account;
import com.nisum.myteam.model.dao.Employee;
import com.nisum.myteam.model.dao.ResourceAllocation;
import com.nisum.myteam.model.vo.ResourceVO;
import com.nisum.myteam.service.IEmployeeService;
import com.nisum.myteam.service.IResourceAllocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
......@@ -44,6 +46,9 @@ public class ReportsController {
@Autowired
private IEmployeeService employeeService;
@Autowired
private IResourceAllocationService resourceService;
//Ok Response
@RequestMapping(value = "/getEmployeesByFunctionalGroup1",
method = RequestMethod.GET,
......@@ -105,12 +110,15 @@ public class ReportsController {
}
/*
//Not Ok Response
@RequestMapping(value = "/getBillabilityDetailsByAccount",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<ColumnChartData> getBillabilityDetailsByAccount()
throws MyTeamException {
ProjectionOperation projectToMatchModel = project()
.andExpression("account").as("categories")
.andExpression("billableStatus").as("seriesName")
......@@ -122,9 +130,9 @@ public class ReportsController {
.as("count"),
projectToMatchModel);
// Convert the aggregation result into a List
AggregationResults<ColumnChartData> groupResults = mongoTemplate
.aggregate(aggregate, ResourceAllocation.class,
AggregationResults<ColumnChartData> groupResults = mongoTemplate.aggregate(aggregate, ResourceAllocation.class,
ColumnChartData.class);
List<ColumnChartData> result = groupResults.getMappedResults();
List<String> statusList = new ArrayList();
......@@ -172,6 +180,7 @@ public class ReportsController {
return new ResponseEntity<>(reportData, HttpStatus.OK);
}
*/
//ok response
@RequestMapping(value = "/getBillabilityDetailsByMonth",
......@@ -312,20 +321,22 @@ public class ReportsController {
return new ResponseEntity<>(empList, HttpStatus.OK);
}
// @RequestMapping(value = "/fetchEmployeeDetailsByAccountBillability",
// method = RequestMethod.GET,
// produces = MediaType.APPLICATION_JSON_VALUE)
// public ResponseEntity<List<ResourceAllocation>> fetchEmployeeDetailsByAccountBillability(
// @RequestParam("account") String account,
// @RequestParam("billabilityStatus") String billabilityStatus)
// throws MyTeamException {
// List<ResourceAllocation> resourcesList = new ArrayList<>();
// if (account != null && !account.isEmpty()) {
// resourcesList = resourceService.findByAccountAndActiveAndBillableStatus(
// account, true, billabilityStatus);
// }
// return new ResponseEntity<>(resourcesList, HttpStatus.OK);
// }
@RequestMapping(value = "/fetchEmployeeDetailsByAccountBillability",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<ResourceVO>> fetchEmployeeDetailsByAccountBillability(
@RequestParam("account") String account,
@RequestParam("billabilityStatus") String billabilityStatus)
throws MyTeamException {
List<ResourceVO> resourcesList = new ArrayList<>();
if (account != null && !account.isEmpty()) {
resourcesList = resourceService.getAllResourcesVO();
}
return new ResponseEntity<>(resourcesList, HttpStatus.OK);
}
@RequestMapping(value = "/fetchEmployeeDetailsByDateBillability",
method = RequestMethod.GET,
......
......@@ -82,7 +82,7 @@ public class ResourceAllocationController {
if (resourceAllocService.isResourceExistsForProject(resourceAllocationReq.getEmployeeId(), resourceAllocationReq.getProjectId())) {
resourceAllocService.updatePreviousResource(resourceAllocationReq, loginEmpId);
resourceAllocService.updateResource(resourceAllocationReq, loginEmpId);
resourceAllocService.insertNewResourceAllocWithNewStatus(resourceAllocationReq, loginEmpId);
}
ResponseDetails createResponseDetails = new ResponseDetails(new Date(), Integer.parseInt(resourceAllocService.respMap.get("statusCode").toString()), resourceAllocService.respMap.get("message").toString(),
......
......@@ -13,32 +13,19 @@ public interface IResourceAllocationService {
ResourceAllocation addResourceAllocation(ResourceAllocation resourceAllocation, String loginEmpId) throws MyTeamException;
void updateResource(ResourceAllocation resourceAllocation, String loginEmpId) throws MyTeamException;
public void updateExistedResourceAlloc(ResourceAllocation resourceAlloc) throws MyTeamException;
void deleteResource(ResourceAllocation resource, String loginEmpId);
public void insertNewResourceAllocWithNewStatus(ResourceAllocation resourceAllocReq, String loginEmpId) throws MyTeamException;
void deleteResource(ResourceAllocation resource, String loginEmpId);
List<ResourceAllocation> getAllResourcesForAllActiveProjects();
// Resource save(Resource resource);
// void addResources(Employee employee, String loginEmpId);
// void inactivateResource(Employee employeeReq, Employee employeeUpdated, String loginEmpId);
List<ResourceAllocation> getResourcesSortByBillingStartDate(String employeeId);
// List<Resource> getAllResourcesForProject(String projectId, String status);
// List<Resource> getResourcesForEmployee(String empId);
// List<Resource> getAllResourcesForProject(String projectId);
List<ResourceVO> getActiveResources(String empId);
// List<Resource> getResourcesForShift(String shift);
public List<ResourceVO> getResourcesForProject(String projectId, String statusFlag);
public List<ResourceAllocation> getResourcesUnderDeliveryLead(String empId);
......@@ -61,5 +48,21 @@ public interface IResourceAllocationService {
public void deleteResourcesUnderProject(String projectId);
public ResourceAllocation addResourceToBenchProject(Employee employee, String loginEmpId) throws MyTeamException;
// List<Resource> getResourcesForShift(String shift);
// List<Resource> getAllResourcesForProject(String projectId, String status);
// List<Resource> getResourcesForEmployee(String empId);
// List<Resource> getAllResourcesForProject(String projectId);
// Resource save(Resource resource);
// void addResources(Employee employee, String loginEmpId);
// void inactivateResource(Employee employeeReq, Employee employeeUpdated, String loginEmpId);
}
......@@ -48,6 +48,8 @@ public class EmployeeService implements IEmployeeService {
@Autowired
private IEmployeeLocationService empLocationService;
@Autowired
private IResourceAllocationService resourceService;
@Override
public Employee createEmployee(Employee employee, String loginEmpId) throws MyTeamException {
......@@ -56,7 +58,7 @@ public class EmployeeService implements IEmployeeService {
employee.setModifiedBy(loginEmpId);
// adding employee to Bench Allocation
// projectService.addNewBeanchAllocation(employee, loginEmpId);
resourceService.addResourceToBenchProject(employee, loginEmpId);
// Saving employee Location Details.
empLocationService.save(employee);
......
......@@ -183,9 +183,6 @@ public class ProjectService implements IProjectService {
}
@Override
public List<EmpLoginData> employeeLoginsBasedOnDate(long id,
String fromDate, String toDate) throws MyTeamException {
......@@ -241,12 +238,9 @@ public class ProjectService implements IProjectService {
@Override
public List<Project> getOnlyActiveProjects() {
return getAllProjects().stream()
.filter(project -> !project.getStatus().equalsIgnoreCase("Completed"))
.collect(Collectors.toList());
}
......@@ -378,16 +372,12 @@ public class ProjectService implements IProjectService {
}
public List<Project> getActiveProjects() throws MyTeamException {
List<Project> projects = projectRepo.findAll();
return projects.stream().filter(project -> project.getStatus().equalsIgnoreCase(MyTeamUtils.ACTIVE)).collect(Collectors.toList());
}
public Project getProjectByProjectId(String projectId) {
Project project = null;
if (StringUtils.isNotBlank(projectId)) {
......@@ -404,10 +394,55 @@ public class ProjectService implements IProjectService {
}
}
// public Resource addNewBeanchAllocation(Employee employee, String loginEmpId) {
// ResourceAllocation resourcePersisted = null;
// Resource resourceBench = new Resource();
// resourceBench.setAccount(MyTeamUtils.BENCH_ACCOUNT);
// resourceBench.setBillableStatus(MyTeamUtils.BENCH_BILLABILITY_STATUS);
// resourceBench.setDesignation(employee.getDesignation());
// resourceBench.setEmailId(employee.getEmailId());
// resourceBench.setEmployeeId(employee.getEmployeeId());
// resourceBench.setMobileNumber(employee.getMobileNumber());
//
// resourceBench.setEmployeeName(employee.getEmployeeName());
// resourceBench.setProjectId(MyTeamUtils.BENCH_PROJECT_ID);
// resourceBench.setStartDate(employee.getDateOfJoining() != null ? employee.getDateOfJoining() : new Date());
//
// Project project = projectRepo.findByProjectId(MyTeamUtils.BENCH_PROJECT_ID);
// resourceBench.setProjectName(project.getProjectName());
// resourceBench.setAccountId(project.getAccountId());
// resourceBench.setDomainId(project.getDomainId());
// resourceBench.setShift(employee.getShift());
// resourceBench.setRole(employee.getRole());
//
// if (null != employee.getEmpStatus() && employee.getEmpStatus().trim().equalsIgnoreCase(MyTeamUtils.IN_ACTIVE_SPACE)) {
// resourceBench.setEndDate(employee.getEndDate());
// resourceBench.setActive(false);
// } else {
// employee.setEmpStatus(MyTeamUtils.ACTIVE);
// resourceBench.setEndDate(project.getProjectEndDate());
// resourceBench.setActive(true);
// }
//
// try {
// resourcePersisted = resourceService.addResource(resourceBench, loginEmpId);
// } catch (MyTeamException e) {
// e.printStackTrace();
// }
//
// return resourcePersisted;
// }
//List<Resource> existingTeammates = resourceRepo.findByProjectId(project.getProjectId());
// for (Resource existingTeammate : existingTeammates) {
// existingTeammate.setActive(false);
......@@ -504,41 +539,5 @@ public class ProjectService implements IProjectService {
// public Resource addNewBeanchAllocation(Employee employee, String loginEmpId) {
// Resource resourcePersisted = null;
// Resource resourceBench = new Resource();
// resourceBench.setAccount(MyTeamUtils.BENCH_ACCOUNT);
// resourceBench.setBillableStatus(MyTeamUtils.BENCH_BILLABILITY_STATUS);
// resourceBench.setDesignation(employee.getDesignation());
// resourceBench.setEmailId(employee.getEmailId());
// resourceBench.setEmployeeId(employee.getEmployeeId());
// resourceBench.setMobileNumber(employee.getMobileNumber());
//
// resourceBench.setEmployeeName(employee.getEmployeeName());
// resourceBench.setProjectId(MyTeamUtils.BENCH_PROJECT_ID);
// resourceBench.setStartDate(employee.getDateOfJoining() != null ? employee.getDateOfJoining() : new Date());
//
// Project project = projectRepo.findByProjectId(MyTeamUtils.BENCH_PROJECT_ID);
// resourceBench.setProjectName(project.getProjectName());
// resourceBench.setAccountId(project.getAccountId());
// resourceBench.setDomainId(project.getDomainId());
// resourceBench.setShift(employee.getShift());
// resourceBench.setRole(employee.getRole());
//
// if (null != employee.getEmpStatus() && employee.getEmpStatus().trim().equalsIgnoreCase(MyTeamUtils.IN_ACTIVE_SPACE)) {
// resourceBench.setEndDate(employee.getEndDate());
// resourceBench.setActive(false);
// } else {
// employee.setEmpStatus(MyTeamUtils.ACTIVE);
// resourceBench.setEndDate(project.getProjectEndDate());
// resourceBench.setActive(true);
// }
//
// try {
// resourcePersisted = resourceService.addResource(resourceBench, loginEmpId);
// } catch (MyTeamException e) {
// e.printStackTrace();
// }
//
// return resourcePersisted;
// }
\ No newline at end of file
......@@ -65,17 +65,7 @@ public class ResourceAllocationService implements IResourceAllocationService {
}
public void updateResourceAlloc(ResourceAllocation resourceAlloc) {
if (resourceAlloc != null) {
ResourceAllocation resourcePers = resourceAllocationRepo.save(resourceAlloc);
respMap.put("statusCode", 801);
respMap.put("message", "resource has been updated");
respMap.put("resourceObj", resourcePers);
}
}
public void updatePreviousResource(ResourceAllocation resourceAllocReq, String loginEmpId) throws MyTeamException {
......@@ -91,11 +81,32 @@ public class ResourceAllocationService implements IResourceAllocationService {
//resourceAllocPrev.setBillingEndDate(); //adding resource.
log.info("After setting the date:::before saving the Resource::" + resourceAllocPrev);
this.updateResourceAlloc(resourceAllocPrev);
this.updateExistedResourceAlloc(resourceAllocPrev);
}
}
public void updateExistedResourceAlloc(ResourceAllocation resourceAlloc) {
if (resourceAlloc != null) {
ResourceAllocation resourcePers = resourceAllocationRepo.save(resourceAlloc);
respMap.put("statusCode", 801);
respMap.put("message", "resource has been updated");
respMap.put("resourceObj", resourcePers);
}
}
public void insertNewResourceAllocWithNewStatus(ResourceAllocation resourceAllocReq, String loginEmpId) throws MyTeamException {
resourceAllocReq.setId(null);
ResourceAllocation resourceAllocationPers = resourceAllocationRepo.insert(resourceAllocReq);
respMap.put("statusCode", 801);
respMap.put("message", "Resource updated successfully");
respMap.put("resourceObj", resourceAllocationPers);
}
public boolean validateBillingStartEndDateAgainstProjectStartEndDate(ResourceAllocation resourceAllocation, String loginEmpId) throws MyTeamException {
......@@ -162,24 +173,22 @@ public class ResourceAllocationService implements IResourceAllocationService {
if (resourceListWithLatestRecord != null && resourceListWithLatestRecord.size() > 0) {
ResourceAllocation resourceAllocPrev = resourceListWithLatestRecord.get(0);//latest resource record.
message = "Resource " + resourceAllocPrev.getEmployeeId() + " already Assigned to the "
+ projectService.getProjectByProjectId(resourceAllocPrev.getProjectId()).getProjectName()
+ " Project" + " from " + resourceAllocPrev.getBillingStartDate() + "to " + resourceAllocPrev.getBillingEndDate();
isAssigned = true;
respMap.put("statusCode", 815);
respMap.put("message", message);
if (!resourceAllocPrev.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)) {
message = "Resource " + resourceAllocPrev.getEmployeeId() + " already Assigned to the "
+ projectService.getProjectByProjectId(resourceAllocPrev.getProjectId()).getProjectName()
+ " Project" + " from " + resourceAllocPrev.getBillingStartDate() + "to " + resourceAllocPrev.getBillingEndDate();
isAssigned = true;
respMap.put("statusCode", 815);
respMap.put("message", message);
}
}
return isAssigned;
}
public void updateResource(ResourceAllocation resourceAllocReq, String loginEmpId) throws MyTeamException {
ResourceAllocation resourceAllocationPers = resourceAllocationRepo.save(resourceAllocReq);
respMap.put("statusCode", 801);
respMap.put("message", "Resource updated successfully");
respMap.put("resourceObj", resourceAllocationPers);
}
public void deleteResource(ResourceAllocation resourceReq, String loginEmpId) {
List<ResourceAllocation> resourcesList = resourceAllocationRepo.findByEmployeeIdAndProjectId(resourceReq.getEmployeeId(), resourceReq.getProjectId());
......@@ -538,6 +547,27 @@ public class ResourceAllocationService implements IResourceAllocationService {
}
@Override
public ResourceAllocation addResourceToBenchProject(Employee employee, String loginEmpId) throws MyTeamException {
ResourceAllocation resourcePersisted = null;
ResourceAllocation resourceBench = new ResourceAllocation();
resourceBench.setProjectId(MyTeamUtils.BENCH_PROJECT_ID);
resourceBench.setEmployeeId(employee.getEmployeeId());
resourceBench.setResourceRole(employee.getRole());
resourceBench.setBillingStartDate(employee.getDateOfJoining() != null ? employee.getDateOfJoining() : new Date());
resourceBench.setBillableStatus(MyTeamUtils.BENCH_BILLABILITY_STATUS);
resourceBench.setEmployeeId(employee.getEmployeeId());
resourceBench.setBillingEndDate(employee.getEndDate());
resourcePersisted = addResourceAllocation(resourceBench, loginEmpId);
return resourcePersisted;
}
}
......
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