Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
bp_custom
Overview
Overview
Details
Activity
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mikhail Gashenko
bp_custom
Commits
054deba7
Commit
054deba7
authored
Jan 26, 2017
by
everdarkgreen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
JsonNode: (draft1) node value update
parent
ae930ecb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
4 deletions
+33
-4
Main.java
src/main/java/kz/arta/synergy/astdev/custom_bp/Main.java
+33
-4
No files found.
src/main/java/kz/arta/synergy/astdev/custom_bp/Main.java
View file @
054deba7
...
@@ -27,6 +27,7 @@ import javax.ejb.ActivationConfigProperty;
...
@@ -27,6 +27,7 @@ import javax.ejb.ActivationConfigProperty;
import
javax.ejb.MessageDriven
;
import
javax.ejb.MessageDriven
;
import
org.codehaus.jackson.map.ObjectMapper
;
import
org.codehaus.jackson.map.ObjectMapper
;
import
org.codehaus.jackson.node.ArrayNode
;
import
org.codehaus.jackson.node.ArrayNode
;
import
org.codehaus.jackson.node.ObjectNode
;
import
org.codehaus.jackson.type.TypeReference
;
import
org.codehaus.jackson.type.TypeReference
;
@MessageDriven
(
name
=
"CustomBP"
,
activationConfig
=
{
@MessageDriven
(
name
=
"CustomBP"
,
activationConfig
=
{
...
@@ -118,7 +119,19 @@ public class Main implements MessageListener {
...
@@ -118,7 +119,19 @@ public class Main implements MessageListener {
}
}
}
}
// private void postDataToCard()
private
void
setComponentValueByID
(
String
formJson
,
String
oldFieldName
,
String
newFieldName
)
{
ObjectMapper
mapper
=
new
ObjectMapper
();
String
result
=
new
String
();
try
{
JsonNode
rootNode
=
mapper
.
readTree
(
formJson
);
}
catch
(
Exception
exc
)
{
LOGGER
.
error
(
"GMP: Invalid card data"
);
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
}
}
private
void
unlockRoute
()
{
private
void
unlockRoute
()
{
try
{
try
{
...
@@ -150,6 +163,21 @@ public class Main implements MessageListener {
...
@@ -150,6 +163,21 @@ public class Main implements MessageListener {
return
new
String
();
return
new
String
();
}
}
private
static
void
replaceValueInNode
(
Iterator
<
JsonNode
>
iter
,
String
fieldName
,
String
newFieldValue
)
{
try
{
while
(
iter
.
hasNext
())
{
JsonNode
n
=
iter
.
next
();
if
(
n
.
has
(
"id"
))
{
if
(
fieldName
.
equals
(
n
.
get
(
"id"
).
asText
()))
{
((
ObjectNode
)
n
).
put
(
"key"
,
newFieldValue
);
}
}
}
}
catch
(
Exception
exc
)
{
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
}
}
private
static
String
searchInNode
(
Iterator
<
JsonNode
>
iter
,
String
fieldName
,
fieldType
ft
)
{
private
static
String
searchInNode
(
Iterator
<
JsonNode
>
iter
,
String
fieldName
,
fieldType
ft
)
{
String
result
=
new
String
();
String
result
=
new
String
();
// different form's component keeps data in different places
// different form's component keeps data in different places
...
@@ -173,23 +201,24 @@ public class Main implements MessageListener {
...
@@ -173,23 +201,24 @@ public class Main implements MessageListener {
return
result
;
return
result
;
}
}
private
static
String
getComponentValueByID
(
final
String
formJson
,
final
String
fieldName
,
fieldType
ft
)
{
private
static
String
getComponentValueByID
(
String
formJson
,
String
fieldName
,
fieldType
ft
)
{
ObjectMapper
mapper
=
new
ObjectMapper
();
ObjectMapper
mapper
=
new
ObjectMapper
();
String
result
=
new
String
();
String
result
=
new
String
();
String
componentType
=
new
String
();
try
{
try
{
JsonNode
rootNode
=
mapper
.
readTree
(
formJson
);
JsonNode
rootNode
=
mapper
.
readTree
(
formJson
);
// gettin
t
first level (root) 'data' node, there may be only two levels
// gettin
g
first level (root) 'data' node, there may be only two levels
ArrayNode
rootDN
=
(
ArrayNode
)
rootNode
.
get
(
"data"
);
ArrayNode
rootDN
=
(
ArrayNode
)
rootNode
.
get
(
"data"
);
Iterator
<
JsonNode
>
rootDNIterator
=
rootDN
.
getElements
();
Iterator
<
JsonNode
>
rootDNIterator
=
rootDN
.
getElements
();
// searching for field value in root 'data' node
result
=
searchInNode
(
rootDNIterator
,
fieldName
,
ft
);
result
=
searchInNode
(
rootDNIterator
,
fieldName
,
ft
);
if
(!
result
.
isEmpty
())
{
if
(!
result
.
isEmpty
())
{
return
result
;
return
result
;
}
}
// root 'data' value does not contain the expected value, search in second (last possible) 'data'
Iterator
<
JsonNode
>
rootDNIterator2
=
rootDN
.
getElements
();
Iterator
<
JsonNode
>
rootDNIterator2
=
rootDN
.
getElements
();
while
(
rootDNIterator2
.
hasNext
())
{
while
(
rootDNIterator2
.
hasNext
())
{
ArrayNode
childNode
=
(
ArrayNode
)
rootDNIterator2
.
next
().
get
(
"data"
);
ArrayNode
childNode
=
(
ArrayNode
)
rootDNIterator2
.
next
().
get
(
"data"
);
...
...
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