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
ce41fc8a
Commit
ce41fc8a
authored
Jan 26, 2017
by
everdarkgreen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
JsonNode: user search working
parent
d1ffe8cb
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
17 deletions
+60
-17
Main.java
src/main/java/kz/arta/synergy/astdev/custom_bp/Main.java
+60
-17
No files found.
src/main/java/kz/arta/synergy/astdev/custom_bp/Main.java
View file @
ce41fc8a
...
...
@@ -36,8 +36,8 @@ import org.codehaus.jackson.node.ArrayNode;
public
class
Main
implements
MessageListener
{
private
enum
fieldType
{
DATE
,
TEXTBOX
private
static
enum
fieldType
{
DATE
,
TEXTBOX
,
USER
}
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
Main
.
class
);
...
...
@@ -81,10 +81,16 @@ public class Main implements MessageListener {
}
}
// Получение ID пользователя
// Получение данных исходной формы
URL
getFormDataURL
=
new
URL
(
"http://127.0.0.1:8080/Synergy/rest/api/asforms/data/"
+
dataUUID
);
// JsonParser sourceFormData = synergyApiGet(getFormDataURL);
String
sourceFormDataString
=
synergyApiGetString
(
getFormDataURL
);
URL
sourceFormURL
=
new
URL
(
"http://127.0.0.1:8080/Synergy/rest/api/asforms/data/"
+
dataUUID
);
// JsonParser sourceFormData = synergyApiGet(sourceFormURL);
String
sourceFormData
=
synergyApiGetString
(
sourceFormURL
);
// Получение ID пользователя
String
userID
=
getComponentValueByID
(
sourceFormData
,
"user1"
,
fieldType
.
USER
);
// Получение значений текущих дат исходной формы
String
b2b1
,
b4b1
,
b5b1
;
...
...
@@ -96,11 +102,18 @@ public class Main implements MessageListener {
String
t26b1
,
t24b1
,
t22b1
;
String
t32b1
,
t30b1
,
t28b1
;
b2b1
=
getDateKeyByFieldName
(
sourceFormDataString
,
"t10-b1-b1"
);
LOGGER
.
info
(
"*** t10-b1-b1 (2017-01-31 00:00:00) *** "
+
b2b1
);
b2b1
=
getComponentValueByID
(
sourceFormData
,
"b2-b1-b1"
,
fieldType
.
DATE
);
b4b1
=
getComponentValueByID
(
sourceFormData
,
"b4-b1"
,
fieldType
.
DATE
);
b5b1
=
getComponentValueByID
(
sourceFormData
,
"b5-b1"
,
fieldType
.
TEXTBOX
);
t4b1
=
getComponentValueByID
(
sourceFormData
,
"b2-b1"
,
fieldType
.
DATE
);
// Получение данных целевой карточки
// URL targetFormURL = new URL("http://127.0.0.1:8080/Synergy/rest/api/asforms/data/")
// String targetFormData = synergyApiGetString(sourceFormURL)
// Разблокировка маршрута""
String
address
=
"http://127.0.0.1:8080/Synergy"
;
...
...
@@ -113,29 +126,59 @@ public class Main implements MessageListener {
}
}
private
static
String
searchInNode
(
Iterator
<
JsonNode
>
iter
,
String
fieldName
,
fieldType
ft
)
{
String
result
=
new
String
();
// different form's component keeps data in different places
String
componentType
=
new
String
();
if
(
ft
==
fieldType
.
DATE
||
ft
==
fieldType
.
USER
)
{
componentType
=
"key"
;
}
else
if
(
ft
==
fieldType
.
TEXTBOX
)
{
componentType
=
"value"
;
}
while
(
iter
.
hasNext
())
{
// search data through content of child 'data' nodes
JsonNode
n
=
iter
.
next
();
if
(
n
.
has
(
"id"
)
&&
n
.
has
(
componentType
))
{
if
(
fieldName
.
equals
(
n
.
get
(
"id"
).
asText
()))
{
result
=
n
.
get
(
componentType
).
asText
();
}
}
}
return
result
;
}
private
static
String
get
DateKeyByFieldName
(
final
String
formJson
,
final
String
fieldName
)
{
private
static
String
get
ComponentValueByID
(
final
String
formJson
,
final
String
fieldName
,
fieldType
ft
)
{
ObjectMapper
mapper
=
new
ObjectMapper
();
String
result
=
new
String
();
String
componentType
=
new
String
();
try
{
JsonNode
rootNode
=
mapper
.
readTree
(
formJson
);
// gettint first level (root) 'data' node, there may be only two levels
ArrayNode
rootDN
=
(
ArrayNode
)
rootNode
.
get
(
"data"
);
Iterator
<
JsonNode
>
rootDNIterator
=
rootDN
.
getElements
();
while
(
rootDNIterator
.
hasNext
())
{
ArrayNode
childNode
=
(
ArrayNode
)
rootDNIterator
.
next
().
get
(
"data"
);
Iterator
<
JsonNode
>
childDNIterator
=
childNode
.
getElements
();
while
(
childDNIterator
.
hasNext
())
{
JsonNode
n
=
childDNIterator
.
next
();
if
(
n
.
has
(
"id"
)
&&
n
.
has
(
"value"
))
{
if
(
fieldName
.
equals
(
n
.
get
(
"id"
).
asText
()))
{
result
=
n
.
get
(
"value"
).
asText
();
}
result
=
searchInNode
(
rootDNIterator
,
fieldName
,
ft
);
if
(!
result
.
isEmpty
())
{
return
result
;
}
Iterator
<
JsonNode
>
rootDNIterator2
=
rootDN
.
getElements
();
while
(
rootDNIterator2
.
hasNext
())
{
ArrayNode
childNode
=
(
ArrayNode
)
rootDNIterator2
.
next
().
get
(
"data"
);
Iterator
<
JsonNode
>
childDNIterator
=
childNode
.
getElements
();
result
=
searchInNode
(
childDNIterator
,
fieldName
,
ft
);
if
(!
result
.
isEmpty
())
{
return
result
;
}
}
return
result
;
}
catch
(
Exception
exc
)
{
LOGGER
.
error
(
"GMP: Invalid form data"
);
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
}
return
result
;
...
...
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