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
9b3b8a29
You need to sign in or sign up before continuing.
Commit
9b3b8a29
authored
Jan 28, 2017
by
Mikhail Gashenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
JsonNode: (draft5) new node value search and update with ObjectMapper
parent
a91e1e7d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
45 deletions
+65
-45
AsNode.java
src/main/java/kz/arta/synergy/astdev/custom_bp/AsNode.java
+21
-0
Main.java
src/main/java/kz/arta/synergy/astdev/custom_bp/Main.java
+44
-45
No files found.
src/main/java/kz/arta/synergy/astdev/custom_bp/AsNode.java
View file @
9b3b8a29
...
@@ -7,6 +7,7 @@ package kz.arta.synergy.astdev.custom_bp;
...
@@ -7,6 +7,7 @@ package kz.arta.synergy.astdev.custom_bp;
import
java.util.List
;
import
java.util.List
;
import
org.codehaus.jackson.annotate.JsonProperty
;
import
org.codehaus.jackson.annotate.JsonProperty
;
import
org.codehaus.jackson.node.ObjectNode
;
/**
/**
*
*
...
@@ -25,6 +26,10 @@ public class AsNode {
...
@@ -25,6 +26,10 @@ public class AsNode {
private
String
value
;
private
String
value
;
@JsonProperty
(
"data"
)
@JsonProperty
(
"data"
)
private
List
<
AsNode
>
data
;
private
List
<
AsNode
>
data
;
@JsonProperty
(
"formatVersion"
)
private
String
formatVersion
;
@JsonProperty
(
"manualTags"
)
private
ObjectNode
manualTags
;
public
String
getId
()
{
public
String
getId
()
{
return
id
;
return
id
;
...
@@ -73,5 +78,21 @@ public class AsNode {
...
@@ -73,5 +78,21 @@ public class AsNode {
public
void
setData
(
List
<
AsNode
>
data
)
{
public
void
setData
(
List
<
AsNode
>
data
)
{
this
.
data
=
data
;
this
.
data
=
data
;
}
}
public
String
getFormatVersion
()
{
return
formatVersion
;
}
public
void
setFormatVersion
(
String
formatVersion
)
{
this
.
formatVersion
=
formatVersion
;
}
public
ObjectNode
getManualTags
()
{
return
manualTags
;
}
public
void
setManualTags
(
ObjectNode
manualTags
)
{
this
.
manualTags
=
manualTags
;
}
}
}
src/main/java/kz/arta/synergy/astdev/custom_bp/Main.java
View file @
9b3b8a29
...
@@ -29,6 +29,10 @@ import org.codehaus.jackson.node.ArrayNode;
...
@@ -29,6 +29,10 @@ import org.codehaus.jackson.node.ArrayNode;
import
org.codehaus.jackson.node.ObjectNode
;
import
org.codehaus.jackson.node.ObjectNode
;
import
org.codehaus.jackson.type.TypeReference
;
import
org.codehaus.jackson.type.TypeReference
;
/**
*
* @author drpsy
*/
@MessageDriven
(
name
=
"CustomBP"
,
activationConfig
=
{
@MessageDriven
(
name
=
"CustomBP"
,
activationConfig
=
{
@ActivationConfigProperty
(
propertyName
=
"destinationType"
,
propertyValue
=
"javax.jms.Queue"
),
@ActivationConfigProperty
(
propertyName
=
"destinationType"
,
propertyValue
=
"javax.jms.Queue"
),
@ActivationConfigProperty
(
propertyName
=
"destination"
,
propertyValue
=
"java:jboss/queues/Integration/CustomBP"
),
@ActivationConfigProperty
(
propertyName
=
"destination"
,
propertyValue
=
"java:jboss/queues/Integration/CustomBP"
),
...
@@ -52,6 +56,10 @@ public class Main implements MessageListener {
...
@@ -52,6 +56,10 @@ public class Main implements MessageListener {
private
String
executionID
=
null
;
// идентификатор блокирующего процесса
private
String
executionID
=
null
;
// идентификатор блокирующего процесса
private
String
documentID
=
null
;
// идентификатор документа реестра
private
String
documentID
=
null
;
// идентификатор документа реестра
/**
*
* @param message
*/
@Override
@Override
public
void
onMessage
(
Message
message
)
{
public
void
onMessage
(
Message
message
)
{
if
(!(
message
instanceof
TextMessage
))
{
if
(!(
message
instanceof
TextMessage
))
{
...
@@ -88,11 +96,13 @@ public class Main implements MessageListener {
...
@@ -88,11 +96,13 @@ public class Main implements MessageListener {
URL
sourceFormURL
=
new
URL
(
"http://127.0.0.1:8080/Synergy/rest/api/asforms/data/"
+
dataUUID
);
URL
sourceFormURL
=
new
URL
(
"http://127.0.0.1:8080/Synergy/rest/api/asforms/data/"
+
dataUUID
);
String
sourceFormData
=
synergyApiGetString
(
sourceFormURL
);
String
sourceFormData
=
synergyApiGetString
(
sourceFormURL
);
// Получение ID пользователя
// Получение ID пользователя
указанного в форме
String
userID
=
getComponentValueByID
(
sourceFormData
,
"user1"
,
fields
.
KEY
);
String
userID
=
getComponentValueByID
(
sourceFormData
,
"user1"
,
fields
.
KEY
);
// По ID пользователя DataUUID целевой карточки
// По ID пользователя указанного в карточке и ID формы получаем DataUUID целевой карточки
String
userCardDataUUID
=
getCardDataUUID
(
userID
,
"04f7809d-f44c-4a2d-950d-6aa8e6c3fea1"
);
// String userCardDataUUID = getCardDataUUID(userID, "04f7809d-f44c-4a2d-950d-6aa8e6c3fea1");
String
userCardDataUUID
=
getCardDataUUID
(
userID
,
"fb44d99d-1579-4ac3-884a-01a6d4f71f9c"
);
// Получение данных целевой карточки по dataUUID
// Получение данных целевой карточки по dataUUID
URL
targetFormURL
=
new
URL
(
"http://127.0.0.1:8080/Synergy/rest/api/asforms/data/"
+
userCardDataUUID
);
URL
targetFormURL
=
new
URL
(
"http://127.0.0.1:8080/Synergy/rest/api/asforms/data/"
+
userCardDataUUID
);
String
targetFormData
=
synergyApiGetString
(
targetFormURL
);
String
targetFormData
=
synergyApiGetString
(
targetFormURL
);
...
@@ -154,18 +164,32 @@ public class Main implements MessageListener {
...
@@ -154,18 +164,32 @@ public class Main implements MessageListener {
*/
*/
private
static
AsNode
findNode
(
List
<
AsNode
>
nodesList
,
String
componentID
)
{
private
static
AsNode
findNode
(
List
<
AsNode
>
nodesList
,
String
componentID
)
{
AsNode
result
=
null
;
AsNode
result
=
null
;
for
(
AsNode
n
:
nodesList
)
{
for
(
AsNode
n
:
nodesList
)
{
if
(
componentID
.
equals
(
n
.
getId
()))
{
if
(
componentID
.
equals
(
n
.
getId
()))
{
result
=
n
;
result
=
n
;
break
;
break
;
}
}
if
(!
n
.
getData
().
isEmpty
())
{
if
(
n
.
getData
()
!=
null
)
{
findNode
(
n
.
getData
(),
componentID
);
result
=
findNode
(
n
.
getData
(),
componentID
);
if
(
result
!=
null
)
{
break
;
}
}
}
}
}
return
result
;
return
result
;
}
}
/**
* Setting new value of requested field of requested component with specified ID
* @param targetJsonAsString
* @param componentID
* @param fieldName
* @param newFieldValue
* @throws AttributeModificationException
* @throws IOException
*/
private
void
updateFieldValue
(
String
targetJsonAsString
,
String
componentID
,
fields
fieldName
,
String
newFieldValue
)
throws
AttributeModificationException
,
IOException
{
private
void
updateFieldValue
(
String
targetJsonAsString
,
String
componentID
,
fields
fieldName
,
String
newFieldValue
)
throws
AttributeModificationException
,
IOException
{
ObjectMapper
objectMapper
=
new
ObjectMapper
();
ObjectMapper
objectMapper
=
new
ObjectMapper
();
try
{
try
{
...
@@ -199,8 +223,6 @@ public class Main implements MessageListener {
...
@@ -199,8 +223,6 @@ public class Main implements MessageListener {
case
VALUE:
case
VALUE:
targetNode
.
setValue
(
newFieldValue
);
targetNode
.
setValue
(
newFieldValue
);
break
;
break
;
default
:
// TODO
break
;
}
}
}
}
}
catch
(
AttributeModificationException
e
)
{
}
catch
(
AttributeModificationException
e
)
{
...
@@ -233,7 +255,16 @@ public class Main implements MessageListener {
...
@@ -233,7 +255,16 @@ public class Main implements MessageListener {
return
new
String
();
return
new
String
();
}
}
private
static
String
getComponentValueByID
(
String
targetJsonAsString
,
String
componentID
,
fields
fieldName
)
throws
NameNotFoundException
,
IOException
{
/**
* Returns value of of specified field of component with specified ID
* @param targetJsonAsString
* @param componentID
* @param fieldName
* @return
* @throws NameNotFoundException
* @throws IOException
*/
private
static
String
getComponentValueByID
(
String
targetJsonAsString
,
String
componentID
,
fields
fieldName
)
throws
Exception
{
// String b2b1 = getComponentValueByID(sourceFormData, "b2-b1-b1", fieldType.DATE);
// String b2b1 = getComponentValueByID(sourceFormData, "b2-b1-b1", fieldType.DATE);
ObjectMapper
objectMapper
=
new
ObjectMapper
();
ObjectMapper
objectMapper
=
new
ObjectMapper
();
String
result
=
null
;
String
result
=
null
;
...
@@ -241,17 +272,17 @@ public class Main implements MessageListener {
...
@@ -241,17 +272,17 @@ public class Main implements MessageListener {
try
{
try
{
JsonNode
rootNode
=
objectMapper
.
readTree
(
targetJsonAsString
);
// read the whole tree
JsonNode
rootNode
=
objectMapper
.
readTree
(
targetJsonAsString
);
// read the whole tree
if
(
rootNode
.
isNull
())
{
if
(
rootNode
.
isNull
())
{
throw
new
NameNotFound
Exception
(
"GMP: Passed data has no JSON content"
);
throw
new
Exception
(
"GMP: Passed data has no JSON content"
);
}
}
JsonNode
rootDataNode
=
rootNode
.
get
(
"data"
);
// read single root 'data' node
JsonNode
rootDataNode
=
rootNode
.
get
(
"data"
);
// read single root 'data' node
if
(
rootDataNode
==
null
)
{
if
(
rootDataNode
==
null
)
{
throw
new
NameNotFound
Exception
(
"GMP: Invalid form data, root \"data\" node does not exists"
);
throw
new
Exception
(
"GMP: Invalid form data, root \"data\" node does not exists"
);
}
}
List
<
AsNode
>
dataNodesList
=
objectMapper
.
readValue
(
rootDataNode
,
new
TypeReference
<
List
<
AsNode
>>()
{});
// map content of single root 'data' node
List
<
AsNode
>
dataNodesList
=
objectMapper
.
readValue
(
rootDataNode
,
new
TypeReference
<
List
<
AsNode
>>()
{});
// map content of single root 'data' node
AsNode
targetNode
=
findNode
(
dataNodesList
,
componentID
);
AsNode
targetNode
=
findNode
(
dataNodesList
,
componentID
);
if
(
targetNode
==
null
)
{
if
(
targetNode
==
null
)
{
throw
new
NameNotFound
Exception
(
"GMP: Node with specified ID is not found in passed JSON"
);
throw
new
Exception
(
"GMP: Node with specified ID is not found in passed JSON"
);
}
else
{
}
else
{
switch
(
fieldName
)
{
switch
(
fieldName
)
{
case
ID:
case
ID:
...
@@ -272,13 +303,12 @@ public class Main implements MessageListener {
...
@@ -272,13 +303,12 @@ public class Main implements MessageListener {
}
}
}
}
return
result
;
return
result
;
}
catch
(
NameNotFound
Exception
e
)
{
}
catch
(
Exception
e
)
{
throw
e
;
throw
e
;
}
}
}
}
/**
/**
* Route unlocking
* Route unlocking
*/
*/
...
@@ -287,43 +317,12 @@ public class Main implements MessageListener {
...
@@ -287,43 +317,12 @@ public class Main implements MessageListener {
String
address
=
"http://127.0.0.1:8080/Synergy"
;
String
address
=
"http://127.0.0.1:8080/Synergy"
;
String
signal
=
"got_agree"
;
String
signal
=
"got_agree"
;
URL
url
=
new
URL
(
address
+
"/rest/api/processes/signal?signal="
+
signal
+
"&executionID="
+
this
.
executionID
+
"¶m1=resolution&value1=signal_is_"
+
signal
);
URL
url
=
new
URL
(
address
+
"/rest/api/processes/signal?signal="
+
signal
+
"&executionID="
+
this
.
executionID
+
"¶m1=resolution&value1=signal_is_"
+
signal
);
synergyApiGet
(
url
);
synergyApiGet
String
(
url
);
}
catch
(
Exception
exc
)
{
}
catch
(
Exception
exc
)
{
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
}
}
}
}
private
static
JsonParser
synergyApiGet
(
final
URL
requestURL
)
{
String
login
=
"111111"
;
String
password
=
"1"
;
try
{
String
output
;
HttpURLConnection
conn
=
(
HttpURLConnection
)
requestURL
.
openConnection
();
conn
.
setRequestMethod
(
"GET"
);
conn
.
setRequestProperty
(
"Accept"
,
"application/json; charset=utf-8"
);
String
encoded
=
Base64
.
encode
((
login
+
":"
+
password
).
getBytes
());
conn
.
setRequestProperty
(
"Authorization"
,
"Basic "
+
encoded
);
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
((
conn
.
getInputStream
())));
StringBuilder
result
=
new
StringBuilder
();
while
((
output
=
br
.
readLine
())
!=
null
)
{
result
.
append
(
output
);
}
conn
.
disconnect
();
JsonFactory
factory
=
new
JsonFactory
();
return
factory
.
createParser
(
result
.
toString
());
}
catch
(
Exception
exc
)
{
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
}
return
null
;
}
private
static
String
synergyApiGetString
(
final
URL
requestURL
)
{
private
static
String
synergyApiGetString
(
final
URL
requestURL
)
{
String
login
=
"111111"
;
String
login
=
"111111"
;
String
password
=
"1"
;
String
password
=
"1"
;
...
...
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