Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mytime
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Narendar Vakiti
mytime
Commits
3e0c4ccb
Commit
3e0c4ccb
authored
Sep 05, 2018
by
b v s satyanarayana
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MT-53_1 :SNS :: ImportEmployeeDataValidations
parent
d28513b8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
71 deletions
+51
-71
UserController.java
...main/java/com/nisum/mytime/controller/UserController.java
+2
-2
UserService.java
src/main/java/com/nisum/mytime/service/UserService.java
+2
-1
UserServiceImpl.java
src/main/java/com/nisum/mytime/service/UserServiceImpl.java
+32
-45
DataValidations.java
src/main/java/com/nisum/mytime/utils/DataValidations.java
+15
-23
No files found.
src/main/java/com/nisum/mytime/controller/UserController.java
View file @
3e0c4ccb
...
...
@@ -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
);
}
...
...
src/main/java/com/nisum/mytime/service/UserService.java
View file @
3e0c4ccb
...
...
@@ -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
;
}
src/main/java/com/nisum/mytime/service/UserServiceImpl.java
View file @
3e0c4ccb
...
...
@@ -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
)
)
{
result
Map
.
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
result
Map
;
}
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
()));
}
}
src/main/java/com/nisum/mytime/utils/DataValidations.java
View file @
3e0c4ccb
...
...
@@ -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
>
fs
Data
=
masterDataRepo
.
findByMasterDataTypeAndMasterDataNameAndActiveStatus
(
MyTimeUtils
.
MASTERDATA_DESIGNATION
,
designation
.
trim
(),
true
);
flag
=
fs
Data
.
size
()
>
MyTimeUtils
.
INT_ZERO
;
List
<
MasterData
>
designation
Data
=
masterDataRepo
.
findByMasterDataTypeAndMasterDataNameAndActiveStatus
(
MyTimeUtils
.
MASTERDATA_DESIGNATION
,
designation
.
trim
(),
true
);
flag
=
designation
Data
.
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
>
fs
Data
=
masterDataRepo
.
findByMasterDataTypeAndMasterDataNameAndActiveStatus
(
MyTimeUtils
.
MASTERDATAD_EMLOYMENT_TYPE
,
employmentType
.
trim
(),
true
);
flag
=
fs
Data
.
size
()
>
MyTimeUtils
.
INT_ZERO
;
List
<
MasterData
>
empType
Data
=
masterDataRepo
.
findByMasterDataTypeAndMasterDataNameAndActiveStatus
(
MyTimeUtils
.
MASTERDATAD_EMLOYMENT_TYPE
,
employmentType
.
trim
(),
true
);
flag
=
empType
Data
.
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
>
fs
Data
=
masterDataRepo
.
findByMasterDataTypeAndMasterDataNameAndActiveStatus
(
MyTimeUtils
.
MASTERDATA_ROLES
,
role
.
trim
(),
true
);
flag
=
fs
Data
.
size
()
>
MyTimeUtils
.
INT_ZERO
;
List
<
MasterData
>
role
Data
=
masterDataRepo
.
findByMasterDataTypeAndMasterDataNameAndActiveStatus
(
MyTimeUtils
.
MASTERDATA_ROLES
,
role
.
trim
(),
true
);
flag
=
role
Data
.
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
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment