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
cf5e57af
Commit
cf5e57af
authored
Sep 06, 2018
by
b v s satyanarayana
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MT-53_3 :SNS :: ImportEmployeeDataValidations
parent
44a90ed6
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
260 additions
and
180 deletions
+260
-180
UserController.java
...main/java/com/nisum/mytime/controller/UserController.java
+2
-2
UserService.java
src/main/java/com/nisum/mytime/service/UserService.java
+1
-1
UserServiceImpl.java
src/main/java/com/nisum/mytime/service/UserServiceImpl.java
+200
-112
DataValidations.java
src/main/java/com/nisum/mytime/utils/DataValidations.java
+44
-32
MyTimeUtils.java
src/main/java/com/nisum/mytime/utils/MyTimeUtils.java
+4
-0
ExportDataController.js
src/main/webapp/WEB-INF/controllers/ExportDataController.js
+9
-33
No files found.
src/main/java/com/nisum/mytime/controller/UserController.java
View file @
cf5e57af
...
...
@@ -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
<
Map
<
String
,
Object
>
>
exportDataFromFile
(
@RequestParam
(
value
=
"file"
)
MultipartFile
file
,
@RequestParam
(
value
=
"empId"
)
String
loginEmpId
)
public
ResponseEntity
<
String
>
exportDataFromFile
(
@RequestParam
(
value
=
"file"
)
MultipartFile
file
,
@RequestParam
(
value
=
"empId"
)
String
loginEmpId
)
throws
MyTimeException
{
log
.
info
(
"Uploaded file: {} with size: {}"
,
file
.
getOriginalFilename
(),
file
.
getSize
());
Map
<
String
,
Object
>
result
=
userService
.
exportDataFromExcelFile
(
file
,
loginEmpId
);
String
result
=
userService
.
exportDataFromExcelFile
(
file
,
loginEmpId
);
return
new
ResponseEntity
<>(
result
,
HttpStatus
.
OK
);
}
...
...
src/main/java/com/nisum/mytime/service/UserService.java
View file @
cf5e57af
...
...
@@ -86,5 +86,5 @@ public interface UserService {
public
boolean
verifyRole
(
String
empId
,
String
roleName
);
Map
<
String
,
Object
>
exportDataFromExcelFile
(
MultipartFile
file
,
String
empId
)
throws
MyTimeException
;
String
exportDataFromExcelFile
(
MultipartFile
file
,
String
empId
)
throws
MyTimeException
;
}
src/main/java/com/nisum/mytime/service/UserServiceImpl.java
View file @
cf5e57af
This diff is collapsed.
Click to expand it.
src/main/java/com/nisum/mytime/utils/DataValidations.java
View file @
cf5e57af
...
...
@@ -16,8 +16,9 @@ import com.nisum.mytime.repository.MasterDataRepo;
public
class
DataValidations
{
public
static
boolean
validateNumber
(
String
number
)
{
boolean
flag
=
false
;
if
(
null
!=
number
&&
!
MyTimeUtils
.
EMPTY_STRING
.
equals
(
number
.
trim
()))
{
flag
=
number
.
matches
(
"^\\d+$"
)
&&
isNumberInRange
(
number
.
trim
());
number
=
number
.
trim
();
if
(!
MyTimeUtils
.
EMPTY_STRING
.
equals
(
number
))
{
flag
=
number
.
matches
(
"^\\d+$"
)
&&
isNumberInRange
(
number
);
}
return
flag
;
}
...
...
@@ -29,10 +30,11 @@ public class DataValidations {
public
static
boolean
validateName
(
String
name
)
{
boolean
flag
=
false
;
if
(
null
!=
name
&&
!
MyTimeUtils
.
EMPTY_STRING
.
equals
(
name
.
trim
()))
{
String
regx
=
"^[\\p{L} .'-]+$"
;
name
=
name
.
trim
();
if
(!
MyTimeUtils
.
EMPTY_STRING
.
equals
(
name
))
{
String
regx
=
"^[\\p{L}]+$"
;
Pattern
pattern
=
Pattern
.
compile
(
regx
,
Pattern
.
CASE_INSENSITIVE
);
Matcher
matcher
=
pattern
.
matcher
(
name
.
trim
()
);
Matcher
matcher
=
pattern
.
matcher
(
name
);
flag
=
matcher
.
find
();
}
return
flag
;
...
...
@@ -41,20 +43,22 @@ public class DataValidations {
public
static
boolean
isValidGender
(
String
gender
)
{
boolean
flag
=
false
;
if
(
null
!=
gender
&&
!
MyTimeUtils
.
EMPTY_STRING
.
equals
(
gender
.
trim
()))
{
flag
=
gender
.
trim
().
equalsIgnoreCase
(
MyTimeUtils
.
MALE
)
||
gender
.
equalsIgnoreCase
(
MyTimeUtils
.
FEMALE
);
gender
=
gender
.
trim
();
if
(
!
MyTimeUtils
.
EMPTY_STRING
.
equals
(
gender
))
{
flag
=
gender
.
equalsIgnoreCase
(
MyTimeUtils
.
MALE
)
||
gender
.
equalsIgnoreCase
(
MyTimeUtils
.
FEMALE
)
||
gender
.
equalsIgnoreCase
(
MyTimeUtils
.
M
)
||
gender
.
equalsIgnoreCase
(
MyTimeUtils
.
F
);
}
return
flag
;
}
public
static
boolean
validateEmail
(
String
email
)
{
boolean
flag
=
false
;
if
(
null
!=
email
&&
!
MyTimeUtils
.
EMPTY_STRING
.
equals
(
email
))
{
email
=
email
.
trim
();
if
(
!
MyTimeUtils
.
EMPTY_STRING
.
equals
(
email
))
{
if
(
email
.
trim
().
endsWith
(
"@nisum.com"
))
{
String
regx
=
"^[\\p{L}
.'-
]+$"
;
String
regx
=
"^[\\p{L}]+$"
;
email
=
email
.
substring
(
0
,
email
.
indexOf
(
"@"
)-
1
);
Pattern
pattern
=
Pattern
.
compile
(
regx
,
Pattern
.
CASE_INSENSITIVE
);
Matcher
matcher
=
pattern
.
matcher
(
email
.
trim
()
);
Matcher
matcher
=
pattern
.
matcher
(
email
);
flag
=
matcher
.
find
();
}
}
...
...
@@ -63,8 +67,8 @@ public class DataValidations {
public
static
boolean
isYesOrNo
(
String
value
)
{
boolean
flag
=
false
;
if
(
null
!=
value
&&
!
MyTimeUtils
.
EMPTY_STRING
.
equals
(
value
.
trim
()))
{
value
=
value
.
trim
();
value
=
value
.
trim
();
if
(!
MyTimeUtils
.
EMPTY_STRING
.
equals
(
value
))
{
flag
=
value
.
equalsIgnoreCase
(
MyTimeUtils
.
YES
)
||
value
.
equalsIgnoreCase
(
MyTimeUtils
.
STRING_Y
)
||
value
.
equalsIgnoreCase
(
MyTimeUtils
.
NO
)
||
value
.
equalsIgnoreCase
(
MyTimeUtils
.
STRING_N
);
}
return
flag
;
...
...
@@ -72,8 +76,9 @@ public class DataValidations {
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
);
functionalGroup
=
functionalGroup
.
trim
();
if
(!
MyTimeUtils
.
EMPTY_STRING
.
equals
(
functionalGroup
))
{
List
<
MasterData
>
fsData
=
masterDataRepo
.
findByMasterDataTypeAndMasterDataNameAndActiveStatus
(
MyTimeUtils
.
MASTERDATA_FG
,
functionalGroup
,
true
);
flag
=
fsData
.
size
()
>
MyTimeUtils
.
INT_ZERO
;
}
return
flag
;
...
...
@@ -81,8 +86,9 @@ public class DataValidations {
public
static
boolean
isValidDesignation
(
String
designation
,
MasterDataRepo
masterDataRepo
)
{
boolean
flag
=
false
;
if
(
null
!=
designation
&&
!
MyTimeUtils
.
EMPTY_STRING
.
equals
(
designation
.
trim
()))
{
List
<
MasterData
>
designationData
=
masterDataRepo
.
findByMasterDataTypeAndMasterDataNameAndActiveStatus
(
MyTimeUtils
.
MASTERDATA_DESIGNATION
,
designation
.
trim
(),
true
);
designation
=
designation
.
trim
();
if
(
!
MyTimeUtils
.
EMPTY_STRING
.
equals
(
designation
))
{
List
<
MasterData
>
designationData
=
masterDataRepo
.
findByMasterDataTypeAndMasterDataNameAndActiveStatus
(
MyTimeUtils
.
MASTERDATA_DESIGNATION
,
designation
,
true
);
flag
=
designationData
.
size
()
>
MyTimeUtils
.
INT_ZERO
;
}
return
flag
;
...
...
@@ -91,10 +97,11 @@ public class DataValidations {
public
static
boolean
isValidEmploymentType
(
String
employmentType
,
MasterDataRepo
masterDataRepo
)
{
boolean
flag
=
false
;
if
(
null
!=
employmentType
&&
MyTimeUtils
.
EMPTY_STRING
.
equals
(
employmentType
)){
employmentType
=
employmentType
.
trim
();
if
(
MyTimeUtils
.
EMPTY_STRING
.
equals
(
employmentType
)){
flag
=
true
;
}
else
if
(
null
!=
employmentType
&&
!
MyTimeUtils
.
EMPTY_STRING
.
equals
(
employmentType
.
trim
()
))
{
List
<
MasterData
>
empTypeData
=
masterDataRepo
.
findByMasterDataTypeAndMasterDataNameAndActiveStatus
(
MyTimeUtils
.
MASTERDATAD_EMLOYMENT_TYPE
,
employmentType
.
trim
()
,
true
);
}
else
if
(
!
MyTimeUtils
.
EMPTY_STRING
.
equals
(
employmentType
))
{
List
<
MasterData
>
empTypeData
=
masterDataRepo
.
findByMasterDataTypeAndMasterDataNameAndActiveStatus
(
MyTimeUtils
.
MASTERDATAD_EMLOYMENT_TYPE
,
employmentType
,
true
);
flag
=
empTypeData
.
size
()
>
MyTimeUtils
.
INT_ZERO
;
}
return
flag
;
...
...
@@ -102,10 +109,11 @@ public class DataValidations {
public
static
boolean
isValidRole
(
String
role
,
MasterDataRepo
masterDataRepo
)
{
boolean
flag
=
false
;
if
(
null
!=
role
&&
MyTimeUtils
.
EMPTY_STRING
.
equals
(
role
)){
role
=
role
.
trim
();
if
(
MyTimeUtils
.
EMPTY_STRING
.
equals
(
role
)){
flag
=
true
;
}
else
if
(
null
!=
role
&&
!
MyTimeUtils
.
EMPTY_STRING
.
equals
(
role
.
trim
().
trim
()
))
{
List
<
MasterData
>
roleData
=
masterDataRepo
.
findByMasterDataTypeAndMasterDataNameAndActiveStatus
(
MyTimeUtils
.
MASTERDATA_ROLES
,
role
.
trim
()
,
true
);
}
else
if
(
!
MyTimeUtils
.
EMPTY_STRING
.
equals
(
role
))
{
List
<
MasterData
>
roleData
=
masterDataRepo
.
findByMasterDataTypeAndMasterDataNameAndActiveStatus
(
MyTimeUtils
.
MASTERDATA_ROLES
,
role
,
true
);
flag
=
roleData
.
size
()
>
MyTimeUtils
.
INT_ZERO
;
}
return
flag
;
...
...
@@ -125,12 +133,14 @@ public class DataValidations {
public
static
boolean
isAgeGreaterThanTwenty
(
Date
dob
,
Date
doj
)
{
boolean
flag
=
false
;
if
(
null
!=
dob
&&
null
!=
doj
)
{
Calendar
dojCal
=
Calendar
.
getInstance
();
dojCal
.
setTime
(
doj
);
Calendar
dobCal
=
Calendar
.
getInstance
();
dobCal
.
setTime
(
dob
);
flag
=
dojCal
.
get
(
Calendar
.
YEAR
)
-
dobCal
.
get
(
Calendar
.
YEAR
)
>
MyTimeUtils
.
INT_TWENTY
;
if
(
dob
==
null
)
{
flag
=
true
;
}
else
if
(
null
!=
doj
)
{
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTime
(
doj
);
int
dojYear
=
cal
.
get
(
Calendar
.
YEAR
);
cal
.
setTime
(
dob
);
flag
=
dojYear
-
cal
.
get
(
Calendar
.
YEAR
)
>
MyTimeUtils
.
INT_TWENTY
;
}
return
flag
;
}
...
...
@@ -138,16 +148,18 @@ public class DataValidations {
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
;
workLocation
=
workLocation
.
trim
();
if
(!
MyTimeUtils
.
EMPTY_STRING
.
equals
(
workLocation
))
{
flag
=
locationRepo
.
findByLocationAndActiveStatus
(
workLocation
,
true
).
size
()
>
MyTimeUtils
.
INT_ZERO
;
}
return
flag
;
}
public
static
boolean
isActive
(
String
active
)
{
boolean
flag
=
false
;
if
(
null
!=
active
&&
MyTimeUtils
.
EMPTY_STRING
.
equals
(
active
.
trim
()))
{
flag
=
MyTimeUtils
.
ACTIVE
.
equalsIgnoreCase
(
active
.
trim
());
active
=
active
.
trim
();
if
(
null
!=
active
&&
MyTimeUtils
.
EMPTY_STRING
.
equals
(
active
))
{
flag
=
MyTimeUtils
.
ACTIVE
.
equalsIgnoreCase
(
active
);
}
return
flag
;
}
...
...
src/main/java/com/nisum/mytime/utils/MyTimeUtils.java
View file @
cf5e57af
...
...
@@ -131,6 +131,8 @@ public class MyTimeUtils {
public
final
static
String
MALE
=
"Male"
;
public
final
static
String
FEMALE
=
"Female"
;
public
final
static
String
M
=
"M"
;
public
final
static
String
F
=
"F"
;
public
final
static
String
YES
=
"Yes"
;
public
final
static
String
NO
=
"No"
;
...
...
@@ -144,4 +146,6 @@ public class MyTimeUtils {
public
final
static
String
MASTERDATA_ROLES
=
"roles"
;
public
final
static
String
FULL_TIME
=
"Full Time"
;
public
final
static
String
CAMA
=
","
;
}
src/main/webapp/WEB-INF/controllers/ExportDataController.js
View file @
cf5e57af
...
...
@@ -24,7 +24,6 @@ myApp
$scope
.
file
=
''
;
$
(
'#upload-file-info'
).
html
(
""
);
}
$scope
.
uploadFiles
=
function
()
{
var
file
=
$scope
.
file
;
var
empId
=
myFactory
.
getEmpId
();
...
...
@@ -38,37 +37,16 @@ myApp
showProgressDialog
(
'Please wait while data is imported from file...!!!'
);
var
formData
=
new
FormData
();
formData
.
append
(
'file'
,
file
);
$http
.
post
(
appConfig
.
appUri
+
"user/fileUpload?empId="
+
empId
,
formData
,
{
transformRequest
:
angular
.
identity
,
headers
:
{
'Content-Type'
:
undefined
},
transformResponse
:
[
function
(
data
)
{
return
data
;
}
]
})
.
then
(
function
mySuccess
(
response
)
{
$http
.
post
(
appConfig
.
appUri
+
"user/fileUpload?empId="
+
empId
,
formData
,{
transformRequest
:
angular
.
identity
,
headers
:
{
'Content-Type'
:
undefined
},
transformResponse
:
[
function
(
data
)
{
return
data
;
}
]})
.
then
(
function
mySuccess
(
response
)
{
$mdDialog
.
hide
();
console
.
log
(
response
.
data
);
var
parsedResponse
=
JSON
.
parse
(
response
.
data
);
var
resp
=
Object
.
keys
(
parsedResponse
)
if
(
Object
.
keys
(
parsedResponse
)[
0
]
==
"Validation Error"
){
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'
);
}
showAlert
(
response
.
data
);
$scope
.
refreshPage
();
},
function
myError
(
response
)
{
$mdDialog
.
hide
();
...
...
@@ -77,9 +55,7 @@ myApp
$scope
.
refreshPage
();
});
}
}
function
showAlert
(
message
)
{
$mdDialog
.
show
(
$mdDialog
.
alert
().
parent
(
angular
.
element
(
document
...
...
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