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