Commit fed165ca authored by Vijay Akula's avatar Vijay Akula

Modified code for all operations in resources as per new db design

parent 3ff7c67b
package com.nisum.myteam.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
......@@ -12,11 +11,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.nisum.myteam.exception.handler.MyTeamException;
import com.nisum.myteam.model.dao.Billing;
import com.nisum.myteam.service.IBillingService;
import lombok.extern.slf4j.Slf4j;
@RestController
......@@ -50,6 +47,8 @@ public class BillingController {
return new ResponseEntity<>(null, HttpStatus.OK);
}
// @RequestMapping(value = "/getEmployeeBillingDetailsAll"
@RequestMapping(value = "/billing", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<Billing>> getAllBillingsForEmployee(@RequestParam("employeeId") String employeeId)
......
......@@ -8,6 +8,8 @@ import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import com.nisum.myteam.model.dao.EmployeeVisa;
import com.nisum.myteam.repository.EmployeeVisaRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
......@@ -38,6 +40,10 @@ public class EmployeeController {
@Autowired
private IEmployeeRoleService employeeRoleService;
@Autowired
private EmployeeVisaRepo employeeVisaRepo;
@RequestMapping(value = "/employees/{empId}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> createEmployee( @RequestBody Employee employeeReq,
@PathVariable(value = "empId") String loginEmpId, HttpServletRequest request) throws MyTeamException {
......@@ -228,5 +234,42 @@ public class EmployeeController {
}
@RequestMapping(value = "/getEmployeesHavingVisa", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
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;
if (employeeVisas != null) {
employeeIds = employeeVisas.stream().map(EmployeeVisa::getEmployeeId).collect(Collectors.toList());
}
if (employeeIds != null && !employeeIds.isEmpty()) {
List<Employee> emps = empService.getActiveEmployees();
for (Employee emp : emps) {
if (employeeIds.contains(emp.getEmployeeId())) {
employees.add(emp);
}
}
}
} else {
if (empService.getActiveEmployees() != null) {
employees = empService.getActiveEmployees().stream()
.sorted((o1, o2) -> o1.getEmployeeName().compareTo(o2.getEmployeeName()))
.collect(Collectors.toList());
}
}
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);
}
}
\ No newline at end of file
......@@ -7,7 +7,6 @@ import com.nisum.myteam.model.dao.Project;
import com.nisum.myteam.service.IEmployeeService;
import com.nisum.myteam.service.IProjectService;
import com.nisum.myteam.statuscodes.ProjectStatus;
import com.nisum.myteam.utils.MyTeamUtils;
import com.nisum.myteam.utils.constants.ApplicationRole;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -38,7 +37,7 @@ public class ProjectController {
public ResponseEntity<?> createProject(@Valid @RequestBody Project projectReq,
@RequestParam(value = "loginEmpId") String loginEmpId, HttpServletRequest request) throws MyTeamException {
if (!projectService.isProjectExists(projectReq.getProjectName())) {
if (!projectService.isProjectExistsByName(projectReq.getProjectName())) {
String accountName = "";
Account account = projectService.getProjectAccount(projectReq.getAccountId());
......@@ -80,7 +79,7 @@ public class ProjectController {
@RequestParam(value = "loginEmpId") String loginEmpId, HttpServletRequest request) throws MyTeamException {
if (projectService.isProjectExistsById(projectId)) {
if (projectService.isProjectExists(project.getProjectName())) {
if (projectService.isProjectExistsByName(project.getProjectName())) {
Project updatedProject = projectService.updateProject(project, loginEmpId);
ResponseDetails getRespDetails = new ResponseDetails(new Date(), ProjectStatus.UPDATE.getCode(),
ProjectStatus.UPDATE.getMessage(), "Project Updation Description", null,
......@@ -183,21 +182,7 @@ public class ProjectController {
}
@RequestMapping(value = "/getMyProjectAllocations", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getMyProjectAllocations(
@RequestParam("employeeId") String employeeId, HttpServletRequest request) throws MyTeamException {
if (employeeId != null && !"".equalsIgnoreCase(employeeId)) {
ResponseDetails getRespDetails = new ResponseDetails(new Date(), 604, "Retrieved the project allocations successfully",
"Projects allocations for an employee", projectService.getProjectsForEmployee(employeeId), request.getRequestURI(), "Project details", null);
return new ResponseEntity<ResponseDetails>(getRespDetails, HttpStatus.OK);
}
ResponseDetails getRespDetails = new ResponseDetails(new Date(), 606, "Please Provide valid employee id",
"Project allocations for an employee", null, request.getRequestURI(), "Project details", null);
return new ResponseEntity<ResponseDetails>(getRespDetails, HttpStatus.OK);
}
}
......
......@@ -42,6 +42,7 @@ public class ResourceController {
private IResourceService resourceService;
@RequestMapping(value = "/resources", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> createResource(@RequestBody Resource resourceReq,
@RequestParam(value = "loginEmpId", required = true) String loginEmpId, HttpServletRequest request) throws MyTeamException {
......@@ -190,63 +191,27 @@ public class ResourceController {
}
@RequestMapping(value = "resources/unAssignedEmployees", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getUnAssignedEmployees(HttpServletRequest request) throws MyTeamException {
List<Employee> employeesList = projectService.getUnAssignedEmployees();
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<?> getEmployeesDashBoard(HttpServletRequest request) throws MyTeamException {
List<EmployeeDashboardVO> employeeDashBoardList = projectService.getEmployeesDashBoard();
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<?> 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;
if (employeeVisas != null) {
employeeIds = employeeVisas.stream().map(EmployeeVisa::getEmployeeId).collect(Collectors.toList());
}
if (employeeIds != null && !employeeIds.isEmpty()) {
List<Employee> emps = employeeService.getActiveEmployees();
for (Employee emp : emps) {
if (employeeIds.contains(emp.getEmployeeId())) {
employees.add(emp);
}
}
}
} else {
if (employeeService.getActiveEmployees() != null) {
employees = employeeService.getActiveEmployees().stream()
.sorted((o1, o2) -> o1.getEmployeeName().compareTo(o2.getEmployeeName()))
.collect(Collectors.toList());
}
}
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 = "resources/unAssignedEmployees", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
// public ResponseEntity<?> getUnAssignedEmployees(HttpServletRequest request) throws MyTeamException {
// List<Employee> employeesList = projectService.getUnAssignedEmployees();
//
// 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 = "/resources/getEmployeesDashBoard", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
// public ResponseEntity<?> getEmployeesDashBoard(HttpServletRequest request) throws MyTeamException {
// List<EmployeeDashboardVO> employeeDashBoardList = projectService.getEmployeesDashBoard();
//
// 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 = "/addEmployeeToTeamWithCheck", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
@RequestMapping(value = "resources/addEmployeeToTeamWithCheck", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> addEmployeeToTeamWithCheck(@RequestBody Resource resourceReq,
@RequestParam(value = "loginEmpId") String loginEmpId, HttpServletRequest request) throws MyTeamException {
......
......@@ -7,6 +7,7 @@ import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import org.bson.types.ObjectId;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.data.annotation.Id;
......@@ -31,7 +32,7 @@ public class Employee implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private String id;
private ObjectId id;
@NotBlank(message="Employee Id cannot be blank")
......
......@@ -32,7 +32,6 @@ public class Project extends AuditFields implements Serializable {
private String projectId;
private String projectName;
private String domainId;
private String domain;
private String accountId;
private String status;
private List<String> employeeIds;
......
......@@ -27,28 +27,20 @@ public class ResourceAllocation extends AuditFields implements Serializable {
private String employeeId;
private String projectId;
private String projectName;
//private String projectName;
@DateTimeFormat(iso = ISO.DATE)
private String billableStatus;
@DateTimeFormat(iso = ISO.DATE)
@DateTimeFormat(iso = ISO.DATE, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSX")
private Date billingStartDate;
@DateTimeFormat(iso = ISO.DATE)
@DateTimeFormat(iso = ISO.DATE, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSX")
private Date billingEndDate;
//private boolean active;
// private String role;
// @DateTimeFormat(iso = ISO.DATE)
// private Date projectStartDate;
//
// @DateTimeFormat(iso = ISO.DATE)
// private Date projectEndDate;
// private boolean active;
private String resourceRole;
}
......@@ -11,13 +11,13 @@ import java.util.List;
public interface ResourceAllocationRepo
extends MongoRepository<ResourceAllocation, String> {
List<Resource> findByProjectId(String projectId);
List<ResourceAllocation> findByProjectId(String projectId);
List<Resource> findByEmployeeId(String employeeId);
List<ResourceAllocation> findByEmployeeId(String employeeId);
Resource findById(ObjectId id);
ResourceAllocation findById(ObjectId id);
Resource findByEmployeeIdAndProjectId(String employeeId, String projectId);
List<ResourceAllocation> findByEmployeeIdAndProjectId(String employeeId, String projectId);
// List<Resource> findByEmployeeIdAndActive(String employeeId, boolean status);
......
package com.nisum.myteam.service;
public class IDashboardService {
import com.nisum.myteam.model.vo.EmployeeDashboardVO;
import java.util.List;
public interface IDashboardService {
public List<EmployeeDashboardVO> getEmployeesDashBoard();
}
package com.nisum.myteam.service;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import org.springframework.stereotype.Service;
import com.nisum.myteam.exception.handler.MyTeamException;
import com.nisum.myteam.model.dao.Account;
import com.nisum.myteam.model.dao.Employee;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
@Service
public interface IEmployeeService {
......
......@@ -16,10 +16,22 @@ public interface IProjectService {
void deleteProject(String projectId);
List<Project> getProjectsUnderDomain(String domainId);
public boolean isProjectExistsByName(String projectName);
public boolean isProjectExistsById(String projectId);
public Project getProjectByProjectId(String projectId);
public long getProjectsCount();
public List<Project> getAllProjects();
List<HashMap<Object, Object>> getProjects() throws MyTeamException;
public List<Project> getOnlyActiveProjects();
List<Project> getProjectsUnderDomain(String domainId);
List<Project> getProjectsUnderDeliveryLead(String managerId) throws MyTeamException;
public Resource addNewBeanchAllocation(Employee employee, String loginEmpId);
......@@ -28,37 +40,23 @@ public interface IProjectService {
String generatePdfReport(long id, String fromDate, String toDate) throws MyTeamException;
List<Resource> getResourcesUnderProject(String empId);
List<Employee> getUnAssignedEmployees();
public List<EmployeeDashboardVO> getEmployeesDashBoard();
public List<HashMap<Object, Object>> getProjectsForEmployee(String empId);
//public List<HashMap<Object, Object>> getProjectsForEmployee(String empId);
public Set<String> accountsAssignedToDl(String empId);
public List<HashMap<Object, Object>> deliveryLeadProjects(String empId) throws MyTeamException;
public List<Project> getAllProjects();
public boolean isProjectExists(String projectName);
public boolean isProjectExistsById(String projectId);
public long getProjectsCount();
public Account getProjectAccount(String accountId);
public Account updateProjSeqinAccount(Account account) throws MyTeamException;
public List<HashMap<Object, Object>> getRoleBasedProjects(String empId) throws MyTeamException;
public List<HashMap<Object, Object>> getProjectsInsteadOfRole() throws MyTeamException;
public List<Project> getProjectsForDeliveryLead(String deliveryLeadId);
public Project getProjectByProjectId(String projectId);
List<Resource> getResourcesUnderProject(String empId);
}
......@@ -4,6 +4,8 @@ import com.nisum.myteam.exception.handler.MyTeamException;
import com.nisum.myteam.model.dao.Employee;
import com.nisum.myteam.model.dao.Resource;
import com.nisum.myteam.model.dao.ResourceAllocation;
import com.nisum.myteam.model.vo.MyProjectAllocationVO;
import com.nisum.myteam.model.vo.ResourceVO;
import org.bson.types.ObjectId;
import java.util.HashMap;
......@@ -11,11 +13,15 @@ import java.util.List;
public interface IResourceAllocationService {
ResourceAllocation addResourceAllocation(ResourceAllocation resourceAllocation, String loginEmpId) throws MyTeamException;
HashMap<String,Object> updateResource(ResourceAllocation resourceAllocation, String loginEmpId) throws MyTeamException;
void updateResource(ResourceAllocation resourceAllocation, String loginEmpId) throws MyTeamException;
void deleteResource(ResourceAllocation resource, String loginEmpId);
Resource deleteResource(String empId, String projectId, ObjectId id, String loginEmpId);
List<ResourceAllocation> getAllResourcesForAllActiveProjects();
// Resource save(Resource resource);
......@@ -23,19 +29,38 @@ public interface IResourceAllocationService {
// void inactivateResource(Employee employeeReq, Employee employeeUpdated, String loginEmpId);
List<ResourceAllocation> getResourcesSortByProjectStartDate(String employeeId);
List<ResourceAllocation> getResourcesSortByBillingStartDate(String employeeId);
// List<Resource> getResourcesForProject(String projectId, String status);
// List<Resource> getAllResourcesForProject(String projectId, String status);
// List<Resource> getResourcesForEmployee(String empId);
// List<Resource> getResourcesForProject(String projectId);
// List<Resource> getAllResourcesForProject(String projectId);
List<ResourceAllocation> getActiveResources(String empId);
// List<Resource> getActiveResources(String empId);
// List<Resource> getResourcesForActiveProjects();
// List<Resource> getResourcesForShift(String shift);
// public List<Resource> getResourcesUnderDeliveryLead(String empId);
public List<ResourceVO> getResourcesForProject(String projectId, String statusFlag);
public List<ResourceAllocation> getResourcesUnderDeliveryLead(String empId);
public List<ResourceAllocation> getBillingsForEmployee(String empId);
public List<ResourceAllocation> getBillingsForProject(String empId, String projectId);
public List<MyProjectAllocationVO> getWorkedProjectsForResource(String empId);
public List<Employee> getUnAssignedEmployees();
public List<ResourceAllocation> getAllResources();
}
......@@ -61,7 +61,7 @@ public class ResourceService implements IResourceService {
private ProjectService projectService;
@Autowired
private EmployeeRepo employeeRoleRepo;
private EmployeeRepo employeeRepo;
public Resource save(Resource resource) {
return resourceRepo.save(resource);
......@@ -306,11 +306,11 @@ public class ResourceService implements IResourceService {
empShiftService.updateEmployeeShift(existingResource, loginEmpId);
existingResource.setShift(resourceReq.getShift());
Employee employeeDB = employeeRoleRepo.findByEmployeeId(resourceReq.getEmployeeId());
Employee employeeDB = employeeRepo.findByEmployeeId(resourceReq.getEmployeeId());
employeeDB.setShift(resourceReq.getShift());
employeeDB.setModifiedBy(loginEmpId);
employeeDB.setLastModifiedOn(new Date());
employeeRoleRepo.save(employeeDB);
employeeRepo.save(employeeDB);
}
existingResource.setAuditFields(loginEmpId, MyTeamUtils.UPDATE);// Setting
// audit
......@@ -335,15 +335,6 @@ public class ResourceService implements IResourceService {
return response;
}
private String validateAgainstDOJ(Resource resource) {
String response = null;
Date empDoj = employeeRoleRepo.findByEmployeeId(resource.getEmployeeId()).getDateOfJoining();
if (resource.getNewBillingStartDate().compareTo(empDoj) < 0) {
response = "Resource Start Date (" + resource.getNewBillingStartDate() + " ) in "
+ resource.getProjectName() + " project should not be before Date of Joining ( " + empDoj + ").";
}
return response;
}
@Override
public Resource deleteResource(String empId, String projectId, ObjectId id, String loginEmpId) {
......@@ -668,17 +659,28 @@ public class ResourceService implements IResourceService {
}
private String validateNewProjectAssignmentStartDate(List<Resource> teamMateList, Resource projectTeamMate) {
private String validateNewProjectAssignmentStartDate(List<Resource> resourceList, Resource resourceReq) {
String response = null;
if (teamMateList != null && teamMateList.size() > 0) {
Resource ptMate = teamMateList.get(0);
if (projectTeamMate.getNewBillingStartDate().compareTo(ptMate.getEndDate()) <= 0) {
response = "Resource Start Date (" + projectTeamMate.getNewBillingStartDate() +" ) in " + projectTeamMate.getProjectName()
+ " project should be after " + ptMate.getProjectName() + " project End Date ( " + ptMate.getEndDate() + ").";
if (resourceList != null && resourceList.size() > 0) {
Resource resource = resourceList.get(0);
if (resourceReq.getNewBillingStartDate().compareTo(resource.getEndDate()) <= 0) {
response = "Resource Start Date (" + resourceReq.getNewBillingStartDate() +" ) in " + resourceReq.getProjectName()
+ " project should be after " + resource.getProjectName() + " project End Date ( " + resource.getEndDate() + ").";
}
} else {
response = validateAgainstDOJ(projectTeamMate);
response = validateAgainstDOJ(resourceReq);
}
return response;
}
private String validateAgainstDOJ(Resource resource) {
String response = null;
Date empDoj = employeeRepo.findByEmployeeId(resource.getEmployeeId()).getDateOfJoining();
if (resource.getNewBillingStartDate().compareTo(empDoj) < 0) {
response = "Resource Start Date (" + resource.getNewBillingStartDate() + " ) in "
+ resource.getProjectName() + " project should not be before Date of Joining ( " + empDoj + ").";
}
return response;
}
}
package com.nisum.myteam.statuscodes;
public class ResourceStatus {
public enum ResourceStatus {
ACTIVE("Active"), IN_ACTIVE("InActive");
private String status;
private ResourceStatus(String status) {
this.status = status;
}
public String getStatus() {
return this.status;
}
}
......@@ -155,8 +155,8 @@ public class MyTeamUtils {
public final static String PROJECT_START_DATE="ProjectStartDate";
public final static String PROJECT_END_DATE="ProjectEndDate";
public final static String BILLING_START_DATE="BillingStartDate";
public final static String BILLING_END_DATE="BillingEndDate";
public final static String BILLING_START_DATE="billingStartDate";
public final static String BILLING_END_DATE="billingEndDate";
}
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