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
8721d24c
Commit
8721d24c
authored
Sep 04, 2018
by
b v s satyanarayana
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MT-53 :SNS :: ImportEmployeeDataValidations
parent
47402225
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
162 additions
and
0 deletions
+162
-0
DataValidations.java
src/main/java/com/nisum/mytime/utils/DataValidations.java
+162
-0
No files found.
src/main/java/com/nisum/mytime/utils/DataValidations.java
0 → 100644
View file @
8721d24c
package
com
.
nisum
.
mytime
.
utils
;
import
java.util.Calendar
;
import
java.util.Date
;
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
com.nisum.mytime.model.MasterData
;
import
com.nisum.mytime.repository.LocationRepo
;
import
com.nisum.mytime.repository.MasterDataRepo
;
@Component
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
()))
{
flag
=
number
.
matches
(
"^\\d+$"
)
&&
isNumberInRange
(
number
.
trim
());
}
return
flag
;
}
public
static
boolean
isNumberInRange
(
String
number
)
{
long
empId
=
Long
.
parseLong
(
number
);
return
(
empId
>=
MyTimeUtils
.
EMPID_START
&&
empId
<=
MyTimeUtils
.
EMPID_END
);
}
public
static
boolean
validateName
(
String
name
)
{
boolean
flag
=
false
;
if
(
null
!=
name
&&
!
MyTimeUtils
.
EMPTY_STRING
.
equals
(
name
.
trim
()))
{
String
regx
=
"^[\\p{L} .'-]+$"
;
Pattern
pattern
=
Pattern
.
compile
(
regx
,
Pattern
.
CASE_INSENSITIVE
);
Matcher
matcher
=
pattern
.
matcher
(
name
.
trim
());
flag
=
matcher
.
find
();
}
return
flag
;
}
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
);
}
return
flag
;
}
public
static
boolean
validateEmail
(
String
email
)
{
boolean
flag
=
false
;
if
(
null
!=
email
&&
!
MyTimeUtils
.
EMPTY_STRING
.
equals
(
email
))
{
if
(
email
.
trim
().
endsWith
(
"@nisum.com"
))
{
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
());
flag
=
matcher
.
find
();
}
}
return
flag
;
}
public
static
boolean
isYesOrNo
(
String
value
)
{
boolean
flag
=
false
;
if
(
null
!=
value
&&
!
MyTimeUtils
.
EMPTY_STRING
.
equals
(
value
.
trim
()))
{
value
=
value
.
trim
();
flag
=
value
.
equalsIgnoreCase
(
MyTimeUtils
.
YES
)
||
value
.
equalsIgnoreCase
(
MyTimeUtils
.
STRING_Y
)
||
value
.
equalsIgnoreCase
(
MyTimeUtils
.
NO
)
||
value
.
equalsIgnoreCase
(
MyTimeUtils
.
STRING_N
);
}
return
flag
;
}
public
static
boolean
isValidFunctionalGroup
(
String
functionalGroup
)
{
boolean
flag
=
false
;
if
(
null
!=
functionalGroup
&&
!
MyTimeUtils
.
EMPTY_STRING
.
equals
(
functionalGroup
.
trim
()))
{
List
<
MasterData
>
fsData
=
masterDataRepo
.
findByMasterDataTypeAndMasterDataNameAndActiveStatus
(
MyTimeUtils
.
MASTERDATA_FG
,
functionalGroup
.
trim
(),
true
);
flag
=
fsData
.
size
()
>
MyTimeUtils
.
INT_ZERO
;
}
return
flag
;
}
public
static
boolean
isValidDesignation
(
String
designation
)
{
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
;
}
return
flag
;
}
public
static
boolean
isValidEmploymentType
(
String
employmentType
)
{
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
;
}
return
flag
;
}
public
static
boolean
isValidRole
(
String
role
)
{
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
;
}
return
flag
;
}
public
static
boolean
isFutureDate
(
Date
date
)
{
boolean
flag
=
false
;
if
(
null
!=
date
)
{
flag
=
new
Date
().
after
(
date
)
;
}
return
flag
;
}
public
static
boolean
isValidDate
(
Date
date
)
{
return
null
!=
date
;
}
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
;
}
return
flag
;
}
public
static
boolean
isValidWorkLocation
(
String
workLocation
)
{
boolean
flag
=
false
;
if
(
null
!=
workLocation
&&
MyTimeUtils
.
EMPTY_STRING
.
equals
(
workLocation
.
trim
()))
{
flag
=
locationRepo
.
findByLocationAndActiveStatus
(
workLocation
.
trim
(),
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
());
}
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