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
e811e3e3
Commit
e811e3e3
authored
2 years ago
by
nivetha
Browse files
Options
Download
Patches
Plain Diff
Remove empty key value from data object
parent
ec725b44
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
+40
-0
...java/com/tarento/formservice/utils/ValidationService.java
with
40 additions
and
0 deletions
+40
-0
src/main/java/com/tarento/formservice/utils/ValidationService.java
+
40
−
0
View file @
e811e3e3
...
...
@@ -2,11 +2,15 @@ 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.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
;
...
...
@@ -55,6 +59,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 +102,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 +113,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
)
{
e
.
printStackTrace
();
}
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