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
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
504 additions
and
513 deletions
+504
-513
Main.java
src/main/java/kz/arta/synergy/astdev/custom_bp/Main.java
+504
-513
No files found.
src/main/java/kz/arta/synergy/astdev/custom_bp/Main.java
View file @
191452a7
package
kz
.
arta
.
synergy
.
astdev
.
custom_bp
;
package
kz
.
arta
.
synergy
.
astdev
.
custom_bp
;
import
com.fasterxml.jackson.core.JsonFactory
;
import
com.fasterxml.jackson.core.JsonFactory
;
import
com.fasterxml.jackson.core.JsonParser
;
import
com.fasterxml.jackson.core.JsonParser
;
import
com.fasterxml.jackson.core.JsonToken
;
import
com.fasterxml.jackson.core.JsonToken
;
import
org.codehaus.jackson.JsonNode
;
import
org.codehaus.jackson.JsonNode
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
javax.jms.Message
;
import
javax.jms.Message
;
import
javax.jms.MessageListener
;
import
javax.jms.MessageListener
;
import
javax.jms.TextMessage
;
import
javax.jms.TextMessage
;
import
java.io.BufferedReader
;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
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.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
java.util.concurrent.TimeUnit
;
import
javax.ejb.ActivationConfigProperty
;
import
javax.ejb.ActivationConfigProperty
;
import
javax.ejb.MessageDriven
;
import
javax.ejb.MessageDriven
;
import
javax.naming.NameNotFoundException
;
import
javax.naming.directory.AttributeModificationException
;
import
javax.naming.directory.AttributeModificationException
;
import
javax.servlet.ServletContext
;
import
javax.xml.bind.DatatypeConverter
;
import
javax.xml.bind.DatatypeConverter
;
import
kz.arta.synergy.api.rest.sample.asforms.APIFormsServiceSave
;
import
kz.arta.synergy.api.rest.sample.asforms.APIFormsServiceSave
;
import
org.codehaus.jackson.map.DeserializationConfig
;
import
org.codehaus.jackson.map.DeserializationConfig
;
import
org.codehaus.jackson.map.ObjectMapper
;
import
org.codehaus.jackson.map.ObjectMapper
;
import
org.codehaus.jackson.map.annotate.JsonSerialize
;
import
org.codehaus.jackson.map.annotate.JsonSerialize
;
import
org.codehaus.jackson.type.TypeReference
;
import
org.codehaus.jackson.type.TypeReference
;
/**
/**
*
*
* @author drpsy
* @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"
),
@ActivationConfigProperty
(
propertyName
=
"reconnectAttempts"
,
propertyValue
=
"32"
),
@ActivationConfigProperty
(
propertyName
=
"reconnectAttempts"
,
propertyValue
=
"32"
),
@ActivationConfigProperty
(
propertyName
=
"reconnectInterval"
,
propertyValue
=
"4000"
),
@ActivationConfigProperty
(
propertyName
=
"reconnectInterval"
,
propertyValue
=
"4000"
),
@ActivationConfigProperty
(
propertyName
=
"acknowledgeMode"
,
propertyValue
=
"Auto-acknowledge"
)})
@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
final
ObjectMapper
OBJECT_MAPPER
=
new
ObjectMapper
();
private
static
final
ObjectMapper
OBJECT_MAPPER
=
new
ObjectMapper
();
private
static
enum
ObjectType
{
private
enum
ObjectType
{
DATE
,
TEXTBOX
,
USER
DATE
,
TEXTBOX
,
USER
}
}
private
static
enum
FieldType
{
private
enum
FieldType
{
ID
,
TYPE
,
LABEL
,
KEY
,
VALUE
ID
,
TYPE
,
LABEL
,
KEY
,
VALUE
}
}
private
String
executionID
=
null
;
// идентификатор блокирующего процесса
private
String
executionID
=
null
;
// идентификатор блокирующего процесса
private
String
documentID
=
null
;
// идентификатор документа реестра
private
String
documentID
=
null
;
// идентификатор документа реестра
private
static
final
String
LOGIN
=
"Ипатьев"
;
private
static
final
String
LOGIN
=
"111111"
;
private
static
final
String
PASSWORD
=
"1"
;
private
static
final
String
PASSWORD
=
"1"
;
// private final String TARGET_FORM_UUID = "fb44d99d-1579-4ac3-884a-01a6d4f71f9c"; // home
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 = "04f7809d-f44c-4a2d-950d-6aa8e6c3fea1"; // work
private
final
String
SYNERGY_ADDRESS
=
"http://127.0.0.1:8080/Synergy"
;
private
final
String
SYNERGY_ADDRESS
=
"http://127.0.0.1:8080/Synergy"
;
private
String
SOURCE_FORM_DATA_UUID
=
null
;
// идентификатор данных по форме записи реестра
private
String
SOURCE_FORM_DATA_UUID
=
null
;
// идентификатор данных по форме записи реестра
private
String
TARGET_FORM_DATA_UUID
=
null
;
private
String
TARGET_FORM_DATA_UUID
=
null
;
@JsonSerialize
(
using
=
AsNodeSerializer
.
class
)
@JsonSerialize
(
using
=
AsNodeSerializer
.
class
)
private
List
<
AsNode
>
sourceFormData
=
null
;
private
List
<
AsNode
>
sourceFormData
=
null
;
@JsonSerialize
(
using
=
AsNodeSerializer
.
class
)
@JsonSerialize
(
using
=
AsNodeSerializer
.
class
)
private
List
<
AsNode
>
targetFormData
=
null
;
private
List
<
AsNode
>
targetFormData
=
null
;
/**
/**
*
*
* @param message
* @param message
*/
*/
@Override
@Override
public
void
onMessage
(
Message
message
)
{
public
void
onMessage
(
Message
message
)
{
// <editor-fold defaultstate="collapsed" desc=" DESCRIPTION ">
// <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
();
parser
.
nextToken
();
parser
.
nextToken
();
String
value
=
parser
.
getText
();
String
value
=
parser
.
getText
();
switch
(
fieldName
)
{
switch
(
fieldName
)
{
case
"dataUUID"
:
case
"dataUUID"
:
SOURCE_FORM_DATA_UUID
=
value
;
SOURCE_FORM_DATA_UUID
=
value
;
break
;
break
;
case
"executionID"
:
case
"executionID"
:
executionID
=
value
;
executionID
=
value
;
break
;
break
;
case
"documentID"
:
case
"documentID"
:
documentID
=
value
;
documentID
=
value
;
break
;
break
;
default
:
default
:
break
;
break
;
}
}
}
}
}
}
// </editor-fold>
// </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"
);
}
}
JsonNode
SourceRootDataNode
=
SourceRootNode
.
get
(
"data"
);
// read single root 'data' node
JsonNode
SourceRootDataNode
=
SourceRootNode
.
get
(
"data"
);
// read single root 'data' node
if
(
SourceRootDataNode
==
null
)
{
if
(
SourceRootDataNode
==
null
)
{
throw
new
AttributeModificationException
(
"GMP: Invalid form data, root \"data\" node does not exists"
);
throw
new
AttributeModificationException
(
"GMP: Invalid form data, root \"data\" node does not exists"
);
}
}
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"
,
FieldType
.
KEY
);
String
userID
=
getElemValByID
(
this
.
sourceFormData
,
"user1"
,
FieldType
.
KEY
);
if
(
userID
==
null
)
{
if
(
userID
==
null
)
{
throw
new
Exception
(
"User in not specified in the order (value of \"user1\" field is not found)"
);
throw
new
Exception
(
"User in not specified in the order (value of \"user1\" field is not found)"
);
}
}
// По 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"
);
}
}
JsonNode
TargetRootDataNode
=
TargetRootNode
.
get
(
"data"
);
JsonNode
TargetRootDataNode
=
TargetRootNode
.
get
(
"data"
);
if
(
TargetRootDataNode
==
null
)
{
if
(
TargetRootDataNode
==
null
)
{
throw
new
AttributeModificationException
(
"GMP: Invalid form data, root \"data\" node does not exists"
);
throw
new
AttributeModificationException
(
"GMP: Invalid form data, root \"data\" node does not exists"
);
}
}
targetFormData
=
OBJECT_MAPPER
.
readValue
(
TargetRootDataNode
,
new
TypeReference
<
List
<
AsNode
>>()
{});
targetFormData
=
OBJECT_MAPPER
.
readValue
(
TargetRootDataNode
,
new
TypeReference
<
List
<
AsNode
>>()
{});
// common vacation period
// common vacation period
String
vacStart
=
getComponentValueByID
(
this
.
sourceFormData
,
"date_start"
,
FieldType
.
KEY
);
String
vacStart
=
getElemValByID
(
this
.
sourceFormData
,
"date_start"
,
FieldType
.
KEY
);
String
vacEnd
=
getComponentValueByID
(
this
.
sourceFormData
,
"date_finish"
,
FieldType
.
KEY
);
String
vacEnd
=
getElemValByID
(
this
.
sourceFormData
,
"date_finish"
,
FieldType
.
KEY
);
String
days
=
getComponentValueByID
(
this
.
sourceFormData
,
"days"
,
FieldType
.
VALUE
);
// String days = getComponentValueByID(this.sourceFormData, "days", FieldType.VALUE);
if
(
vacStart
==
null
||
vacEnd
==
null
)
{
if
(
vacStart
==
null
||
vacEnd
==
null
)
{
throw
new
Exception
(
"Vacation period is not specified"
);
throw
new
Exception
(
"Vacation period is not specified"
);
}
}
// first table - periods
// first table - periods
String
b2b1
=
getElemValByID
(
this
.
sourceFormData
,
"b2-b1"
,
FieldType
.
KEY
);
String
b2b1
=
getComponentValueByID
(
this
.
sourceFormData
,
"b2-b1"
,
FieldType
.
KEY
);
String
b4b1
=
getElemValByID
(
this
.
sourceFormData
,
"b4-b1"
,
FieldType
.
KEY
);
String
b4b1
=
getComponentValueByID
(
this
.
sourceFormData
,
"b4-b1"
,
FieldType
.
KEY
);
// first table - num of days
// first table - num of days
String
b5b1
=
getElemValByID
(
this
.
sourceFormData
,
"b5-b1"
,
FieldType
.
VALUE
);
String
b5b1
=
getComponentValueByID
(
this
.
sourceFormData
,
"b5-b1"
,
FieldType
.
VALUE
);
if
(
notNull
(
b2b1
,
b4b1
))
{
// отображается key
if
(
notNull
(
b2b1
,
b4b1
))
{
// отображается key
addTblRow
(
vacStart
,
vacEnd
,
b2b1
,
b4b1
,
b5b1
);
constructNewTableRow
(
vacStart
,
vacEnd
,
b2b1
,
b4b1
,
b5b1
);
updateTargetForm
();
updateTargetForm
();
return
;
return
;
}
}
// second table - periods
// second table - periods
String
t4b1
=
getElemValByID
(
this
.
sourceFormData
,
"t4-b1"
,
FieldType
.
KEY
);
String
t4b1
=
getComponentValueByID
(
this
.
sourceFormData
,
"t4-b1"
,
FieldType
.
KEY
);
String
t6b1
=
getElemValByID
(
this
.
sourceFormData
,
"t6-b1"
,
FieldType
.
KEY
);
String
t6b1
=
getComponentValueByID
(
this
.
sourceFormData
,
"t6-b1"
,
FieldType
.
KEY
);
String
t10b1
=
getElemValByID
(
this
.
sourceFormData
,
"t10-b1"
,
FieldType
.
KEY
);
String
t10b1
=
getComponentValueByID
(
this
.
sourceFormData
,
"t10-b1"
,
FieldType
.
KEY
);
String
t12b1
=
getElemValByID
(
this
.
sourceFormData
,
"t12-b1"
,
FieldType
.
KEY
);
String
t12b1
=
getComponentValueByID
(
this
.
sourceFormData
,
"t12-b1"
,
FieldType
.
KEY
);
// second table - num of days
// second table - num of days
String
t2b1
=
getElemValByID
(
this
.
sourceFormData
,
"t2-b1"
,
FieldType
.
VALUE
);
String
t2b1
=
getComponentValueByID
(
this
.
sourceFormData
,
"t2-b1"
,
FieldType
.
VALUE
);
String
t8b1
=
getElemValByID
(
this
.
sourceFormData
,
"t8-b1"
,
FieldType
.
VALUE
);
String
t8b1
=
getComponentValueByID
(
this
.
sourceFormData
,
"t8-b1"
,
FieldType
.
VALUE
);
if
(
notNull
(
t4b1
,
t6b1
,
t10b1
,
t12b1
))
{
if
(
notNull
(
t4b1
,
t6b1
,
t10b1
,
t12b1
))
{
addTblRow
(
vacStart
,
vacEnd
,
t4b1
,
t6b1
,
t2b1
);
constructNewTableRow
(
vacStart
,
vacEnd
,
t4b1
,
t6b1
,
t2b1
);
addTblRow
(
vacStart
,
vacEnd
,
t10b1
,
t12b1
,
t8b1
);
constructNewTableRow
(
vacStart
,
vacEnd
,
t10b1
,
t12b1
,
t8b1
);
updateTargetForm
();
updateTargetForm
();
return
;
return
;
}
}
// third table - periods
// third table - periods
String
t18b1
=
getElemValByID
(
this
.
sourceFormData
,
"t18-b1"
,
FieldType
.
KEY
);
String
t18b1
=
getComponentValueByID
(
this
.
sourceFormData
,
"t18-b1"
,
FieldType
.
KEY
);
String
t20b1
=
getElemValByID
(
this
.
sourceFormData
,
"t20-b1"
,
FieldType
.
KEY
);
String
t20b1
=
getComponentValueByID
(
this
.
sourceFormData
,
"t20-b1"
,
FieldType
.
KEY
);
String
t24b1
=
getElemValByID
(
this
.
sourceFormData
,
"t24-b1"
,
FieldType
.
KEY
);
String
t24b1
=
getComponentValueByID
(
this
.
sourceFormData
,
"t24-b1"
,
FieldType
.
KEY
);
String
t26b1
=
getElemValByID
(
this
.
sourceFormData
,
"t26-b1"
,
FieldType
.
KEY
);
String
t26b1
=
getComponentValueByID
(
this
.
sourceFormData
,
"t26-b1"
,
FieldType
.
KEY
);
String
t30b1
=
getElemValByID
(
this
.
sourceFormData
,
"t30-b1"
,
FieldType
.
KEY
);
String
t30b1
=
getComponentValueByID
(
this
.
sourceFormData
,
"t30-b1"
,
FieldType
.
KEY
);
String
t32b1
=
getElemValByID
(
this
.
sourceFormData
,
"t32-b1"
,
FieldType
.
KEY
);
String
t32b1
=
getComponentValueByID
(
this
.
sourceFormData
,
"t32-b1"
,
FieldType
.
KEY
);
// third table - num of days
// third table - num of days
String
t16b1
=
getElemValByID
(
this
.
sourceFormData
,
"t16-b1"
,
FieldType
.
VALUE
);
String
t16b1
=
getComponentValueByID
(
this
.
sourceFormData
,
"t16-b1"
,
FieldType
.
VALUE
);
String
t22b1
=
getElemValByID
(
this
.
sourceFormData
,
"t22-b1"
,
FieldType
.
VALUE
);
String
t22b1
=
getComponentValueByID
(
this
.
sourceFormData
,
"t22-b1"
,
FieldType
.
VALUE
);
String
t28b1
=
getElemValByID
(
this
.
sourceFormData
,
"t28-b1"
,
FieldType
.
VALUE
);
String
t28b1
=
getComponentValueByID
(
this
.
sourceFormData
,
"t28-b1"
,
FieldType
.
VALUE
);
if
(
notNull
(
t18b1
,
t20b1
,
t24b1
,
t26b1
,
t30b1
,
t32b1
))
{
if
(
notNull
(
t18b1
,
t20b1
,
t24b1
,
t26b1
,
t30b1
,
t32b1
))
{
addTblRow
(
vacStart
,
vacEnd
,
t18b1
,
t20b1
,
t16b1
);
constructNewTableRow
(
vacStart
,
vacEnd
,
t18b1
,
t20b1
,
t16b1
);
addTblRow
(
vacStart
,
vacEnd
,
t24b1
,
t26b1
,
t22b1
);
constructNewTableRow
(
vacStart
,
vacEnd
,
t24b1
,
t26b1
,
t22b1
);
addTblRow
(
vacStart
,
vacEnd
,
t30b1
,
t32b1
,
t28b1
);
constructNewTableRow
(
vacStart
,
vacEnd
,
t30b1
,
t32b1
,
t28b1
);
updateTargetForm
();
updateTargetForm
();
return
;
return
;
}
}
}
catch
(
Exception
exc
)
{
}
catch
(
Exception
exc
)
{
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
}
finally
{
}
finally
{
unlockRoute
();
// Разблокировка маршрута
unlockRoute
();
// Разблокировка маршрута
}
}
}
}
private
static
boolean
notNull
(
Object
...
args
)
{
private
List
<
AsNode
>
constructTableHeader
()
throws
IOException
{
for
(
Object
arg
:
args
)
{
InputStream
inputStream
=
getClass
().
getClassLoader
().
getResourceAsStream
(
"table_header.json"
);
if
(
arg
==
null
)
{
List
<
AsNode
>
l
=
OBJECT_MAPPER
.
readValue
(
inputStream
,
new
TypeReference
<
List
<
AsNode
>>()
{});
return
false
;
return
l
;
}
}
}
return
true
;
private
static
boolean
notNull
(
Object
...
args
)
{
}
for
(
Object
arg
:
args
)
{
if
(
arg
==
null
)
{
private
void
addTblRow
(
String
vacStart
,
String
vacEnd
,
String
perStart
,
String
perEnd
,
String
numDays
)
throws
Exception
{
return
false
;
}
AsNode
tableNode
=
findNode
(
targetFormData
,
"table"
);
}
if
(
tableNode
==
null
)
{
return
true
;
addTableHeaders
();
}
}
private
void
constructNewTableRow
(
String
vacStart
,
String
vacEnd
,
String
perStart
,
String
perEnd
,
String
numDays
)
throws
Exception
{
tableNode
=
findNode
(
targetFormData
,
"table"
);
// update reference
AsNode
tableNode
=
findNode
(
targetFormData
,
"table"
);
if
(
tableNode
!=
null
)
{
if
(
tableNode
!=
null
)
{
List
<
AsNode
>
tableDataNodesList
=
tableNode
.
getData
();
List
<
AsNode
>
tableDataNodesList
=
tableNode
.
getData
();
String
tablesCounter
=
Integer
.
toString
(
appendabeTableRowsCount
(
tableDataNodesList
,
"start"
,
"b"
)
+
1
);
String
tablesCounter
=
Integer
.
toString
(
appendabeTableRowsCount
(
tableDataNodesList
,
"start"
,
"b"
)
+
1
);
AsNode
n1
=
new
AsNode
();
AsNode
n1
=
new
AsNode
();
AsNode
n2
=
new
AsNode
();
AsNode
n2
=
new
AsNode
();
AsNode
n3
=
new
AsNode
();
AsNode
n3
=
new
AsNode
();
AsNode
n4
=
new
AsNode
();
AsNode
n4
=
new
AsNode
();
AsNode
n5
=
new
AsNode
();
AsNode
n5
=
new
AsNode
();
AsNode
n6
=
new
AsNode
();
AsNode
n6
=
new
AsNode
();
AsNode
n7
=
new
AsNode
();
AsNode
n7
=
new
AsNode
();
n1
.
setId
(
"start-b"
+
tablesCounter
);
n1
.
setId
(
"start-b"
+
tablesCounter
);
n1
.
setType
(
"date"
);
n1
.
setType
(
"date"
);
n1
.
setLabel
(
" "
);
n1
.
setLabel
(
" "
);
n1
.
setValue
(
dateValueFromKey
(
vacStart
));
n1
.
setValue
(
dateValueFromKey
(
vacStart
));
n1
.
setKey
(
vacStart
);
n1
.
setKey
(
vacStart
);
n2
.
setId
(
"finish-b"
+
tablesCounter
);
n2
.
setId
(
"finish-b"
+
tablesCounter
);
n2
.
setType
(
"date"
);
n2
.
setType
(
"date"
);
n2
.
setLabel
(
" "
);
n2
.
setLabel
(
" "
);
n2
.
setValue
(
dateValueFromKey
(
vacEnd
));
n2
.
setValue
(
dateValueFromKey
(
vacEnd
));
n2
.
setKey
(
vacEnd
);
n2
.
setKey
(
vacEnd
);
n3
.
setId
(
"days-b"
+
tablesCounter
);
n3
.
setId
(
"days-b"
+
tablesCounter
);
n3
.
setType
(
"textbox"
);
n3
.
setType
(
"textbox"
);
n3
.
setLabel
(
" "
);
n3
.
setLabel
(
" "
);
n3
.
setValue
(
numDays
);
n3
.
setValue
(
numDays
);
n4
.
setId
(
"matpom-b"
+
tablesCounter
);
n4
.
setId
(
"matpom-b"
+
tablesCounter
);
n4
.
setType
(
"listbox"
);
n4
.
setType
(
"listbox"
);
n4
.
setValue
(
""
);
n4
.
setValue
(
""
);
n4
.
setKey
(
""
);
// TODO: Update or not update?
n4
.
setKey
(
""
);
// TODO: Update or not update?
n5
.
setId
(
"period_start-b"
+
tablesCounter
);
n5
.
setId
(
"period_start-b"
+
tablesCounter
);
n5
.
setType
(
"date"
);
n5
.
setType
(
"date"
);
n5
.
setValue
(
dateValueFromKey
(
perStart
));
n5
.
setValue
(
dateValueFromKey
(
perStart
));
n5
.
setKey
(
perStart
);
n5
.
setKey
(
perStart
);
n6
.
setId
(
"period_finish-b"
+
tablesCounter
);
n6
.
setId
(
"period_finish-b"
+
tablesCounter
);
n6
.
setType
(
"date"
);
n6
.
setType
(
"date"
);
n6
.
setValue
(
dateValueFromKey
(
perEnd
));
n6
.
setValue
(
dateValueFromKey
(
perEnd
));
n6
.
setKey
(
perEnd
);
n6
.
setKey
(
perEnd
);
n7
.
setId
(
"otozvano-b"
+
tablesCounter
);
n7
.
setId
(
"otozvano-b"
+
tablesCounter
);
n7
.
setType
(
"texbox"
);
n7
.
setType
(
"texbox"
);
n7
.
setLabel
(
" "
);
n7
.
setLabel
(
" "
);
tableDataNodesList
.
add
(
n1
);
tableDataNodesList
.
add
(
n1
);
tableDataNodesList
.
add
(
n2
);
tableDataNodesList
.
add
(
n2
);
tableDataNodesList
.
add
(
n3
);
tableDataNodesList
.
add
(
n3
);
tableDataNodesList
.
add
(
n4
);
tableDataNodesList
.
add
(
n4
);
tableDataNodesList
.
add
(
n5
);
tableDataNodesList
.
add
(
n5
);
tableDataNodesList
.
add
(
n6
);
tableDataNodesList
.
add
(
n6
);
tableDataNodesList
.
add
(
n7
);
tableDataNodesList
.
add
(
n7
);
}
else
{
}
else
{
throw
new
Exception
(
"Failed to add new table, aborting"
);
// get root data node, it is our target
}
AsNode
rootDataNode
=
findNode
(
targetFormData
,
"data"
);
}
// construct new "table" node
AsNode
newDataNode
=
new
AsNode
();
private
void
addTableHeaders
()
throws
IOException
{
List
<
AsNode
>
header
=
constructTableHeader
();
InputStream
inputStream
=
getClass
().
getClassLoader
().
getResourceAsStream
(
"table_header.json"
);
// pushing fields to new node
List
<
AsNode
>
headers
=
OBJECT_MAPPER
.
readValue
(
inputStream
,
new
TypeReference
<
List
<
AsNode
>>()
{});
newDataNode
.
setId
(
"table"
);
// construct new "table" node
newDataNode
.
setType
(
"appendable_table"
);
AsNode
newDataNode
=
new
AsNode
();
newDataNode
.
setKey
(
""
);
// pushing fields to new node
newDataNode
.
setData
(
header
);
newDataNode
.
setId
(
"table"
);
newDataNode
.
setType
(
"appendable_table"
);
newDataNode
.
setKey
(
""
);
newDataNode
.
setData
(
headers
);
}
}
targetFormData
.
add
(
newDataNode
);
}
private
int
dateDiffToDays
(
String
dateLess
,
String
dateMore
)
throws
ParseException
{
Date
dateMore_
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
parse
(
dateMore
);
private
int
appendabeTableRowsCount
(
List
<
AsNode
>
lan
,
String
tableID
,
String
tableElementID
)
{
Date
dateLess_
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
parse
(
dateLess
);
int
counter
=
0
;
for
(;;)
{
long
diff
=
dateMore_
.
getTime
()
-
dateLess_
.
getTime
();
String
searchString
=
tableID
+
"-"
+
tableElementID
+
Integer
.
toString
(
counter
+
1
);
TimeUnit
.
DAYS
.
convert
(
diff
,
TimeUnit
.
MILLISECONDS
);
AsNode
n
=
findNode
(
lan
,
searchString
);
if
(
n
==
null
)
{
return
(
int
)
TimeUnit
.
DAYS
.
convert
(
diff
,
TimeUnit
.
MILLISECONDS
);
break
;
}
}
else
{
counter
++;
private
int
appendabeTableRowsCount
(
List
<
AsNode
>
lan
,
String
tableID
,
String
tableElementID
)
{
}
int
counter
=
0
;
}
for
(;;)
{
return
counter
;
String
searchString
=
tableID
+
"-"
+
tableElementID
+
Integer
.
toString
(
counter
+
1
);
}
AsNode
n
=
findNode
(
lan
,
searchString
);
if
(
n
==
null
)
{
private
void
updateTargetForm
()
throws
IOException
,
Exception
{
break
;
// SERIALIZATION
}
else
{
OBJECT_MAPPER
.
setSerializationInclusion
(
JsonSerialize
.
Inclusion
.
NON_NULL
);
counter
++;
String
serialData
=
OBJECT_MAPPER
.
writeValueAsString
(
targetFormData
);
}
}
// String login, String password, String address, String formUUID, String uuid, String data
return
counter
;
APIFormsServiceSave
saver
=
new
APIFormsServiceSave
(
LOGIN
,
PASSWORD
,
SYNERGY_ADDRESS
,
TARGET_FORM_UUID
,
TARGET_FORM_DATA_UUID
,
"\"data\": "
+
serialData
);
}
saver
.
save
();
}
private
void
updateTargetForm
()
throws
IOException
,
Exception
{
// SERIALIZATION
/**
OBJECT_MAPPER
.
setSerializationInclusion
(
JsonSerialize
.
Inclusion
.
NON_NULL
);
* Returns node which has specifies ID
String
serialData
=
OBJECT_MAPPER
.
writeValueAsString
(
targetFormData
);
* @param nodesList - List of nodes
* @param objectID - Component ID
// String login, String password, String address, String formUUID, String uuid, String data
* @return AsNode if such exists, null otherwise
APIFormsServiceSave
saver
=
new
APIFormsServiceSave
(
LOGIN
,
PASSWORD
,
SYNERGY_ADDRESS
,
TARGET_FORM_UUID
,
TARGET_FORM_DATA_UUID
,
"\"data\": "
+
serialData
);
*/
saver
.
save
();
private
static
AsNode
findNode
(
List
<
AsNode
>
nodesList
,
String
objectID
)
{
}
AsNode
result
=
null
;
/**
for
(
AsNode
n
:
nodesList
)
{
* Returns node which has specifies ID
if
(
result
!=
null
)
break
;
// prevent relooping if result has already been found
* @param nodesList - List of nodes
* @param objectID - Component ID
if
(
objectID
.
equals
(
n
.
getId
()))
{
* @return AsNode if such exists, null otherwise
result
=
n
;
*/
}
else
if
(
n
.
getData
()
!=
null
)
{
private
static
AsNode
findNode
(
List
<
AsNode
>
nodesList
,
String
objectID
)
{
result
=
findNode
(
n
.
getData
(),
objectID
);
AsNode
result
=
null
;
}
}
for
(
AsNode
n
:
nodesList
)
{
if
(
result
!=
null
)
break
;
// prevent relooping if result has already been found
return
result
;
}
if
(
objectID
.
equals
(
n
.
getId
()))
{
result
=
n
;
private
static
String
dateValueFromKey
(
String
keyValue
)
throws
ParseException
{
}
else
if
(
n
.
getData
()
!=
null
)
{
Date
date
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
parse
(
keyValue
);
result
=
findNode
(
n
.
getData
(),
objectID
);
return
new
SimpleDateFormat
(
"dd.MM.yyy"
).
format
(
date
);
}
}
}
/**
return
result
;
* Setting new value of requested field of requested component with specified ID
}
* @param targetJsonAsString
* @param objectID
private
static
String
dateValueFromKey
(
String
keyValue
)
throws
ParseException
{
* @param fieldType
Date
date
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
parse
(
keyValue
);
* @param newFieldValue
return
new
SimpleDateFormat
(
"dd.MM.yyy"
).
format
(
date
);
* @throws AttributeModificationException
}
* @throws IOException
*/
/**
private
boolean
updateFieldValue
(
List
<
AsNode
>
dataNodesList
,
String
objectID
,
FieldType
fieldType
,
String
newFieldValue
)
{
* Setting new value of requested field of requested component with specified ID
try
{
* @param targetJsonAsString
AsNode
targetNode
=
findNode
(
dataNodesList
,
objectID
);
* @param objectID
if
(
targetNode
==
null
)
{
* @param fieldType
return
false
;
* @param newFieldValue
}
else
{
* @throws AttributeModificationException
switch
(
fieldType
)
{
* @throws IOException
case
ID:
*/
targetNode
.
setId
(
newFieldValue
);
private
boolean
updateFieldValue
(
List
<
AsNode
>
dataNodesList
,
String
objectID
,
FieldType
fieldType
,
String
newFieldValue
)
{
break
;
try
{
case
TYPE:
AsNode
targetNode
=
findNode
(
dataNodesList
,
objectID
);
targetNode
.
setType
(
newFieldValue
);
if
(
targetNode
==
null
)
{
break
;
return
false
;
case
LABEL:
}
else
{
targetNode
.
setLabel
(
newFieldValue
);
switch
(
fieldType
)
{
break
;
case
ID:
case
KEY:
targetNode
.
setId
(
newFieldValue
);
targetNode
.
setKey
(
newFieldValue
);
break
;
break
;
case
TYPE:
case
VALUE:
targetNode
.
setType
(
newFieldValue
);
targetNode
.
setValue
(
newFieldValue
);
break
;
break
;
case
LABEL:
}
targetNode
.
setLabel
(
newFieldValue
);
}
break
;
return
true
;
case
KEY:
}
catch
(
Exception
e
)
{
targetNode
.
setKey
(
newFieldValue
);
throw
e
;
break
;
}
case
VALUE:
}
targetNode
.
setValue
(
newFieldValue
);
break
;
/**
}
* Returns user's card data UUID by form's UUID
}
* @param userID - User identifier
return
true
;
* @param formUUID - Form's data UUID
}
catch
(
Exception
e
)
{
* @return Specified user's card data UUID
throw
e
;
*/
}
private
static
String
getCardDataUUID
(
String
userID
,
String
formUUID
)
{
}
ObjectMapper
mapper
=
new
ObjectMapper
();
try
{
/**
URL
url
=
new
URL
(
"http://127.0.0.1:8080/Synergy/rest/api/personalrecord/forms/"
+
userID
);
* Returns user's card data UUID by form's UUID
String
res
=
synergyApiGetString
(
url
);
* @param userID - User identifier
* @param formUUID - Form's data UUID
List
<
Card
>
cardsList
=
mapper
.
readValue
(
res
,
new
TypeReference
<
List
<
Card
>>(){});
* @return Specified user's card data UUID
*/
for
(
Card
c
:
cardsList
)
{
private
static
String
getCardDataUUID
(
String
userID
,
String
formUUID
)
{
if
(
formUUID
.
equals
(
c
.
getFormUUID
()))
{
ObjectMapper
mapper
=
new
ObjectMapper
();
return
c
.
getDataUUID
();
try
{
}
URL
url
=
new
URL
(
"http://127.0.0.1:8080/Synergy/rest/api/personalrecord/forms/"
+
userID
);
}
String
res
=
synergyApiGetString
(
url
);
}
catch
(
Exception
exc
)
{
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
List
<
Card
>
cardsList
=
mapper
.
readValue
(
res
,
new
TypeReference
<
List
<
Card
>>(){});
}
return
new
String
();
for
(
Card
c
:
cardsList
)
{
}
if
(
formUUID
.
equals
(
c
.
getFormUUID
()))
{
return
c
.
getDataUUID
();
/**
}
* Returns value of of specified field of component with specified ID
}
* @param targetJsonAsString
}
catch
(
Exception
exc
)
{
* @param objectID
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
* @param fieldType
}
* @return
return
new
String
();
* @throws NameNotFoundException
}
* @throws IOException
*/
/**
private
static
String
getElemValByID
(
List
<
AsNode
>
dataNodesList
,
String
objectID
,
FieldType
fieldType
)
throws
Exception
{
* Returns value of of specified field of component with specified ID
String
result
=
null
;
* @param targetJsonAsString
try
{
* @param objectID
* @param fieldType
AsNode
targetNode
=
findNode
(
dataNodesList
,
objectID
);
* @return
if
(
targetNode
==
null
)
{
* @throws NameNotFoundException
return
null
;
* @throws IOException
}
else
{
*/
switch
(
fieldType
)
{
private
static
String
getComponentValueByID
(
List
<
AsNode
>
dataNodesList
,
String
objectID
,
FieldType
fieldType
)
throws
Exception
{
case
ID:
String
result
=
null
;
result
=
targetNode
.
getId
();
// may be for cheking if component with such ID exists at all
try
{
break
;
case
TYPE:
AsNode
targetNode
=
findNode
(
dataNodesList
,
objectID
);
result
=
targetNode
.
getType
();
if
(
targetNode
==
null
)
{
break
;
return
null
;
case
LABEL:
}
else
{
result
=
targetNode
.
getLabel
();
switch
(
fieldType
)
{
break
;
case
ID:
case
KEY:
result
=
targetNode
.
getId
();
// may be for cheking if component with such ID exists at all
result
=
targetNode
.
getKey
();
break
;
break
;
case
TYPE:
case
VALUE:
result
=
targetNode
.
getType
();
result
=
targetNode
.
getValue
();
break
;
break
;
case
LABEL:
}
result
=
targetNode
.
getLabel
();
}
break
;
return
result
;
case
KEY:
}
catch
(
Exception
e
)
{
result
=
targetNode
.
getKey
();
throw
e
;
break
;
}
case
VALUE:
result
=
targetNode
.
getValue
();
}
break
;
}
/**
}
* Route unlocking
return
result
;
*/
}
catch
(
Exception
e
)
{
private
void
unlockRoute
()
{
throw
e
;
try
{
}
String
address
=
"http://127.0.0.1:8080/Synergy"
;
String
signal
=
"got_agree"
;
}
URL
url
=
new
URL
(
address
+
"/rest/api/processes/signal?signal="
+
signal
+
"&executionID="
+
this
.
executionID
+
"¶m1=resolution&value1=signal_is_"
+
signal
);
synergyApiGetString
(
url
);
/**
}
catch
(
Exception
exc
)
{
* Route unlocking
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
*/
}
private
void
unlockRoute
()
{
}
try
{
String
address
=
"http://127.0.0.1:8080/Synergy"
;
private
static
String
synergyApiGetString
(
final
URL
requestURL
)
{
String
signal
=
"got_agree"
;
try
{
URL
url
=
new
URL
(
address
+
"/rest/api/processes/signal?signal="
+
signal
+
"&executionID="
+
this
.
executionID
+
"¶m1=resolution&value1=signal_is_"
+
signal
);
String
output
;
synergyApiGetString
(
url
);
}
catch
(
Exception
exc
)
{
HttpURLConnection
conn
=
(
HttpURLConnection
)
requestURL
.
openConnection
();
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
conn
.
setRequestMethod
(
"GET"
);
}
conn
.
setRequestProperty
(
"Accept"
,
"application/json; charset=utf-8"
);
}
String
encoded
=
DatatypeConverter
.
printBase64Binary
((
LOGIN
+
":"
+
PASSWORD
).
getBytes
());
// String encoded = Base64.encode((this.LOGIN + ":" + this.PASSWORD).getBytes());
private
static
String
synergyApiGetString
(
final
URL
requestURL
)
{
conn
.
setRequestProperty
(
"Authorization"
,
"Basic "
+
encoded
);
try
{
String
output
;
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
((
conn
.
getInputStream
())));
StringBuilder
result
=
new
StringBuilder
();
HttpURLConnection
conn
=
(
HttpURLConnection
)
requestURL
.
openConnection
();
while
((
output
=
br
.
readLine
())
!=
null
)
{
conn
.
setRequestMethod
(
"GET"
);
result
.
append
(
output
);
conn
.
setRequestProperty
(
"Accept"
,
"application/json; charset=utf-8"
);
}
String
encoded
=
DatatypeConverter
.
printBase64Binary
((
LOGIN
+
":"
+
PASSWORD
).
getBytes
());
// String encoded = Base64.encode((this.LOGIN + ":" + this.PASSWORD).getBytes());
conn
.
disconnect
();
conn
.
setRequestProperty
(
"Authorization"
,
"Basic "
+
encoded
);
JsonFactory
factory
=
new
JsonFactory
();
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
((
conn
.
getInputStream
())));
return
result
.
toString
();
StringBuilder
result
=
new
StringBuilder
();
}
catch
(
Exception
exc
)
{
while
((
output
=
br
.
readLine
())
!=
null
)
{
LOGGER
.
error
(
exc
.
getMessage
(),
exc
);
result
.
append
(
output
);
}
}
return
null
;
conn
.
disconnect
();
}
}
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