Commit 3e0c4ccb authored by b v s satyanarayana's avatar b v s satyanarayana

MT-53_1 :SNS :: ImportEmployeeDataValidations

parent d28513b8
......@@ -283,10 +283,10 @@ public class UserController {
@RequestMapping(value = "/fileUpload", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<String> exportDataFromFile(@RequestParam(value = "file") MultipartFile file, @RequestParam(value="empId") String loginEmpId)
public ResponseEntity<Map<String, Object>> exportDataFromFile(@RequestParam(value = "file") MultipartFile file, @RequestParam(value="empId") String loginEmpId)
throws MyTimeException {
log.info("Uploaded file: {} with size: {}", file.getOriginalFilename(), file.getSize());
String result = userService.exportDataFromExcelFile(file,loginEmpId);
Map<String, Object> result = userService.exportDataFromExcelFile(file,loginEmpId);
return new ResponseEntity<>(result, HttpStatus.OK);
}
......
......@@ -2,6 +2,7 @@ package com.nisum.mytime.service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.web.multipart.MultipartFile;
......@@ -81,5 +82,5 @@ public interface UserService {
public boolean verifyRole(String empId, String roleName);
String exportDataFromExcelFile(MultipartFile file, String empId) throws MyTimeException;
Map<String,Object> exportDataFromExcelFile(MultipartFile file, String empId) throws MyTimeException;
}
......@@ -547,10 +547,9 @@ public class UserServiceImpl implements UserService {
}
@Override
public String exportDataFromExcelFile(MultipartFile file, String empId)
public Map<String,Object> exportDataFromExcelFile(MultipartFile file, String empId)
throws MyTimeException {
String result = "Failure";
int counter = 0;
Map<String,Object> resultMap = new HashMap<String, Object>();
try {
PoijiOptions options = PoijiOptions.PoijiOptionsBuilder.settings()
.preferNullOverDefault(true).datePattern("dd-MMM-yyyy")
......@@ -560,20 +559,17 @@ public class UserServiceImpl implements UserService {
file.getInputStream(), PoijiExcelType.XLS,
EmployeeRoles.class, options);
validateExcelRecords(employees);
Map<String,Object> validationResult = validateExcelRecords(employees);
if (!employees.isEmpty()) {
for (EmployeeRoles employee : employees) {
if (null != employee.getEmployeeId()) {
findAndModifyEmployeeRole(employee,empId);
}else {
counter++;
}
findAndModifyEmployeeRole(employee,empId);
}
if (counter == 0) {
result = "Success";
if (null != validationResult && ! (validationResult.entrySet().size() > MyTimeUtils.INT_ZERO) ) {
resultMap.put("Success", "Success");
log.info("Exported {} employee records from file: {}", employees.size(), file.getOriginalFilename());
} else {
resultMap.put("Validation Erroe ", validationResult);
log.info( "Uploaded file: {}, does not contain valid employee records", file.getOriginalFilename());
}
}
......@@ -581,7 +577,7 @@ public class UserServiceImpl implements UserService {
log.error("Exception occured while exporting the data from excel file due to: {}",e);
throw new MyTimeException("");
}
return result;
return resultMap;
}
private void findAndModifyEmployeeRole(EmployeeRoles employee,String empId) {
......@@ -645,15 +641,15 @@ public class UserServiceImpl implements UserService {
flag = false;
}else if(! DataValidations.isValidDate(empRole.getDateOfJoining())) {
flag = false;
}else if(! DataValidations.isValidFunctionalGroup(empRole.getFunctionalGroup())) {
}else if(! DataValidations.isValidFunctionalGroup(empRole.getFunctionalGroup(),masterDataRepo)) {
flag = false;
}else if(! DataValidations.isValidDesignation(empRole.getDesignation())) {
}else if(! DataValidations.isValidDesignation(empRole.getDesignation(),masterDataRepo)) {
flag = false;
}else if(! DataValidations.isValidWorkLocation(empRole.getEmpLocation())) {
}else if(! DataValidations.isValidWorkLocation(empRole.getEmpLocation(), locationRepo)) {
flag = false;
}else if(! DataValidations.isValidEmploymentType(empRole.getEmploymentType())) {
}else if(! DataValidations.isValidEmploymentType(empRole.getEmploymentType(),masterDataRepo)) {
flag = false;
}else if(! DataValidations.isValidRole(empRole.getRole())) {
}else if(! DataValidations.isValidRole(empRole.getRole(),masterDataRepo)) {
flag = false;
}else if(! DataValidations.isYesOrNo(empRole.getHasPassort())) {
flag = false;
......@@ -664,28 +660,24 @@ public class UserServiceImpl implements UserService {
}
if( flag) {
if(empRole.getDateOfBirth() != null) {
flag = DataValidations.isAgeGreaterThanTwenty(empRole.getDateOfBirth(), empRole.getDateOfJoining());
}
if(MyTimeUtils.YES.equals(empRole.getHasPassort())){
flag = DataValidations.isFutureDate(empRole.getPassportExpiryDate());
}
if(MyTimeUtils.YES.equals(empRole.getHasB1())) {
flag = DataValidations.isFutureDate(empRole.getB1ExpiryDate());
}
if(null != empRole.getEmpStatus() && ! MyTimeUtils.EMPTY_STRING.equals(empRole.getEmpStatus().trim()) ) {
String empStatus = empRole.getEmpStatus().trim();
if(empStatus.equalsIgnoreCase(MyTimeUtils.IN_ACTIVE) || MyTimeUtils.IN_ACTIVE_SPACE.equalsIgnoreCase(empStatus) || MyTimeUtils.IN_HYPEN_ACTIVE_SPACE.equalsIgnoreCase(empStatus)) {
flag = DataValidations.isValidDate(empRole.getEndDate());
if(DataValidations.isAgeGreaterThanTwenty(empRole.getDateOfBirth(), empRole.getDateOfJoining())){
if(MyTimeUtils.YES.equals(empRole.getHasPassort())){
flag = DataValidations.isFutureDate(empRole.getPassportExpiryDate());
if(MyTimeUtils.YES.equals(empRole.getHasB1())) {
flag = DataValidations.isFutureDate(empRole.getB1ExpiryDate());
}
}
if(null != empRole.getEmpStatus() && ! MyTimeUtils.EMPTY_STRING.equals(empRole.getEmpStatus().trim()) ) {
String empStatus = empRole.getEmpStatus().trim();
if(empStatus.equalsIgnoreCase(MyTimeUtils.IN_ACTIVE) || MyTimeUtils.IN_ACTIVE_SPACE.equalsIgnoreCase(empStatus) || MyTimeUtils.IN_HYPEN_ACTIVE_SPACE.equalsIgnoreCase(empStatus)) {
flag = DataValidations.isValidDate(empRole.getEndDate());
}
}
}
if(flag) {
empIdsSet.add(empRole.getEmployeeId().trim());
}else {
invalidEmpRecsMap.put(Integer.toString(rowNumber), empRole.getEmployeeName());
if(!flag) {
invalidEmpRecsMap.put(Integer.toString(rowNumber), empRole.getEmployeeName());
invalidEmpRecs.add(empRole);
}
}else {
......@@ -700,14 +692,9 @@ public class UserServiceImpl implements UserService {
employees.removeAll(invalidEmpRecs);
}
}
finalMap.put("Below emp records are not valid", invalidEmpRecsMap);
if(finalMap.entrySet().size() > MyTimeUtils.INT_ZERO) {
finalMap.put("Below emp records are not valid", invalidEmpRecsMap);
}
return finalMap;
}
public void getExistingEmployess(List<EmployeeRoles> employees) {
List<EmployeeRoles> existingEmployess = employeeRolesRepo.findByEmployeeIdIn(employees.stream().map(EmployeeRoles :: getEmployeeId).collect(Collectors.toSet()));
}
}
......@@ -6,22 +6,14 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import com.nisum.mytime.model.MasterData;
import com.nisum.mytime.repository.LocationRepo;
import com.nisum.mytime.repository.MasterDataRepo;
@Component
@Service
public class DataValidations {
@Autowired
private static MasterDataRepo masterDataRepo;
@Autowired
private static LocationRepo locationRepo;
public static boolean validateNumber(String number) {
boolean flag = false;
if(null != number && !MyTimeUtils.EMPTY_STRING.equals(number.trim())) {
......@@ -78,7 +70,7 @@ public class DataValidations {
return flag;
}
public static boolean isValidFunctionalGroup(String functionalGroup) {
public static boolean isValidFunctionalGroup(String functionalGroup,MasterDataRepo masterDataRepo) {
boolean flag = false;
if(null != functionalGroup && !MyTimeUtils.EMPTY_STRING.equals(functionalGroup.trim())) {
List<MasterData> fsData = masterDataRepo.findByMasterDataTypeAndMasterDataNameAndActiveStatus(MyTimeUtils.MASTERDATA_FG, functionalGroup.trim(), true);
......@@ -87,34 +79,34 @@ public class DataValidations {
return flag;
}
public static boolean isValidDesignation(String designation) {
public static boolean isValidDesignation(String designation, MasterDataRepo masterDataRepo) {
boolean flag = false;
if(null != designation && !MyTimeUtils.EMPTY_STRING.equals(designation.trim())) {
List<MasterData> fsData = masterDataRepo.findByMasterDataTypeAndMasterDataNameAndActiveStatus(MyTimeUtils.MASTERDATA_DESIGNATION, designation.trim(), true);
flag = fsData.size() > MyTimeUtils.INT_ZERO;
List<MasterData> designationData = masterDataRepo.findByMasterDataTypeAndMasterDataNameAndActiveStatus(MyTimeUtils.MASTERDATA_DESIGNATION, designation.trim(), true);
flag = designationData.size() > MyTimeUtils.INT_ZERO;
}
return flag;
}
public static boolean isValidEmploymentType(String employmentType) {
public static boolean isValidEmploymentType(String employmentType, MasterDataRepo masterDataRepo) {
boolean flag = false;
if(null != employmentType && MyTimeUtils.EMPTY_STRING.equals(employmentType)){
flag = true;
}else if(null != employmentType && !MyTimeUtils.EMPTY_STRING.equals(employmentType.trim())) {
List<MasterData> fsData = masterDataRepo.findByMasterDataTypeAndMasterDataNameAndActiveStatus(MyTimeUtils.MASTERDATAD_EMLOYMENT_TYPE, employmentType.trim(), true);
flag = fsData.size() > MyTimeUtils.INT_ZERO ;
List<MasterData> empTypeData = masterDataRepo.findByMasterDataTypeAndMasterDataNameAndActiveStatus(MyTimeUtils.MASTERDATAD_EMLOYMENT_TYPE, employmentType.trim(), true);
flag = empTypeData.size() > MyTimeUtils.INT_ZERO ;
}
return flag;
}
public static boolean isValidRole(String role) {
public static boolean isValidRole(String role,MasterDataRepo masterDataRepo) {
boolean flag = false;
if(null != role && MyTimeUtils.EMPTY_STRING.equals(role)){
flag = true;
}else if(null != role && !MyTimeUtils.EMPTY_STRING.equals(role.trim().trim())) {
List<MasterData> fsData = masterDataRepo.findByMasterDataTypeAndMasterDataNameAndActiveStatus(MyTimeUtils.MASTERDATA_ROLES, role.trim(), true);
flag = fsData.size() > MyTimeUtils.INT_ZERO;
List<MasterData> roleData = masterDataRepo.findByMasterDataTypeAndMasterDataNameAndActiveStatus(MyTimeUtils.MASTERDATA_ROLES, role.trim(), true);
flag = roleData.size() > MyTimeUtils.INT_ZERO;
}
return flag;
}
......@@ -144,10 +136,10 @@ public class DataValidations {
}
public static boolean isValidWorkLocation(String workLocation) {
public static boolean isValidWorkLocation(String workLocation, LocationRepo locationRepo) {
boolean flag = false;
if(null != workLocation && MyTimeUtils.EMPTY_STRING.equals(workLocation.trim())) {
flag = locationRepo.findByLocationAndActiveStatus(workLocation.trim(), true).size() > MyTimeUtils.INT_ZERO ;
if(null != workLocation && !MyTimeUtils.EMPTY_STRING.equals(workLocation.trim())) {
flag= locationRepo.findByLocationAndActiveStatus(workLocation.trim(), true). size() > MyTimeUtils.INT_ZERO ;
}
return flag;
}
......
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