Commit 85d15817 authored by Md Suleman's avatar Md Suleman

Updated response object for substatus

parent c5b5d564
#Tue Jun 18 14:38:29 IST 2019
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5.1-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-3.5.1-all.zip
...@@ -11,6 +11,7 @@ import javax.servlet.http.HttpServletRequest; ...@@ -11,6 +11,7 @@ import javax.servlet.http.HttpServletRequest;
import com.nisum.myteam.model.dao.EmployeeVisa; import com.nisum.myteam.model.dao.EmployeeVisa;
import com.nisum.myteam.repository.EmployeeVisaRepo; import com.nisum.myteam.repository.EmployeeVisaRepo;
import com.nisum.myteam.service.impl.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
...@@ -36,7 +37,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -36,7 +37,7 @@ import lombok.extern.slf4j.Slf4j;
public class EmployeeController { public class EmployeeController {
@Autowired @Autowired
private IEmployeeService empService; private EmployeeService empService;
@Autowired @Autowired
private IEmployeeRoleService employeeRoleService; private IEmployeeRoleService employeeRoleService;
...@@ -71,7 +72,7 @@ public class EmployeeController { ...@@ -71,7 +72,7 @@ public class EmployeeController {
if (empService.isEmployeeExistsById(loginEmpId)) { if (empService.isEmployeeExistsById(loginEmpId)) {
Employee employeeUpdated = empService.updateEmployee(employeeReq, loginEmpId); Employee employeeUpdated = empService.updateEmployee(employeeReq, loginEmpId);
ResponseDetails updateRespDetails = new ResponseDetails(new Date(), 906, "Employee has been updated", ResponseDetails updateRespDetails = new ResponseDetails(new Date(), 906, empService.messege ,
"Employee Updation", null, request.getRequestURI(), "Updation Employee details", "Employee Updation", null, request.getRequestURI(), "Updation Employee details",
employeeUpdated); employeeUpdated);
return new ResponseEntity<ResponseDetails>(updateRespDetails, HttpStatus.OK); return new ResponseEntity<ResponseDetails>(updateRespDetails, HttpStatus.OK);
......
...@@ -6,10 +6,12 @@ import com.nisum.myteam.model.AttendenceData; ...@@ -6,10 +6,12 @@ import com.nisum.myteam.model.AttendenceData;
import com.nisum.myteam.model.FunctionalGroup; import com.nisum.myteam.model.FunctionalGroup;
import com.nisum.myteam.model.Mail; import com.nisum.myteam.model.Mail;
import com.nisum.myteam.model.dao.Employee; import com.nisum.myteam.model.dao.Employee;
import com.nisum.myteam.model.dao.EmployeeSubStatus;
import com.nisum.myteam.service.IFunctionalGroupService; import com.nisum.myteam.service.IFunctionalGroupService;
import com.nisum.myteam.service.IMailService; import com.nisum.myteam.service.IMailService;
import com.nisum.myteam.service.impl.AttendanceService; import com.nisum.myteam.service.impl.AttendanceService;
import com.nisum.myteam.service.impl.EmployeeService; import com.nisum.myteam.service.impl.EmployeeService;
import com.nisum.myteam.service.impl.SubStatusService;
import com.nisum.myteam.statuscodes.EmployeeStatus; import com.nisum.myteam.statuscodes.EmployeeStatus;
import com.nisum.myteam.utils.MyTeamDateUtils; import com.nisum.myteam.utils.MyTeamDateUtils;
import com.nisum.myteam.utils.MyTeamUtils; import com.nisum.myteam.utils.MyTeamUtils;
...@@ -52,6 +54,9 @@ public class LeaveNotificationScheduler { ...@@ -52,6 +54,9 @@ public class LeaveNotificationScheduler {
@Autowired @Autowired
private IFunctionalGroupService functionalGroupService; private IFunctionalGroupService functionalGroupService;
@Autowired
private SubStatusService subStatusService;
// @Scheduled(cron = "${email.leave.notification.shift1.cron}") // @Scheduled(cron = "${email.leave.notification.shift1.cron}")
public void scheduleLeaveMailForShift1Empls() throws IOException, MessagingException, MyTeamException { public void scheduleLeaveMailForShift1Empls() throws IOException, MessagingException, MyTeamException {
...@@ -118,7 +123,8 @@ public class LeaveNotificationScheduler { ...@@ -118,7 +123,8 @@ public class LeaveNotificationScheduler {
mail.setSubject(mailSubject); mail.setSubject(mailSubject);
employee = employeeService.getEmployeeById(absentee.getEmployeeId()); employee = employeeService.getEmployeeById(absentee.getEmployeeId());
empSubStatus = (String)employee.getEmpSubStatus(); EmployeeSubStatus subStatus = subStatusService.getCurrentSubStatus(employee.getEmployeeId());
empSubStatus = (String)subStatus.getSubStatus();
if (empSubStatus == null) if (empSubStatus == null)
empSubStatus = ""; empSubStatus = "";
......
...@@ -13,6 +13,8 @@ import java.util.Set; ...@@ -13,6 +13,8 @@ import java.util.Set;
@Service @Service
public interface IEmployeeService { public interface IEmployeeService {
public String messege = "";
boolean isEmployeeExistsById(String employeeId); boolean isEmployeeExistsById(String employeeId);
Employee createEmployee(Employee employeeRoles, String empId) throws MyTeamException; Employee createEmployee(Employee employeeRoles, String empId) throws MyTeamException;
......
...@@ -9,6 +9,7 @@ import com.nisum.myteam.model.dao.*; ...@@ -9,6 +9,7 @@ import com.nisum.myteam.model.dao.*;
import com.nisum.myteam.service.*; import com.nisum.myteam.service.*;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.FindAndModifyOptions; import org.springframework.data.mongodb.core.FindAndModifyOptions;
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
...@@ -50,7 +51,7 @@ public class EmployeeService implements IEmployeeService { ...@@ -50,7 +51,7 @@ public class EmployeeService implements IEmployeeService {
private IEmployeeRoleService employeeRoleService; private IEmployeeRoleService employeeRoleService;
@Autowired @Autowired
private IEmployeeLocationService empLocationService; private EmployeeLocationService empLocationService;
@Autowired @Autowired
private IResourceService resourceService; private IResourceService resourceService;
...@@ -58,6 +59,8 @@ public class EmployeeService implements IEmployeeService { ...@@ -58,6 +59,8 @@ public class EmployeeService implements IEmployeeService {
@Autowired @Autowired
private ISubStatusService subStatusService; private ISubStatusService subStatusService;
public String message = "";
@Override @Override
public Employee createEmployee(Employee employee, String loginEmpId) throws MyTeamException { public Employee createEmployee(Employee employee, String loginEmpId) throws MyTeamException {
employee.setCreatedOn(new Date()); employee.setCreatedOn(new Date());
...@@ -75,6 +78,7 @@ public class EmployeeService implements IEmployeeService { ...@@ -75,6 +78,7 @@ public class EmployeeService implements IEmployeeService {
@Override @Override
public Employee updateEmployee(Employee employeeReq, String loginEmpId) throws ParseException { public Employee updateEmployee(Employee employeeReq, String loginEmpId) throws ParseException {
message = "Employee has been updated";
// update all emp details to inactive if employee is inactive // update all emp details to inactive if employee is inactive
Query query = new Query(Criteria.where("employeeId").is(employeeReq.getEmployeeId())); Query query = new Query(Criteria.where("employeeId").is(employeeReq.getEmployeeId()));
Update update = new Update(); Update update = new Update();
...@@ -126,16 +130,16 @@ public class EmployeeService implements IEmployeeService { ...@@ -126,16 +130,16 @@ public class EmployeeService implements IEmployeeService {
latestSubStatus.setId(currentSubStatus.getId()); latestSubStatus.setId(currentSubStatus.getId());
subStatusService.updateExistingEmplyeeSubStatus(latestSubStatus); subStatusService.updateExistingEmplyeeSubStatus(latestSubStatus);
}else{ }else{
subStatusService.addEmployeeSubStatus(latestSubStatus); message = "Employee is already "+currentSubStatus.getSubStatus()+" from "+currentSubStatus.getFromDate()+" to "+currentSubStatus.getToDate();
} }
}else{ }else{
currentSubStatus = subStatusService.getLatestEmployeeSubStatus(employeeReq.getEmployeeId()); // currentSubStatus = subStatusService.getLatestEmployeeSubStatus(employeeReq.getEmployeeId());
if(currentSubStatus == null) // if(currentSubStatus == null)
subStatusService.addEmployeeSubStatus(latestSubStatus); subStatusService.addEmployeeSubStatus(latestSubStatus);
else { // else {
latestSubStatus.setId(currentSubStatus.getId()); // latestSubStatus.setId(currentSubStatus.getId());
subStatusService.updateExistingEmplyeeSubStatus(latestSubStatus); // subStatusService.updateExistingEmplyeeSubStatus(latestSubStatus);
} // }
} }
} }
...@@ -241,17 +245,38 @@ public class EmployeeService implements IEmployeeService { ...@@ -241,17 +245,38 @@ public class EmployeeService implements IEmployeeService {
@Override @Override
public List<Employee> getEmployeesByStatus(String status) { public List<Employee> getEmployeesByStatus(String status) {
// if (status.equals("all")) {
// return employeeRepo.findAll(new Sort(Sort.Direction.ASC, "employeeName"));
// } else if (status.equals("Vacation")) {
// Query query = new Query();
// query.addCriteria(Criteria.where("empSubStatus").ne("Resigned").andOperator(Criteria.where("empSubStatus").ne(null),Criteria.where("empSubStatus").ne("")));
// return mongoTemplate.find(query, Employee.class);
// } else if (status.equals("Resigned")) {
// return employeeRepo.findByEmpSubStatusOrderByEmployeeNameAsc("Resigned");
// } else {
// return employeeRepo.findByEmpStatus(status);
// }
List<Employee> employeesList = employeeRepo.findAll(new Sort(Sort.Direction.ASC, "employeeName"));
employeesList.stream().forEach(e -> {
EmployeeSubStatus subStatus = subStatusService.getCurrentSubStatus(e.getEmployeeId());
if(subStatus!=null)
e.setEmpSubStatus((EmployeeSubStatus) subStatus);
else
e.setEmpSubStatus(null);
});
if (status.equals("all")) { if (status.equals("all")) {
return employeeRepo.findAll(new Sort(Sort.Direction.ASC, "employeeName")); return employeesList;
} else if (status.equals("Vacation")) { } else if (status.equals("Vacation")) {
Query query = new Query();
query.addCriteria(Criteria.where("empSubStatus").ne("Resigned").andOperator(Criteria.where("empSubStatus").ne(null),Criteria.where("empSubStatus").ne(""))); return employeesList.stream().filter(e -> e.getEmpSubStatus()!= null ||
return mongoTemplate.find(query, Employee.class); (e.getEmpSubStatus()!=null && !e.getEmpSubStatus().equals("Resigned")) ||
(e.getEmpSubStatus()!=null && !e.getEmpSubStatus().equals(""))).collect(Collectors.toList());
} else if (status.equals("Resigned")) { } else if (status.equals("Resigned")) {
return employeeRepo.findByEmpSubStatusOrderByEmployeeNameAsc("Resigned"); return employeeRepo.findByEmpSubStatusOrderByEmployeeNameAsc("Resigned");
} else { } else {
return employeeRepo.findByEmpStatus(status); return employeesList.stream().filter(e->e.getEmpStatus().equals(status)).collect(Collectors.toList());
} }
} }
...@@ -276,15 +301,15 @@ public class EmployeeService implements IEmployeeService { ...@@ -276,15 +301,15 @@ public class EmployeeService implements IEmployeeService {
public List<String> getEmployeeDetailsForAutocomplete() { public List<String> getEmployeeDetailsForAutocomplete() {
List<Employee> employeeList = employeeRepo.findAll(); List<Employee> employeeList = employeeRepo.findAll();
List<String> resultList = new ArrayList<>(); List<String> resultList = new ArrayList<>();
employeeList.stream().sorted(java.util.Comparator.comparing(Employee::getEmployeeId)) employeeList.stream().sorted(Comparator.comparing(Employee::getEmployeeId))
.collect(Collectors.toList()).forEach(employee -> { .collect(Collectors.toList()).forEach(employee -> {
resultList.add(employee.getEmployeeId()); resultList.add(employee.getEmployeeId());
}); });
employeeList.stream().sorted(java.util.Comparator.comparing(Employee::getEmployeeName)) employeeList.stream().sorted(Comparator.comparing(Employee::getEmployeeName))
.collect(Collectors.toList()).forEach(employee -> { .collect(Collectors.toList()).forEach(employee -> {
resultList.add(employee.getEmployeeName()); resultList.add(employee.getEmployeeName());
}); });
employeeList.stream().sorted(java.util.Comparator.comparing(Employee::getEmailId)).collect(Collectors.toList()) employeeList.stream().sorted(Comparator.comparing(Employee::getEmailId)).collect(Collectors.toList())
.forEach(employee -> { .forEach(employee -> {
resultList.add(employee.getEmailId()); resultList.add(employee.getEmailId());
}); });
......
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