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
191452a7
Commit
191452a7
authored
Jan 31, 2017
by
Mikhail Gashenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
JsonNode: working
parent
a9db2f2c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
63 deletions
+54
-63
Main.java
src/main/java/kz/arta/synergy/astdev/custom_bp/Main.java
+54
-63
No files found.
src/main/java/kz/arta/synergy/astdev/custom_bp/Main.java
View file @
191452a7
...
...
@@ -12,7 +12,7 @@ import javax.jms.Message;
import
javax.jms.MessageListener
;
import
javax.jms.TextMessage
;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
...
...
@@ -22,12 +22,12 @@ import java.text.ParseException;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.concurrent.TimeUnit
;
import
javax.ejb.ActivationConfigProperty
;
import
javax.ejb.MessageDriven
;
import
javax.naming.NameNotFoundException
;
import
javax.naming.directory.AttributeModificationException
;
import
javax.servlet.ServletContext
;
import
javax.xml.bind.DatatypeConverter
;
import
kz.arta.synergy.api.rest.sample.asforms.APIFormsServiceSave
;
import
org.codehaus.jackson.map.DeserializationConfig
;
...
...
@@ -51,20 +51,20 @@ public class Main implements MessageListener {
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
Main
.
class
);
private
static
final
ObjectMapper
OBJECT_MAPPER
=
new
ObjectMapper
();
private
static
enum
ObjectType
{
private
enum
ObjectType
{
DATE
,
TEXTBOX
,
USER
}
private
static
enum
FieldType
{
private
enum
FieldType
{
ID
,
TYPE
,
LABEL
,
KEY
,
VALUE
}
private
String
executionID
=
null
;
// идентификатор блокирующего процесса
private
String
documentID
=
null
;
// идентификатор документа реестра
private
static
final
String
LOGIN
=
"
Ипатьев"
;
private
static
final
String
LOGIN
=
"
111111"
;
private
static
final
String
PASSWORD
=
"1"
;
// private final String TARGET_FORM_UUID = "fb44d99d-1579-4ac3-884a-01a6d4f71f9c"; // home
private
final
String
TARGET_FORM_UUID
=
"04f7809d-f44c-4a2d-950d-6aa8e6c3fea1"
;
// work
private
final
String
TARGET_FORM_UUID
=
"fb44d99d-1579-4ac3-884a-01a6d4f71f9c"
;
// home
// private final String TARGET_FORM_UUID = "04f7809d-f44c-4a2d-950d-6aa8e6c3fea1"; // work
private
final
String
SYNERGY_ADDRESS
=
"http://127.0.0.1:8080/Synergy"
;
private
String
SOURCE_FORM_DATA_UUID
=
null
;
// идентификатор данных по форме записи реестра
private
String
TARGET_FORM_DATA_UUID
=
null
;
...
...
@@ -129,7 +129,7 @@ public class Main implements MessageListener {
sourceFormData
=
OBJECT_MAPPER
.
readValue
(
SourceRootDataNode
,
new
TypeReference
<
List
<
AsNode
>>()
{});
// map content of single root 'data' node
// TARGET FORM: Получение ID пользователя указанного в форме
String
userID
=
get
ComponentValueByID
(
this
.
sourceFormData
,
"user1"
,
FieldType
.
KEY
);
String
userID
=
get
ElemValByID
(
this
.
sourceFormData
,
"user1"
,
FieldType
.
KEY
);
if
(
userID
==
null
)
{
throw
new
Exception
(
"User in not specified in the order (value of \"user1\" field is not found)"
);
}
...
...
@@ -150,58 +150,57 @@ public class Main implements MessageListener {
targetFormData
=
OBJECT_MAPPER
.
readValue
(
TargetRootDataNode
,
new
TypeReference
<
List
<
AsNode
>>()
{});
// common vacation period
String
vacStart
=
getComponentValueByID
(
this
.
sourceFormData
,
"date_start"
,
FieldType
.
KEY
);
String
vacEnd
=
getComponentValueByID
(
this
.
sourceFormData
,
"date_finish"
,
FieldType
.
KEY
);
String
days
=
getComponentValueByID
(
this
.
sourceFormData
,
"days"
,
FieldType
.
VALUE
);
String
vacStart
=
getElemValByID
(
this
.
sourceFormData
,
"date_start"
,
FieldType
.
KEY
);
String
vacEnd
=
getElemValByID
(
this
.
sourceFormData
,
"date_finish"
,
FieldType
.
KEY
);
// String days = getComponentValueByID(this.sourceFormData, "days", FieldType.VALUE);
if
(
vacStart
==
null
||
vacEnd
==
null
)
{
throw
new
Exception
(
"Vacation period is not specified"
);
}
// first table - periods
String
b2b1
=
get
ComponentValueByID
(
this
.
sourceFormData
,
"b2-b1"
,
FieldType
.
KEY
);
String
b4b1
=
get
ComponentValueByID
(
this
.
sourceFormData
,
"b4-b1"
,
FieldType
.
KEY
);
String
b2b1
=
get
ElemValByID
(
this
.
sourceFormData
,
"b2-b1"
,
FieldType
.
KEY
);
String
b4b1
=
get
ElemValByID
(
this
.
sourceFormData
,
"b4-b1"
,
FieldType
.
KEY
);
// first table - num of days
String
b5b1
=
get
ComponentValueByID
(
this
.
sourceFormData
,
"b5-b1"
,
FieldType
.
VALUE
);
String
b5b1
=
get
ElemValByID
(
this
.
sourceFormData
,
"b5-b1"
,
FieldType
.
VALUE
);
if
(
notNull
(
b2b1
,
b4b1
))
{
// отображается key
constructNewTableRow
(
vacStart
,
vacEnd
,
b2b1
,
b4b1
,
b5b1
);
addTblRow
(
vacStart
,
vacEnd
,
b2b1
,
b4b1
,
b5b1
);
updateTargetForm
();
return
;
}
// second table - periods
String
t4b1
=
get
ComponentValueByID
(
this
.
sourceFormData
,
"t4-b1"
,
FieldType
.
KEY
);
String
t6b1
=
get
ComponentValueByID
(
this
.
sourceFormData
,
"t6-b1"
,
FieldType
.
KEY
);
String
t10b1
=
get
ComponentValueByID
(
this
.
sourceFormData
,
"t10-b1"
,
FieldType
.
KEY
);
String
t12b1
=
get
ComponentValueByID
(
this
.
sourceFormData
,
"t12-b1"
,
FieldType
.
KEY
);
String
t4b1
=
get
ElemValByID
(
this
.
sourceFormData
,
"t4-b1"
,
FieldType
.
KEY
);
String
t6b1
=
get
ElemValByID
(
this
.
sourceFormData
,
"t6-b1"
,
FieldType
.
KEY
);
String
t10b1
=
get
ElemValByID
(
this
.
sourceFormData
,
"t10-b1"
,
FieldType
.
KEY
);
String
t12b1
=
get
ElemValByID
(
this
.
sourceFormData
,
"t12-b1"
,
FieldType
.
KEY
);
// second table - num of days
String
t2b1
=
get
ComponentValueByID
(
this
.
sourceFormData
,
"t2-b1"
,
FieldType
.
VALUE
);
String
t8b1
=
get
ComponentValueByID
(
this
.
sourceFormData
,
"t8-b1"
,
FieldType
.
VALUE
);
String
t2b1
=
get
ElemValByID
(
this
.
sourceFormData
,
"t2-b1"
,
FieldType
.
VALUE
);
String
t8b1
=
get
ElemValByID
(
this
.
sourceFormData
,
"t8-b1"
,
FieldType
.
VALUE
);
if
(
notNull
(
t4b1
,
t6b1
,
t10b1
,
t12b1
))
{
constructNewTableRow
(
vacStart
,
vacEnd
,
t4b1
,
t6b1
,
t2b1
);
constructNewTableRow
(
vacStart
,
vacEnd
,
t10b1
,
t12b1
,
t8b1
);
addTblRow
(
vacStart
,
vacEnd
,
t4b1
,
t6b1
,
t2b1
);
addTblRow
(
vacStart
,
vacEnd
,
t10b1
,
t12b1
,
t8b1
);
updateTargetForm
();
return
;
}
// third table - periods
String
t18b1
=
get
ComponentValueByID
(
this
.
sourceFormData
,
"t18-b1"
,
FieldType
.
KEY
);
String
t20b1
=
get
ComponentValueByID
(
this
.
sourceFormData
,
"t20-b1"
,
FieldType
.
KEY
);
String
t24b1
=
get
ComponentValueByID
(
this
.
sourceFormData
,
"t24-b1"
,
FieldType
.
KEY
);
String
t26b1
=
get
ComponentValueByID
(
this
.
sourceFormData
,
"t26-b1"
,
FieldType
.
KEY
);
String
t30b1
=
get
ComponentValueByID
(
this
.
sourceFormData
,
"t30-b1"
,
FieldType
.
KEY
);
String
t32b1
=
get
ComponentValueByID
(
this
.
sourceFormData
,
"t32-b1"
,
FieldType
.
KEY
);
String
t18b1
=
get
ElemValByID
(
this
.
sourceFormData
,
"t18-b1"
,
FieldType
.
KEY
);
String
t20b1
=
get
ElemValByID
(
this
.
sourceFormData
,
"t20-b1"
,
FieldType
.
KEY
);
String
t24b1
=
get
ElemValByID
(
this
.
sourceFormData
,
"t24-b1"
,
FieldType
.
KEY
);
String
t26b1
=
get
ElemValByID
(
this
.
sourceFormData
,
"t26-b1"
,
FieldType
.
KEY
);
String
t30b1
=
get
ElemValByID
(
this
.
sourceFormData
,
"t30-b1"
,
FieldType
.
KEY
);
String
t32b1
=
get
ElemValByID
(
this
.
sourceFormData
,
"t32-b1"
,
FieldType
.
KEY
);
// third table - num of days
String
t16b1
=
get
ComponentValueByID
(
this
.
sourceFormData
,
"t16-b1"
,
FieldType
.
VALUE
);
String
t22b1
=
get
ComponentValueByID
(
this
.
sourceFormData
,
"t22-b1"
,
FieldType
.
VALUE
);
String
t28b1
=
get
ComponentValueByID
(
this
.
sourceFormData
,
"t28-b1"
,
FieldType
.
VALUE
);
String
t16b1
=
get
ElemValByID
(
this
.
sourceFormData
,
"t16-b1"
,
FieldType
.
VALUE
);
String
t22b1
=
get
ElemValByID
(
this
.
sourceFormData
,
"t22-b1"
,
FieldType
.
VALUE
);
String
t28b1
=
get
ElemValByID
(
this
.
sourceFormData
,
"t28-b1"
,
FieldType
.
VALUE
);
if
(
notNull
(
t18b1
,
t20b1
,
t24b1
,
t26b1
,
t30b1
,
t32b1
))
{
constructNewTableRow
(
vacStart
,
vacEnd
,
t18b1
,
t20b1
,
t16b1
);
constructNewTableRow
(
vacStart
,
vacEnd
,
t24b1
,
t26b1
,
t22b1
);
constructNewTableRow
(
vacStart
,
vacEnd
,
t30b1
,
t32b1
,
t28b1
);
addTblRow
(
vacStart
,
vacEnd
,
t18b1
,
t20b1
,
t16b1
);
addTblRow
(
vacStart
,
vacEnd
,
t24b1
,
t26b1
,
t22b1
);
addTblRow
(
vacStart
,
vacEnd
,
t30b1
,
t32b1
,
t28b1
);
updateTargetForm
();
return
;
}
...
...
@@ -213,12 +212,6 @@ public class Main implements MessageListener {
}
}
private
List
<
AsNode
>
constructTableHeader
()
throws
IOException
{
InputStream
inputStream
=
getClass
().
getClassLoader
().
getResourceAsStream
(
"table_header.json"
);
List
<
AsNode
>
l
=
OBJECT_MAPPER
.
readValue
(
inputStream
,
new
TypeReference
<
List
<
AsNode
>>()
{});
return
l
;
}
private
static
boolean
notNull
(
Object
...
args
)
{
for
(
Object
arg
:
args
)
{
if
(
arg
==
null
)
{
...
...
@@ -228,8 +221,14 @@ public class Main implements MessageListener {
return
true
;
}
private
void
constructNewTableRow
(
String
vacStart
,
String
vacEnd
,
String
perStart
,
String
perEnd
,
String
numDays
)
throws
Exception
{
private
void
addTblRow
(
String
vacStart
,
String
vacEnd
,
String
perStart
,
String
perEnd
,
String
numDays
)
throws
Exception
{
AsNode
tableNode
=
findNode
(
targetFormData
,
"table"
);
if
(
tableNode
==
null
)
{
addTableHeaders
();
}
tableNode
=
findNode
(
targetFormData
,
"table"
);
// update reference
if
(
tableNode
!=
null
)
{
List
<
AsNode
>
tableDataNodesList
=
tableNode
.
getData
();
String
tablesCounter
=
Integer
.
toString
(
appendabeTableRowsCount
(
tableDataNodesList
,
"start"
,
"b"
)
+
1
);
...
...
@@ -286,30 +285,22 @@ public class Main implements MessageListener {
tableDataNodesList
.
add
(
n6
);
tableDataNodesList
.
add
(
n7
);
}
else
{
// get root data node, it is our target
AsNode
rootDataNode
=
findNode
(
targetFormData
,
"data"
);
throw
new
Exception
(
"Failed to add new table, aborting"
);
}
}
private
void
addTableHeaders
()
throws
IOException
{
InputStream
inputStream
=
getClass
().
getClassLoader
().
getResourceAsStream
(
"table_header.json"
);
List
<
AsNode
>
headers
=
OBJECT_MAPPER
.
readValue
(
inputStream
,
new
TypeReference
<
List
<
AsNode
>>()
{});
// construct new "table" node
AsNode
newDataNode
=
new
AsNode
();
List
<
AsNode
>
header
=
constructTableHeader
();
// pushing fields to new node
newDataNode
.
setId
(
"table"
);
newDataNode
.
setType
(
"appendable_table"
);
newDataNode
.
setKey
(
""
);
newDataNode
.
setData
(
header
);
}
}
private
int
dateDiffToDays
(
String
dateLess
,
String
dateMore
)
throws
ParseException
{
Date
dateMore_
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
parse
(
dateMore
);
Date
dateLess_
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
parse
(
dateLess
);
long
diff
=
dateMore_
.
getTime
()
-
dateLess_
.
getTime
();
TimeUnit
.
DAYS
.
convert
(
diff
,
TimeUnit
.
MILLISECONDS
);
newDataNode
.
setData
(
headers
);
return
(
int
)
TimeUnit
.
DAYS
.
convert
(
diff
,
TimeUnit
.
MILLISECONDS
);
targetFormData
.
add
(
newDataNode
);
}
private
int
appendabeTableRowsCount
(
List
<
AsNode
>
lan
,
String
tableID
,
String
tableElementID
)
{
...
...
@@ -436,7 +427,7 @@ public class Main implements MessageListener {
* @throws NameNotFoundException
* @throws IOException
*/
private
static
String
get
ComponentValueByID
(
List
<
AsNode
>
dataNodesList
,
String
objectID
,
FieldType
fieldType
)
throws
Exception
{
private
static
String
get
ElemValByID
(
List
<
AsNode
>
dataNodesList
,
String
objectID
,
FieldType
fieldType
)
throws
Exception
{
String
result
=
null
;
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