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
a91e1e7d
Commit
a91e1e7d
authored
Jan 28, 2017
by
Mikhail Gashenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
JsonNode: (draft4) new node value search and update with ObjectMapper
parent
f58d6c80
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
549 additions
and
472 deletions
+549
-472
.gitignore
.gitignore
+2
-0
pom.xml
pom.xml
+113
-107
AsNode.java
src/main/java/kz/arta/synergy/astdev/custom_bp/AsNode.java
+77
-0
Main.java
src/main/java/kz/arta/synergy/astdev/custom_bp/Main.java
+357
-365
No files found.
.gitignore
0 → 100644
View file @
a91e1e7d
/target/
\ No newline at end of file
pom.xml
View file @
a91e1e7d
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
kz.arta.synergy.astdev
</groupId>
<groupId>
kz.arta.synergy.astdev
</groupId>
<artifactId>
custom_bp
</artifactId>
<artifactId>
custom_bp
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<version>
1.0-SNAPSHOT
</version>
<packaging>
war
</packaging>
<packaging>
war
</packaging>
<name>
custom_bp
</name>
<name>
custom_bp
</name>
<properties>
<properties>
<endorsed.dir>
${project.build.directory}/endorsed
</endorsed.dir>
<endorsed.dir>
${project.build.directory}/endorsed
</endorsed.dir>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
</properties>
</properties>
<dependencies>
<dependencies>
<dependency>
<dependency>
<groupId>
org.slf4j
</groupId>
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-api
</artifactId>
<artifactId>
slf4j-api
</artifactId>
<version>
1.5.6
</version>
<version>
1.5.6
</version>
<type>
jar
</type>
<type>
jar
</type>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
com.fasterxml.jackson.core
</groupId>
<groupId>
com.fasterxml.jackson.core
</groupId>
<artifactId>
jackson-core
</artifactId>
<artifactId>
jackson-core
</artifactId>
<version>
2.8.5
</version>
<version>
2.8.5
</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
javax.jms
</groupId>
<groupId>
javax.jms
</groupId>
<artifactId>
jms-api
</artifactId>
<artifactId>
jms-api
</artifactId>
<version>
1.1-rev-1
</version>
<version>
1.1-rev-1
</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.codehaus.jackson
</groupId>
<groupId>
org.codehaus.jackson
</groupId>
<artifactId>
jackson-mapper-asl
</artifactId>
<artifactId>
jackson-mapper-asl
</artifactId>
<version>
1.9.10
</version>
<version>
1.9.10
</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
javax
</groupId>
<groupId>
org.codehaus.jackson
</groupId>
<artifactId>
javaee-web-api
</artifactId>
<artifactId>
jackson-core-asl
</artifactId>
<version>
6.0
</version>
<version>
1.9.13
</version>
<scope>
provided
</scope>
<type>
jar
</type>
</dependency>
</dependency>
</dependencies>
<dependency>
<groupId>
javax
</groupId>
<build>
<artifactId>
javaee-web-api
</artifactId>
<plugins>
<version>
6.0
</version>
<plugin>
<scope>
provided
</scope>
<groupId>
org.apache.maven.plugins
</groupId>
</dependency>
<artifactId>
maven-compiler-plugin
</artifactId>
</dependencies>
<version>
2.3.2
</version>
<configuration>
<build>
<source>
1.7
</source>
<plugins>
<target>
1.7
</target>
<plugin>
<compilerArguments>
<groupId>
org.apache.maven.plugins
</groupId>
<endorseddirs>
${endorsed.dir}
</endorseddirs>
<artifactId>
maven-compiler-plugin
</artifactId>
</compilerArguments>
<version>
2.3.2
</version>
</configuration>
<configuration>
</plugin>
<source>
1.7
</source>
<plugin>
<target>
1.7
</target>
<groupId>
org.apache.maven.plugins
</groupId>
<compilerArguments>
<artifactId>
maven-war-plugin
</artifactId>
<endorseddirs>
${endorsed.dir}
</endorseddirs>
<version>
2.1.1
</version>
</compilerArguments>
<configuration>
</configuration>
<failOnMissingWebXml>
false
</failOnMissingWebXml>
</plugin>
</configuration>
<plugin>
</plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<plugin>
<artifactId>
maven-war-plugin
</artifactId>
<groupId>
org.apache.maven.plugins
</groupId>
<version>
2.1.1
</version>
<artifactId>
maven-dependency-plugin
</artifactId>
<configuration>
<version>
2.1
</version>
<failOnMissingWebXml>
false
</failOnMissingWebXml>
<executions>
</configuration>
<execution>
</plugin>
<phase>
validate
</phase>
<plugin>
<goals>
<groupId>
org.apache.maven.plugins
</groupId>
<goal>
copy
</goal>
<artifactId>
maven-dependency-plugin
</artifactId>
</goals>
<version>
2.1
</version>
<configuration>
<executions>
<outputDirectory>
${endorsed.dir}
</outputDirectory>
<execution>
<silent>
true
</silent>
<phase>
validate
</phase>
<artifactItems>
<goals>
<artifactItem>
<goal>
copy
</goal>
<groupId>
javax
</groupId>
</goals>
<artifactId>
javaee-endorsed-api
</artifactId>
<configuration>
<version>
6.0
</version>
<outputDirectory>
${endorsed.dir}
</outputDirectory>
<type>
jar
</type>
<silent>
true
</silent>
</artifactItem>
<artifactItems>
</artifactItems>
<artifactItem>
</configuration>
<groupId>
javax
</groupId>
</execution>
<artifactId>
javaee-endorsed-api
</artifactId>
</executions>
<version>
6.0
</version>
</plugin>
<type>
jar
</type>
</plugins>
</artifactItem>
</build>
</artifactItems>
<reporting>
</configuration>
<plugins>
</execution>
<plugin>
</executions>
<groupId>
org.apache.maven.plugins
</groupId>
</plugin>
<artifactId>
maven-checkstyle-plugin
</artifactId>
</plugins>
<configuration>
</build>
<configLocation>
config/sun_checks.xml
</configLocation>
<reporting>
</configuration>
<plugins>
</plugin>
<plugin>
</plugins>
<groupId>
org.apache.maven.plugins
</groupId>
</reporting>
<artifactId>
maven-checkstyle-plugin
</artifactId>
</project>
<configuration>
<configLocation>
config/sun_checks.xml
</configLocation>
</configuration>
</plugin>
</plugins>
</reporting>
</project>
src/main/java/kz/arta/synergy/astdev/custom_bp/AsNode.java
0 → 100644
View file @
a91e1e7d
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package
kz
.
arta
.
synergy
.
astdev
.
custom_bp
;
import
java.util.List
;
import
org.codehaus.jackson.annotate.JsonProperty
;
/**
*
* @author drpsy
*/
public
class
AsNode
{
@JsonProperty
(
"id"
)
private
String
id
;
@JsonProperty
(
"type"
)
private
String
type
;
@JsonProperty
(
"label"
)
private
String
label
;
@JsonProperty
(
"key"
)
private
String
key
;
@JsonProperty
(
"value"
)
private
String
value
;
@JsonProperty
(
"data"
)
private
List
<
AsNode
>
data
;
public
String
getId
()
{
return
id
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
public
String
getType
()
{
return
type
;
}
public
void
setType
(
String
type
)
{
this
.
type
=
type
;
}
public
String
getLabel
()
{
return
label
;
}
public
void
setLabel
(
String
label
)
{
this
.
label
=
label
;
}
public
String
getKey
()
{
return
key
;
}
public
void
setKey
(
String
key
)
{
this
.
key
=
key
;
}
public
String
getValue
()
{
return
value
;
}
public
void
setValue
(
String
value
)
{
this
.
value
=
value
;
}
public
List
<
AsNode
>
getData
()
{
return
data
;
}
public
void
setData
(
List
<
AsNode
>
data
)
{
this
.
data
=
data
;
}
}
src/main/java/kz/arta/synergy/astdev/custom_bp/Main.java
View file @
a91e1e7d
/*
package
kz
.
arta
.
synergy
.
astdev
.
custom_bp
;
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
import
com.sun.org.apache.xerces.internal.impl.dv.util.Base64
;
* and open the template in the editor.
import
com.fasterxml.jackson.core.JsonFactory
;
*/
import
com.fasterxml.jackson.core.JsonParser
;
package
kz
.
arta
.
synergy
.
astdev
.
custom_bp
;
import
com.fasterxml.jackson.core.JsonToken
;
import
org.codehaus.jackson.JsonNode
;
import
com.sun.org.apache.xerces.internal.impl.dv.util.Base64
;
import
com.fasterxml.jackson.core.JsonFactory
;
import
org.slf4j.Logger
;
import
com.fasterxml.jackson.core.JsonParser
;
import
org.slf4j.LoggerFactory
;
import
com.fasterxml.jackson.core.JsonToken
;
import
org.codehaus.jackson.JsonNode
;
import
javax.jms.Message
;
import
javax.jms.MessageListener
;
import
org.slf4j.Logger
;
import
javax.jms.TextMessage
;
import
org.slf4j.LoggerFactory
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
javax.jms.Message
;
import
java.io.InputStreamReader
;
import
javax.jms.MessageListener
;
import
java.net.HttpURLConnection
;
import
javax.jms.TextMessage
;
import
java.net.URL
;
import
java.io.BufferedReader
;
import
java.util.Iterator
;
import
java.io.InputStreamReader
;
import
java.util.List
;
import
java.net.HttpURLConnection
;
import
javax.ejb.ActivationConfigProperty
;
import
java.net.URL
;
import
javax.ejb.MessageDriven
;
import
java.util.Iterator
;
import
javax.naming.NameNotFoundException
;
import
java.util.List
;
import
javax.naming.directory.AttributeModificationException
;
import
javax.ejb.ActivationConfigProperty
;
import
javax.naming.directory.InvalidAttributesException
;
import
javax.ejb.MessageDriven
;
import
org.codehaus.jackson.map.ObjectMapper
;
import
javax.naming.directory.InvalidAttributesException
;
import
org.codehaus.jackson.node.ArrayNode
;
import
org.codehaus.jackson.map.ObjectMapper
;
import
org.codehaus.jackson.node.ObjectNode
;
import
org.codehaus.jackson.node.ArrayNode
;
import
org.codehaus.jackson.type.TypeReference
;
import
org.codehaus.jackson.node.ObjectNode
;
import
org.codehaus.jackson.type.TypeReference
;
@MessageDriven
(
name
=
"CustomBP"
,
activationConfig
=
{
@ActivationConfigProperty
(
propertyName
=
"destinationType"
,
propertyValue
=
"javax.jms.Queue"
),
@MessageDriven
(
name
=
"CustomBP"
,
activationConfig
=
{
@ActivationConfigProperty
(
propertyName
=
"destination"
,
propertyValue
=
"java:jboss/queues/Integration/CustomBP"
),
@ActivationConfigProperty
(
propertyName
=
"destinationType"
,
propertyValue
=
"javax.jms.Queue"
),
@ActivationConfigProperty
(
propertyName
=
"reconnectAttempts"
,
propertyValue
=
"32"
),
@ActivationConfigProperty
(
propertyName
=
"destination"
,
propertyValue
=
"java:jboss/queues/Integration/CustomBP"
),
@ActivationConfigProperty
(
propertyName
=
"reconnectInterval"
,
propertyValue
=
"4000"
),
@ActivationConfigProperty
(
propertyName
=
"reconnectAttempts"
,
propertyValue
=
"32"
),
@ActivationConfigProperty
(
propertyName
=
"acknowledgeMode"
,
propertyValue
=
"Auto-acknowledge"
)})
@ActivationConfigProperty
(
propertyName
=
"reconnectInterval"
,
propertyValue
=
"4000"
),
@ActivationConfigProperty
(
propertyName
=
"acknowledgeMode"
,
propertyValue
=
"Auto-acknowledge"
)})
public
class
Main
implements
MessageListener
{
public
class
Main
implements
MessageListener
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
Main
.
class
);
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
Main
.
class
);
private
static
enum
fieldType
{
DATE
,
TEXTBOX
,
USER
private
static
enum
fieldType
{
}
DATE
,
TEXTBOX
,
USER
}
private
static
enum
fields
{
ID
,
TYPE
,
LABEL
,
KEY
,
VALUE
private
String
dataUUID
=
null
;
// идентификатор данных по форме записи реестра
}
private
String
executionID
=
null
;
// идентификатор блокирующего процесса
private
String
documentID
=
null
;
// идентификатор документа реестра
private
String
dataUUID
=
null
;
// идентификатор данных по форме записи реестра
private
String
executionID
=
null
;
// идентификатор блокирующего процесса
@Override
private
String
documentID
=
null
;
// идентификатор документа реестра
public
void
onMessage
(
Message
message
)
{
if
(!(
message
instanceof
TextMessage
))
{
@Override
return
;
public
void
onMessage
(
Message
message
)
{
}
if
(!(
message
instanceof
TextMessage
))
{
return
;
try
{
}
JsonFactory
factory
=
new
JsonFactory
();
JsonParser
parser
=
factory
.
createParser
(((
TextMessage
)
message
).
getText
());
try
{
JsonToken
token
=
null
;
JsonFactory
factory
=
new
JsonFactory
();
JsonParser
parser
=
factory
.
createParser
(((
TextMessage
)
message
).
getText
());
while
((
token
=
parser
.
nextToken
())
!=
null
)
{
JsonToken
token
=
null
;
if
(
token
==
JsonToken
.
FIELD_NAME
)
{
String
fieldName
=
parser
.
getText
();
while
((
token
=
parser
.
nextToken
())
!=
null
)
{
parser
.
nextToken
();
if
(
token
==
JsonToken
.
FIELD_NAME
)
{
String
value
=
parser
.
getText
();
String
fieldName
=
parser
.
getText
();
switch
(
fieldName
)
{
parser
.
nextToken
();
case
"dataUUID"
:
String
value
=
parser
.
getText
();
dataUUID
=
value
;
switch
(
fieldName
)
{
break
;
case
"dataUUID"
:
case
"executionID"
:
dataUUID
=
value
;
executionID
=
value
;
break
;
break
;
case
"executionID"
:
case
"documentID"
:
executionID
=
value
;
documentID
=
value
;
break
;
break
;
case
"documentID"
:
default
:
documentID
=
value
;
break
;
break
;
}
default
:
}
break
;
}
}
}
// Получение данных исходной формы (той, по которой запущен маршрут)
}
URL
sourceFormURL
=
new
URL
(
"http://127.0.0.1:8080/Synergy/rest/api/asforms/data/"
+
dataUUID
);
String
sourceFormData
=
synergyApiGetString
(
sourceFormURL
);
// Получение данных исходной формы (той, по которой запущен маршрут)
URL
sourceFormURL
=
new
URL
(
"http://127.0.0.1:8080/Synergy/rest/api/asforms/data/"
+
dataUUID
);
// Получение ID пользователя
String
sourceFormData
=
synergyApiGetString
(
sourceFormURL
);
String
userID
=
getComponentValueByID
(
sourceFormData
,
"user1"
,
fieldType
.
USER
);
// Получение ID пользователя
// По ID пользователя DataUUID целевой карточки
String
userID
=
getComponentValueByID
(
sourceFormData
,
"user1"
,
fields
.
KEY
);
String
userCardDataUUID
=
getCardDataUUID
(
userID
,
"04f7809d-f44c-4a2d-950d-6aa8e6c3fea1"
);
// Получение данных целевой карточки по dataUUID
// По ID пользователя DataUUID целевой карточки
URL
targetFormURL
=
new
URL
(
"http://127.0.0.1:8080/Synergy/rest/api/asforms/data/"
+
userCardDataUUID
);
String
userCardDataUUID
=
getCardDataUUID
(
userID
,
"04f7809d-f44c-4a2d-950d-6aa8e6c3fea1"
);
String
targetFormData
=
synergyApiGetString
(
targetFormURL
);
// Получение данных целевой карточки по dataUUID
URL
targetFormURL
=
new
URL
(
"http://127.0.0.1:8080/Synergy/rest/api/asforms/data/"
+
userCardDataUUID
);
// Получение значений текущих дат исходной формы
String
targetFormData
=
synergyApiGetString
(
targetFormURL
);
String
b5b1
;
// Получение значений текущих дат исходной формы
String
t2b1
;
String
b5b1
;
String
t8b1
;
String
t2b1
;
// String t18b1, t20b1, t16b1;
String
t8b1
;
// String t26b1, t24b1, t22b1;
// String t32b1, t30b1, t28b1;
// String t18b1, t20b1, t16b1;
// String t26b1, t24b1, t22b1;
// first table
// String t32b1, t30b1, t28b1;
String
b2b1
=
getComponentValueByID
(
sourceFormData
,
"b2-b1-b1"
,
fieldType
.
DATE
);
String
b4b1
=
getComponentValueByID
(
sourceFormData
,
"b4-b1-b1"
,
fieldType
.
DATE
);
// first table
String
b2b1
=
getComponentValueByID
(
sourceFormData
,
"b2-b1-b1"
,
fields
.
KEY
);
if
(!
b2b1
.
isEmpty
()
&&
!
b4b1
.
isEmpty
())
{
String
b4b1
=
getComponentValueByID
(
sourceFormData
,
"b4-b1-b1"
,
fields
.
KEY
);
setComponentValueByID
(
targetFormData
,
"start-b1"
,
"key"
,
b2b1
);
setComponentValueByID
(
targetFormData
,
"finish-b1"
,
"key"
,
b4b1
);
if
(!
b2b1
.
isEmpty
()
&&
!
b4b1
.
isEmpty
())
{
updateFieldValue
(
targetFormData
,
"start-b1"
,
fields
.
KEY
,
b2b1
);
unlockRoute
();
updateFieldValue
(
targetFormData
,
"finish-b1"
,
fields
.
KEY
,
b4b1
);
return
;
}
unlockRoute
();
return
;
// Second table
}
// String t4b1 = getComponentValueByID(sourceFormData, "t2-b1", fieldType.DATE);
// String t6b1 = getComponentValueByID(sourceFormData, "b6-b1", fieldType.DATE);
// Second table
// String t10b1 = getComponentValueByID(sourceFormData, "t10-b1", fieldType.DATE);
// String t4b1 = getComponentValueByID(sourceFormData, "t2-b1", fieldType.DATE);
// String t12b1 = getComponentValueByID(sourceFormData, "t12-b1", fieldType.DATE);
// String t6b1 = getComponentValueByID(sourceFormData, "b6-b1", fieldType.DATE);
//
// String t10b1 = getComponentValueByID(sourceFormData, "t10-b1", fieldType.DATE);
// if (!t4b1.isEmpty() && !t6b1.isEmpty() && !t10b1.isEmpty() && !t12b1.isEmpty()) {
// String t12b1 = getComponentValueByID(sourceFormData, "t12-b1", fieldType.DATE);
// setComponentValueByID(targetFormData, "start-b1", "key", b2b1);
//
// setComponentValueByID(targetFormData, "start-b1", "key", b2b1);
// if (!t4b1.isEmpty() && !t6b1.isEmpty() && !t10b1.isEmpty() && !t12b1.isEmpty()) {
// setComponentValueByID(targetFormData, "start-b1", "key", b2b1);
// setComponentValueByID(targetFormData, "start-b1", "key", b2b1);
// setComponentValueByID(targetFormData, "start-b1", "key", b2b1);
// setComponentValueByID(targetFormData, "start-b1", "key", b2b1);
//
// setComponentValueByID(targetFormData, "start-b1", "key", b2b1);
// unlockRoute();
// setComponentValueByID(targetFormData, "start-b1", "key", b2b1);
// return;
//
// }
// unlockRoute();
// return;
// Разблокировка маршрута
// }
unlockRoute
();
// Разблокировка маршрута
}
catch
(
Exception
exc
)
{
unlockRoute
();
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
}
}
catch
(
Exception
exc
)
{
}
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
}
private
void
setComponentValueByID
(
String
targetJsonAsString
,
String
componentID
,
String
fieldName
,
String
newFieldValue
)
throws
InvalidAttributesException
{
}
ObjectMapper
mapper
=
new
ObjectMapper
();
try
{
// NEW METHODS
JsonNode
rootNode
=
mapper
.
readTree
(
targetJsonAsString
);
/**
* Returns node which has specifies ID
// getting first level (root) 'data' node, there may be only two levels
* @param nodesList - List of nodes
ArrayNode
rootDN
=
(
ArrayNode
)
rootNode
.
get
(
"data"
);
* @param componentID - Component ID
Iterator
<
JsonNode
>
rootDNIterator
=
rootDN
.
getElements
();
// all objects of first 'data'
* @return AsNode if such exists, null otherwise
*/
// searching for field value in root 'data' node and setting new value if found
private
static
AsNode
findNode
(
List
<
AsNode
>
nodesList
,
String
componentID
)
{
JsonNode
node
=
searchInNode2
(
rootDNIterator
,
componentID
,
fieldName
);
AsNode
result
=
null
;
// setting node value
for
(
AsNode
n
:
nodesList
)
{
if
(
node
!=
null
)
{
if
(
componentID
.
equals
(
n
.
getId
()))
{
setValueInNode
(
node
,
componentID
,
newFieldValue
,
componentID
);
result
=
n
;
return
;
break
;
}
}
if
(!
n
.
getData
().
isEmpty
())
{
// root 'data' value does not contain the expected value, search in second (last possible) 'data'
findNode
(
n
.
getData
(),
componentID
);
Iterator
<
JsonNode
>
rootDNIterator2
=
rootDN
.
getElements
();
// all objects of first 'data'
}
while
(
rootDNIterator2
.
hasNext
())
{
}
ArrayNode
childNode
=
(
ArrayNode
)
rootDNIterator2
.
next
().
get
(
"data"
);
// get next 'data'
return
result
;
}
if
(
childNode
!=
null
)
{
Iterator
<
JsonNode
>
childDNIterator
=
childNode
.
getElements
();
private
void
updateFieldValue
(
String
targetJsonAsString
,
String
componentID
,
fields
fieldName
,
String
newFieldValue
)
throws
AttributeModificationException
,
IOException
{
node
=
searchInNode2
(
childDNIterator
,
componentID
,
fieldName
);
ObjectMapper
objectMapper
=
new
ObjectMapper
();
}
try
{
JsonNode
rootNode
=
objectMapper
.
readTree
(
targetJsonAsString
);
// read the whole tree
}
if
(
rootNode
.
isNull
())
{
throw
new
AttributeModificationException
(
"GMP: Passed data has no JSON content"
);
if
(
node
!=
null
)
{
}
setValueInNode
(
node
,
componentID
,
newFieldValue
,
componentID
);
JsonNode
rootDataNode
=
rootNode
.
get
(
"data"
);
// read single root 'data' node
}
else
{
if
(
rootDataNode
==
null
)
{
throw
new
InvalidAttributesException
(
"GMP: Target form field cannot be updated"
);
throw
new
AttributeModificationException
(
"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
}
catch
(
Exception
exc
)
{
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
AsNode
targetNode
=
findNode
(
dataNodesList
,
componentID
);
}
if
(
targetNode
==
null
)
{
}
throw
new
AttributeModificationException
(
"GMP: Node with specified ID is not found in passed JSON"
);
}
else
{
private
void
unlockRoute
()
{
switch
(
fieldName
)
{
try
{
case
ID:
String
address
=
"http://127.0.0.1:8080/Synergy"
;
targetNode
.
setId
(
newFieldValue
);
String
signal
=
"got_agree"
;
break
;
URL
url
=
new
URL
(
address
+
"/rest/api/processes/signal?signal="
+
signal
+
"&executionID="
+
this
.
executionID
+
"¶m1=resolution&value1=signal_is_"
+
signal
);
case
TYPE:
synergyApiGet
(
url
);
targetNode
.
setType
(
newFieldValue
);
}
catch
(
Exception
exc
)
{
break
;
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
case
LABEL:
}
targetNode
.
setLabel
(
newFieldValue
);
}
break
;
case
KEY:
// get user's card data uuid by formuuid
targetNode
.
setKey
(
newFieldValue
);
private
static
String
getCardDataUUID
(
String
userID
,
String
formUUID
)
{
break
;
ObjectMapper
mapper
=
new
ObjectMapper
();
case
VALUE:
try
{
targetNode
.
setValue
(
newFieldValue
);
URL
url
=
new
URL
(
"http://127.0.0.1:8080/Synergy/rest/api/personalrecord/forms/"
+
userID
);
break
;
String
res
=
synergyApiGetString
(
url
);
default
:
// TODO
break
;
List
<
Card
>
cardsList
=
mapper
.
readValue
(
res
,
new
TypeReference
<
List
<
Card
>>(){});
}
}
for
(
Card
c
:
cardsList
)
{
}
catch
(
AttributeModificationException
e
)
{
if
(
formUUID
.
equals
(
c
.
getFormUUID
()))
{
throw
e
;
return
c
.
getDataUUID
();
}
}
}
}
}
catch
(
Exception
exc
)
{
/**
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
* Returns user's card data UUID by form's UUID
}
* @param userID - User identifier
return
new
String
();
* @param formUUID - Forms' data UUID
}
* @return Specified user's card data UUID
*/
private
static
void
setValueInNode
(
JsonNode
node
,
String
componentID
,
String
newFieldValue
,
String
componentFieldName
)
throws
InvalidAttributesException
{
private
static
String
getCardDataUUID
(
String
userID
,
String
formUUID
)
{
if
(
node
==
null
)
{
ObjectMapper
mapper
=
new
ObjectMapper
();
throw
new
InvalidAttributesException
(
"JsonNode cannot be null"
);
try
{
}
URL
url
=
new
URL
(
"http://127.0.0.1:8080/Synergy/rest/api/personalrecord/forms/"
+
userID
);
String
res
=
synergyApiGetString
(
url
);
try
{
ObjectNode
objectNode
=
(
ObjectNode
)
node
;
List
<
Card
>
cardsList
=
mapper
.
readValue
(
res
,
new
TypeReference
<
List
<
Card
>>(){});
objectNode
.
put
(
componentFieldName
,
newFieldValue
);
}
catch
(
Exception
exc
)
{
for
(
Card
c
:
cardsList
)
{
throw
exc
;
if
(
formUUID
.
equals
(
c
.
getFormUUID
()))
{
}
return
c
.
getDataUUID
();
}
}
}
private
static
String
searchInNode
(
Iterator
<
JsonNode
>
iter
,
String
fieldName
,
fieldType
ft
)
{
}
catch
(
Exception
exc
)
{
String
result
=
new
String
();
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
// different form's component keeps data in different places
}
String
componentType
=
new
String
();
return
new
String
();
if
(
ft
==
fieldType
.
DATE
||
ft
==
fieldType
.
USER
)
{
}
componentType
=
"key"
;
}
else
if
(
ft
==
fieldType
.
TEXTBOX
)
{
private
static
String
getComponentValueByID
(
String
targetJsonAsString
,
String
componentID
,
fields
fieldName
)
throws
NameNotFoundException
,
IOException
{
componentType
=
"value"
;
// String b2b1 = getComponentValueByID(sourceFormData, "b2-b1-b1", fieldType.DATE);
}
ObjectMapper
objectMapper
=
new
ObjectMapper
();
String
result
=
null
;
while
(
iter
.
hasNext
())
{
// search data through content of child 'data' nodes
try
{
JsonNode
n
=
iter
.
next
();
JsonNode
rootNode
=
objectMapper
.
readTree
(
targetJsonAsString
);
// read the whole tree
if
(
rootNode
.
isNull
())
{
if
(
n
.
has
(
"id"
)
&&
n
.
has
(
componentType
))
{
throw
new
NameNotFoundException
(
"GMP: Passed data has no JSON content"
);
if
(
fieldName
.
equals
(
n
.
get
(
"id"
).
asText
()))
{
}
result
=
n
.
get
(
componentType
).
asText
();
JsonNode
rootDataNode
=
rootNode
.
get
(
"data"
);
// read single root 'data' node
}
if
(
rootDataNode
==
null
)
{
}
throw
new
NameNotFoundException
(
"GMP: Invalid form data, root \"data\" node does not exists"
);
}
}
return
result
;
List
<
AsNode
>
dataNodesList
=
objectMapper
.
readValue
(
rootDataNode
,
new
TypeReference
<
List
<
AsNode
>>()
{});
// map content of single root 'data' node
}
AsNode
targetNode
=
findNode
(
dataNodesList
,
componentID
);
private
static
JsonNode
searchInNode2
(
Iterator
<
JsonNode
>
iter
,
String
componentID
,
String
componentFieldName
)
{
if
(
targetNode
==
null
)
{
throw
new
NameNotFoundException
(
"GMP: Node with specified ID is not found in passed JSON"
);
while
(
iter
.
hasNext
())
{
}
else
{
// search data through content of child 'data' nodes
switch
(
fieldName
)
{
JsonNode
n
=
iter
.
next
();
case
ID:
result
=
targetNode
.
getId
();
// may be for cheking if component with such ID exists at all
if
(
n
.
has
(
"id"
)
&&
n
.
has
(
componentFieldName
))
{
break
;
if
(
componentID
.
equals
(
n
.
get
(
"id"
).
asText
()))
{
case
TYPE:
return
n
;
result
=
targetNode
.
getType
();
}
break
;
}
case
LABEL:
}
result
=
targetNode
.
getLabel
();
return
null
;
break
;
}
case
KEY:
result
=
targetNode
.
getKey
();
private
static
String
getComponentValueByID
(
String
formJson
,
String
fieldName
,
fieldType
ft
)
{
break
;
ObjectMapper
mapper
=
new
ObjectMapper
();
case
VALUE:
String
result
=
new
String
();
result
=
targetNode
.
getValue
();
break
;
try
{
}
JsonNode
rootNode
=
mapper
.
readTree
(
formJson
);
}
return
result
;
// getting first level (root) 'data' node, there may be only two levels
}
catch
(
NameNotFoundException
e
)
{
ArrayNode
rootDN
=
(
ArrayNode
)
rootNode
.
get
(
"data"
);
throw
e
;
Iterator
<
JsonNode
>
rootDNIterator
=
rootDN
.
getElements
();
}
// searching for field value in root 'data' node
}
result
=
searchInNode
(
rootDNIterator
,
fieldName
,
ft
);
if
(!
result
.
isEmpty
())
{
return
result
;
/**
}
* Route unlocking
*/
// root 'data' value does not contain the expected value, search in second (last possible) 'data'
private
void
unlockRoute
()
{
Iterator
<
JsonNode
>
rootDNIterator2
=
rootDN
.
getElements
();
// 'reset' iterator (create new one)
try
{
while
(
rootDNIterator2
.
hasNext
())
{
String
address
=
"http://127.0.0.1:8080/Synergy"
;
ArrayNode
childNode
=
(
ArrayNode
)
rootDNIterator2
.
next
().
get
(
"data"
);
String
signal
=
"got_agree"
;
Iterator
<
JsonNode
>
childDNIterator
=
childNode
.
getElements
();
URL
url
=
new
URL
(
address
+
"/rest/api/processes/signal?signal="
+
signal
+
"&executionID="
+
this
.
executionID
+
"¶m1=resolution&value1=signal_is_"
+
signal
);
synergyApiGet
(
url
);
result
=
searchInNode
(
childDNIterator
,
fieldName
,
ft
);
}
catch
(
Exception
exc
)
{
if
(!
result
.
isEmpty
())
{
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
return
result
;
}
}
}
}
return
result
;
private
static
JsonParser
synergyApiGet
(
final
URL
requestURL
)
{
}
catch
(
Exception
exc
)
{
String
login
=
"111111"
;
LOGGER
.
error
(
"GMP: Invalid form data"
);
String
password
=
"1"
;
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
}
try
{
return
result
;
String
output
;
}
HttpURLConnection
conn
=
(
HttpURLConnection
)
requestURL
.
openConnection
();
private
static
JsonParser
synergyApiGet
(
final
URL
requestURL
)
{
conn
.
setRequestMethod
(
"GET"
);
String
login
=
"Ипатьев"
;
conn
.
setRequestProperty
(
"Accept"
,
"application/json; charset=utf-8"
);
String
password
=
"1"
;
String
encoded
=
Base64
.
encode
((
login
+
":"
+
password
).
getBytes
());
try
{
conn
.
setRequestProperty
(
"Authorization"
,
"Basic "
+
encoded
);
String
output
;
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
((
conn
.
getInputStream
())));
HttpURLConnection
conn
=
(
HttpURLConnection
)
requestURL
.
openConnection
();
StringBuilder
result
=
new
StringBuilder
();
conn
.
setRequestMethod
(
"GET"
);
while
((
output
=
br
.
readLine
())
!=
null
)
{
conn
.
setRequestProperty
(
"Accept"
,
"application/json; charset=utf-8"
);
result
.
append
(
output
);
}
String
encoded
=
Base64
.
encode
((
login
+
":"
+
password
).
getBytes
());
conn
.
setRequestProperty
(
"Authorization"
,
"Basic "
+
encoded
);
conn
.
disconnect
();
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
((
conn
.
getInputStream
())));
JsonFactory
factory
=
new
JsonFactory
();
StringBuilder
result
=
new
StringBuilder
();
return
factory
.
createParser
(
result
.
toString
());
while
((
output
=
br
.
readLine
())
!=
null
)
{
}
catch
(
Exception
exc
)
{
result
.
append
(
output
);
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
}
}
conn
.
disconnect
();
return
null
;
}
JsonFactory
factory
=
new
JsonFactory
();
return
factory
.
createParser
(
result
.
toString
());
private
static
String
synergyApiGetString
(
final
URL
requestURL
)
{
}
catch
(
Exception
exc
)
{
String
login
=
"111111"
;
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
String
password
=
"1"
;
}
try
{
return
null
;
String
output
;
}
HttpURLConnection
conn
=
(
HttpURLConnection
)
requestURL
.
openConnection
();
private
static
String
synergyApiGetString
(
final
URL
requestURL
)
{
conn
.
setRequestMethod
(
"GET"
);
String
login
=
"Ипатьев"
;
conn
.
setRequestProperty
(
"Accept"
,
"application/json; charset=utf-8"
);
String
password
=
"1"
;
String
encoded
=
Base64
.
encode
((
login
+
":"
+
password
).
getBytes
());
try
{
conn
.
setRequestProperty
(
"Authorization"
,
"Basic "
+
encoded
);
String
output
;
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
((
conn
.
getInputStream
())));
HttpURLConnection
conn
=
(
HttpURLConnection
)
requestURL
.
openConnection
();
StringBuilder
result
=
new
StringBuilder
();
conn
.
setRequestMethod
(
"GET"
);
while
((
output
=
br
.
readLine
())
!=
null
)
{
conn
.
setRequestProperty
(
"Accept"
,
"application/json; charset=utf-8"
);
result
.
append
(
output
);
}
String
encoded
=
Base64
.
encode
((
login
+
":"
+
password
).
getBytes
());
conn
.
setRequestProperty
(
"Authorization"
,
"Basic "
+
encoded
);
conn
.
disconnect
();
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
((
conn
.
getInputStream
())));
JsonFactory
factory
=
new
JsonFactory
();
StringBuilder
result
=
new
StringBuilder
();
return
result
.
toString
();
while
((
output
=
br
.
readLine
())
!=
null
)
{
}
catch
(
Exception
exc
)
{
result
.
append
(
output
);
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
}
}
conn
.
disconnect
();
return
null
;
}
JsonFactory
factory
=
new
JsonFactory
();
}
return
result
.
toString
();
}
catch
(
Exception
exc
)
{
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
}
return
null
;
}
}
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