Unverified Commit d8a67851 authored by mshaik-nisum-com's avatar mshaik-nisum-com Committed by GitHub

Merge pull request #185 from nisum-inc/FEATURE/MT-53_2_ImportEmployeeDataValidations

MT-53_2 :SNS :: ImportEmployeeDataValidations
parents 324a252b 7c4a570a
...@@ -572,14 +572,14 @@ public class UserServiceImpl implements UserService { ...@@ -572,14 +572,14 @@ public class UserServiceImpl implements UserService {
for (EmployeeRoles employee : employees) { for (EmployeeRoles employee : employees) {
findAndModifyEmployeeRole(employee,empId); findAndModifyEmployeeRole(employee,empId);
} }
}
if (null != validationResult && ! (validationResult.entrySet().size() > MyTimeUtils.INT_ZERO) ) { if (null != validationResult && ! (validationResult.entrySet().size() > MyTimeUtils.INT_ZERO) ) {
resultMap.put("Success", "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); resultMap.put("Validation Error", 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());
} }
}
} catch (Exception e) { } catch (Exception e) {
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("");
...@@ -621,7 +621,7 @@ public class UserServiceImpl implements UserService { ...@@ -621,7 +621,7 @@ public class UserServiceImpl implements UserService {
private Map<String,Object> validateExcelRecords(List<EmployeeRoles> employees) { private Map<String,Object> validateExcelRecords(List<EmployeeRoles> employees) {
boolean flag = false; boolean flag = false;
Map<String, String> invalidEmpRecsMap = new HashMap<String, String>(); List<String> invalidEmpRecsList = new ArrayList<String>();
Map<String,Object> finalMap = new HashMap<String, Object>(); Map<String,Object> finalMap = new HashMap<String, Object>();
...@@ -635,7 +635,7 @@ public class UserServiceImpl implements UserService { ...@@ -635,7 +635,7 @@ public class UserServiceImpl implements UserService {
List<EmployeeRoles> existingEmployess = employeeRolesRepo.findByEmployeeIdIn(empIdsSet); List<EmployeeRoles> existingEmployess = employeeRolesRepo.findByEmployeeIdIn(empIdsSet);
if(existingEmployess.size() > MyTimeUtils.INT_ZERO) { if(existingEmployess.size() > MyTimeUtils.INT_ZERO) {
finalMap.put("Below emp records already avilable in db", existingEmployess.stream().map(EmployeeRoles :: getEmployeeId).collect(Collectors.toSet()).toString()); finalMap.put("Below emp records ids existed ", existingEmployess.stream().map(EmployeeRoles :: getEmployeeId).collect(Collectors.toSet()));
employees.removeAll(existingEmployess); employees.removeAll(existingEmployess);
} }
...@@ -684,11 +684,11 @@ public class UserServiceImpl implements UserService { ...@@ -684,11 +684,11 @@ public class UserServiceImpl implements UserService {
} }
} }
if(!flag) { if(!flag) {
invalidEmpRecsMap.put(Integer.toString(rowNumber), empRole.getEmployeeName()); invalidEmpRecsList.add(Integer.toString(rowNumber));
invalidEmpRecs.add(empRole); invalidEmpRecs.add(empRole);
} }
}else { }else {
invalidEmpRecsMap.put(Integer.toString(rowNumber), empRole.getEmployeeName()); invalidEmpRecsList.add(Integer.toString(rowNumber));
invalidEmpRecs.add(empRole); invalidEmpRecs.add(empRole);
} }
rowNumber += 1; rowNumber += 1;
...@@ -700,7 +700,7 @@ public class UserServiceImpl implements UserService { ...@@ -700,7 +700,7 @@ public class UserServiceImpl implements UserService {
} }
} }
if(finalMap.entrySet().size() > MyTimeUtils.INT_ZERO) { if(finalMap.entrySet().size() > MyTimeUtils.INT_ZERO) {
finalMap.put("Below emp records are not valid", invalidEmpRecsMap); finalMap.put("Please check the following row number records", invalidEmpRecsList);
} }
return finalMap; return finalMap;
} }
......
...@@ -58,10 +58,17 @@ myApp ...@@ -58,10 +58,17 @@ myApp
function mySuccess(response) { function mySuccess(response) {
$mdDialog.hide(); $mdDialog.hide();
console.log(response.data); console.log(response.data);
if(response.data == "Success") var parsedResponse = JSON.parse(response.data);
showAlert('Data imported from file successfully.'); var resp = Object.keys(parsedResponse)
else if(response.data == "Failure") if(Object.keys(parsedResponse)[0] == "Validation Error"){
showAlert('Uploaded file does not contain valid employee data...!!!'); var empIdError = parsedResponse[resp[0]]["Below emp records are not valid"];
var excelRowError = parsedResponse[resp[0]]["Below emp records already avilable in db"];
showAlert(Object.keys(parsedResponse[resp[0]])[0] + " " + empIdError.join() + "\n" + Object.keys(parsedResponse[resp[0]])[1] + " " + excelRowError.join());
}
else{
showAlert('Successfully Uploaded');
}
$scope.refreshPage(); $scope.refreshPage();
}, function myError(response) { }, function myError(response) {
$mdDialog.hide(); $mdDialog.hide();
......
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