Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Register
Sign in
Toggle navigation
Menu
UPSMF
uphrh-smf-form
Commits
83aa858b
Commit
83aa858b
authored
2 years ago
by
Darshan M N
Browse files
Options
Download
Plain Diff
Merge branch 'master' of
https://git.idc.tarento.com/smf/smf-form
parents
889b614a
c9fe67a5
master
bulk-download
cvs_download
delete-form
emailContentUpdate
inspection-flow-changes
institute-district
lat-long
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/com/tarento/formservice/utils/ValidationService.java
+44
-0
...java/com/tarento/formservice/utils/ValidationService.java
with
44 additions
and
0 deletions
+44
-0
src/main/java/com/tarento/formservice/utils/ValidationService.java
+
44
−
0
View file @
83aa858b
...
...
@@ -2,11 +2,17 @@ package com.tarento.formservice.utils;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
org.apache.commons.lang.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.tarento.formservice.model.IncomingData
;
import
com.tarento.formservice.model.Status
;
import
com.tarento.formservice.models.Field
;
...
...
@@ -15,6 +21,8 @@ import com.tarento.formservice.models.FormDetail;
@Service
public
class
ValidationService
{
public
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
ValidationService
.
class
);
public
String
validateCreateForm
(
FormDetail
form
)
throws
JsonProcessingException
{
if
(
form
==
null
)
{
...
...
@@ -55,6 +63,10 @@ public class ValidationService {
}
if
(
incomingData
.
getDataObject
()
==
null
)
{
return
Constants
.
ResponseMessages
.
DATA_OBJECT_MISSING
;
}
else
{
if
(
incomingData
.
getDataObject
()
instanceof
Map
)
{
incomingData
.
setDataObject
(
removeEmptyFields
(
incomingData
.
getDataObject
()));
}
}
return
Constants
.
ResponseCodes
.
SUCCESS
;
}
...
...
@@ -94,6 +106,10 @@ public class ValidationService {
}
if
(
incomingData
.
getDataObject
()
==
null
)
{
return
Constants
.
ResponseMessages
.
DATA_OBJECT_MISSING
;
}
else
{
if
(
incomingData
.
getDataObject
()
instanceof
Map
)
{
incomingData
.
setDataObject
(
removeEmptyFields
(
incomingData
.
getDataObject
()));
}
}
if
(
incomingData
.
getInspectorSummaryDataObject
()
==
null
)
{
return
Constants
.
ResponseMessages
.
INSPECTOR_SUMMARY_MISSING
;
...
...
@@ -101,6 +117,34 @@ public class ValidationService {
return
Constants
.
ResponseCodes
.
SUCCESS
;
}
/**
* Iterates the data object and removes if any empty key or value present with
* in the data object
*
* @param dataObject
* Object
* @return Object
*/
public
Object
removeEmptyFields
(
Object
dataObject
)
{
try
{
ConcurrentHashMap
<
String
,
Object
>
dataObjectMap
=
new
ObjectMapper
().
convertValue
(
dataObject
,
new
TypeReference
<
ConcurrentHashMap
<
String
,
Object
>>()
{
});
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
dataObjectMap
.
entrySet
())
{
if
(
entry
.
getKey
().
equals
(
StringUtils
.
EMPTY
)
||
(
entry
.
getValue
()
instanceof
String
&&
(
entry
.
getValue
()
==
null
||
entry
.
getValue
().
equals
(
StringUtils
.
EMPTY
))))
{
dataObjectMap
.
remove
(
entry
.
getKey
());
}
else
if
(
entry
.
getValue
()
instanceof
Map
)
{
entry
.
setValue
(
removeEmptyFields
(
entry
.
getValue
()));
}
}
return
dataObjectMap
;
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
String
.
format
(
Constants
.
EXCEPTION
,
"removeEmptyFields"
,
e
.
getMessage
()));
}
return
dataObject
;
}
public
String
validateReturnedApplication
(
IncomingData
incomingData
)
{
if
(
incomingData
==
null
)
{
return
Constants
.
ResponseMessages
.
CHECK_REQUEST_PARAMS
;
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets