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
86664330
Commit
86664330
authored
Jan 29, 2017
by
Mikhail Gashenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
JsonNode: (draft10) successful update of existing values in table
parent
fdd8570f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
57 deletions
+60
-57
AsNode.java
src/main/java/kz/arta/synergy/astdev/custom_bp/AsNode.java
+25
-24
Main.java
src/main/java/kz/arta/synergy/astdev/custom_bp/Main.java
+35
-33
No files found.
src/main/java/kz/arta/synergy/astdev/custom_bp/AsNode.java
View file @
86664330
...
@@ -2,7 +2,7 @@ package kz.arta.synergy.astdev.custom_bp;
...
@@ -2,7 +2,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;
import
org.codehaus.jackson.node.ObjectNode
;
/**
/**
*
*
...
@@ -23,10 +23,10 @@ public class AsNode {
...
@@ -23,10 +23,10 @@ public class AsNode {
@JsonProperty
(
"data"
)
@JsonProperty
(
"data"
)
private
List
<
AsNode
>
data
;
private
List
<
AsNode
>
data
;
//
@JsonProperty("formatVersion")
@JsonProperty
(
"formatVersion"
)
//
private String formatVersion;
private
String
formatVersion
;
//
@JsonProperty("manualTags")
@JsonProperty
(
"manualTags"
)
//
private ObjectNode manualTags;
private
ObjectNode
manualTags
;
public
String
getId
()
{
public
String
getId
()
{
return
id
;
return
id
;
...
@@ -55,10 +55,10 @@ public class AsNode {
...
@@ -55,10 +55,10 @@ public class AsNode {
public
String
getKey
()
{
public
String
getKey
()
{
return
key
;
return
key
;
}
}
//
//
public void setKey(String key) {
public
void
setKey
(
String
key
)
{
//
this.key = key;
this
.
key
=
key
;
//
}
}
public
String
getValue
()
{
public
String
getValue
()
{
return
value
;
return
value
;
...
@@ -76,20 +76,20 @@ public class AsNode {
...
@@ -76,20 +76,20 @@ public class AsNode {
this
.
data
=
data
;
this
.
data
=
data
;
}
}
//
public String getFormatVersion() {
public
String
getFormatVersion
()
{
//
return formatVersion;
return
formatVersion
;
//
}
}
//
//
public void setFormatVersion(String formatVersion) {
public
void
setFormatVersion
(
String
formatVersion
)
{
//
this.formatVersion = formatVersion;
this
.
formatVersion
=
formatVersion
;
//
}
}
//
//
public ObjectNode getManualTags() {
public
ObjectNode
getManualTags
()
{
//
return manualTags;
return
manualTags
;
//
}
}
//
//
public void setManualTags(ObjectNode manualTags) {
public
void
setManualTags
(
ObjectNode
manualTags
)
{
//
this.manualTags = manualTags;
this
.
manualTags
=
manualTags
;
//
}
}
}
}
\ No newline at end of file
src/main/java/kz/arta/synergy/astdev/custom_bp/Main.java
View file @
86664330
...
@@ -16,6 +16,9 @@ import java.io.IOException;
...
@@ -16,6 +16,9 @@ import java.io.IOException;
import
java.io.InputStreamReader
;
import
java.io.InputStreamReader
;
import
java.net.HttpURLConnection
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.net.URL
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
javax.ejb.ActivationConfigProperty
;
import
javax.ejb.ActivationConfigProperty
;
import
javax.ejb.MessageDriven
;
import
javax.ejb.MessageDriven
;
...
@@ -44,10 +47,10 @@ public class Main implements MessageListener {
...
@@ -44,10 +47,10 @@ 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
final
ObjectMapper
OBJECT_MAPPER
=
new
ObjectMapper
();
private
static
final
ObjectMapper
OBJECT_MAPPER
=
new
ObjectMapper
();
private
static
enum
f
ieldType
{
private
static
enum
F
ieldType
{
DATE
,
TEXTBOX
,
USER
DATE
,
TEXTBOX
,
USER
}
}
private
static
enum
fields
{
private
static
enum
ObjectType
{
ID
,
TYPE
,
LABEL
,
KEY
,
VALUE
ID
,
TYPE
,
LABEL
,
KEY
,
VALUE
}
}
...
@@ -72,15 +75,16 @@ public class Main implements MessageListener {
...
@@ -72,15 +75,16 @@ public class Main implements MessageListener {
*/
*/
@Override
@Override
public
void
onMessage
(
Message
message
)
{
public
void
onMessage
(
Message
message
)
{
// <editor-fold defaultstate="collapsed" desc=" DESCRIPTION ">
if
(!(
message
instanceof
TextMessage
))
{
if
(!(
message
instanceof
TextMessage
))
{
return
;
return
;
}
}
try
{
try
{
JsonFactory
factory
=
new
JsonFactory
();
JsonFactory
factory
=
new
JsonFactory
();
JsonParser
parser
=
factory
.
createParser
(((
TextMessage
)
message
).
getText
());
JsonParser
parser
=
factory
.
createParser
(((
TextMessage
)
message
).
getText
());
JsonToken
token
=
null
;
JsonToken
token
=
null
;
while
((
token
=
parser
.
nextToken
())
!=
null
)
{
while
((
token
=
parser
.
nextToken
())
!=
null
)
{
if
(
token
==
JsonToken
.
FIELD_NAME
)
{
if
(
token
==
JsonToken
.
FIELD_NAME
)
{
String
fieldName
=
parser
.
getText
();
String
fieldName
=
parser
.
getText
();
...
@@ -102,17 +106,13 @@ public class Main implements MessageListener {
...
@@ -102,17 +106,13 @@ public class Main implements MessageListener {
}
}
}
}
// </editor-fold>
// Configure ObjectMapper
// Configure ObjectMapper
OBJECT_MAPPER
.
configure
(
DeserializationConfig
.
Feature
.
FAIL_ON_UNKNOWN_PROPERTIES
,
false
);
OBJECT_MAPPER
.
configure
(
DeserializationConfig
.
Feature
.
FAIL_ON_UNKNOWN_PROPERTIES
,
false
);
// SOURCE FORM: Получение данных исходной формы (той, по которой запущен маршрут)
// SOURCE FORM: Получение данных исходной формы (той, по которой запущен маршрут)
URL
sourceFormURL
=
new
URL
(
SYNERGY_ADDRESS
+
"/rest/api/asforms/data/"
+
SOURCE_FORM_DATA_UUID
);
URL
sourceFormURL
=
new
URL
(
SYNERGY_ADDRESS
+
"/rest/api/asforms/data/"
+
SOURCE_FORM_DATA_UUID
);
String
sourceFormDataAsString
=
synergyApiGetString
(
sourceFormURL
);
String
sourceFormDataAsString
=
synergyApiGetString
(
sourceFormURL
);
JsonNode
SourceRootNode
=
OBJECT_MAPPER
.
readTree
(
sourceFormDataAsString
);
// read the whole tree
JsonNode
SourceRootNode
=
OBJECT_MAPPER
.
readTree
(
sourceFormDataAsString
);
// read the whole tree
if
(
SourceRootNode
.
isNull
())
{
if
(
SourceRootNode
.
isNull
())
{
throw
new
AttributeModificationException
(
"GMP: Passed data has no JSON content"
);
throw
new
AttributeModificationException
(
"GMP: Passed data has no JSON content"
);
...
@@ -123,22 +123,14 @@ public class Main implements MessageListener {
...
@@ -123,22 +123,14 @@ public class Main implements MessageListener {
}
}
sourceFormData
=
OBJECT_MAPPER
.
readValue
(
SourceRootDataNode
,
new
TypeReference
<
List
<
AsNode
>>()
{});
// map content of single root 'data' node
sourceFormData
=
OBJECT_MAPPER
.
readValue
(
SourceRootDataNode
,
new
TypeReference
<
List
<
AsNode
>>()
{});
// map content of single root 'data' node
// TARGET FORM: Получение ID пользователя указанного в форме
// TARGET FORM: Получение ID пользователя указанного в форме
String
userID
=
getComponentValueByID
(
this
.
sourceFormData
,
"user1"
,
fields
.
KEY
);
String
userID
=
getComponentValueByID
(
this
.
sourceFormData
,
"user1"
,
ObjectType
.
KEY
);
// По ID пользователя указанного в карточке и ID формы получаем DataUUID целевой карточки (ID for work: "04f7809d-f44c-4a2d-950d-6aa8e6c3fea1")
// По ID пользователя указанного в карточке и ID формы получаем DataUUID целевой карточки (ID for work: "04f7809d-f44c-4a2d-950d-6aa8e6c3fea1")
TARGET_FORM_DATA_UUID
=
getCardDataUUID
(
userID
,
TARGET_FORM_UUID
);
TARGET_FORM_DATA_UUID
=
getCardDataUUID
(
userID
,
TARGET_FORM_UUID
);
// Получение данных целевой карточки по dataUUID
// Получение данных целевой карточки по dataUUID
URL
targetFormURL
=
new
URL
(
SYNERGY_ADDRESS
+
"/rest/api/asforms/data/"
+
TARGET_FORM_DATA_UUID
);
URL
targetFormURL
=
new
URL
(
SYNERGY_ADDRESS
+
"/rest/api/asforms/data/"
+
TARGET_FORM_DATA_UUID
);
String
targetFormDataAsString
=
synergyApiGetString
(
targetFormURL
);
String
targetFormDataAsString
=
synergyApiGetString
(
targetFormURL
);
JsonNode
TargetRootNode
=
OBJECT_MAPPER
.
readTree
(
targetFormDataAsString
);
JsonNode
TargetRootNode
=
OBJECT_MAPPER
.
readTree
(
targetFormDataAsString
);
if
(
TargetRootNode
.
isNull
())
{
if
(
TargetRootNode
.
isNull
())
{
throw
new
AttributeModificationException
(
"GMP: Passed data has no JSON content"
);
throw
new
AttributeModificationException
(
"GMP: Passed data has no JSON content"
);
...
@@ -160,21 +152,25 @@ public class Main implements MessageListener {
...
@@ -160,21 +152,25 @@ public class Main implements MessageListener {
// String t32b1, t30b1, t28b1;
// String t32b1, t30b1, t28b1;
// first table
// first table
String
b2b1
=
getComponentValueByID
(
this
.
sourceFormData
,
"b2-b1-b1"
,
fields
.
VALUE
);
String
b2b1
=
getComponentValueByID
(
this
.
sourceFormData
,
"b2-b1-b1"
,
ObjectType
.
KEY
);
String
b4b1
=
getComponentValueByID
(
this
.
sourceFormData
,
"b4-b1-b1"
,
fields
.
VALUE
);
String
b4b1
=
getComponentValueByID
(
this
.
sourceFormData
,
"b4-b1-b1"
,
ObjectType
.
KEY
);
if
(!
b2b1
.
isEmpty
()
&&
!
b4b1
.
isEmpty
())
{
// отображается key
updateFieldValue
(
this
.
targetFormData
,
"start-b1"
,
ObjectType
.
KEY
,
b2b1
);
updateFieldValue
(
this
.
targetFormData
,
"finish-b1"
,
ObjectType
.
KEY
,
b4b1
);
updateFieldValue
(
this
.
targetFormData
,
"start-b1"
,
ObjectType
.
VALUE
,
dataValueFromKey
(
b2b1
));
updateFieldValue
(
this
.
targetFormData
,
"finish-b1"
,
ObjectType
.
VALUE
,
dataValueFromKey
(
b4b1
));
if
(!
b2b1
.
isEmpty
()
&&
!
b4b1
.
isEmpty
())
{
updateFieldValue
(
this
.
targetFormData
,
"start-b1"
,
fields
.
VALUE
,
b2b1
);
updateFieldValue
(
this
.
targetFormData
,
"finish-b1"
,
fields
.
VALUE
,
b4b1
);
updateTargetForm
();
updateTargetForm
();
}
}
// Second table
// Second table
// String t4b1 = getComponentValueByID(sourceFormData, "t2-b1",
f
ieldType.DATE);
// String t4b1 = getComponentValueByID(sourceFormData, "t2-b1",
F
ieldType.DATE);
// String t6b1 = getComponentValueByID(sourceFormData, "b6-b1",
f
ieldType.DATE);
// String t6b1 = getComponentValueByID(sourceFormData, "b6-b1",
F
ieldType.DATE);
// String t10b1 = getComponentValueByID(sourceFormData, "t10-b1",
f
ieldType.DATE);
// String t10b1 = getComponentValueByID(sourceFormData, "t10-b1",
F
ieldType.DATE);
// String t12b1 = getComponentValueByID(sourceFormData, "t12-b1",
f
ieldType.DATE);
// String t12b1 = getComponentValueByID(sourceFormData, "t12-b1",
F
ieldType.DATE);
//
//
// if (!t4b1.isEmpty() && !t6b1.isEmpty() && !t10b1.isEmpty() && !t12b1.isEmpty()) {
// if (!t4b1.isEmpty() && !t6b1.isEmpty() && !t10b1.isEmpty() && !t12b1.isEmpty()) {
// setComponentValueByID(targetFormData, "start-b1", "key", b2b1);
// setComponentValueByID(targetFormData, "start-b1", "key", b2b1);
...
@@ -196,7 +192,6 @@ public class Main implements MessageListener {
...
@@ -196,7 +192,6 @@ public class Main implements MessageListener {
}
}
}
}
private
void
updateTargetForm
()
throws
IOException
,
Exception
{
private
void
updateTargetForm
()
throws
IOException
,
Exception
{
// SERIALIZATION
// SERIALIZATION
OBJECT_MAPPER
.
setSerializationInclusion
(
JsonSerialize
.
Inclusion
.
NON_NULL
);
OBJECT_MAPPER
.
setSerializationInclusion
(
JsonSerialize
.
Inclusion
.
NON_NULL
);
...
@@ -229,6 +224,12 @@ public class Main implements MessageListener {
...
@@ -229,6 +224,12 @@ public class Main implements MessageListener {
return
result
;
return
result
;
}
}
private
static
String
dataValueFromKey
(
String
keyValue
)
throws
ParseException
{
Date
date
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
parse
(
keyValue
);
return
new
SimpleDateFormat
(
"dd.MM.yyy"
).
format
(
date
);
}
/**
/**
* Setting new value of requested field of requested component with specified ID
* Setting new value of requested field of requested component with specified ID
* @param targetJsonAsString
* @param targetJsonAsString
...
@@ -238,7 +239,7 @@ public class Main implements MessageListener {
...
@@ -238,7 +239,7 @@ public class Main implements MessageListener {
* @throws AttributeModificationException
* @throws AttributeModificationException
* @throws IOException
* @throws IOException
*/
*/
private
void
updateFieldValue
(
List
<
AsNode
>
dataNodesList
,
String
componentID
,
fields
fieldName
,
String
newFieldValue
)
throws
AttributeModificationException
,
IOException
{
private
void
updateFieldValue
(
List
<
AsNode
>
dataNodesList
,
String
componentID
,
ObjectType
fieldName
,
String
newFieldValue
)
throws
AttributeModificationException
,
IOException
{
try
{
try
{
...
@@ -257,7 +258,8 @@ public class Main implements MessageListener {
...
@@ -257,7 +258,8 @@ public class Main implements MessageListener {
targetNode
.
setLabel
(
newFieldValue
);
targetNode
.
setLabel
(
newFieldValue
);
break
;
break
;
case
KEY:
case
KEY:
throw
new
AttributeModificationException
(
"GMP: Modification of \"key\" attribute is forbidden according to specification"
);
targetNode
.
setKey
(
newFieldValue
);
break
;
case
VALUE:
case
VALUE:
targetNode
.
setValue
(
newFieldValue
);
targetNode
.
setValue
(
newFieldValue
);
break
;
break
;
...
@@ -267,7 +269,7 @@ public class Main implements MessageListener {
...
@@ -267,7 +269,7 @@ public class Main implements MessageListener {
throw
e
;
throw
e
;
}
}
}
}
/**
/**
* Returns user's card data UUID by form's UUID
* Returns user's card data UUID by form's UUID
* @param userID - User identifier
* @param userID - User identifier
...
@@ -302,7 +304,7 @@ public class Main implements MessageListener {
...
@@ -302,7 +304,7 @@ public class Main implements MessageListener {
* @throws NameNotFoundException
* @throws NameNotFoundException
* @throws IOException
* @throws IOException
*/
*/
private
static
String
getComponentValueByID
(
List
<
AsNode
>
dataNodesList
,
String
componentID
,
fields
fieldName
)
throws
Exception
{
private
static
String
getComponentValueByID
(
List
<
AsNode
>
dataNodesList
,
String
componentID
,
ObjectType
fieldName
)
throws
Exception
{
String
result
=
null
;
String
result
=
null
;
try
{
try
{
...
...
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