Commit 0861416c authored by Vijay Akula's avatar Vijay Akula

Added response format for the get methods of resource controller

parent 97c144c6
......@@ -97,75 +97,131 @@ public class ResourceController {
// @RequestMapping(value = "/getEmployeeProjectInfo"
@RequestMapping(value = "/resources/employeeId/{employeeId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<Resource>> getResourcesSortByStartDate(@PathVariable(value = "employeeId",required = true) String employeeId)
public ResponseEntity<?> getResourcesSortByStartDate(@PathVariable(value = "employeeId", required = true) String employeeId, HttpServletRequest request)
throws MyTeamException {
List<Resource> projectInfo = resourceService.getResourcesSortByStartDate(employeeId);
return new ResponseEntity<>(projectInfo, HttpStatus.OK);
if (StringUtils.isNotBlank(employeeId)) {
List<Resource> resourcesList = resourceService.getResourcesSortByStartDate(employeeId);
ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Resources have been retrieved successfully",
"List of Resources for an employee", resourcesList, request.getRequestURI(), "Resource List details", null);
return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
}
ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Please provide the valid Employee Id",
"Employee Id is not valid", null, request.getRequestURI(), "Resource details", null);
return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
}
//@RequestMapping(value = "/getMyTeamDetails"
@RequestMapping(value = "/resources/active", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<Resource>> getActiveResources(@RequestParam("employeeId") String employeeId)
public ResponseEntity<?> getActiveResources(@RequestParam(value = "employeeId", required = false) String employeeId, HttpServletRequest request)
throws MyTeamException {
if (StringUtils.isNotBlank(employeeId)) {
List<Resource> employeesRoles = resourceService.getActiveResources(employeeId);
return new ResponseEntity<>(employeesRoles, HttpStatus.OK);
}
ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Resources have been retrieved successfully",
"List of Resources who are active in the projects", employeesRoles, request.getRequestURI(), "Resource List details", null);
return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
}
ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Please provide the valid Employee Id",
"Employee Id is not valid", null, request.getRequestURI(), "Resource details", null);
return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
}
// @RequestMapping(value = "/getShiftDetails"
@RequestMapping(value = "/resources/shifts/{shift}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<Resource>> getResourcesForShift(@PathVariable("shift") String shift)
public ResponseEntity<?> getResourcesForShift(@PathVariable(value = "shift", required = true) String shift, HttpServletRequest request)
throws MyTeamException {
if (StringUtils.isNotBlank(shift)) {
List<Resource> resourcesList = resourceService.getResourcesForShift(shift);
return new ResponseEntity<>(resourcesList, HttpStatus.OK);
ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Resources have been retrieved successfully",
"List of Resources for the provided shift", resourcesList, request.getRequestURI(), "Resource List for shift", null);
return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
}
ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Please provide the valid Shift value",
"List of Resources for the provided shift", null, request.getRequestURI(), "Resource details", null);
return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
}
// @RequestMapping(value = "/getProjectAllocations"
@RequestMapping(value = "/resources/projects", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<Resource>> getResourcesAllocatedForAllProjects() throws MyTeamException {
public ResponseEntity<?> getResourcesAllocatedForAllProjects(HttpServletRequest request) throws MyTeamException {
List<Resource> resourcesList = resourceService.getResourcesForActiveProjects();
return new ResponseEntity<>(resourcesList, HttpStatus.OK);
ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Resources have been retrieved successfully",
"List of Resources for the projects", resourcesList, request.getRequestURI(), "Resource details", null);
return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
}
// @RequestMapping(value = "/getProjectDetails"
@RequestMapping(value = "/resources/project/{projectId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<Resource>> getResourcesForProject(@PathVariable("projectId") String projectId,
@RequestParam(value = "status", required = false, defaultValue = MyTeamUtils.ACTIVE) String status)
public ResponseEntity<?> getResourcesForProject(@PathVariable(value = "projectId", required = true) String projectId,
@RequestParam(value = "status", required = false, defaultValue = MyTeamUtils.ACTIVE) String status,
HttpServletRequest request)
throws MyTeamException {
if (StringUtils.isNotBlank(projectId)) {
List<Resource> resourcesList = resourceService.getResourcesForProject(projectId, status);
return new ResponseEntity<>(resourcesList, HttpStatus.OK);
ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Resources have been retrieved successfully",
"List of Resources for a project", resourcesList, request.getRequestURI(), "Resource details", null);
return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
}
ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Please provide ProjectId",
"List of Resources for a project", null, request.getRequestURI(), "Resource details", null);
return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
}
//@RequestMapping(value = "/getTeamDetails"
@RequestMapping(value = "/resources/deliverylead/{deliveryLeadId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<Resource>> getTeamDetails(@PathVariable("deliveryLeadId") String deliveryLeadId)
public ResponseEntity<?> getTeamDetails(@PathVariable(value = "deliveryLeadId", required = true) String deliveryLeadId, HttpServletRequest request)
throws MyTeamException {
if (StringUtils.isNotBlank(deliveryLeadId)) {
List<Resource> resourcesList = resourceService.getResourcesUnderDeliveryLead(deliveryLeadId);
return new ResponseEntity<>(resourcesList, HttpStatus.OK);
ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Resources have been retrieved successfully",
"List of Resources for a project", resourcesList, request.getRequestURI(), "Resource details", null);
}
ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Please provide ProjectId",
"List of Resources for DeliveryLead", null, request.getRequestURI(), "Resource details", null);
return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
}
@RequestMapping(value = "resources/unAssignedEmployees", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<Employee>> getUnAssignedEmployees() throws MyTeamException {
public ResponseEntity<?> getUnAssignedEmployees(HttpServletRequest request) throws MyTeamException {
List<Employee> employeesList = projectService.getUnAssignedEmployees();
return new ResponseEntity<>(employeesList, HttpStatus.OK);
}
ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Resources have been retrieved successfully",
"List of Resources who are not assigned to project", employeesList, request.getRequestURI(), "Resource details", null);
return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
}
@RequestMapping(value = "/getEmployeesDashBoard", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<EmployeeDashboardVO>> getEmployeesDashBoard() throws MyTeamException {
public ResponseEntity<?> getEmployeesDashBoard(HttpServletRequest request) throws MyTeamException {
List<EmployeeDashboardVO> employeeDashBoardList = projectService.getEmployeesDashBoard();
return new ResponseEntity<>(employeeDashBoardList, HttpStatus.OK);
ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Resources have been retrieved successfully",
"List of Resources for dashboard", employeeDashBoardList, request.getRequestURI(), "Resource details", null);
return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
}
@RequestMapping(value = "/getEmployeesHavingVisa", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<Employee>> getEmployeesHavingVisa(@RequestParam("visa") String passport)
public ResponseEntity<?> getEmployeesHavingVisa(@RequestParam("visa") String passport,HttpServletRequest request)
throws MyTeamException {
List<Employee> employees = new ArrayList<>();
if (passport != null && !"passport".equalsIgnoreCase(passport)) {
List<EmployeeVisa> employeeVisas = employeeVisaRepo.findByVisaName(passport);
List<String> employeeIds = null;
......@@ -180,20 +236,20 @@ public class ResourceController {
}
}
}
return new ResponseEntity<>(employees, HttpStatus.OK);
} else {
// List<EmployeeRoles> employees = new ArrayList<>();
if (employeeService.getActiveEmployees() != null) {
employees = employeeService.getActiveEmployees().stream()
.sorted((o1, o2) -> o1.getEmployeeName().compareTo(o2.getEmployeeName()))
.collect(Collectors.toList());
}
return new ResponseEntity<>(employees, HttpStatus.OK);
}
}
ResponseDetails responseDetails = new ResponseDetails(new Date(), 602, "Resources have been retrieved successfully",
"List of Resources who has visa", employees, request.getRequestURI(), "Resource details", null);
return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.OK);
}
@RequestMapping(value = "/addEmployeeToTeamWithCheck", method = RequestMethod.POST, produces = MediaType.TEXT_PLAIN_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
......
......@@ -127,22 +127,25 @@ public class ResourceService implements IResourceService {
}
@Override
public String updateResource(Resource resource, String loginEmpId) throws MyTeamException {
public String updateResource(Resource resourceReq, String loginEmpId) throws MyTeamException {
// String result = null;
MyTeamResultDTO myResultDto = new MyTeamResultDTO();
myResultDto.setResultCode(MyTeamResultDTO.SUCCESS_CODE);
myResultDto.setResultData("TeamMate updated successfuly");
Resource existingTeammate = resourceRepo.findById(resource.getId());
Resource existingResource = resourceRepo.findById(resourceReq.getId());
log.info("From database: Resource Details::"+existingResource);
List<Billing> listBD = billingService.getActiveBillings(resource.getEmployeeId(), resource.getProjectId());
Date resEndDate = resource.getEndDate();
Date resEndDate = resourceReq.getEndDate();
log.info("ResEndDate::"+resEndDate);
List<Billing> listBD = billingService.getActiveBillings(resourceReq.getEmployeeId(), resourceReq.getProjectId());
// Handling past or present endDate (To "Inactive" the Resource)
if (resEndDate.compareTo(new Date()) <= 0 && resEndDate.compareTo(existingTeammate.getEndDate()) != 0) {
existingTeammate.setActive(false);
existingTeammate.setEndDate(resEndDate);
if (resEndDate.compareTo(new Date()) <= 0 && resEndDate.compareTo(existingResource.getEndDate()) != 0) {
existingResource.setActive(false);
existingResource.setEndDate(resEndDate);
if (listBD != null && !listBD.isEmpty()) {
Billing billingDetailsExisting = listBD.get(0);
Date actualEndDate = resEndDate;
......@@ -159,8 +162,8 @@ public class ResourceService implements IResourceService {
billingDetails.setBillingStartDate(resEndDate);
billingDetails.setAccount(MyTeamUtils.BENCH_ACCOUNT);
billingDetails.setActive(true);
billingDetails.setEmployeeId(existingTeammate.getEmployeeId());
billingDetails.setEmployeeName(existingTeammate.getEmployeeName());
billingDetails.setEmployeeId(existingResource.getEmployeeId());
billingDetails.setEmployeeName(existingResource.getEmployeeName());
// billingDetails.setCreateDate(new Date());// Commented as added
// common audit fields
billingDetails.setProjectId(MyTeamUtils.BENCH_PROJECT_ID);
......@@ -175,14 +178,14 @@ public class ResourceService implements IResourceService {
billingService.addBilling(billingDetails, loginEmpId);
newBenchAllocation.setBillableStatus(MyTeamUtils.BENCH_BILLABILITY_STATUS);
newBenchAllocation.setDesignation(existingTeammate.getDesignation());
newBenchAllocation.setEmailId(existingTeammate.getEmailId());
newBenchAllocation.setEmployeeId(existingTeammate.getEmployeeId());
newBenchAllocation.setDesignation(existingResource.getDesignation());
newBenchAllocation.setEmailId(existingResource.getEmailId());
newBenchAllocation.setEmployeeId(existingResource.getEmployeeId());
newBenchAllocation.setActive(true);
newBenchAllocation.setEmployeeName(existingTeammate.getEmployeeName());
newBenchAllocation.setEmployeeName(existingResource.getEmployeeName());
newBenchAllocation.setProjectId(MyTeamUtils.BENCH_PROJECT_ID);
newBenchAllocation.setShift(existingTeammate.getShift());
newBenchAllocation.setRole(existingTeammate.getRole());
newBenchAllocation.setShift(existingResource.getShift());
newBenchAllocation.setRole(existingResource.getRole());
Calendar cal = Calendar.getInstance();
cal.setTime(resEndDate);
......@@ -197,11 +200,17 @@ public class ResourceService implements IResourceService {
myResultDto.setResultCode(MyTeamResultDTO.SUCCESS_CODE);
myResultDto.setResultData(
"Resource Successfully moved from " + resource.getProjectName() + " project to Bench.");
"Resource Successfully moved from " + resourceReq.getProjectName() + " project to Bench.");
} else {
log.info("Before compare billable status::");
log.info("Existing Resource:::"+existingResource);
log.info("Resource Request Details::"+resourceReq);
// Handling Resource Project Billability Status change
if (resource.getBillableStatus() != null && existingTeammate.getBillableStatus() != null
&& !existingTeammate.getBillableStatus().equalsIgnoreCase(resource.getBillableStatus())) {
if (resourceReq.getBillableStatus() != null && existingResource.getBillableStatus() != null
&& !existingResource.getBillableStatus().equalsIgnoreCase(resourceReq.getBillableStatus())) {
/*
* List<BillingDetails> bDetailsList =
* teamMatesBillingRepo.findByEmployeeId(projectTeamMate.
......@@ -209,20 +218,20 @@ public class ResourceService implements IResourceService {
* (!e.isActive())).sorted(Comparator.comparing(BillingDetails::
* getBillingEndDate).reversed()) .collect(Collectors.toList());
*/
String result = validateBillabilityStartDate(listBD, resource);
String result = validateBillabilityStartDate(listBD, resourceReq);
if (result != null) { // Invalid Billability Start date
return result;
}
if (listBD != null && !listBD.isEmpty()) {
Billing billingDetails = listBD.get(0);
Calendar cal = Calendar.getInstance();
cal.setTime(resource.getNewBillingStartDate());
cal.setTime(resourceReq.getNewBillingStartDate());
cal.add(Calendar.DAY_OF_MONTH, -1);
Date startDate = existingTeammate.getNewBillingStartDate() != null
? existingTeammate.getNewBillingStartDate() : existingTeammate.getStartDate();
if (startDate.getDate() == resource.getNewBillingStartDate().getDate()) {
Date startDate = existingResource.getNewBillingStartDate() != null
? existingResource.getNewBillingStartDate() : existingResource.getStartDate();
if (startDate.getDate() == resourceReq.getNewBillingStartDate().getDate()) {
billingDetails.setBillingEndDate(
DateUtils.truncate(resource.getNewBillingStartDate(), Calendar.DATE));
DateUtils.truncate(resourceReq.getNewBillingStartDate(), Calendar.DATE));
} else {
billingDetails.setBillingEndDate(DateUtils.truncate(cal.getTime(), Calendar.DATE));
}
......@@ -230,41 +239,41 @@ public class ResourceService implements IResourceService {
billingService.updateBilling(billingDetails, loginEmpId);
}
Billing billings = new Billing();
billings.setEmployeeId(resource.getEmployeeId());
billings.setEmployeeName(resource.getEmployeeName());
billings.setProjectId(resource.getProjectId());
billings.setAccount(existingTeammate.getAccount());
billings.setProjectName(resource.getProjectName());
billings.setBillableStatus(resource.getBillableStatus());
billings.setEmployeeId(resourceReq.getEmployeeId());
billings.setEmployeeName(resourceReq.getEmployeeName());
billings.setProjectId(resourceReq.getProjectId());
billings.setAccount(existingResource.getAccount());
billings.setProjectName(resourceReq.getProjectName());
billings.setBillableStatus(resourceReq.getBillableStatus());
billings.setActive(true);
billings.setBillingStartDate(DateUtils.truncate(resource.getNewBillingStartDate(), Calendar.DATE));
billings.setBillingStartDate(DateUtils.truncate(resourceReq.getNewBillingStartDate(), Calendar.DATE));
billings.setBillingEndDate(DateUtils.truncate(resEndDate, Calendar.DATE));
// billings.setCreateDate(new Date());// Commented as added
// common audit fields
billingService.addBilling(billings, loginEmpId);
existingTeammate.setBillableStatus(resource.getBillableStatus());
existingTeammate
.setNewBillingStartDate(DateUtils.truncate(resource.getNewBillingStartDate(), Calendar.DATE));
existingResource.setBillableStatus(resourceReq.getBillableStatus());
existingResource
.setNewBillingStartDate(DateUtils.truncate(resourceReq.getNewBillingStartDate(), Calendar.DATE));
} else {// Handling Billability Start Date change
List<Billing> bDetailsList = billingRepo.findByEmployeeId(resource.getEmployeeId()).stream()
List<Billing> bDetailsList = billingRepo.findByEmployeeId(resourceReq.getEmployeeId()).stream()
.filter(e -> (!e.isActive()))
.sorted(Comparator.comparing(Billing::getBillingEndDate).reversed())
.collect(Collectors.toList());
String result = validateBillabilityStartDate(bDetailsList, resource);
String result = validateBillabilityStartDate(bDetailsList, resourceReq);
if (result != null) { // Invalid Billability Start date
return result;
}
if (bDetailsList != null && !bDetailsList.isEmpty()) {
Calendar cal = Calendar.getInstance();
cal.setTime(resource.getNewBillingStartDate());
cal.setTime(resourceReq.getNewBillingStartDate());
cal.add(Calendar.DAY_OF_MONTH, -1);
Billing preBillingDetails = bDetailsList.get(0);
if (preBillingDetails.getBillingStartDate().getDate() == resource.getNewBillingStartDate()
if (preBillingDetails.getBillingStartDate().getDate() == resourceReq.getNewBillingStartDate()
.getDate()) {
preBillingDetails.setBillingEndDate(
DateUtils.truncate(resource.getNewBillingStartDate(), Calendar.DATE));
DateUtils.truncate(resourceReq.getNewBillingStartDate(), Calendar.DATE));
} else {
preBillingDetails.setBillingEndDate(DateUtils.truncate(cal.getTime(), Calendar.DATE));
}
......@@ -273,46 +282,46 @@ public class ResourceService implements IResourceService {
if (listBD != null && !listBD.isEmpty()) {
Billing billingDetails = listBD.get(0);
billingDetails
.setBillingStartDate(DateUtils.truncate(resource.getNewBillingStartDate(), Calendar.DATE));
.setBillingStartDate(DateUtils.truncate(resourceReq.getNewBillingStartDate(), Calendar.DATE));
billingDetails.setBillingEndDate(DateUtils.truncate(resEndDate, Calendar.DATE));
billingService.addBilling(billingDetails, loginEmpId);
}
existingTeammate
.setNewBillingStartDate(DateUtils.truncate(resource.getNewBillingStartDate(), Calendar.DATE));
existingResource
.setNewBillingStartDate(DateUtils.truncate(resourceReq.getNewBillingStartDate(), Calendar.DATE));
}
if (resEndDate.compareTo(existingTeammate.getEndDate()) != 0) {
existingTeammate.setEndDate(resEndDate);
if (resEndDate.compareTo(existingResource.getEndDate()) != 0) {
existingResource.setEndDate(resEndDate);
}
}
if (MyTeamResultDTO.SUCCESS_CODE.equals(myResultDto.getResultCode())) {
// Handling Role change
if ((existingTeammate.getRole() != null && !existingTeammate.getRole().equalsIgnoreCase(resource.getRole()))
|| (resource.getRole() != null)
&& !resource.getRole().equalsIgnoreCase(existingTeammate.getRole())) {
existingTeammate.setRole(resource.getRole());
addOrUpdateTeamMateRole(resource.getRole(), resource.getProjectId(), resource.getEmployeeId(), true,
if ((existingResource.getRole() != null && !existingResource.getRole().equalsIgnoreCase(resourceReq.getRole()))
|| (resourceReq.getRole() != null)
&& !resourceReq.getRole().equalsIgnoreCase(existingResource.getRole())) {
existingResource.setRole(resourceReq.getRole());
addOrUpdateTeamMateRole(resourceReq.getRole(), resourceReq.getProjectId(), resourceReq.getEmployeeId(), true,
loginEmpId);
}
// Handling Shift change
if ((existingTeammate.getShift() != null
&& !existingTeammate.getShift().equalsIgnoreCase(resource.getShift()))
|| (resource.getShift() != null)
&& !resource.getShift().equalsIgnoreCase(existingTeammate.getShift())) {
if ((existingResource.getShift() != null
&& !existingResource.getShift().equalsIgnoreCase(resourceReq.getShift()))
|| (resourceReq.getShift() != null)
&& !resourceReq.getShift().equalsIgnoreCase(existingResource.getShift())) {
empShiftService.updateEmployeeShift(existingTeammate, loginEmpId);
empShiftService.updateEmployeeShift(existingResource, loginEmpId);
existingTeammate.setShift(resource.getShift());
Employee employeeDB = employeeRoleRepo.findByEmployeeId(resource.getEmployeeId());
employeeDB.setShift(resource.getShift());
existingResource.setShift(resourceReq.getShift());
Employee employeeDB = employeeRoleRepo.findByEmployeeId(resourceReq.getEmployeeId());
employeeDB.setShift(resourceReq.getShift());
employeeDB.setModifiedBy(loginEmpId);
employeeDB.setLastModifiedOn(new Date());
employeeRoleRepo.save(employeeDB);
}
existingTeammate.setAuditFields(loginEmpId, MyTeamUtils.UPDATE);// Setting
existingResource.setAuditFields(loginEmpId, MyTeamUtils.UPDATE);// Setting
// audit
// fields
resourceRepo.save(existingTeammate);
resourceRepo.save(existingResource);
}
return myResultDto.getResultData()[myResultDto.getDataArrayCounter()];
}
......
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