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
cb7319e8
Commit
cb7319e8
authored
Jan 30, 2017
by
Mikhail Gashenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
JsonNode: (draft10) successful table row add!
parent
86664330
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
117 additions
and
37 deletions
+117
-37
Main.java
src/main/java/kz/arta/synergy/astdev/custom_bp/Main.java
+117
-37
No files found.
src/main/java/kz/arta/synergy/astdev/custom_bp/Main.java
View file @
cb7319e8
...
@@ -47,10 +47,10 @@ public class Main implements MessageListener {
...
@@ -47,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
Field
Type
{
private
static
enum
Object
Type
{
DATE
,
TEXTBOX
,
USER
DATE
,
TEXTBOX
,
USER
}
}
private
static
enum
Object
Type
{
private
static
enum
Field
Type
{
ID
,
TYPE
,
LABEL
,
KEY
,
VALUE
ID
,
TYPE
,
LABEL
,
KEY
,
VALUE
}
}
...
@@ -124,7 +124,7 @@ public class Main implements MessageListener {
...
@@ -124,7 +124,7 @@ 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"
,
Object
Type
.
KEY
);
String
userID
=
getComponentValueByID
(
this
.
sourceFormData
,
"user1"
,
Field
Type
.
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
...
@@ -152,25 +152,37 @@ public class Main implements MessageListener {
...
@@ -152,25 +152,37 @@ 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"
,
ObjectType
.
KEY
);
String
b2b1
=
getComponentValueByID
(
this
.
sourceFormData
,
"b2-b1-b1"
,
FieldType
.
KEY
);
String
b4b1
=
getComponentValueByID
(
this
.
sourceFormData
,
"b4-b1-b1"
,
ObjectType
.
KEY
);
String
b4b1
=
getComponentValueByID
(
this
.
sourceFormData
,
"b4-b1-b1"
,
FieldType
.
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
==
null
||
b4b1
==
null
)
{
// отображается key
throw
new
Exception
(
"Source date fields is empty"
);
}
else
{
constructNewTableRow
(
b2b1
,
b4b1
);
updateTargetForm
();
updateTargetForm
();
}
}
// boolean key_b2b1 = false, key_b4b1 = false, val_b2b1 = false, val_b4b1 = false;
// if (!b2b1.isEmpty() && !b4b1.isEmpty()) { // do not update with empty values
// key_b2b1 = updateFieldValue(this.targetFormData, "start-b1", FieldType.KEY, b2b1);
// key_b4b1 = updateFieldValue(this.targetFormData, "finish-b1", FieldType.KEY, b4b1);
// val_b2b1 = updateFieldValue(this.targetFormData, "start-b1", FieldType.VALUE, dateValueFromKey(b2b1));
// val_b4b1 = updateFieldValue(this.targetFormData, "finish-b1", FieldType.VALUE, dateValueFromKey(b4b1));
// }
//
// if (key_b2b1 && key_b4b1 && val_b2b1 && val_b4b1) {
// updateTargetForm();
// }
// Second table
// Second table
// String t4b1 = getComponentValueByID(sourceFormData, "t2-b1",
Field
Type.DATE);
// String t4b1 = getComponentValueByID(sourceFormData, "t2-b1",
Object
Type.DATE);
// String t6b1 = getComponentValueByID(sourceFormData, "b6-b1",
Field
Type.DATE);
// String t6b1 = getComponentValueByID(sourceFormData, "b6-b1",
Object
Type.DATE);
// String t10b1 = getComponentValueByID(sourceFormData, "t10-b1",
Field
Type.DATE);
// String t10b1 = getComponentValueByID(sourceFormData, "t10-b1",
Object
Type.DATE);
// String t12b1 = getComponentValueByID(sourceFormData, "t12-b1",
Field
Type.DATE);
// String t12b1 = getComponentValueByID(sourceFormData, "t12-b1",
Object
Type.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);
...
@@ -192,6 +204,75 @@ public class Main implements MessageListener {
...
@@ -192,6 +204,75 @@ public class Main implements MessageListener {
}
}
}
}
private
void
constructNewTableRow
(
String
b2b1
,
String
b4b1
)
throws
Exception
{
AsNode
tableNode
=
findNode
(
targetFormData
,
"table"
);
if
(
tableNode
!=
null
)
{
List
<
AsNode
>
tableDataNodesList
=
tableNode
.
getData
();
String
tablesCounter
=
Integer
.
toString
(
appendabeTableRowsCount
(
tableDataNodesList
,
"start"
,
"b"
)
+
1
);
AsNode
n1
=
new
AsNode
();
AsNode
n2
=
new
AsNode
();
AsNode
n3
=
new
AsNode
();
AsNode
n4
=
new
AsNode
();
AsNode
n5
=
new
AsNode
();
AsNode
n6
=
new
AsNode
();
AsNode
n7
=
new
AsNode
();
n1
.
setId
(
"start-b"
+
tablesCounter
);
n1
.
setType
(
"date"
);
n1
.
setLabel
(
" "
);
n1
.
setValue
(
dateValueFromKey
(
b2b1
));
n1
.
setKey
(
b2b1
);
n2
.
setId
(
"finish-b"
+
tablesCounter
);
n2
.
setType
(
"date"
);
n2
.
setLabel
(
" "
);
n2
.
setValue
(
dateValueFromKey
(
b4b1
));
n2
.
setKey
(
b4b1
);
n3
.
setId
(
"days-b"
+
tablesCounter
);
n3
.
setType
(
"textbox"
);
n3
.
setLabel
(
" "
);
n4
.
setId
(
"matpom-b"
+
tablesCounter
);
n4
.
setType
(
"listbox"
);
n4
.
setValue
(
""
);
n4
.
setKey
(
"1"
);
n5
.
setId
(
"period_start-b"
+
tablesCounter
);
n5
.
setType
(
"date"
);
n6
.
setId
(
"period_finish-b"
+
tablesCounter
);
n6
.
setType
(
"date"
);
n7
.
setId
(
"otozvano-b"
+
tablesCounter
);
n7
.
setType
(
"texbox"
);
n7
.
setLabel
(
" "
);
tableDataNodesList
.
add
(
n1
);
tableDataNodesList
.
add
(
n2
);
tableDataNodesList
.
add
(
n3
);
tableDataNodesList
.
add
(
n4
);
tableDataNodesList
.
add
(
n5
);
tableDataNodesList
.
add
(
n6
);
tableDataNodesList
.
add
(
n7
);
}
}
private
int
appendabeTableRowsCount
(
List
<
AsNode
>
lan
,
String
tableID
,
String
tableElementID
)
{
int
counter
=
0
;
for
(;;)
{
String
searchString
=
tableID
+
"-"
+
tableElementID
+
Integer
.
toString
(
counter
+
1
);
AsNode
n
=
findNode
(
lan
,
searchString
);
if
(
n
==
null
)
{
break
;
}
else
{
counter
++;
}
}
return
counter
;
}
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
);
...
@@ -205,26 +286,26 @@ public class Main implements MessageListener {
...
@@ -205,26 +286,26 @@ public class Main implements MessageListener {
/**
/**
* Returns node which has specifies ID
* Returns node which has specifies ID
* @param nodesList - List of nodes
* @param nodesList - List of nodes
* @param
componen
tID - Component ID
* @param
objec
tID - Component ID
* @return AsNode if such exists, null otherwise
* @return AsNode if such exists, null otherwise
*/
*/
private
static
AsNode
findNode
(
List
<
AsNode
>
nodesList
,
String
componen
tID
)
{
private
static
AsNode
findNode
(
List
<
AsNode
>
nodesList
,
String
objec
tID
)
{
AsNode
result
=
null
;
AsNode
result
=
null
;
for
(
AsNode
n
:
nodesList
)
{
for
(
AsNode
n
:
nodesList
)
{
if
(
result
!=
null
)
break
;
// prevent relooping if result has already been found
if
(
result
!=
null
)
break
;
// prevent relooping if result has already been found
if
(
componen
tID
.
equals
(
n
.
getId
()))
{
if
(
objec
tID
.
equals
(
n
.
getId
()))
{
result
=
n
;
result
=
n
;
}
else
if
(
n
.
getData
()
!=
null
)
{
}
else
if
(
n
.
getData
()
!=
null
)
{
result
=
findNode
(
n
.
getData
(),
componen
tID
);
result
=
findNode
(
n
.
getData
(),
objec
tID
);
}
}
}
}
return
result
;
return
result
;
}
}
private
static
String
dat
a
ValueFromKey
(
String
keyValue
)
throws
ParseException
{
private
static
String
dat
e
ValueFromKey
(
String
keyValue
)
throws
ParseException
{
Date
date
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
parse
(
keyValue
);
Date
date
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
parse
(
keyValue
);
return
new
SimpleDateFormat
(
"dd.MM.yyy"
).
format
(
date
);
return
new
SimpleDateFormat
(
"dd.MM.yyy"
).
format
(
date
);
...
@@ -233,21 +314,19 @@ public class Main implements MessageListener {
...
@@ -233,21 +314,19 @@ public class Main implements MessageListener {
/**
/**
* 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
* @param
componen
tID
* @param
objec
tID
* @param field
Nam
e
* @param field
Typ
e
* @param newFieldValue
* @param newFieldValue
* @throws AttributeModificationException
* @throws AttributeModificationException
* @throws IOException
* @throws IOException
*/
*/
private
void
updateFieldValue
(
List
<
AsNode
>
dataNodesList
,
String
componentID
,
ObjectType
fieldName
,
String
newFieldValue
)
throws
AttributeModificationException
,
IOException
{
private
boolean
updateFieldValue
(
List
<
AsNode
>
dataNodesList
,
String
objectID
,
FieldType
fieldType
,
String
newFieldValue
)
{
try
{
try
{
AsNode
targetNode
=
findNode
(
dataNodesList
,
objectID
);
AsNode
targetNode
=
findNode
(
dataNodesList
,
componentID
);
if
(
targetNode
==
null
)
{
if
(
targetNode
==
null
)
{
throw
new
AttributeModificationException
(
"GMP: Node with specified ID is not found in passed JSON"
)
;
return
false
;
}
else
{
}
else
{
switch
(
field
Nam
e
)
{
switch
(
field
Typ
e
)
{
case
ID:
case
ID:
targetNode
.
setId
(
newFieldValue
);
targetNode
.
setId
(
newFieldValue
);
break
;
break
;
...
@@ -265,7 +344,8 @@ public class Main implements MessageListener {
...
@@ -265,7 +344,8 @@ public class Main implements MessageListener {
break
;
break
;
}
}
}
}
}
catch
(
AttributeModificationException
e
)
{
return
true
;
}
catch
(
Exception
e
)
{
throw
e
;
throw
e
;
}
}
}
}
...
@@ -298,21 +378,21 @@ public class Main implements MessageListener {
...
@@ -298,21 +378,21 @@ public class Main implements MessageListener {
/**
/**
* Returns value of of specified field of component with specified ID
* Returns value of of specified field of component with specified ID
* @param targetJsonAsString
* @param targetJsonAsString
* @param
componen
tID
* @param
objec
tID
* @param field
Nam
e
* @param field
Typ
e
* @return
* @return
* @throws NameNotFoundException
* @throws NameNotFoundException
* @throws IOException
* @throws IOException
*/
*/
private
static
String
getComponentValueByID
(
List
<
AsNode
>
dataNodesList
,
String
componentID
,
ObjectType
fieldNam
e
)
throws
Exception
{
private
static
String
getComponentValueByID
(
List
<
AsNode
>
dataNodesList
,
String
objectID
,
FieldType
fieldTyp
e
)
throws
Exception
{
String
result
=
null
;
String
result
=
null
;
try
{
try
{
AsNode
targetNode
=
findNode
(
dataNodesList
,
componen
tID
);
AsNode
targetNode
=
findNode
(
dataNodesList
,
objec
tID
);
if
(
targetNode
==
null
)
{
if
(
targetNode
==
null
)
{
throw
new
Exception
(
"GMP: Node with specified ID is not found in passed JSON"
)
;
return
null
;
}
else
{
}
else
{
switch
(
field
Nam
e
)
{
switch
(
field
Typ
e
)
{
case
ID:
case
ID:
result
=
targetNode
.
getId
();
// may be for cheking if component with such ID exists at all
result
=
targetNode
.
getId
();
// may be for cheking if component with such ID exists at all
break
;
break
;
...
...
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